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
This commit is contained in:
bai.zixv 2024-07-11 15:08:03 +08:00
parent f6dd7fbccb
commit e1eee17965
3 changed files with 8 additions and 2 deletions

View File

@ -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,
},

View File

@ -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',

View File

@ -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