From 43ae68df94e4f5581debcf7eab18fb86220d9146 Mon Sep 17 00:00:00 2001 From: "wu.jian2" Date: Tue, 27 Jun 2023 15:17:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=AE=9A=E4=B9=89JS=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=9B=86=E6=B7=BB=E5=8A=A0=E5=8A=A8=E6=80=81=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/customDatasetComponents/jsDataSet/index.vue | 2 +- data-room-ui/packages/js/mixins/commonMixins.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/data-room-ui/example/customDatasetComponents/jsDataSet/index.vue b/data-room-ui/example/customDatasetComponents/jsDataSet/index.vue index bbb5f0c9..af8d7a21 100644 --- a/data-room-ui/example/customDatasetComponents/jsDataSet/index.vue +++ b/data-room-ui/example/customDatasetComponents/jsDataSet/index.vue @@ -613,7 +613,7 @@ export default { scriptMethod = new Function(scriptAfterReplacement) } catch (error) { this.passTest = false - this.$message.error('脚本执行错误,请检查脚本') + this.$message.error(`脚本执行错误,请检查脚本,具体错误:${error}`) return } // 调用方法生成随机数据 diff --git a/data-room-ui/packages/js/mixins/commonMixins.js b/data-room-ui/packages/js/mixins/commonMixins.js index 04e965d6..c063c9fb 100644 --- a/data-room-ui/packages/js/mixins/commonMixins.js +++ b/data-room-ui/packages/js/mixins/commonMixins.js @@ -142,8 +142,13 @@ export default { // 数据集脚本前端执行 if (res.executionByFrontend) { try { - const returnResult = eval(`(${res.data})`)() - res.data = returnResult + const scriptAfterReplacement = res.data.replace(/\${(.*?)}/g, (match, p) => { + // 根据parmas的key获取value + return `'${this.config.dataSource?.params[p]}' || '${p}'` + }) + // eslint-disable-next-line no-new-func + const scriptMethod = new Function(scriptAfterReplacement) + res.data = scriptMethod() } catch (error) { console.error('数据集脚本执行失败', error) }