Przeglądaj źródła

fix: 修复数据模板异常选中bug

cfort 1 rok temu
rodzic
commit
ee2df606ca

+ 25 - 25
src/business/platform/data/templaterender/templates/list.vue

@@ -187,7 +187,7 @@
             :template-key="dataTemplate.key"
             :add-data-cont="addDataCont"
             :previous-data-template="dataTemplate"
-            @callback="search"
+            @callback="search('callback')"
             @close="closeDataTemplateFormrenderDialog"
         />
         <!-- 流程定义选择器 -->
@@ -248,7 +248,7 @@
             :task-id="taskId"
             :add-data-cont="addDataCont"
             :previous-data-template="dataTemplate"
-            @callback="search"
+            @callback="search('callback')"
             @close="loadFlowFData"
         />
         <Scan
@@ -691,16 +691,19 @@ export default {
             }
             const { listData } = this
             const allSelectId = this.getAllSelectId()
-            for (let i = 0; i < listData.length; i++) {
-                const row = listData[i]
-                if (allSelectId.indexOf(this.getPkValue(row)) >= 0) {
+            listData.forEach(row => {
+                const pkValue = this.getPkValue(row)
+                if (allSelectId.includes(pkValue)) {
                     if (this.multiple) {
                         tableEl.toggleSelectionRow(row, true)
                     } else {
                         tableEl.setSelectionRadio(row)
                     }
+                    // fixbug: 替换所有选中列表中的数据为最新数据,避免脚本返回的选中数据不更新
+                    const index = this.selectionAll.findIndex(item => this.getPkValue(item) === pkValue)
+                    this.selectionAll[index] = row
                 }
-            }
+            })
         },
         /**
          * 获取选择的ID
@@ -714,6 +717,10 @@ export default {
             }
             return [this.getPkValue(this.selectionAll)]
         },
+        initSelect () {
+            this.selection = this.multiple ? [] : {}
+            this.selectionAll = this.multiple ? [] : {}
+        },
         /**
          * 根据key获取对象的值
          * 用于解决key值大小写不同的问题
@@ -736,14 +743,19 @@ export default {
         /**
          * 加载数据
          */
-        loadData (outerKey) {
+        loadData (outerKey, type) {
             // 仅模板类型为对话框时触发页内loading事件,其余根据接口判定触发全局loading
             this.loading = this.dataTemplate.type === 'dialog'
             if (this.$utils.isEmpty(this.template)) return
             queryDataTable(this.getFormatParams(outerKey), this.dataTemplate.type).then((response) => {
                 this.loading = false
                 ActionUtils.handleListData(this, response.data)
-                this.setSelectRow()
+                // 回调查询不再选中原有数据
+                if (type !== 'callback') {
+                    this.setSelectRow()
+                } else {
+                    this.initSelect()
+                }
                 if (this.$refs.crud) {
                     this.$refs.crud.handleTableHeight()
                     debounce(() => {
@@ -791,7 +803,6 @@ export default {
                                     refSerchForm.params[getBuildSearchForm.prop[0]] = val[0]
                                     refSerchForm.params[getBuildSearchForm.prop[1]] = val[1]
                                     refSerchForm.params['daterange-prefix' + index] = [val[0], val[1]]
-
                                     break
                             }
                             // refSerchForm.params[getBuildSearchForm.modelValue] = val
@@ -835,9 +846,9 @@ export default {
             this.loadData()
         },
         // 查询数据
-        search () {
+        search (type) {
             this.hadDoSearch = true
-            this.loadData()
+            this.loadData('', type)
             this.addDataCont = {}
         },
         /* 流程页面关闭,刷新当前页面*/
@@ -1759,6 +1770,7 @@ export default {
             }).then((response) => {
                 this.afterScript(action, position, selection, data, () => {
                     ActionUtils.removeSuccessMessage()
+                    this.initSelect()
                     this.search()
                 })
             }).catch(() => {})
@@ -1807,22 +1819,10 @@ export default {
             })
         },
         setValue (data) {
-            const obj = {}
-            Object.values(data).forEach((item) => {
-                obj[item] = ''
-            })
-            return obj
+            return Array.isArray(data) ? data.map(item => ({ [item]: '' })) : {}
         },
         getKeys (data) {
-            const obj = {}
-            if (data.length > 0) {
-                data.forEach((item) => {
-                    obj[item.label] = item.name
-                })
-                return obj
-            } else {
-                return obj
-            }
+            return Array.isArray(data) ? data.map(item => ({ [item.label]: item.name })) : {}
         },
         xlsxFileClick () {
             this.xlsxFileVisible = true