Skip to content

Commit 5fb4b28

Browse files
committed
fix(Message): 修复message重复进入位置异常与single默认值改为true (#2711)
1 parent e4742fc commit 5fb4b28

16 files changed

+68
-32
lines changed

src/message-item/index.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { MessageType, MessageProps } from '../message/message.interface';
2+
import { getInstance } from '../common/utils';
3+
4+
type Context = WechatMiniprogram.Page.TrivialInstance | WechatMiniprogram.Component.TrivialInstance;
5+
6+
interface MessageActionOptionsType extends Optional<MessageProps> {
7+
context?: Context;
8+
selector?: string;
9+
}
10+
11+
const showMessage = function (options: MessageActionOptionsType, theme: MessageType = MessageType.info) {
12+
const { context, selector = '#t-message', ...otherOptions } = options;
13+
const instance = getInstance(context, selector);
14+
15+
if (instance) {
16+
instance.resetData(() => {
17+
instance.setData({ theme, ...otherOptions }, instance.show.bind(instance));
18+
});
19+
20+
return instance;
21+
}
22+
console.error('未找到组件,请确认 selector && context 是否正确');
23+
};
24+
25+
export default {
26+
info(options: MessageActionOptionsType) {
27+
return showMessage(options, MessageType.info);
28+
},
29+
success(options: MessageActionOptionsType) {
30+
return showMessage(options, MessageType.success);
31+
},
32+
warning(options: MessageActionOptionsType) {
33+
return showMessage(options, MessageType.warning);
34+
},
35+
error(options: MessageActionOptionsType) {
36+
return showMessage(options, MessageType.error);
37+
},
38+
hide(options: MessageActionOptionsType) {
39+
const { context, selector = '#t-message' } = { ...options };
40+
const instance = getInstance(context, selector);
41+
if (!instance) {
42+
return;
43+
}
44+
instance.hide();
45+
},
46+
};

src/message/message-item/message.json renamed to src/message-item/message-item.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"component": true,
33
"styleIsolation": "apply-shared",
44
"usingComponents": {
5-
"t-icon": "../../icon/icon",
6-
"t-link": "../../link/link"
5+
"t-icon": "../icon/icon",
6+
"t-link": "../link/link"
77
}
88
}

src/message/message-item/message.less renamed to src/message-item/message-item.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import '../../common/style/index.less';
1+
@import '../common/style/index.less';
22

33
@message-height: 96rpx;
44
@message-horizontal-padding: 32rpx;

src/message/message-item/message.ts renamed to src/message-item/message-item.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { SuperComponent, wxComponent, ComponentsOptionsType } from '../../common/src/index';
2-
import config from '../../common/config';
3-
import { MessageProps } from '../message.interface';
4-
import props from '../props';
5-
import { getRect, unitConvert, calcIcon, isObject } from '../../common/utils';
1+
import { SuperComponent, wxComponent, ComponentsOptionsType } from '../common/src/index';
2+
import config from '../common/config';
3+
import { MessageProps } from '../message/message.interface';
4+
import props from '../message/props';
5+
import { getRect, unitConvert, calcIcon, isObject } from '../common/utils';
66

77
const { prefix } = config;
88
const name = `${prefix}-message`;

src/message/message-item/message.wxml renamed to src/message-item/message-item.wxml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<wxs src="./message.wxs" module="this"></wxs>
2-
<wxs src="../../common/utils.wxs" module="_" />
3-
<import src="../../common/template/icon.wxml" />
1+
<wxs src="./message-item.wxs" module="this"></wxs>
2+
<wxs src="../common/utils.wxs" module="_" />
3+
<import src="../common/template/icon.wxml" />
44
<block wx:if="{{visible}}">
55
<view
66
class="{{classPrefix}} class {{prefix}}-class {{classPrefix}}--{{theme}} {{fadeClass}}"

