[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.__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!)
};
}
}

View File

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

View File

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

View File

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