From b5166edeec62c8598192f755155ab633bb9b81b7 Mon Sep 17 00:00:00 2001 From: lao Date: Wed, 25 Sep 2024 14:17:10 +0800 Subject: [PATCH] =?UTF-8?q?udpate=20message:=E7=A9=BA=E5=80=BC=E6=8B=A6?= =?UTF-8?q?=E6=88=AA=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/message/demo/empty-disabled.md | 56 +++++++++++++++++++++++ components/message/index.tsx | 11 +++++ 2 files changed, 67 insertions(+) create mode 100644 components/message/demo/empty-disabled.md diff --git a/components/message/demo/empty-disabled.md b/components/message/demo/empty-disabled.md new file mode 100644 index 0000000..74bb990 --- /dev/null +++ b/components/message/demo/empty-disabled.md @@ -0,0 +1,56 @@ +--- +order: 9 +title: + zh-CN: emptyDisabled配置项 + en-US: emptyDisabled +--- + +## zh-CN + +通过message.config可设置emptyDisabled配置项:若设置为true,则拒绝空内容(如mesage.error("")或message.error(undefined))弹出 + +## en-US + +emptyDisabled + +```jsx +import { message,Switch, Button, Space } from 'apusic-ui'; + +const infoEmptyStr = () => { + message.info(''); +}; +const infoUndefined = () => { + message.info(undefined); +}; +const commoninfoEmptyStr = () => { + message.success({ content: '', duration: 2, showStyle: false }); +}; + +function handleChangeOfEmptyDisabled(checked){ + message.config({ + emptyDisabled:checked + }); +} + +ReactDOM.render( +
+
+ emptyDisabled: + +
+
+ + + + + +
, + mountNode, +); +``` diff --git a/components/message/index.tsx b/components/message/index.tsx index 3234477..fc5def1 100755 --- a/components/message/index.tsx +++ b/components/message/index.tsx @@ -24,6 +24,7 @@ let getContainer: () => HTMLElement; let maxCount: number; let rtl = false; let shouldLockKeyByContent:boolean = false; //若设置为true,则默认设置message的key为content(当content为string类型的时候) +let emptyDisabled:boolean = false; //若设置为true,则则拒绝空内容(如mesage.error("")或message.error(undefined))弹出 export function getKeyThenIncreaseKey() { return key++; @@ -31,6 +32,7 @@ export function getKeyThenIncreaseKey() { export interface ConfigOptions { shouldLockKeyByContent?: boolean; //若设置为true,则默认设置message的key为content(当content为string类型的时候) + emptyDisabled?: boolean; //若设置为true,则则拒绝空内容(如mesage.error("")或message.error(undefined))弹出 top?: number; duration?: number; prefixCls?: string; @@ -70,6 +72,11 @@ function setMessageConfig(options: ConfigOptions) { shouldLockKeyByContent = options.shouldLockKeyByContent; messageInstance = null; } + + if(options.emptyDisabled !== undefined) { + emptyDisabled = options.emptyDisabled; + messageInstance = null; + } } function getRCNotificationInstance( @@ -173,6 +180,10 @@ function notice(args: ArgsProps): MessageType { //默认设置message的key为content(当content为string类型的时候) forceKey = args.content; } + if(emptyDisabled&&(args.content===""||args.content===undefined)){ + console.log("message空值拦截"); + return (()=>{}) as any; //空值拦截 + } // const target = args.key || key++; const target = forceKey || key++; const closePromise = new Promise(resolve => { -- Gitee