mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 12:08:13 +08:00
Merge pull request #4277 from pianruijie/feat/form-event-action
feat:toast支持取消合并state
This commit is contained in:
commit
a249f9faf7
@ -179,43 +179,19 @@ export default {
|
||||
submitSucc: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'dialog',
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
val: '${event.data}'
|
||||
},
|
||||
dialog: {
|
||||
title: `提交成功`,
|
||||
data: {
|
||||
val: '${val}'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'tpl',
|
||||
tpl: '${val|json}'
|
||||
}
|
||||
]
|
||||
msg: '提交成功:${event.data|json}'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
submitFail: {
|
||||
submitSucc: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'dialog',
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
val: '${event.data}'
|
||||
},
|
||||
dialog: {
|
||||
title: `提交失败`,
|
||||
data: {
|
||||
val: '${val}'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'tpl',
|
||||
tpl: '${val|json}'
|
||||
}
|
||||
]
|
||||
msg: '提交失败:${event.data|json}'
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -13,7 +13,7 @@ import Transition, {
|
||||
import React from 'react';
|
||||
import cx from 'classnames';
|
||||
import Html from './Html';
|
||||
import {uuid, autobind, noop, isMobile} from '../utils/helper';
|
||||
import {guid, autobind, noop, isMobile} from '../utils/helper';
|
||||
import {ClassNamesFn, themeable, classnames, ThemeProps} from '../theme';
|
||||
import {Icon} from './icons';
|
||||
import {LocaleProps, localeable, TranslateFn} from '../locale';
|
||||
@ -115,23 +115,25 @@ export class ToastComponent extends React.Component<
|
||||
}
|
||||
|
||||
notifiy(level: string, content: any, config?: any) {
|
||||
let items = this.state.items.concat();
|
||||
const useMobileUI = (config.useMobileUI || this.props.useMobileUI) && isMobile();
|
||||
if (useMobileUI) {
|
||||
// 移动端只能存在一个
|
||||
items = [];
|
||||
}
|
||||
items.push({
|
||||
body: content,
|
||||
level,
|
||||
...config,
|
||||
id: uuid(),
|
||||
position: config.position || (useMobileUI ? 'center' : config.position),
|
||||
timeout: config.timeout || (useMobileUI ? 3000 : undefined),
|
||||
});
|
||||
this.setState({
|
||||
items,
|
||||
useMobileUI
|
||||
this.setState((state) => {
|
||||
let items = state.items.concat();
|
||||
if (useMobileUI) {
|
||||
// 移动端只能存在一个
|
||||
items = [];
|
||||
}
|
||||
items.push({
|
||||
body: content,
|
||||
level,
|
||||
...config,
|
||||
id: guid(),
|
||||
position: config.position || (useMobileUI ? 'center' : config.position),
|
||||
timeout: config.timeout || (useMobileUI ? 3000 : undefined),
|
||||
});
|
||||
return {
|
||||
items,
|
||||
useMobileUI
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -184,7 +186,6 @@ export class ToastComponent extends React.Component<
|
||||
const items = this.state.items;
|
||||
const mobileUI = (useMobileUI || this.state.useMobileUI) && isMobile();
|
||||
const groupedItems = groupBy(items, item => item.position || position);
|
||||
|
||||
return Object.keys(groupedItems).map(position => {
|
||||
const toasts = groupedItems[position];
|
||||
return (
|
||||
|
@ -138,7 +138,6 @@ export async function dispatchEvent(
|
||||
|
||||
unbindEvent = bindEvent(renderer);
|
||||
}
|
||||
|
||||
// 没有可处理的监听
|
||||
if (!rendererEventListeners.length) {
|
||||
return Promise.resolve();
|
||||
@ -152,7 +151,6 @@ export async function dispatchEvent(
|
||||
data,
|
||||
scoped
|
||||
});
|
||||
|
||||
// 过滤&排序
|
||||
const listeners = rendererEventListeners
|
||||
.filter(
|
||||
|
Loading…
Reference in New Issue
Block a user