Forráskód Böngészése

fix: 优化行的 formJson.list 解析,过滤掉布局类控件,增加安全性

xieyong 2 hete
szülő
commit
a9f525c2d4
1 módosított fájl, 33 hozzáadás és 24 törlés
  1. 33 24
      src/views/bpm/collaborative/index.vue

+ 33 - 24
src/views/bpm/collaborative/index.vue

@@ -70,7 +70,7 @@
                 @keyup.enter.native="handleSearch"
                 @submit.native.prevent
               >
-                <el-row :gutter="[20, 20]" style="row-gap: 20px">
+                <el-row :gutter="20" style="row-gap: 20px">
                   <el-col v-bind="{ span: 5 }">
                     <el-form-item
                       label="关键字:"
@@ -257,29 +257,8 @@
                     overflow-y: auto;
                   "
                 >
-                  <template
-                    v-if="row?.formJson?.makingJson"
-                    v-for="(item, index) in JSON.parse(
-                      row?.formJson?.makingJson
-                    )?.list.filter(
-                      (val) =>
-                        ![
-                          'grid',
-                          'blank',
-                          'report',
-                          'component',
-                          'card',
-                          'collapse',
-                          'tabs',
-                          'inline',
-                          'divider',
-                          'alert',
-                          'table',
-                          'subform',
-                          'dialog'
-                        ].includes(val.type)
-                    )"
-                  >
+                  <template v-if="getRowRemarkList(row).length">
+                    <template v-for="item in getRowRemarkList(row)">
                     <div style="display: flex">
                       <div>{{ item.name }}:</div>
                       <div v-if="item.type == 'imgupload'">
@@ -333,6 +312,7 @@
                         {{ formatValue(row[item.model]) }}
                       </div>
                     </div>
+                    </template>
                   </template>
                 </div>
               </template>
@@ -377,6 +357,7 @@
   import { listOrganizations } from '@/api/system/organization';
   import tabMixins from '@/mixins/tableColumnsMixin';
   import { getGroupUserTree } from '@/api/main';
+  import { getToken, getCurrentUser } from '@/utils/token-util';
 
   // 默认表单数据
   const defaultParams = {
@@ -604,6 +585,34 @@
       this.handleSearch();
     },
     methods: {
+      // 安全解析行的 formJson.list,过滤掉布局类控件;makingJson 为空或非法时返回 []
+      getRowRemarkList(row) {
+        const makingJson = row && row.formJson && row.formJson.makingJson;
+        if (!makingJson || typeof makingJson !== 'string') return [];
+        let parsed;
+        try {
+          parsed = JSON.parse(makingJson);
+        } catch (e) {
+          return [];
+        }
+        const list = (parsed && parsed.list) || [];
+        const excludeTypes = [
+          'grid',
+          'blank',
+          'report',
+          'component',
+          'card',
+          'collapse',
+          'tabs',
+          'inline',
+          'divider',
+          'alert',
+          'table',
+          'subform',
+          'dialog'
+        ];
+        return list.filter((val) => val && !excludeTypes.includes(val.type));
+      },
       formatValue(value) {
         if (value === null || value === undefined) {
           return ''; // 空值处理