Bladeren bron

fix:处理子表日期有值再去除后提交成null报错的问题

liujiayin 2 jaren geleden
bovenliggende
commit
fab22d7b17

+ 6 - 5
src/business/platform/bpmn/form/action.js

@@ -165,9 +165,10 @@ export default {
                 text: this.$t('common.saving')
             })
             if (!formData) return
+            const replaceFormData = this.$utils.replaceNullWithEmpty(formData)
             bpmTaskSave({
                 taskId: this.taskId,
-                data: JSON.stringify(formData)
+                data: JSON.stringify(replaceFormData)
             }).then(response => {
                 loading.close()
                 this.$alert(`已保存表单内容!`, {
@@ -192,7 +193,7 @@ export default {
             if (firstNodeUserAssign) {
                 const formData = this.getFormData()
                 if (!formData) return
-                this.submitFormData = formData
+                this.submitFormData = this.$utils.replaceNullWithEmpty(formData)
                 this.startFlowDialogVisible = true
             } else {
                 this.saveStartFlow()
@@ -208,7 +209,7 @@ export default {
             const jsonData = {
                 defId: this.defId,
                 version: this.version || '0',
-                data: JSON.stringify(formData)
+                data: JSON.stringify(this.$utils.replaceNullWithEmpty(formData))
             }
             if (this.$utils.isNotEmpty(params.nodeUsers)) {
                 jsonData.nodeUsers = JSON.stringify(params.nodeUsers) || ''
@@ -256,7 +257,7 @@ export default {
             const jsonData = {
                 defId: this.defId,
                 version: this.version || '',
-                data: JSON.stringify(formData)
+                data: JSON.stringify(this.$utils.replaceNullWithEmpty(formData))
             }
             if (this.$utils.isNotEmpty(this.proInstId) && !this.copyFlow) {
                 jsonData.proInstId = this.proInstId || ''
@@ -316,7 +317,7 @@ export default {
                 text: this.$t('common.saving')
             })
             params.taskId = this.taskId
-            params.data = JSON.stringify(formData)
+            params.data = JSON.stringify(this.$utils.replaceNullWithEmpty(formData))
 
             if (actionName === 'agree') {
                 agree(params).then(response => {

+ 1 - 1
src/business/platform/data/templaterender/form/action.js

@@ -117,7 +117,7 @@ export default {
         version: this.version,
         formKey: this.formKey,
         pk: this.pkValue,
-        data: JSON.stringify(formData)
+        data: JSON.stringify(this.$utils.replaceNullWithEmpty(formData))
       }
       const loading = this.$loading({
         lock: true,

+ 29 - 7
src/business/platform/form/utils/custom/joinCURD.js

@@ -62,15 +62,37 @@ const sig = sql => {
     return md5(rul + '' + salt)
 }
 
+// 替换对象中的空数据
+const replaceNullWithEmpty = obj => {
+    function replaceValue (value) {
+        if (value === null) {
+            return ''
+        } else if (typeof value === 'object') {
+            if (Array.isArray(value)) {
+                return value.map(item => replaceValue(item))
+            } else {
+                return mapValues(value, v => replaceValue(v))
+            }
+        } else {
+            return value
+        }
+    }
+    return replaceValue(obj)
+}
+
 const dealData = (method, data) => {
-    // 序列化
-    if (typeof data == 'object') {
-        data = JSON.stringify(data)
+    const strType = ['sql']
+    // 查询方法直接拼接字符串
+    if (strType.includes(method)) {
+        data = `{"${method}":"${data}"}`
+    } else {
+        // 其余方法先处理数据
+        if (typeof data === 'object') {
+            data = JSON.stringify(replaceNullWithEmpty(data))
+        } else {
+            data = JSON.stringify(replaceNullWithEmpty(JSON.parse(data)))
+        }
     }
-    // 对需要拼接key值的方法做处理
-    let strType = ['sql']
-    let isStr = strType.includes(method)
-    data = isStr ? `{"${method}":"${data}"}` : data
     //加密,获取md5密文
     let md5 = sig(data)
     // 结果拼接

+ 21 - 1
src/utils/util.js

@@ -276,7 +276,27 @@ const util = {
       }
     }
     return result
-  }
+  },
+  /**
+     * 替换对象中的null为空字符串
+     * @param  {Object} obj 目标对象
+     */
+  replaceNullWithEmpty: function (obj) {
+    function replaceValue(value) {
+        if (value === null) {
+            return ''
+        } else if (typeof value === 'object') {
+            if (Array.isArray(value)) {
+                return value.map(item => replaceValue(item))
+            } else {
+                return mapValues(value, v => replaceValue(v))
+            }
+        } else {
+            return value
+        }
+    }
+    return replaceValue(obj)
+}
 }
 
 export default util