From e1eee179654def275a0d8e6c368d51fbd3cd6e12 Mon Sep 17 00:00:00 2001 From: "bai.zixv" Date: Thu, 11 Jul 2024 15:08:03 +0800 Subject: [PATCH] feat: jsparse, add crypto lib & feat: jsparse, jscode tooptip & fix: workflow, json parse, CodeMirror (#1306) Reviewed-on: https://git.daoyoucloud.com:8443/daoyoucloud/tachybase/pulls/1306 --- .../src/client/features/js-parse/JSParse.instruction.ts | 3 +++ .../src/client/features/json-parse/JSONParse.instruction.ts | 2 +- .../src/server/features/js-parse/JSParse.instruction.ts | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/js-parse/JSParse.instruction.ts b/packages/plugins/@tachybase/plugin-workflow/src/client/features/js-parse/JSParse.instruction.ts index d756fb9d0..df082c738 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/client/features/js-parse/JSParse.instruction.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/client/features/js-parse/JSParse.instruction.ts @@ -27,6 +27,9 @@ export class JSParseInstruction extends Instruction { type: 'string', title: tval('JSCode expression'), 'x-decorator': 'FormItem', + 'x-decorator-props': { + tooltip: 'ctx.data\nctx.body\n__ctx\nlib.JSON\nlib.qrcode\ncanvas\nlib.dayjs\nlib.log', + }, 'x-component': 'CodeMirror', required: true, }, diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/json-parse/JSONParse.instruction.ts b/packages/plugins/@tachybase/plugin-workflow/src/client/features/json-parse/JSONParse.instruction.ts index adc072e69..c794e479f 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/client/features/json-parse/JSONParse.instruction.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/client/features/json-parse/JSONParse.instruction.ts @@ -27,7 +27,7 @@ export class JSONParseInstruction extends Instruction { type: 'string', title: tval('Query expression'), 'x-decorator': 'FormItem', - 'x-component': 'Input.TextArea', + 'x-component': 'CodeMirror', }, model: { type: 'array', diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/js-parse/JSParse.instruction.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/js-parse/JSParse.instruction.ts index 72f86f40c..74e4c8d3c 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/features/js-parse/JSParse.instruction.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/js-parse/JSParse.instruction.ts @@ -1,3 +1,5 @@ +import crypto from 'crypto'; + import * as canvas from 'canvas'; import _ from 'lodash'; import qrcode from 'qrcode'; @@ -19,6 +21,7 @@ export class JSParseInstruction extends Instruction { JSON, canvas, qrcode, + crypto, log: console.log, }, }); @@ -62,7 +65,7 @@ function mapModel(data, model) { } async function evalSimulate(jsCode, { ctx, lib }) { - const AsyncFunction = async function () {}.constructor; + const AsyncFunction: any = async function () {}.constructor; return await new AsyncFunction('$root', `with($root) { ${jsCode}; }`)({ ctx, // 允许用户覆盖,这个时候可以使用 _ctx