vdesign-ui 0.2.8 → 0.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,8 @@ import Vue from 'vue';
2
2
  import ToastComponent from './index.vue';
3
3
  import { inBrowser } from '../utils/env';
4
4
 
5
+ let queueResult = []
6
+ let allowMultiple = false
5
7
 
6
8
  function getType(value) {
7
9
  if (value !== value) return 'NaN';
@@ -12,8 +14,8 @@ class VdToast extends Vue.extend(ToastComponent) {
12
14
  constructor(options) {
13
15
  super();
14
16
  this.vm = this.$mount();
15
-
16
17
  this.timer = null
18
+ this.allowMultiple = allowMultiple
17
19
 
18
20
  // 判断传入的 options 类型,并进行赋值
19
21
  if (typeof options === 'string' || typeof options === 'number') {
@@ -33,11 +35,16 @@ class VdToast extends Vue.extend(ToastComponent) {
33
35
  init() {
34
36
  if (inBrowser) {
35
37
  document.body.appendChild(this.vm.$el)
38
+ if (!this.allowMultiple) {
39
+ queueResult.forEach(toast => {
40
+ toast.clear()
41
+ })
42
+ queueResult = [];
43
+ }
36
44
  this.start()
37
45
  }
38
46
  }
39
47
 
40
-
41
48
  start() {
42
49
  clearTimeout(this.timer)
43
50
  /**
@@ -51,7 +58,6 @@ class VdToast extends Vue.extend(ToastComponent) {
51
58
  }, 0)
52
59
  }
53
60
 
54
-
55
61
  end() {
56
62
  /**
57
63
  * 关闭过渡效果之后移除真实 DOM 树节点
@@ -65,12 +71,27 @@ class VdToast extends Vue.extend(ToastComponent) {
65
71
  this.isShow = false
66
72
  if (inBrowser && this.vm.$el) {
67
73
  setTimeout(() => {
68
- this.vm.$el.parentNode.removeChild(this.vm.$el);
74
+ this.vm.$el.parentNode && this.vm.$el.parentNode.removeChild(this.vm.$el);
69
75
  }, 500)
70
76
  }
71
77
  }
72
78
  }
73
79
 
74
- const Toast = options => new VdToast(options)
80
+ const Toast = (options) => {
81
+ const NewOption = new VdToast(options)
82
+ queueResult.push(NewOption)
83
+ return NewOption
84
+ }
85
+
86
+ Toast.clear = () => {
87
+ queueResult.forEach(toast => {
88
+ toast.clear()
89
+ })
90
+ queueResult = [];
91
+ }
92
+
93
+ Toast.allowMultiple = () => {
94
+ allowMultiple = true
95
+ }
75
96
 
76
97
  export default Toast