Kaynağa Gözat

[update] 通用接口、表单数据保存接口数据预处理,替换null值

cfort 2 yıl önce
ebeveyn
işleme
f0b3d62a8a

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

@@ -4,170 +4,170 @@ import { startFlowFromEdit } from '@/api/platform/bpmn/bpmInst'
 import Print from '@/utils/print'
 
 export default {
-  methods: {
-    emitEventHandler(actionKey, args) {
-      const action = args && args.attributes ? args.attributes.button_type || actionKey : actionKey
-      this.actionName = actionKey
-      switch (action) {
-        case 'close': // 关闭窗口
-          this.closeDialog()
-          break
-        case 'save':
-          this.handleSave()
-          break
-        case 'print':
-          this.handlePrint()
-          break
-        case 'sefStartFlow':
-          this.handleStartFlowFrom(args && args.attributes ? args.attributes.deflow : '')
-          break
-        case 'custom':
-          if(this.actionName == 'dingDanKaiLizanCun'){
-            this.handleSave()
-            break
-          }
-        default:
-          break
-      }
-    },
-    handleStartFlowFrom(flowKey) {
-      // 表单提交校验
-      if (this.$utils.isEmpty(flowKey)) {
-        // this.$message.warning('请检查是否绑定流程!')
-        this.bpmDefDialogVisible = true
-        return
-      }
-      // 验证表单是否正确
-      this.validate(valid => {
-        if (valid) {
-          // 表单提交校验
-          this.formSubmitVerify((result, errorMsg) => {
-            if (!result) {
-              this.$message.closeAll()
-              return this.$message.warning(errorMsg)
+    methods: {
+        emitEventHandler (actionKey, args) {
+            const action = args && args.attributes ? args.attributes.button_type || actionKey : actionKey
+            this.actionName = actionKey
+            switch (action) {
+                case 'close': // 关闭窗口
+                    this.closeDialog()
+                    break
+                case 'save':
+                    this.handleSave()
+                    break
+                case 'print':
+                    this.handlePrint()
+                    break
+                case 'sefStartFlow':
+                    this.handleStartFlowFrom(args && args.attributes ? args.attributes.deflow : '')
+                    break
+                case 'custom':
+                    if (this.actionName === 'dingDanKaiLizanCun') {
+                        this.handleSave()
+                        break
+                    }
+                default:
+                    break
             }
-            if (flowKey) {
-              this.$confirm('确定启动流程吗?', '提示', {
-                confirmButtonText: '确定',
-                cancelButtonText: '取消',
-                type: 'warning'
-              }).then(() => {
-                this.handleStartFlowFromEdit(flowKey)
-              }).catch(() => {})
-            } else {
-              this.bpmDefDialogVisible = true
+        },
+        handleStartFlowFrom (flowKey) {
+            // 表单提交校验
+            if (this.$utils.isEmpty(flowKey)) {
+                // this.$message.warning('请检查是否绑定流程!')
+                this.bpmDefDialogVisible = true
+                return
             }
-          })
-        } else {
-          this.formErrorToast()
-        }
-      })
-    },
-    handleDialogActionEvent(key, data) {
-      if (key === 'clean') {
-        this.bpmDefValue = {}
-      } else if (key === 'confirm') {
-        this.handleStartFlowFromEdit(data.defKey)
-      }
-    },
-    handleStartFlowFromEdit(flowKey) {
-      const formData = JSON.stringify(this.getFormData())
-      startFlowFromEdit({
-        data: formData,
-        flowKey: flowKey,
-        pk: this.pkValue || ''
-      }).then(response => {
-        this.bpmDefDialogVisible = false
-        this.$message({
-          message: '流程启动成功!',
-          type: 'success'
-        })
-        // 后置事件
-        this.afterScript(this.actionName, {
-          data: response.data,
-          variables: response.variables
-        }, () => {
-          this.callbackPage()
-        })
-      }).catch(() => {
-        this.bpmDefDialogVisible = false
-      })
-    },
-    // 保存
-    handleSave() {
-      // 验证表单是否正确
-      this.validate(valid => {
-        if (valid) {
-          // 表单提交校验
-          this.formSubmitVerify((result, errorMsg) => {
-            if (!result) {
-              this.$message.closeAll()
-              return this.$message.warning(errorMsg)
+            // 验证表单是否正确
+            this.validate(valid => {
+                if (valid) {
+                    // 表单提交校验
+                    this.formSubmitVerify((result, errorMsg) => {
+                        if (!result) {
+                            this.$message.closeAll()
+                            return this.$message.warning(errorMsg)
+                        }
+                        if (flowKey) {
+                            this.$confirm('确定启动流程吗?', '提示', {
+                                confirmButtonText: '确定',
+                                cancelButtonText: '取消',
+                                type: 'warning'
+                            }).then(() => {
+                                this.handleStartFlowFromEdit(flowKey)
+                            }).catch(() => {})
+                        } else {
+                            this.bpmDefDialogVisible = true
+                        }
+                    })
+                } else {
+                    this.formErrorToast()
+                }
+            })
+        },
+        handleDialogActionEvent (key, data) {
+            if (key === 'clean') {
+                this.bpmDefValue = {}
+            } else if (key === 'confirm') {
+                this.handleStartFlowFromEdit(data.defKey)
             }
-            // 保存数据
-            this.saveData()
-          })
-        } else {
-          this.formErrorToast()
-        }
-      })
-    },
-    // 保存数据
-    saveData() {
-      // 表单数据
-      const formData = this.getFormData()
-      const jsonData = {
-        boCode: this.boCode,
-        version: this.version,
-        formKey: this.formKey,
-        pk: this.pkValue,
-        data: JSON.stringify(formData)
-      }
-      const loading = this.$loading({
-        lock: true,
-        text: this.$t('common.saving')
-      })
-      saveFormData(jsonData).then(response => {
-        loading.close()
-        this.$alert(`保存表单成功!`, {
-          showClose: false
-        }).then(() => {
-          // 后置事件
-          this.afterScript(this.actionName, {
-            data: response.data,
-            variables: response.variables
-          }, () => {
-            this.callbackPage()
-          })
-        }).catch(() => {
-        })
-      }).catch(() => {
-        loading.close()
-      })
-    },
-    /**
-     * 打印
-     */
-    handlePrint() {
-      if (this.$utils.isNotEmpty(this.printTemplateId)) {
-        // 打开打印模版页面
-        this.formPrintTemplateDialogVisible = true
-      } else {
-      //  window.print()
-        const loading = this.$loading({
-          lock: true,
-          text: this.$t('common.loading')
-        })
-        setTimeout(() => {
-          Print(this.$refs.formrender.$el, {
-            title: '',
-            callback: () => {
-              loading.close()
+        },
+        handleStartFlowFromEdit (flowKey) {
+            const formData = JSON.stringify(this.getFormData())
+            startFlowFromEdit({
+                data: formData,
+                flowKey: flowKey,
+                pk: this.pkValue || ''
+            }).then(response => {
+                this.bpmDefDialogVisible = false
+                this.$message({
+                    message: '流程启动成功!',
+                    type: 'success'
+                })
+                // 后置事件
+                this.afterScript(this.actionName, {
+                    data: response.data,
+                    variables: response.variables
+                }, () => {
+                    this.callbackPage()
+                })
+            }).catch(() => {
+                this.bpmDefDialogVisible = false
+            })
+        },
+        // 保存
+        handleSave () {
+            // 验证表单是否正确
+            this.validate(valid => {
+                if (valid) {
+                    // 表单提交校验
+                    this.formSubmitVerify((result, errorMsg) => {
+                        if (!result) {
+                            this.$message.closeAll()
+                            return this.$message.warning(errorMsg)
+                        }
+                        // 保存数据
+                        this.saveData()
+                    })
+                } else {
+                    this.formErrorToast()
+                }
+            })
+        },
+        // 保存数据
+        saveData () {
+            // 表单数据
+            const formData = this.getFormData()
+            const jsonData = {
+                boCode: this.boCode,
+                version: this.version,
+                formKey: this.formKey,
+                pk: this.pkValue,
+                data: JSON.stringify(this.$common.replaceNullWithEmpty(formData))
             }
-          })
-        }, 300)
-      }
-    }
+            const loading = this.$loading({
+                lock: true,
+                text: this.$t('common.saving')
+            })
+            saveFormData(jsonData).then(response => {
+                loading.close()
+                this.$alert(`保存表单成功!`, {
+                    showClose: false
+                }).then(() => {
+                    // 后置事件
+                    this.afterScript(this.actionName, {
+                        data: response.data,
+                        variables: response.variables
+                    }, () => {
+                        this.callbackPage()
+                    })
+                }).catch(() => {
+                })
+            }).catch(() => {
+                loading.close()
+            })
+        },
+        /**
+         * 打印
+         */
+        handlePrint () {
+            if (this.$utils.isNotEmpty(this.printTemplateId)) {
+                // 打开打印模版页面
+                this.formPrintTemplateDialogVisible = true
+            } else {
+                //  window.print()
+                const loading = this.$loading({
+                    lock: true,
+                    text: this.$t('common.loading')
+                })
+                setTimeout(() => {
+                    Print(this.$refs.formrender.$el, {
+                        title: '',
+                        callback: () => {
+                            loading.close()
+                        }
+                    })
+                }, 300)
+            }
+        }
 
-  }
+    }
 }

+ 19 - 1
src/business/platform/form/utils/custom/joinCURD.js

@@ -1,6 +1,7 @@
 import request from '@/utils/request'
 import { normal } from './requestType'
 import { encryptByAes } from '@/utils/encrypt'
+import { mapValues } from 'lodash'
 // 请求方式默认POST
 const post = (type, data, method = 'post', loading = false) => {
     const requestUrl = `business/v3/sys/universal/${normal[type]}`
@@ -15,6 +16,23 @@ const post = (type, data, method = 'post', loading = false) => {
     })
 }
 
+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 = (args, type) => {
     // sql方法特殊处理
@@ -23,7 +41,7 @@ const dealData = (args, type) => {
             sql: args.replace(/\n/g, ' ')
         }
     }
-    const data = typeof args === 'object' ? JSON.stringify(args) : args
+    const data = typeof args === 'object' ? JSON.stringify(replaceNullWithEmpty(args)) : args
     const res = {
         ciphertext: encryptByAes(data),
         plaintext: args