feat: 新增forceSilenceInsideError环境变量支持屏蔽组件中展示msg信息 (#8722)

* feat: 支持屏蔽组件中展示msg信息,默认展示

* feat: 提交遗漏字段

* 修改字段名,增加注释

---------

Co-authored-by: zhaojianhui <zhaojianhui@baidu.com>
This commit is contained in:
zhaojianhui 2023-11-15 16:37:11 +08:00 committed by GitHub
parent 1f1ce12d73
commit e44425b356
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 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

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

View File

@ -500,6 +500,7 @@ export default class Dialog extends React.Component<DialogProps> {
const {
store,
render,
env,
classnames: cx,
showErrorMsg,
showLoading,
@ -514,7 +515,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

@ -491,6 +491,7 @@ export default class Drawer extends React.Component<DrawerProps> {
const {
store,
render,
env,
classnames: cx,
showErrorMsg,
footerClassName
@ -501,7 +502,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

@ -853,6 +853,7 @@ export default class Page extends React.Component<PageProps> {
body,
bodyClassName,
render,
env,
aside,
asideClassName,
classnames: cx,
@ -896,7 +897,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

@ -785,6 +785,7 @@ export default class Service extends React.Component<ServiceProps> {
style,
store,
render,
env,
classPrefix: ns,
classnames: cx,
loadingConfig,
@ -793,7 +794,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