mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +08:00
chore: action countDown 在actionType为ajax时,请求通过再执行倒计时操作、dialog header 传递动作属性 (#4000)
* LocationPicker ak支持数据解析,可用于统一地图配置 * drawer header传递动作属性,在header中也可以提交、关闭等操作 * action countDown 在actionType为ajax时,请求通过再执行倒计时操作 * dialog header 传递动作属性 * 修一些编码规范问题 Co-authored-by: metooweb <1058776960@qq.com> Co-authored-by: wuduoyi <wuduoyi@baidu.com>
This commit is contained in:
parent
8c64dc0000
commit
a4b475b8ea
@ -157,20 +157,28 @@ export class RootRenderer extends React.Component<RootRendererProps> {
|
||||
store.setCurrentAction(action);
|
||||
store.openDrawer(ctx);
|
||||
} else if (action.actionType === 'toast') {
|
||||
action.toast?.items?.forEach((item:any) => {
|
||||
env.notify(item.level || 'info', item.body ? renderChild('body', item.body, {
|
||||
...this.props,
|
||||
data: ctx
|
||||
}) : '', {
|
||||
...action.toast,
|
||||
...item,
|
||||
title: item.title ? renderChild('title', item.title, {
|
||||
...this.props,
|
||||
data: ctx
|
||||
}) : null,
|
||||
useMobileUI: env.useMobileUI
|
||||
})
|
||||
})
|
||||
action.toast?.items?.forEach((item: any) => {
|
||||
env.notify(
|
||||
item.level || 'info',
|
||||
item.body
|
||||
? renderChild('body', item.body, {
|
||||
...this.props,
|
||||
data: ctx
|
||||
})
|
||||
: '',
|
||||
{
|
||||
...action.toast,
|
||||
...item,
|
||||
title: item.title
|
||||
? renderChild('title', item.title, {
|
||||
...this.props,
|
||||
data: ctx
|
||||
})
|
||||
: null,
|
||||
useMobileUI: env.useMobileUI
|
||||
}
|
||||
);
|
||||
});
|
||||
} else if (action.actionType === 'ajax') {
|
||||
store.setCurrentAction(action);
|
||||
store
|
||||
@ -197,7 +205,11 @@ export class RootRenderer extends React.Component<RootRendererProps> {
|
||||
store.data
|
||||
);
|
||||
})
|
||||
.catch(() => {});
|
||||
.catch(e => {
|
||||
if (throwErrors || action.countDown) {
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
} else if (
|
||||
action.actionType === 'copy' &&
|
||||
(action.content || action.copy)
|
||||
|
@ -398,7 +398,8 @@ const ActionProps = [
|
||||
'copy',
|
||||
'copyFormat',
|
||||
'payload',
|
||||
'requireSelected'
|
||||
'requireSelected',
|
||||
'countDown'
|
||||
];
|
||||
import {filterContents} from './Remark';
|
||||
import {ClassNamesFn, themeable, ThemeProps} from '../theme';
|
||||
@ -659,8 +660,7 @@ export class Action extends React.Component<ActionProps, ActionState> {
|
||||
(action as AjaxActionSchema).api = api;
|
||||
}
|
||||
|
||||
onAction(e, action);
|
||||
|
||||
await onAction(e, action);
|
||||
if (countDown) {
|
||||
const countDownEnd = Date.now() + countDown * 1000;
|
||||
this.setState({
|
||||
@ -668,9 +668,7 @@ export class Action extends React.Component<ActionProps, ActionState> {
|
||||
inCountDown: true,
|
||||
timeLeft: countDown
|
||||
});
|
||||
|
||||
localStorage.setItem(this.localStorageKey, String(countDownEnd));
|
||||
|
||||
setTimeout(() => {
|
||||
this.handleCountDown();
|
||||
}, 1000);
|
||||
@ -874,11 +872,14 @@ export class ActionRenderer extends React.Component<
|
||||
}
|
||||
|
||||
if (!ignoreConfirm && action.confirmText && env.confirm) {
|
||||
env
|
||||
.confirm(filter(action.confirmText, data))
|
||||
.then((confirmed: boolean) => confirmed && onAction(e, action, data));
|
||||
let confirmed = await env.confirm(filter(action.confirmText, data));
|
||||
if (confirmed) {
|
||||
await onAction(e, action, data);
|
||||
} else if (action.countDown) {
|
||||
throw new Error('cancel');
|
||||
}
|
||||
} else {
|
||||
onAction(e, action, data);
|
||||
await onAction(e, action, data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -665,7 +665,11 @@ export default class CRUD extends React.Component<CRUDProps, any> {
|
||||
: this.search(undefined, undefined, true, true);
|
||||
action.close && this.closeTarget(action.close);
|
||||
})
|
||||
.catch(() => {});
|
||||
.catch((e) => {
|
||||
if (throwErrors || action.countDown) {
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
} else if (
|
||||
pickerMode &&
|
||||
(action.actionType === 'confirm' || action.actionType === 'submit')
|
||||
|
@ -538,7 +538,8 @@ export default class Dialog extends React.Component<DialogProps> {
|
||||
</a>
|
||||
) : null}
|
||||
{render('title', title, {
|
||||
data: store.formData
|
||||
data: store.formData,
|
||||
onAction: this.handleAction
|
||||
})}
|
||||
</div>
|
||||
) : showCloseButton !== false && !store.loading ? (
|
||||
@ -553,7 +554,8 @@ export default class Dialog extends React.Component<DialogProps> {
|
||||
|
||||
{header
|
||||
? render('header', header, {
|
||||
data: store.formData
|
||||
data: store.formData,
|
||||
onAction: this.handleAction
|
||||
})
|
||||
: null}
|
||||
|
||||
@ -827,7 +829,11 @@ export class DialogRenderer extends Dialog {
|
||||
this.closeTarget(action.close);
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
.catch(e => {
|
||||
if (throwErrors || action.countDown) {
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
} else if (onAction) {
|
||||
let ret = onAction(
|
||||
e,
|
||||
|
@ -821,7 +821,11 @@ export class DrawerRenderer extends Drawer {
|
||||
this.closeTarget(action.close);
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
.catch((e) => {
|
||||
if (throwErrors || action.countDown) {
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
} else if (onAction) {
|
||||
let ret = onAction(
|
||||
e,
|
||||
|
@ -1193,7 +1193,7 @@ export default class Form extends React.Component<FormProps, object> {
|
||||
})
|
||||
.catch(e => {
|
||||
onFailed && onFailed(e, store.errors);
|
||||
if (throwErrors) {
|
||||
if (throwErrors || action.countDown) {
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
@ -467,6 +467,7 @@ export default class Page extends React.Component<PageProps> {
|
||||
store.openDrawer(ctx);
|
||||
} else if (action.actionType === 'ajax') {
|
||||
store.setCurrentAction(action);
|
||||
|
||||
return store
|
||||
.saveRemote(action.api as string, ctx, {
|
||||
successMessage:
|
||||
@ -486,7 +487,11 @@ export default class Page extends React.Component<PageProps> {
|
||||
redirect && env.jumpTo(redirect, action);
|
||||
action.reload && this.reloadTarget(action.reload, store.data);
|
||||
})
|
||||
.catch(() => {});
|
||||
.catch((e) => {
|
||||
if (throwErrors || action.countDown) {
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return onAction(e, action, ctx, throwErrors, delegate || this.context);
|
||||
}
|
||||
|
@ -523,7 +523,11 @@ export default class Service extends React.Component<ServiceProps> {
|
||||
redirect && env.jumpTo(redirect, action);
|
||||
action.reload && this.reloadTarget(action.reload, store.data);
|
||||
})
|
||||
.catch(() => {});
|
||||
.catch((e) => {
|
||||
if (throwErrors || action.countDown) {
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
onAction(e, action, data, throwErrors, delegate || this.context);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user