feat: 支持屏蔽组件中展示msg信息,默认展示 (#8751)

Co-authored-by: zhaojianhui <zhaojianhui@baidu.com>
This commit is contained in:
zhaojianhui 2023-11-16 16:01:48 +08:00 committed by GitHub
parent 90ec85977d
commit 58a66fbdf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 5 deletions

View File

@ -28,6 +28,8 @@ export interface WsObject {
}
export interface RendererEnv {
/* 强制隐藏组件内部的报错信息,会覆盖组件内部属性 */
forceSilenceInsideError?: boolean;
session?: string;
fetcher: (api: Api, data?: any, options?: object) => Promise<Payload>;
isCancel: (val: any) => boolean;

View File

@ -51,5 +51,7 @@ export const env: RenderOptions = {
toast[type]
? toast[type](msg, type === 'error' ? '系统错误' : '系统消息')
: console.warn('[Notify]', type, msg);
}
},
/* 强制隐藏组件内部的报错信息,会覆盖组件内部属性 */
forceSilenceInsideError: false
};

View File

@ -502,6 +502,7 @@ export default class Dialog extends React.Component<DialogProps> {
const {
store,
render,
env,
classnames: cx,
showErrorMsg,
showLoading,
@ -517,7 +518,9 @@ export default class Dialog extends React.Component<DialogProps> {
{showLoading !== false ? (
<Spinner size="sm" key="info" show={store.loading} />
) : null}
{store.error && showErrorMsg !== false ? (
{!env.forceSilenceInsideError &&
store.error &&
showErrorMsg !== false ? (
<span className={cx('Dialog-error')}>{store.msg}</span>
) : null}
</div>

View File

@ -497,6 +497,7 @@ export default class Drawer extends React.Component<DrawerProps> {
const {
store,
render,
env,
classnames: cx,
showErrorMsg,
footerClassName,
@ -515,7 +516,7 @@ export default class Drawer extends React.Component<DrawerProps> {
{store.loading || store.error ? (
<div className={cx('Drawer-info')}>
<Spinner size="sm" key="info" show={store.loading} />
{showErrorMsg && store.error ? (
{!env.forceSilenceInsideError && showErrorMsg && store.error ? (
<span className={cx('Drawer-error')}>{store.msg}</span>
) : null}
</div>

View File

@ -924,7 +924,9 @@ export default class Page extends React.Component<PageProps> {
loadingConfig={loadingConfig}
/>
{store.error && showErrorMsg !== false ? (
{!env.forceSilenceInsideError &&
store.error &&
showErrorMsg !== false ? (
<Alert
level="danger"
showCloseButton

View File

@ -793,6 +793,7 @@ export default class Service extends React.Component<ServiceProps> {
style,
store,
render,
env,
classPrefix: ns,
classnames: cx,
loadingConfig,
@ -801,7 +802,9 @@ export default class Service extends React.Component<ServiceProps> {
return (
<div className={cx(`${ns}Service`, className)} style={style}>
{store.error && showErrorMsg !== false ? (
{!env.forceSilenceInsideError &&
store.error &&
showErrorMsg !== false ? (
<Alert
level="danger"
showCloseButton