Преглед изворни кода

1701 补充报表传参逻辑

liujiayin пре 2 година
родитељ
комит
aa1d8378c6
1 измењених фајлова са 51 додато и 24 уклоњено
  1. 51 24
      src/business/platform/data/templaterender/templates/list.vue

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

@@ -395,7 +395,10 @@ export default {
         }
     },
     data () {
+        const { first = '', second = '' } = this.$store.getters.level || {}
         return {
+            first,
+            second,
             npmDialogFormVisible: false, // 弹窗
             defId: '', // 编辑dialog需要使用
             proInstId: '', // 编制暂存数据
@@ -1014,7 +1017,6 @@ export default {
             this.beforeScript(command, position, selection, data, async () => {
                 let src = ''
                 this.readonly = false
-                const { first = '', second = '' } = this.$store.getters.level || {}
                 const { userId } = this.$store.getters || {}
                 switch (buttonType) {
                     case 'search': // 查询
@@ -1081,31 +1083,27 @@ export default {
                                 this.$refs.snapshot.handleActionEvent('preview', 0)
                             }, 500)
                         } else {
-                            if (!button.reportPath) {
-                                this.$message.warning('请先配置对应报表路径!')
-                                return
+                            if (this.handleVerify(button.reportPath, selection, data)) {
+                                src = this.$reportPath.replace('show', 'pdf') + button.reportPath.split('&')[0] + `&` + this.getReportParams(button.reportPath, selection, data)
+                                this.$common.preview(this, src)
                             }
-                            src = `${this.$reportPath.replace('show', 'pdf')}${button.reportPath}&id_=${selection}&org_=${first}&second_=${second}`
-                            // console.log(src)
-                            this.$common.preview(this, src)
                         }
                         break
                     case 'download': // 下载记录
-                        if (!button.reportPath) {
-                            this.$message.warning('请先配置对应报表路径!')
-                            return
+                        if (this.handleVerify(button.reportPath, selection, data)) {
+                            this.$common.snapshoot({
+                                url: this.$getReportFile(button.reportPath.split('&')[0], this.getReportParams(button.reportPath, selection, data)),
+                                name: selection,
+                                type: 'pdf'
+                            }).then((res) => {
+                                if (!res.data || !res.data.id) {
+                                    this.$message.error('生成文件失败,请重试!')
+                                    return
+                                }
+                                this.$common.download(res.data)
+                            })
                         }
-                        this.$common.snapshoot({
-                            url: this.$getReportFile(button.reportPath, `id_=${selection}&org_=${first}&second_=${second}`),
-                            name: selection,
-                            type: 'pdf'
-                        }).then((res) => {
-                            if (!res.data || !res.data.id) {
-                                this.$message.error('生成文件失败,请重试!')
-                                return
-                            }
-                            this.$common.download(res.data)
-                        })
+
                         break
                     case 'print': // 打印
                         ActionUtils.selectedRecord(selection).then((id) => {
@@ -1358,10 +1356,9 @@ export default {
             }
             // 判断地点是否第一层级
             const position = this.$store.getters.userInfo.positions
-            const first = this.$store.getters.level.first
             let showBoolean = false
-            if (position && position.length > 0 && first) {
-                showBoolean = position.some((item) => item.id === first)
+            if (position && position.length > 0 && this.first) {
+                showBoolean = position.some((item) => item.id === this.first)
             }
             const columnsShow = this.listConfig.columns.some((item) => item.prop === 'di_dian_')
             if (!showBoolean && columnsShow) {
@@ -2026,6 +2023,36 @@ export default {
             }
             // conso
             this.handleAction(buttonTypeAct, buttonAct.position, selectAct, dataAct, indexAct, buttonAct)
+        },
+        getReportParams (path, selection, data) {
+            /**
+             * 1、原报表路径:安全管理/紫外灯辐照度值测定记录表.rpx
+             * 2、补充报表路径:安全管理/紫外灯辐照度值测定记录表.rpx&id_=id_
+             * 2-1、最后那么id_表示在列上的字段属性,增加报表传参的便捷性;
+             * 2-2、有些列表需要展示的是子表的数据,但是报表需要展示的是主表数据,列表唯一字段只能是子表id_,所以主表的id_就不能也叫id_;
+             * 2-3、受限于报表快照生成的参数获取,当前只补充关于id_的逻辑;
+             */
+            const str = `org_=${this.first}&second_=${this.second}&id_=`
+            const arr = path.split('&')
+            if (arr.length === 2) {
+                const fieldArr = arr[1].split('=')
+                return str + `${data[fieldArr[1]]}`
+            } else {
+                // 如果是没有传参,还是原报表路径
+                return str + `${selection}`
+            }
+        },
+        handleVerify (path, selection, data) {
+            let state = true
+            if (Array.isArray(selection) || Array.isArray(data)) {
+                this.$message.error('表单按钮请放到管理列~')
+                state = false
+            }
+            if (!path) {
+                this.$message.warning('请先配置对应报表路径~')
+                state = false
+            }
+            return state
         }
     }
 }