[amis-saas-7476]:动作中页面参数显示问题&组件数据初始化时上下文获取问题

Change-Id: Id8420adf7b12ecf6e9c5f6d603804f578d2d2c3a
This commit is contained in:
hsm-lv 2022-10-18 20:06:32 +08:00
parent 9c96baca03
commit 7df75b140c
4 changed files with 74 additions and 36 deletions

View File

@ -572,6 +572,7 @@ export const renderCmptActionSelect = (
form.setValueByName('args.__comboType', undefined); form.setValueByName('args.__comboType', undefined);
form.setValueByName('args.__valueInput', undefined); form.setValueByName('args.__valueInput', undefined);
form.setValueByName('args.__containerType', undefined); form.setValueByName('args.__containerType', undefined);
if (SELECT_PROPS_CONTAINER.includes(rendererType)) { if (SELECT_PROPS_CONTAINER.includes(rendererType)) {
form.setValueByName( form.setValueByName(
'__setValueDs', '__setValueDs',
@ -1102,11 +1103,17 @@ export const getEventControlConfig = (
) => { ) => {
let config = {...action}; let config = {...action};
if (['setValue', 'url'].includes(action.actionType) && action.args) { if (['link', 'url'].includes(action.actionType) && action.args?.params) {
const prop = action.actionType === 'setValue' ? 'value' : 'params'; config.args = {
...config.args,
params: objectToComboArray(action.args?.params)
};
}
if (['setValue'].includes(action.actionType) && action.args?.value) {
!config.args && (config.args = {}); !config.args && (config.args = {});
if (Array.isArray(action.args[prop])) { if (Array.isArray(action.args?.value)) {
config.args[prop] = action.args[prop].reduce( config.args.value = action.args?.value.reduce(
(arr: any, valueItem: any, index: number) => { (arr: any, valueItem: any, index: number) => {
if (!arr[index]) { if (!arr[index]) {
arr[index] = {}; arr[index] = {};
@ -1118,8 +1125,8 @@ export const getEventControlConfig = (
); );
// 目前只有给combo赋值会是数组所以认为是全量的赋值方式 // 目前只有给combo赋值会是数组所以认为是全量的赋值方式
config.args['__comboType'] = 'all'; config.args['__comboType'] = 'all';
} else if (typeof action.args[prop] === 'object') { } else if (typeof action.args?.value === 'object') {
config.args[prop] = objectToComboArray(action.args[prop]); config.args.value = objectToComboArray(action.args?.value);
config.args['__containerType'] = 'appoint'; config.args['__containerType'] = 'appoint';
// 如果有index认为是给指定序号的combo赋值所以认为是指定序号的赋值方式 // 如果有index认为是给指定序号的combo赋值所以认为是指定序号的赋值方式
if (action.args.index !== undefined) { if (action.args.index !== undefined) {
@ -1127,19 +1134,21 @@ export const getEventControlConfig = (
} }
} else if ( } else if (
action.actionType === 'setValue' && action.actionType === 'setValue' &&
typeof action.args[prop] === 'string' typeof action.args?.value === 'string'
) { ) {
config.args['__containerType'] = 'all'; config.args['__containerType'] = 'all';
config.args['__valueInput'] = config.args['value']; config.args['__valueInput'] = config.args['value'];
delete config.args?.value; delete config.args?.value;
} }
} }
if ( if (
action.actionType === 'ajax' && action.actionType === 'ajax' &&
typeof action?.args?.api === 'string' typeof action?.args?.api === 'string'
) { ) {
action.args.api = normalizeApi(action?.args?.api); action.args.api = normalizeApi(action?.args?.api);
} }
// 获取动作专有配置参数 // 获取动作专有配置参数
const innerArgs: any = getPropOfAcion( const innerArgs: any = getPropOfAcion(
action, action,
@ -1295,16 +1304,20 @@ export const getEventControlConfig = (
} }
// 转换下格式 // 转换下格式
if (['setValue', 'url'].includes(action.actionType)) { if (['link', 'url'].includes(action.actionType)) {
const propName = action.actionType === 'setValue' ? 'value' : 'params'; action.args = {
if ( ...action.args,
action.actionType === 'setValue' && params: comboArrayToObject(config.args?.params)
config.args?.__valueInput !== undefined };
) { }
// 转换下格式
if (action.actionType === 'setValue') {
if (config.args?.__valueInput !== undefined) {
action.args = { action.args = {
value: config.args?.__valueInput value: config.args?.__valueInput
}; };
} else if (Array.isArray(config.args?.[propName])) { } else if (Array.isArray(config.args?.value)) {
action.args = action.args ?? {}; action.args = action.args ?? {};
if ( if (
action.__rendererName === 'combo' && action.__rendererName === 'combo' &&
@ -1312,7 +1325,7 @@ export const getEventControlConfig = (
) { ) {
// combo特殊处理 // combo特殊处理
let tempArr: any = []; let tempArr: any = [];
config.args?.[propName].forEach((valueItem: any, index: number) => { config.args?.value.forEach((valueItem: any, index: number) => {
valueItem.item.forEach((item: any) => { valueItem.item.forEach((item: any) => {
if (!tempArr[index]) { if (!tempArr[index]) {
tempArr[index] = {}; tempArr[index] = {};
@ -1322,16 +1335,12 @@ export const getEventControlConfig = (
}); });
action.args = { action.args = {
...action.args, ...action.args,
[propName]: tempArr value: tempArr
}; };
} else { } else {
let tmpObj: any = {};
config.args?.[propName].forEach((item: any) => {
tmpObj[item.key] = item.val;
});
action.args = { action.args = {
...action.args, ...action.args,
[propName]: tmpObj value: comboArrayToObject(config.args?.value!)
}; };
} }
} }

View File

@ -513,20 +513,23 @@ export class EventControl extends React.Component<
item => item.value === action.componentId item => item.value === action.componentId
); );
// 获取组件数据动作所需上下文
let setValueDs: any = null; let setValueDs: any = null;
if (actionConfig?.actionType === 'setValue') { if (
const rendererType = node?.type; actionConfig?.actionType === 'setValue' &&
const rendererName = node?.label; node?.id &&
// todo:这里会闪一下需要从amis查下问题 SELECT_PROPS_CONTAINER.includes(node?.type || '')
if (SELECT_PROPS_CONTAINER.includes(rendererType || '')) { ) {
const curVariable = rawVariables.find( const targetDataSchema: any = await getContextSchemas?.(node.id, true);
item => item.label === `${rendererName}变量` const targetDataSchemaIns = new DataSchema(targetDataSchema || []);
); const targetVariables =
setValueDs = curVariable?.children?.filter( targetDataSchemaIns?.getDataPropsAsOptions() || [];
(item: ContextVariables) => item.value !== '$$id'
); setValueDs = targetVariables?.filter(
} (item: ContextVariables) => item.value !== '$$id'
);
} }
data.actionData = { data.actionData = {
eventKey: data.actionData!.eventKey, eventKey: data.actionData!.eventKey,
actionIndex: data.actionData!.actionIndex, actionIndex: data.actionData!.actionIndex,

View File

@ -21,6 +21,7 @@ export interface ComponentInfo {
disabled?: boolean; disabled?: boolean;
actions?: RendererPluginAction[]; // 动作集 actions?: RendererPluginAction[]; // 动作集
children?: ComponentInfo[]; children?: ComponentInfo[];
id: string;
} }
export interface ContextVariables { export interface ContextVariables {

View File

@ -1036,11 +1036,36 @@ setSchemaTpl('app-page', {
}); });
setSchemaTpl('app-page-args', { setSchemaTpl('app-page-args', {
type: 'ae-DataMappingControl', type: 'combo',
name: 'params', name: 'params',
label: '页面参数', label: '页面参数',
schema: {type: 'object', properties: {}}, multiple: true,
mode: 'horizontal' 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( setSchemaTpl(