index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <div class="app-container">
  3. <div class="display-module">
  4. <dynamic-component-wrapper
  5. v-if="vueCode"
  6. :code="vueCode"
  7. @button-click="handleButtonClick"
  8. />
  9. </div>
  10. <div class="operation-module">
  11. <div class="current-button">
  12. 当前选择按钮: {{ currentButtonName || '未选择按钮 或 按钮不支持绑定脚本'}}
  13. </div>
  14. <el-form :model="formData" :rules="rules" ref="formRef" label-width="100px">
  15. <el-form-item label="绑定脚本" prop="select1">
  16. <el-select v-model="formData.select1" placeholder="请选择">
  17. <el-option
  18. v-for="item in options1"
  19. :key="item.value"
  20. :label="item.label"
  21. :value="item.value">
  22. </el-option>
  23. </el-select>
  24. </el-form-item>
  25. <el-form-item label="脚本类型" prop="select2">
  26. <el-select v-model="formData.select2" placeholder="请选择">
  27. <el-option
  28. v-for="item in options2"
  29. :key="item.value"
  30. :label="item.label"
  31. :value="item.value">
  32. </el-option>
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item>
  36. <el-button type="primary" @click="onSubmit">提交</el-button>
  37. </el-form-item>
  38. </el-form>
  39. </div>
  40. </div>
  41. </template>
  42. <script>
  43. import { getVuePage, listBusinessFlowScript, queryBtnScriptApi, addBtnScriptApi, updateBtnScriptApi } from "@/api/businessFlow/vuePage";
  44. import DynamicComponentWrapper from '@/components/BusinessFlow/DynamicComponentWrapper.vue'
  45. import { parseComponent } from '@/utils/templateParser'
  46. export default {
  47. name: 'BindingPageScript',
  48. components: {
  49. DynamicComponentWrapper
  50. },
  51. data () {
  52. return {
  53. // 跳转页面-路由传递的row中的Id的值
  54. rowId: null,
  55. // 获取到的所有数据
  56. vuePageData: {},
  57. //获取到的vueCode, vue代码值
  58. vueCode: '',
  59. //获取到的tenantId值
  60. tenantId: null,
  61. // 获取到的vueKey值--uuid
  62. vueKey:'',
  63. loading:false,
  64. formData:{
  65. select1:'',
  66. select2:''
  67. },
  68. // 脚本下拉
  69. options1:[],
  70. // 脚本类型
  71. options2:[
  72. {
  73. value: "query",
  74. label: this.$t('excuteBtn.query'),
  75. },
  76. {
  77. value: "add",
  78. label: this.$t('excuteBtn.insert'),
  79. },
  80. {
  81. value: "update",
  82. label: this.$t('excuteBtn.update'),
  83. },
  84. {
  85. value: "delete",
  86. label: this.$t('excuteBtn.delete'),
  87. },
  88. {
  89. value: "other",
  90. label: this.$t('excuteBtn.otherMethod'),
  91. },
  92. ],
  93. btnScriptFlag:false,//按钮是否绑定脚本
  94. currentButtonName:'',//当前选择按钮名字
  95. // 添加防抖标记
  96. isQuerying: false,
  97. queryTimer: null,
  98. // 添加表单验证规则
  99. rules: {
  100. select1: [
  101. { required: true, message: '请选择绑定脚本', trigger: 'change' }
  102. ],
  103. select2: [
  104. { required: true, message: '请选择脚本类型', trigger: 'change' }
  105. ]
  106. },
  107. }
  108. },
  109. created () {
  110. // 获取路由传递的参数
  111. const rowId = this.$route.query.mode
  112. console.log('路由传递的rowId:', rowId)
  113. if(rowId){
  114. this.rowId = rowId
  115. this.getList()
  116. this.getScriptList()
  117. }
  118. },
  119. methods: {
  120. getList() {
  121. this.loading = true;
  122. let id = this.rowId
  123. console.log('this.rowId:', this.rowId)
  124. getVuePage(id).then(response => {
  125. if(response.code == 200){
  126. this.vuePageData = response.data;
  127. const vueCodeStr = decodeURIComponent(response.data?.vueCode)
  128. this.vueCode = vueCodeStr
  129. this.vueKey = response.data?.vueKey
  130. this.tenantId = response.data?.tenantId
  131. console.log('[this.vuePageData]', this.vuePageData)
  132. console.log('[this.vueCode]', this.vueCode)
  133. console.log('[this.tenantId]', this.tenantId)
  134. }else{
  135. this.vuePageData = {}
  136. }
  137. this.loading = false;
  138. });
  139. },
  140. getScriptList(){
  141. listBusinessFlowScript({ isEnablePaging: false }).then(response => {
  142. console.log('[response]', response)
  143. if(response.code == 200){
  144. this.options1 = response.rows.map(row=>{
  145. return{
  146. ...row,
  147. label: row.remark,
  148. value: row.businessKey
  149. }
  150. })
  151. }
  152. })
  153. },
  154. handleButtonClick(buttonData) {
  155. console.log('按钮点击事件:', buttonData);
  156. this.currentButtonName = buttonData.text
  157. let data = {
  158. vueKey: this.vueKey,
  159. vueContent: buttonData.text, // 使用按钮的文本内容
  160. }
  161. // 使用防抖处理查询请求
  162. this.debounceQueryBtnScript(data);
  163. },
  164. // 添加防抖方法
  165. debounceQueryBtnScript(data) {
  166. if (this.isQuerying) {
  167. return;
  168. }
  169. if (this.queryTimer) {
  170. clearTimeout(this.queryTimer);
  171. }
  172. this.queryTimer = setTimeout(() => {
  173. this.isQuerying = true;
  174. this.queryBtnScript(data).finally(() => {
  175. this.isQuerying = false;
  176. });
  177. }, 300);
  178. },
  179. // 修改查询方法返回 Promise
  180. queryBtnScript(data){
  181. console.log('[data]', data)
  182. return queryBtnScriptApi(data).then(response => {
  183. console.log('[response]', response)
  184. if(response.code ===200 ){
  185. if(response.msg == '未绑定'){
  186. this.btnScriptFlag = false
  187. this.formData = {
  188. select1:'',
  189. select2:''
  190. }
  191. }else{
  192. console.log('[response.data]', response.data)
  193. let data = response.data
  194. this.btnScriptFlag = true
  195. this.formData = {
  196. select1:data.businessKey,
  197. select2:data.businessType
  198. }
  199. }
  200. }
  201. }).catch(error => {
  202. console.error('查询按钮脚本失败:', error);
  203. });
  204. },
  205. // 表单提交
  206. onSubmit(){
  207. this.$refs.formRef.validate((valid) => {
  208. if (valid) {
  209. console.log('[this.vueKey]',this.vueKey,)
  210. console.log('[this.currentButtonName]',this.currentButtonName,)
  211. console.log('[this.formData]',this.formData,)
  212. let data = {
  213. vueKey: this.vueKey,
  214. vueContent: this.currentButtonName,
  215. businessKey: this.formData.select1,
  216. businessType: this.formData.select2
  217. }
  218. console.log('[data]',data)
  219. addBtnScriptApi(data).then(response => {
  220. console.log('[response]', response)
  221. if (response.code === 200) {
  222. this.$message.success('绑定成功');
  223. // 重置表单
  224. // this.$refs.formRef.resetFields();
  225. } else {
  226. this.$message.error(response.msg || '绑定失败');
  227. }
  228. })
  229. } else {
  230. this.$message.warning('请填写必填项');
  231. return false;
  232. }
  233. });
  234. },
  235. }
  236. }
  237. </script>
  238. <style lang="scss">
  239. // 全局样式,确保下拉框在最上层
  240. .el-select-dropdown {
  241. z-index: 99999 !important;
  242. }
  243. </style>
  244. <style lang="scss" scoped>
  245. .app-container {
  246. position: relative;
  247. width: 100%;
  248. height: 100%;
  249. display: flex;
  250. flex-direction: row;
  251. }
  252. .display-module {
  253. flex: 70%;
  254. position: relative;
  255. z-index: 1;
  256. // 添加样式隔离
  257. :deep(.dynamic-component-container) {
  258. height: 100%;
  259. overflow: auto;
  260. // 重置一些可能影响全局的样式
  261. * {
  262. box-sizing: border-box;
  263. }
  264. // 确保Element UI组件样式正确
  265. .el-button,
  266. .el-input,
  267. .el-select,
  268. .el-table {
  269. font-family: inherit;
  270. }
  271. }
  272. }
  273. .operation-module {
  274. flex: 30%;
  275. position: relative;
  276. z-index: 9999;
  277. background: #fff;
  278. padding: 20px;
  279. box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
  280. :deep(.el-select) {
  281. width: 100%;
  282. }
  283. }
  284. </style>