msg 优化,成功提示支持 msgTimeout (#1471)

* msg优化,成功提示支持msgTimeout

* fix notify
This commit is contained in:
RickCole 2021-01-28 11:41:58 +08:00 committed by GitHub
parent ef954daa5c
commit 9dd69d128a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 25 deletions

View File

@ -124,7 +124,14 @@ export interface RenderOptions {
session?: string;
fetcher?: (config: fetcherConfig) => Promise<fetcherResult>;
isCancel?: (value: any) => boolean;
notify?: (type: 'error' | 'success', msg: string) => void;
notify?: (
type: 'error' | 'success',
msg: string,
conf?: {
closeButton?: boolean;
timeout?: number;
}
) => void;
jumpTo?: (to: string, action?: Action, ctx?: object) => void;
alert?: (msg: string) => void;
confirm?: (msg: string, title?: string) => boolean | Promise<boolean>;
@ -272,9 +279,9 @@ const defaultOptions: RenderOptions = {
},
alert,
confirm,
notify: (type, msg) =>
notify: (type, msg, conf) =>
toast[type]
? toast[type](msg, type === 'error' ? 'Error' : 'Info')
? toast[type](msg, type === 'error' ? 'Error' : 'Info', conf)
: console.warn('[Notify]', type, msg),
jumpTo: (to: string, action?: any) => {

View File

@ -192,7 +192,7 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
if (!json.ok) {
self.updateMessage(
json.msg || options.errorMessage || self.__('CRUD.fetchFailed'),
json.msg ?? options.errorMessage ?? self.__('CRUD.fetchFailed'),
true
);
getEnv(self).notify(
@ -301,7 +301,7 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
self.hasNext = !!hasNext;
}
self.updateMessage(json.msg || options.successMessage);
self.updateMessage(json.msg ?? options.successMessage);
// 配置了获取成功提示后提示,默认是空不会提示。
options &&
@ -371,7 +371,7 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
if (!json.ok) {
self.updateMessage(
json.msg || options.errorMessage || self.__('saveFailed'),
json.msg ?? options.errorMessage ?? self.__('saveFailed'),
true
);
getEnv(self).notify(
@ -386,8 +386,18 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
);
throw new ServerError(self.msg);
} else {
self.updateMessage(json.msg || options.successMessage);
self.msg && getEnv(self).notify('success', self.msg);
self.updateMessage(json.msg ?? options.successMessage);
self.msg &&
getEnv(self).notify(
'success',
self.msg,
json.msgTimeout !== undefined
? {
closeButton: true,
timeout: json.msgTimeout
}
: undefined
);
}
return json.data;
} catch (e) {

View File

@ -311,14 +311,14 @@ export const FormStore = ServiceStore.named('FormStore')
!isEmpty(errors) && setRestErrors(errors);
self.updateMessage(
json.msg ||
self.__(options && options.errorMessage) ||
json.msg ??
self.__(options && options.errorMessage) ??
self.__('Form.validateFailed'),
true
);
} else {
self.updateMessage(
json.msg || self.__(options && options.errorMessage),
json.msg ?? self.__(options && options.errorMessage),
true
);
}
@ -335,9 +335,19 @@ export const FormStore = ServiceStore.named('FormStore')
}
self.markSaving(false);
self.updateMessage(
json.msg || self.__(options && options.successMessage)
json.msg ?? self.__(options && options.successMessage)
);
self.msg && getEnv(self).notify('success', self.msg);
self.msg &&
getEnv(self).notify(
'success',
self.msg,
json.msgTimeout !== undefined
? {
closeButton: true,
timeout: json.msgTimeout
}
: undefined
);
return json.data;
}
} catch (e) {

View File

@ -475,7 +475,7 @@ export const FormItemStore = StoreNode.named('FormItemStore')
setErrorFlag !== false &&
setError(
self.__('Form.loadOptionsFailed', {
reason: json.msg || (config && config.errorMessage)
reason: json.msg ?? (config && config.errorMessage)
})
);
getEnv(self).notify(

View File

@ -80,7 +80,7 @@ export const ServiceStore = iRendererStore
fetchCancel = null;
if (!json.ok) {
updateMessage(json.msg || (options && options.errorMessage), true);
updateMessage(json.msg ?? (options && options.errorMessage), true);
getEnv(self).notify(
'error',
json.msg,
@ -108,7 +108,7 @@ export const ServiceStore = iRendererStore
}
}
updateMessage(json.msg || (options && options.successMessage));
updateMessage(json.msg ?? (options && options.successMessage));
// 配置了获取成功提示后提示,默认是空不会提示。
options &&
@ -181,7 +181,7 @@ export const ServiceStore = iRendererStore
}
if (!json.ok) {
updateMessage(json.msg || (options && options.errorMessage), true);
updateMessage(json.msg ?? (options && options.errorMessage), true);
getEnv(self).notify(
'error',
self.msg,
@ -201,7 +201,7 @@ export const ServiceStore = iRendererStore
}
}
updateMessage(json.msg || (options && options.successMessage));
updateMessage(json.msg ?? (options && options.successMessage));
// 配置了获取成功提示后提示,默认是空不会提示。
options &&
@ -268,8 +268,8 @@ export const ServiceStore = iRendererStore
if (!json.ok) {
updateMessage(
json.msg ||
(options && options.errorMessage) ||
json.msg ??
(options && options.errorMessage) ??
self.__('saveFailed'),
true
);
@ -283,8 +283,18 @@ export const ServiceStore = iRendererStore
}
}
updateMessage(json.msg || (options && options.successMessage));
self.msg && getEnv(self).notify('success', self.msg);
updateMessage(json.msg ?? (options && options.successMessage));
self.msg &&
getEnv(self).notify(
'success',
self.msg,
json.msgTimeout !== undefined
? {
closeButton: true,
timeout: json.msgTimeout
}
: undefined
);
}
markSaving(false);
@ -362,8 +372,8 @@ export const ServiceStore = iRendererStore
if (!json.ok) {
updateMessage(
json.msg ||
(options && options.errorMessage) ||
json.msg ??
(options && options.errorMessage) ??
self.__('fetchFailed'),
true
);
@ -388,7 +398,7 @@ export const ServiceStore = iRendererStore
!!(api as ApiObject).replaceData
);
}
updateMessage(json.msg || (options && options.successMessage));
updateMessage(json.msg ?? (options && options.successMessage));
// 配置了获取成功提示后提示,默认是空不会提示。
options &&