mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
feat:调整ajax动作配置结构
This commit is contained in:
parent
f50682f612
commit
9547578c34
@ -172,7 +172,6 @@ export const runActions = async (
|
||||
if (!actionInstrance) {
|
||||
actionInstrance = getActionByType('component');
|
||||
}
|
||||
|
||||
// 这些节点的子节点运行逻辑由节点内部实现
|
||||
await runAction(actionInstrance, actionConfig, renderer, event);
|
||||
if (event.stoped) {
|
||||
|
@ -13,15 +13,13 @@ import {
|
||||
|
||||
export interface IAjaxAction extends ListenerAction {
|
||||
action: 'ajax';
|
||||
args: {
|
||||
api: Api;
|
||||
messages?: {
|
||||
success: string;
|
||||
failed: string;
|
||||
};
|
||||
options?: Record<string, any>;
|
||||
[propName: string]: any;
|
||||
api: Api;
|
||||
messages?: {
|
||||
success: string;
|
||||
failed: string;
|
||||
};
|
||||
options?: Record<string, any>;
|
||||
[propName: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,19 +44,25 @@ export class AjaxAction implements RendererAction {
|
||||
throw new Error('env.fetcher is required!');
|
||||
}
|
||||
if (this.fetcherType === 'download' && action.actionType === 'download') {
|
||||
// 兼容老的格式
|
||||
if ((action as any).args?.api) {
|
||||
(action as any).args.api.responseType = 'blob';
|
||||
}
|
||||
if ((action as any)?.api) {
|
||||
(action as any).api.responseType = 'blob';
|
||||
}
|
||||
}
|
||||
|
||||
const env = event.context.env;
|
||||
const silent = action?.options?.silent ?? action.args?.options?.silent;
|
||||
const messages =
|
||||
(action?.api as ApiObject)?.messages ??
|
||||
(action.args?.api as ApiObject)?.messages;
|
||||
try {
|
||||
const result = await env.fetcher(
|
||||
typeof action.args?.api === 'string'
|
||||
? action.args.api
|
||||
: omit(action.args.api, 'data'),
|
||||
(action.args?.api as any)?.data ?? action.data ?? {},
|
||||
action.args?.options ?? {}
|
||||
action?.api ?? action.args?.api,
|
||||
action.data ?? {},
|
||||
action?.options ?? action.args?.options ?? {}
|
||||
);
|
||||
const responseData =
|
||||
!isEmpty(result.data) || result.ok
|
||||
@ -78,18 +82,15 @@ export class AjaxAction implements RendererAction {
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
if (!action.args?.options?.silent) {
|
||||
if (!silent) {
|
||||
if (!result.ok) {
|
||||
throw new ServerError(
|
||||
(action.args?.api as ApiObject)?.messages?.failed ??
|
||||
action.args?.messages?.failed ??
|
||||
result.msg,
|
||||
messages?.failed ?? action.args?.messages?.failed ?? result.msg,
|
||||
result
|
||||
);
|
||||
} else {
|
||||
const msg =
|
||||
(action.args?.api as ApiObject)?.messages?.success ??
|
||||
messages?.success ??
|
||||
action.args?.messages?.success ??
|
||||
result.msg ??
|
||||
result.defaultMsg;
|
||||
@ -109,7 +110,7 @@ export class AjaxAction implements RendererAction {
|
||||
|
||||
return result.data;
|
||||
} catch (e) {
|
||||
if (!action.args?.options?.silent) {
|
||||
if (!silent) {
|
||||
if (e.type === 'ServerError') {
|
||||
const result = (e as ServerError).response;
|
||||
env.notify(
|
||||
|
@ -12,8 +12,8 @@ export const BASE_ACTION_PROPS = [
|
||||
'__actionDesc',
|
||||
'preventDefault',
|
||||
'stopPropagation',
|
||||
'expression',
|
||||
'outputVar'
|
||||
'expression'
|
||||
// 'outputVar'
|
||||
];
|
||||
|
||||
export default class CmptActionSelect extends React.Component<RendererProps> {
|
||||
|
@ -690,9 +690,9 @@ export const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
|
||||
actionLabel: '发送请求',
|
||||
actionType: 'ajax',
|
||||
description: '配置并发送API请求',
|
||||
innerArgs: ['api', 'options'],
|
||||
// innerArgs: ['api', 'options'],
|
||||
descDetail: (info: any) => {
|
||||
let apiInfo = info?.args?.api;
|
||||
let apiInfo = info?.api ?? info?.args?.api;
|
||||
if (typeof apiInfo === 'string') {
|
||||
apiInfo = normalizeApi(apiInfo);
|
||||
}
|
||||
@ -711,43 +711,72 @@ export const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
|
||||
type: 'wrapper',
|
||||
className: 'p-none',
|
||||
body: [
|
||||
getArgsWrapper(
|
||||
[
|
||||
getSchemaTpl('apiControl', {
|
||||
name: 'api',
|
||||
label: '配置请求',
|
||||
mode: 'horizontal',
|
||||
size: 'lg',
|
||||
inputClassName: 'm-b-none',
|
||||
renderLabel: true,
|
||||
required: true
|
||||
}),
|
||||
// getArgsWrapper(
|
||||
// [
|
||||
// getSchemaTpl('apiControl', {
|
||||
// name: 'api',
|
||||
// label: '配置请求',
|
||||
// mode: 'horizontal',
|
||||
// size: 'lg',
|
||||
// inputClassName: 'm-b-none',
|
||||
// renderLabel: true,
|
||||
// required: true
|
||||
// }),
|
||||
// {
|
||||
// name: 'options',
|
||||
// type: 'combo',
|
||||
// label: tipedLabel(
|
||||
// '静默请求',
|
||||
// '开启后,服务请求将以静默模式发送,即不会弹出成功或报错提示。'
|
||||
// ),
|
||||
// mode: 'horizontal',
|
||||
// items: [
|
||||
// {
|
||||
// type: 'switch',
|
||||
// name: 'silent',
|
||||
// label: false,
|
||||
// onText: '开启',
|
||||
// offText: '关闭',
|
||||
// mode: 'horizontal',
|
||||
// pipeIn: defaultValue(false)
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// ],
|
||||
// false,
|
||||
// {
|
||||
// className: 'action-apiControl'
|
||||
// }
|
||||
// ),
|
||||
getSchemaTpl('apiControl', {
|
||||
name: 'api',
|
||||
label: '配置请求',
|
||||
mode: 'horizontal',
|
||||
size: 'lg',
|
||||
inputClassName: 'm-b-none',
|
||||
renderLabel: true,
|
||||
required: true
|
||||
}),
|
||||
{
|
||||
name: 'options',
|
||||
type: 'combo',
|
||||
label: tipedLabel(
|
||||
'静默请求',
|
||||
'开启后,服务请求将以静默模式发送,即不会弹出成功或报错提示。'
|
||||
),
|
||||
mode: 'horizontal',
|
||||
items: [
|
||||
{
|
||||
name: 'options',
|
||||
type: 'combo',
|
||||
label: tipedLabel(
|
||||
'静默请求',
|
||||
'开启后,服务请求将以静默模式发送,即不会弹出成功或报错提示。'
|
||||
),
|
||||
type: 'switch',
|
||||
name: 'silent',
|
||||
label: false,
|
||||
onText: '开启',
|
||||
offText: '关闭',
|
||||
mode: 'horizontal',
|
||||
items: [
|
||||
{
|
||||
type: 'switch',
|
||||
name: 'silent',
|
||||
label: false,
|
||||
onText: '开启',
|
||||
offText: '关闭',
|
||||
mode: 'horizontal',
|
||||
pipeIn: defaultValue(false)
|
||||
}
|
||||
]
|
||||
pipeIn: defaultValue(false)
|
||||
}
|
||||
],
|
||||
false,
|
||||
{
|
||||
className: 'action-apiControl'
|
||||
}
|
||||
),
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'outputVar',
|
||||
type: 'input-text',
|
||||
@ -787,26 +816,35 @@ export const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
|
||||
actionLabel: '下载文件',
|
||||
actionType: 'download',
|
||||
description: '触发下载文件',
|
||||
innerArgs: ['api'],
|
||||
// innerArgs: ['api'],
|
||||
schema: {
|
||||
type: 'wrapper',
|
||||
style: {padding: '0'},
|
||||
body: [
|
||||
getArgsWrapper(
|
||||
getSchemaTpl('apiControl', {
|
||||
name: 'api',
|
||||
label: '配置请求',
|
||||
mode: 'horizontal',
|
||||
inputClassName: 'm-b-none',
|
||||
size: 'lg',
|
||||
renderLabel: true,
|
||||
required: true
|
||||
}),
|
||||
false,
|
||||
{
|
||||
className: 'action-apiControl'
|
||||
}
|
||||
)
|
||||
// getArgsWrapper(
|
||||
// getSchemaTpl('apiControl', {
|
||||
// name: 'api',
|
||||
// label: '配置请求',
|
||||
// mode: 'horizontal',
|
||||
// inputClassName: 'm-b-none',
|
||||
// size: 'lg',
|
||||
// renderLabel: true,
|
||||
// required: true
|
||||
// }),
|
||||
// false,
|
||||
// {
|
||||
// className: 'action-apiControl'
|
||||
// }
|
||||
// )
|
||||
getSchemaTpl('apiControl', {
|
||||
name: 'api',
|
||||
label: '配置请求',
|
||||
mode: 'horizontal',
|
||||
inputClassName: 'm-b-none',
|
||||
size: 'lg',
|
||||
renderLabel: true,
|
||||
required: true
|
||||
})
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -2738,11 +2776,13 @@ export const getEventControlConfig = (
|
||||
config.__actionExpression = action.args?.value;
|
||||
}
|
||||
|
||||
if (
|
||||
action.actionType === 'ajax' &&
|
||||
typeof action?.args?.api === 'string'
|
||||
) {
|
||||
action.args.api = normalizeApi(action?.args?.api);
|
||||
if (['ajax', 'download'].includes(action.actionType)) {
|
||||
config.api = action.api ?? action?.args?.api;
|
||||
config.options = action.options ?? action?.args?.options;
|
||||
if (typeof action?.api === 'string') {
|
||||
config.api = normalizeApi(action?.api);
|
||||
}
|
||||
delete config.args;
|
||||
}
|
||||
|
||||
// 获取动作专有配置参数
|
||||
@ -2753,7 +2793,7 @@ export const getEventControlConfig = (
|
||||
manager.pluginActions,
|
||||
commonActions
|
||||
);
|
||||
|
||||
console.log(innerArgs);
|
||||
// 处理刷新组件动作的追加参数
|
||||
if (config.actionType === 'reload') {
|
||||
config.__resetPage = config.args?.resetPage;
|
||||
@ -3006,7 +3046,6 @@ export const getEventControlConfig = (
|
||||
delete action.__actionExpression;
|
||||
delete action.__statusType;
|
||||
}
|
||||
|
||||
delete action.config;
|
||||
|
||||
return action;
|
||||
|
Loading…
Reference in New Issue
Block a user