Merge pull request #6378 from 2betop/chore-alert

chore: alert 支持多个实例
This commit is contained in:
hsm-lv 2023-03-15 14:03:28 +08:00 committed by GitHub
commit 4b3b1505dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,7 @@ export interface AlertProps extends ThemeProps, LocaleProps {
title?: string;
confirmBtnLevel?: string;
alertBtnLevel?: string;
isolate?: boolean;
}
export interface AlertState {
@ -54,6 +55,7 @@ export class Alert extends React.Component<AlertProps, AlertState> {
content: '',
confirm: false
};
originInstance: Alert | null;
constructor(props: AlertProps) {
super(props);
@ -64,8 +66,11 @@ export class Alert extends React.Component<AlertProps, AlertState> {
this.handleFormSubmit = this.handleFormSubmit.bind(this);
this.scopeRef = this.scopeRef.bind(this);
if (!props.isolate) {
this.originInstance = Alert.instance;
Alert.instance = this;
}
}
static defaultProps = {
confirmText: 'confirm',
@ -86,7 +91,10 @@ export class Alert extends React.Component<AlertProps, AlertState> {
}
componentWillUnmount() {
Alert.instance = null;
if (Alert.instance === this) {
Alert.instance = this.originInstance || null;
this.originInstance = null;
}
}
schemaSope: any;