mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 20:18:03 +08:00
feat:ajaxAction传参处理
This commit is contained in:
parent
4a4527c55d
commit
202b9bb5af
@ -13,7 +13,7 @@ import {
|
||||
export interface IAjaxAction extends ListenerAction {
|
||||
action: 'ajax';
|
||||
args: {
|
||||
api: Api;
|
||||
api: ApiObject;
|
||||
messages?: {
|
||||
success: string;
|
||||
failed: string;
|
||||
@ -52,11 +52,10 @@ export class AjaxAction implements RendererAction {
|
||||
|
||||
const env = event.context.env;
|
||||
try {
|
||||
const result = await env.fetcher(
|
||||
action.args?.api,
|
||||
action.data ?? {},
|
||||
action.args?.options ?? {}
|
||||
);
|
||||
const data = action.args?.api?.data ?? action.data ?? {};
|
||||
const api = {...(action.args?.api ?? {})};
|
||||
delete api?.data;
|
||||
const result = await env.fetcher(api, data, action.args?.options ?? {});
|
||||
const responseData =
|
||||
!isEmpty(result.data) || result.ok
|
||||
? normalizeApiResponseData(result.data)
|
||||
@ -79,14 +78,14 @@ export class AjaxAction implements RendererAction {
|
||||
if (!action.args?.options?.silent) {
|
||||
if (!result.ok) {
|
||||
throw new ServerError(
|
||||
(action.args?.api as ApiObject)?.messages?.failed ??
|
||||
action.args?.api?.messages?.failed ??
|
||||
action.args?.messages?.failed ??
|
||||
result.msg,
|
||||
result
|
||||
);
|
||||
} else {
|
||||
const msg =
|
||||
(action.args?.api as ApiObject)?.messages?.success ??
|
||||
action.args?.api?.messages?.success ??
|
||||
action.args?.messages?.success ??
|
||||
result.msg ??
|
||||
result.defaultMsg;
|
||||
|
Loading…
Reference in New Issue
Block a user