src/message/README.en-US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ theme | String | info | options:info/success/warning/error。Typescript:`Mes
1818
visible | Boolean | false | \- | N
1919
default-visible | Boolean | false | uncontrolled property | N
2020
z-index | Number | 15000 | \- | N
21-
single | Boolean | false | Whether to display only one message. Note that when single=false, the three categories of link, scroll, and close will not be covered.| N
21+
single | Boolean | true | Whether to display only one message. Note that when single=false, the three categories of link, scroll, and close will not be covered.| N
2222
gap | String | 12 | The spacing between two messages, default 12px. Example: '12', '12px', '18rpx' | N
2323

2424
### Message Events

src/message/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ visible | Boolean | false | 是否显示,隐藏时默认销毁组件 | N
5858
default-visible | Boolean | false | 是否显示,隐藏时默认销毁组件。非受控属性 | N
5959
z-index | Number | 15000 | 元素层级,样式默认为 15000 | N
6060
link | String / Object / Slot | - | 链接名称。值为字符串表示链接名称,值为 `Object` 类型,表示透传至 `Link`。 | N
61-
single | Boolean | false | 是否仅显示一条消息。注意 single=false 时带链接、滚动、带关闭此三类不会被覆盖 | N
61+
single | Boolean | true | 是否仅显示一条消息。注意 single=false 时带链接、滚动、带关闭此三类不会被覆盖 | N
6262
gap | String | 12 | 两条消息之间的间距,默认12px。示例:'12', '12px', '18rpx' | N
6363
### Message Events
6464

src/message/__test__/__snapshots__/demo.test.js.snap

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,6 @@ exports[`Message Message base demo works fine 1`] = `
5858
>
5959
带按钮的通知
6060
</t-button>
61-
<t-button
62-
block="{{true}}"
63-
size="large"
64-
tClass="external-class"
65-
theme="primary"
66-
variant="outline"
67-
bind:tap="showSingleMessage"
68-
>
69-
纯文字的通知单例
70-
</t-button>
7161
</wx-view>
7262
</base>
7363
`;

src/message/__test__/__snapshots__/index.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ exports[`message props : style && customStyle 1`] = `
66
id="t-message"
77
>
88
<t-message-item
9-
id="t-message_0"
9+
id="t-message"
1010
bind:close-btn-click="handleClose"
1111
bind:link-click="handleLinkClick"
1212
>
1313
<wx-view
1414
animation="{{Array []}}"
1515
ariaRole="alert"
1616
class="t-message class t-class t-message--warning "
17-
id="t-message_0"
17+
id="t-message"
1818
style="z-index:15000;top:20px;left:32rpx;right:32rpx; color: red; font-size: 9px;"
1919
>
2020
<wx-view

src/message/__test__/index.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ describe('message', () => {
206206
content: `这是第${i}条消息通知`,
207207
duration: -1,
208208
gap: '16',
209+
single: false,
209210
});
210211
};
211212
showMessageFn('1');

src/message/_example/base/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Component({
88
offset: [90, 32],
99
duration: 5000,
1010
icon: false,
11+
// single: false, // 打开注释体验多个消息叠加效果
1112
content: '这是一条纯文字的消息通知 5s消失',
1213
});
1314
},

src/message/_example/base/index.wxml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,4 @@
2020
<t-button t-class="external-class" theme="primary" variant="outline" size="large" block bind:tap="showBtnMessage"
2121
>带按钮的通知</t-button
2222
>
23-
24-
<t-button t-class="external-class" theme="primary" variant="outline" size="large" block bind:tap="showSingleMessage"
25-
>纯文字的通知单例</t-button
26-
>
2723
</view>

src/message/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ interface MessageActionOptionsType extends Optional<MessageProps> {
1111
const showMessage = function (options: MessageActionOptionsType, theme: MessageType = MessageType.info) {
1212
const { context, selector = '#t-message', ...otherOptions } = options;
1313
const instance = getInstance(context, selector);
14-
14+
if (typeof otherOptions.single !== 'boolean') {
15+
otherOptions.single = true;
16+
}
1517
if (instance) {
1618
instance.setMessage(otherOptions, theme);
1719
return instance;

src/message/message.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"component": true,
33
"styleIsolation": "apply-shared",
44
"usingComponents": {
5-
"t-message-item": "./message-item/message"
5+
"t-message-item": "../message-item/message-item"
66
}
77
}

src/message/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const props: TdMessageProps = {
8383
*/
8484
single: {
8585
type: Boolean,
86-
value: false,
86+
value: true,
8787
},
8888
};
8989

0 commit comments

Comments
 (0)