Skip to content

Commit 12e0b7a

Browse files
committed
feat: notify
1 parent 6d38c6d commit 12e0b7a

File tree

4 files changed

+119
-15
lines changed

4 files changed

+119
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { shallowMount, mount } from '@vue/test-utils'
2+
import Notify from '../notify.vue';
3+
import Vue from 'vue';
4+
5+
6+
describe('notify.vue', () => {
7+
const wrapper = shallowMount(Notify, {
8+
propsData: {
9+
type: 'warn',
10+
msg: "通知内容"
11+
}
12+
});
13+
14+
it('自定义背景色和字体颜色', () => {
15+
wrapper.setProps({
16+
color: '#ad0000',
17+
background: '#ffe1e1'
18+
});
19+
return Vue.nextTick().then(function () {
20+
expect(wrapper.find('.nut-notify').hasStyle('color', '#ad0000')).toBe(true);
21+
expect(wrapper.find('.nut-notify').hasStyle('background', '#ffe1e1')).toBe(true);
22+
})
23+
});
24+
// it('自定义时长', () => {
25+
// wrapper.setProps({
26+
// color: '#ad0000',
27+
// background: '#ffe1e1'
28+
// });
29+
// return Vue.nextTick().then(function () {
30+
// expect(wrapper.find('.nut-notify').hasStyle('color', '#ad0000')).toBe(true);
31+
// expect(wrapper.find('.nut-notify').hasStyle('background', '#ffe1e1')).toBe(true);
32+
// })
33+
// });
34+
});

src/packages/notify/demo.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
<label>组件调用</label>
6161
</span>
6262
</nut-cell>
63-
<nut-notify :showPopup="show" type="success" msg="组件调用">
64-
<span>hello</span>
63+
<nut-notify :showPopup="show" type="success" msg="hello" duration="10000">
64+
<!-- <span>hello</span> -->
6565
</nut-notify>
6666
</div>
6767
<h4>修改默认配置</h4>
@@ -129,7 +129,7 @@ export default {
129129
this.show = true;
130130
setTimeout(() => {
131131
this.show = false;
132-
}, 2000);
132+
}, 200);
133133
},
134134
defaultNotify() {
135135
this.$notify.setDefaultOptions({

src/packages/notify/doc.md

+81-11
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,92 @@
22

33
## 基本用法
44

5-
```html
6-
<nut-noticebar
7-
text="华为畅享9新品即将上市,活动期间0元预约可参与抽奖,赢HUAWEI WATCH等好礼,更多产品信息请持续关注!"
8-
></nut-noticebar>
5+
文字提示
6+
```javascript
7+
export default {
8+
mounted() {
9+
this.$notify.text('通知内容', {
10+
onClosed() {
11+
console.log('close');
12+
},
13+
onClick: () => {
14+
console.log('click');
15+
},
16+
onOpened: () => {
17+
console.log('opened');
18+
}
19+
});
20+
}
21+
}
922
```
1023
## 通知类型
11-
文字内容多于一行时,可通过scrollable参数控制是否开启滚动
12-
```html
13-
<nut-noticebar
14-
text="华为畅享9新品即将上市,活动期间0元预约可参与抽奖,赢HUAWEI WATCH等好礼,更多产品信息请持续关注!"
15-
:scrollable="false"
16-
></nut-noticebar>
24+
### 主要通知
25+
```javascript
26+
mounted(){
27+
this.$notify.primary('通知内容');
28+
}
29+
```
30+
### 成功通知
31+
```javascript
32+
mounted(){
33+
this.$notify.success('通知内容');
34+
}
35+
```
36+
### 危险通知
37+
```javascript
38+
mounted(){
39+
this.$notify.danger('通知内容');
40+
}
41+
```
42+
### 警告通知
43+
```javascript
44+
mounted(){
45+
this.$notify.warn('通知内容');
46+
}
1747
```
1848
## 自定义样式
49+
### 自定义样式
50+
```javascript
51+
mounted(){
52+
this.$notify.text(val, {
53+
color: '#ad0000',
54+
background: '#ffe1e1'
55+
});
56+
}
57+
```
58+
### 自定义时长
59+
```javascript
60+
mounted(){
61+
this.$notify.text(val, {
62+
duration: 10000
63+
});
64+
}
65+
```
66+
## 组件调用
67+
```html
68+
<nut-notify :showPopup="show" type="success" msg="组件调用">
69+
<span>hello</span>
70+
</nut-notify>
71+
```
1972

73+
```javascript
74+
mounted(){
75+
this.show = true;
76+
setTimeout(() => {
77+
this.show = false;
78+
}, 2000);
79+
}
80+
```
81+
## 修改默认配置
82+
通过**Notify.setDefaultOptions**函数可以全局修改 Notify 的默认配置,**值得注意的是,标签形式的组件不支持默认样式**
83+
```javascript
84+
// 更改所有Toast展示时长设置为5000毫秒
85+
this.$notify.setDefaultOptions({
86+
duration: 5000
87+
});
88+
// 重置所有 Toast 的默认配置
89+
this.$notify.resetDefaultOptions();
90+
```
2091

2192

2293

@@ -45,6 +116,5 @@
45116
| 方法名 | 说明 | 参数 | 返回值 |
46117
| -------------------------- | -------------------------------- | ------- | ------- |
47118
| Notify | 提示的信息 | options | message | notify 实例 |
48-
| Notify.clear | 关闭提示 | - | void |
49119
| Notify.setDefaultOptions | 修改默认配置,对所有 Notify 生效 | options | void |
50120
| Notify.resetDefaultOptions | 重置默认配置,对所有 Notify 生效 | String | void |

src/packages/notify/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import './notify.scss';
55
const NotifyArr = [Notify, NotifyVue];
66
// console.log(NotifyArr, Notify.text('Notify'));
77
NotifyArr.install = function (Vue) {
8-
Vue.prototype['$notify'] = Notify;
8+
// Vue.prototype['$notify'] = Notify;
99
Vue.component(NotifyVue.name, NotifyVue);
1010
};
1111

0 commit comments

Comments
 (0)