From ce77375f667fa7dbd277b43658dcae8b4a1b91b5 Mon Sep 17 00:00:00 2001 From: "zude.hzd" Date: Tue, 1 Sep 2020 15:45:27 +0800 Subject: [PATCH] fix: fix NextTable callback function --- packages/demo/public/assets.json | 8 ++------ packages/editor-setters/src/index.tsx | 14 ++++++++++++-- packages/types/src/value-type.ts | 27 ++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/packages/demo/public/assets.json b/packages/demo/public/assets.json index fd5886db8..095625619 100644 --- a/packages/demo/public/assets.json +++ b/packages/demo/public/assets.json @@ -904,11 +904,7 @@ },{ "name": "callback", "description": "callback", - "propType": "JsonSetter", - "defaultValue": { - "type": "JSFunction", - "value": "(rowData, action, table) => {\n return table.editRow(rowData).then((row) => {\n console.log(row);\n })}" - } + "setter": "FunctionSetter" }] } }, @@ -916,7 +912,7 @@ "title": "Title", "callback": { "type": "JSFunction", - "value": "(rowData, action, table) => {\n return table.editRow(rowData).then((row) => {\n console.log(row);\n })}" + "value": "function(){}" } } } diff --git a/packages/editor-setters/src/index.tsx b/packages/editor-setters/src/index.tsx index 5d2bf11ec..c79f0cfc7 100644 --- a/packages/editor-setters/src/index.tsx +++ b/packages/editor-setters/src/index.tsx @@ -1,6 +1,6 @@ import React, { Component } from 'react'; import { registerSetter } from '@ali/lowcode-editor-core'; -import { isJSExpression } from '@ali/lowcode-types'; +import { isJSExpression,isJSFunction } from '@ali/lowcode-types'; import { DatePicker, TimePicker, Input, Radio, Select, Switch, NumberPicker } from '@alifd/next'; import ExpressionSetter from './expression-setter'; import ColorSetter from './color-setter'; @@ -91,6 +91,16 @@ const VariableSetter ={ recommend: true, }; + +const FunctionBindSetter = { + component: FunctionSetter, + title: '函数绑定', + condition: (field: any) => { + const v = field.getValue(); + return v == isJSFunction(v); + }, +} + const builtinSetters: any = { StringSetter, NumberSetter, @@ -110,7 +120,7 @@ const builtinSetters: any = { JsonSetter, StyleSetter, IconSetter, - FunctionSetter + FunctionSetter:FunctionBindSetter }; registerSetter(builtinSetters); diff --git a/packages/types/src/value-type.ts b/packages/types/src/value-type.ts index 34f0c38c5..a294ed082 100644 --- a/packages/types/src/value-type.ts +++ b/packages/types/src/value-type.ts @@ -17,6 +17,23 @@ export interface JSExpression { [key: string]: any; } +// 函数 +export interface JSFunction{ + type: 'JSFunction'; + /** + * 函数字符串 + */ + value: string; + /** + * 模拟值 + */ + mock?: any; + /** + * 额外扩展属性,如 extType、events + */ + [key: string]: any; +} + export interface JSSlot { name?: string; type: 'JSSlot'; @@ -39,7 +56,7 @@ export interface JSONObject { } // 复合类型 -export type CompositeValue = JSONValue | JSExpression | JSSlot | CompositeArray | CompositeObject; +export type CompositeValue = JSONValue | JSExpression | JSSlot | CompositeArray | CompositeObject | JSFunction; export type CompositeArray = CompositeValue[]; export interface CompositeObject { [key: string]: CompositeValue; @@ -50,6 +67,14 @@ export function isJSExpression(data: any): data is JSExpression { return data && data.type === 'JSExpression'; } + +export function isJSFunction(data: any): data is JSFunction { + return data && data.type === 'JSFunction'; +} + + + + export function isJSSlot(data: any): data is JSSlot { return data && data.type === 'JSSlot'; }