From 2a1ff039fb6c18bc423eb0b469893b6df3f9fae1 Mon Sep 17 00:00:00 2001 From: "wu.jian2" Date: Sat, 14 Oct 2023 12:15:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DJS=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=E5=8A=A8=E6=80=81=E5=8F=82=E6=95=B0=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=A1=AB=E5=85=85=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E5=A4=84=E7=90=86=E5=8F=82=E6=95=B0=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/JsComponents/ParamsSettingDialog.vue | 13 ++++-- .../DataSetManagement/src/JsEditForm.vue | 42 ++++++++++--------- .../packages/js/mixins/commonMixins.js | 9 ++-- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/data-room-ui/packages/DataSetManagement/src/JsComponents/ParamsSettingDialog.vue b/data-room-ui/packages/DataSetManagement/src/JsComponents/ParamsSettingDialog.vue index 2ae24c11..84284b15 100644 --- a/data-room-ui/packages/DataSetManagement/src/JsComponents/ParamsSettingDialog.vue +++ b/data-room-ui/packages/DataSetManagement/src/JsComponents/ParamsSettingDialog.vue @@ -171,6 +171,11 @@ export default { default: () => [] } }, + computed: { + innerParamsList () { + return cloneDeep(this.paramsList) + } + }, data () { return { dialogVisible: false @@ -187,7 +192,7 @@ export default { this.dialogVisible = false }, addParam () { - this.paramsList.push({ + this.innerParamsList.push({ name: '', type: '', value: '', @@ -197,10 +202,10 @@ export default { }) }, delRow (index) { - this.paramsList.splice(index, 1) + this.innerParamsList.splice(index, 1) }, checkParamsName (value) { - const checkList = this.paramsList.filter(item => item.fieldName === value.name) + const checkList = this.innerParamsList.filter(item => item.fieldName === value.name) if (checkList.length) { this.$message.warning('参数名称不可以与字段名相同!') value.name = '' @@ -210,7 +215,7 @@ export default { this.dialogVisible = false }, confirm () { - this.$emit('saveParams', cloneDeep(this.paramsList)) + this.$emit('saveParams', this.innerParamsList) this.dialogVisible = false } } diff --git a/data-room-ui/packages/DataSetManagement/src/JsEditForm.vue b/data-room-ui/packages/DataSetManagement/src/JsEditForm.vue index c0e9369b..0b5cfe5a 100644 --- a/data-room-ui/packages/DataSetManagement/src/JsEditForm.vue +++ b/data-room-ui/packages/DataSetManagement/src/JsEditForm.vue @@ -432,6 +432,7 @@ export default { }) } return { + autoFill: true, dataForm: { id: '', name: '', @@ -642,7 +643,9 @@ export default { try { const scriptAfterReplacement = javascript.replace(/\${(.*?)}/g, (match, p) => { const value = this.dataForm.config.paramsList.find(param => param.name === p).value - if (!isNaN(value)) { + if (value === null || value === undefined || value === '') { + return "''" + } else if (!isNaN(value)) { return value } else { return `'${value}'` @@ -654,8 +657,8 @@ export default { this.passTest = false const javascriptParams = javascript.match(/\${(.*?)}/g) // 取出${}中的参数名 + let paramList = [] if (javascriptParams) { - const paramList = [] javascriptParams.forEach(item => { const name = item.replace(/\${(.*?)}/g, '$1') const param = this.dataForm.config.paramsList.find(param => param.name === name) @@ -664,24 +667,12 @@ export default { paramList.push(name) } }) - this.$confirm(`脚本中的参数${paramList.join(',')}不存在,是否添加?`, '提示', { - confirmButtonText: '确定', - cancelButtonText: '取消', - customClass: 'bs-el-message-box', - type: 'warning' - }).then(() => { - paramList.forEach(name => { - this.dataForm.config.paramsList.push({ - name, - type: '', - value: '', - status: 1, - require: 0, - remark: '' - }) - }) - }).catch(() => {}) + if (this.autoFill && paramList.length > 0) { + this.addParams(paramList) + paramList = [] + } } else { + console.info(error) this.$message.error(`脚本执行错误,请检查脚本,具体错误:${error}`) } return @@ -762,6 +753,19 @@ export default { this.$message.error('请填写脚本') } }, + addParams (paramList) { + this.$refs.paramsSettingDialog.open() + paramList.forEach(name => { + this.dataForm.config.paramsList.push({ + name, + type: '', + value: '', + status: 1, + require: 0, + remark: '' + }) + }) + }, // 执行事件 // toExecute () { // if (this.dataForm.config.paramsList.length) { diff --git a/data-room-ui/packages/js/mixins/commonMixins.js b/data-room-ui/packages/js/mixins/commonMixins.js index ef43ee6a..228e4cb0 100644 --- a/data-room-ui/packages/js/mixins/commonMixins.js +++ b/data-room-ui/packages/js/mixins/commonMixins.js @@ -156,8 +156,9 @@ export default { try { const scriptAfterReplacement = res.data.script.replace(/\${(.*?)}/g, (match, p) => { const value = this.config.dataSource?.params[p] - - if (!isNaN(value)) { + if (value === null || value === undefined || value === '') { + return "''" + } else if (!isNaN(value)) { return value || p } else { return `'${value}' || '${p}'` @@ -224,7 +225,9 @@ export default { try { const scriptAfterReplacement = res.data.script.replace(/\${(.*?)}/g, (match, p) => { const value = this.config.dataSource?.params[p] - if (!isNaN(value)) { + if (value === null || value === undefined || value === '') { + return "''" + } else if (!isNaN(value)) { return value || p } else { return `'${value}' || '${p}'`