From 7df75b140c72e8d224f5c040e340ba393d46420a Mon Sep 17 00:00:00 2001 From: hsm-lv Date: Tue, 18 Oct 2022 20:06:32 +0800 Subject: [PATCH] =?UTF-8?q?[amis-saas-7476]:=E5=8A=A8=E4=BD=9C=E4=B8=AD?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=8F=82=E6=95=B0=E6=98=BE=E7=A4=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98&=E7=BB=84=E4=BB=B6=E6=95=B0=E6=8D=AE=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E6=97=B6=E4=B8=8A=E4=B8=8B=E6=96=87=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id8420adf7b12ecf6e9c5f6d603804f578d2d2c3a --- .../src/renderer/event-control/helper.tsx | 51 +++++++++++-------- .../src/renderer/event-control/index.tsx | 27 +++++----- .../src/renderer/event-control/types.ts | 1 + packages/amis-editor/src/tpl/common.tsx | 31 +++++++++-- 4 files changed, 74 insertions(+), 36 deletions(-) diff --git a/packages/amis-editor/src/renderer/event-control/helper.tsx b/packages/amis-editor/src/renderer/event-control/helper.tsx index 1df2e23db..2e9b2d7bf 100644 --- a/packages/amis-editor/src/renderer/event-control/helper.tsx +++ b/packages/amis-editor/src/renderer/event-control/helper.tsx @@ -572,6 +572,7 @@ export const renderCmptActionSelect = ( form.setValueByName('args.__comboType', undefined); form.setValueByName('args.__valueInput', undefined); form.setValueByName('args.__containerType', undefined); + if (SELECT_PROPS_CONTAINER.includes(rendererType)) { form.setValueByName( '__setValueDs', @@ -1102,11 +1103,17 @@ export const getEventControlConfig = ( ) => { let config = {...action}; - if (['setValue', 'url'].includes(action.actionType) && action.args) { - const prop = action.actionType === 'setValue' ? 'value' : 'params'; + if (['link', 'url'].includes(action.actionType) && action.args?.params) { + config.args = { + ...config.args, + params: objectToComboArray(action.args?.params) + }; + } + + if (['setValue'].includes(action.actionType) && action.args?.value) { !config.args && (config.args = {}); - if (Array.isArray(action.args[prop])) { - config.args[prop] = action.args[prop].reduce( + if (Array.isArray(action.args?.value)) { + config.args.value = action.args?.value.reduce( (arr: any, valueItem: any, index: number) => { if (!arr[index]) { arr[index] = {}; @@ -1118,8 +1125,8 @@ export const getEventControlConfig = ( ); // 目前只有给combo赋值会是数组,所以认为是全量的赋值方式 config.args['__comboType'] = 'all'; - } else if (typeof action.args[prop] === 'object') { - config.args[prop] = objectToComboArray(action.args[prop]); + } else if (typeof action.args?.value === 'object') { + config.args.value = objectToComboArray(action.args?.value); config.args['__containerType'] = 'appoint'; // 如果有index,认为是给指定序号的combo赋值,所以认为是指定序号的赋值方式 if (action.args.index !== undefined) { @@ -1127,19 +1134,21 @@ export const getEventControlConfig = ( } } else if ( action.actionType === 'setValue' && - typeof action.args[prop] === 'string' + typeof action.args?.value === 'string' ) { config.args['__containerType'] = 'all'; config.args['__valueInput'] = config.args['value']; delete config.args?.value; } } + if ( action.actionType === 'ajax' && typeof action?.args?.api === 'string' ) { action.args.api = normalizeApi(action?.args?.api); } + // 获取动作专有配置参数 const innerArgs: any = getPropOfAcion( action, @@ -1295,16 +1304,20 @@ export const getEventControlConfig = ( } // 转换下格式 - if (['setValue', 'url'].includes(action.actionType)) { - const propName = action.actionType === 'setValue' ? 'value' : 'params'; - if ( - action.actionType === 'setValue' && - config.args?.__valueInput !== undefined - ) { + if (['link', 'url'].includes(action.actionType)) { + action.args = { + ...action.args, + params: comboArrayToObject(config.args?.params) + }; + } + + // 转换下格式 + if (action.actionType === 'setValue') { + if (config.args?.__valueInput !== undefined) { action.args = { value: config.args?.__valueInput }; - } else if (Array.isArray(config.args?.[propName])) { + } else if (Array.isArray(config.args?.value)) { action.args = action.args ?? {}; if ( action.__rendererName === 'combo' && @@ -1312,7 +1325,7 @@ export const getEventControlConfig = ( ) { // combo特殊处理 let tempArr: any = []; - config.args?.[propName].forEach((valueItem: any, index: number) => { + config.args?.value.forEach((valueItem: any, index: number) => { valueItem.item.forEach((item: any) => { if (!tempArr[index]) { tempArr[index] = {}; @@ -1322,16 +1335,12 @@ export const getEventControlConfig = ( }); action.args = { ...action.args, - [propName]: tempArr + value: tempArr }; } else { - let tmpObj: any = {}; - config.args?.[propName].forEach((item: any) => { - tmpObj[item.key] = item.val; - }); action.args = { ...action.args, - [propName]: tmpObj + value: comboArrayToObject(config.args?.value!) }; } } diff --git a/packages/amis-editor/src/renderer/event-control/index.tsx b/packages/amis-editor/src/renderer/event-control/index.tsx index c540cb752..6cf32c6aa 100644 --- a/packages/amis-editor/src/renderer/event-control/index.tsx +++ b/packages/amis-editor/src/renderer/event-control/index.tsx @@ -513,20 +513,23 @@ export class EventControl extends React.Component< item => item.value === action.componentId ); + // 获取组件数据动作所需上下文 let setValueDs: any = null; - if (actionConfig?.actionType === 'setValue') { - const rendererType = node?.type; - const rendererName = node?.label; - // todo:这里会闪一下,需要从amis查下问题 - if (SELECT_PROPS_CONTAINER.includes(rendererType || '')) { - const curVariable = rawVariables.find( - item => item.label === `${rendererName}变量` - ); - setValueDs = curVariable?.children?.filter( - (item: ContextVariables) => item.value !== '$$id' - ); - } + if ( + actionConfig?.actionType === 'setValue' && + node?.id && + SELECT_PROPS_CONTAINER.includes(node?.type || '') + ) { + const targetDataSchema: any = await getContextSchemas?.(node.id, true); + const targetDataSchemaIns = new DataSchema(targetDataSchema || []); + const targetVariables = + targetDataSchemaIns?.getDataPropsAsOptions() || []; + + setValueDs = targetVariables?.filter( + (item: ContextVariables) => item.value !== '$$id' + ); } + data.actionData = { eventKey: data.actionData!.eventKey, actionIndex: data.actionData!.actionIndex, diff --git a/packages/amis-editor/src/renderer/event-control/types.ts b/packages/amis-editor/src/renderer/event-control/types.ts index e6611a8cf..d34b30e38 100644 --- a/packages/amis-editor/src/renderer/event-control/types.ts +++ b/packages/amis-editor/src/renderer/event-control/types.ts @@ -21,6 +21,7 @@ export interface ComponentInfo { disabled?: boolean; actions?: RendererPluginAction[]; // 动作集 children?: ComponentInfo[]; + id: string; } export interface ContextVariables { diff --git a/packages/amis-editor/src/tpl/common.tsx b/packages/amis-editor/src/tpl/common.tsx index cfd3803c7..e2e101d2c 100644 --- a/packages/amis-editor/src/tpl/common.tsx +++ b/packages/amis-editor/src/tpl/common.tsx @@ -1036,11 +1036,36 @@ setSchemaTpl('app-page', { }); setSchemaTpl('app-page-args', { - type: 'ae-DataMappingControl', + type: 'combo', name: 'params', label: '页面参数', - schema: {type: 'object', properties: {}}, - mode: 'horizontal' + multiple: true, + removable: true, + addable: true, + strictMode: false, + canAccessSuperData: true, + size: 'lg', + mode: 'horizontal', + items: [ + { + name: 'key', + type: 'input-text', + placeholder: '参数名', + source: '${__pageInputSchema}', + labelField: 'label', + valueField: 'value', + required: true + }, + { + name: 'val', + type: 'input-formula', + placeholder: '参数值', + variables: '${variables}', + evalMode: false, + variableMode: 'tabs', + inputMode: 'input-group' + } + ] }); setSchemaTpl(