Blame view

src/components/base/notification/notification.vue 2.51 KB
7c15ac9e   梁灏   add Message compo...
1
  <template>
6cadeba4   梁灏   support Message
2
3
4
      <div :class="classes" :style="styles">
          <Notice
              v-for="notice in notices"
21dad188   梁灏   prevent dispatch ...
5
              :key="notice.name"
7c15ac9e   梁灏   add Message compo...
6
              :prefix-cls="prefixCls"
6cadeba4   梁灏   support Message
7
              :styles="notice.styles"
e0bd31a6   Aresn   update Message
8
              :type="notice.type"
7c15ac9e   梁灏   add Message compo...
9
10
11
              :content="notice.content"
              :duration="notice.duration"
              :closable="notice.closable"
6cadeba4   梁灏   support Message
12
              :name="notice.name"
40f8606f   梁灏   add Notice component
13
              :transition-name="notice.transitionName"
7c15ac9e   梁灏   add Message compo...
14
15
16
17
18
              :on-close="notice.onClose">
          </Notice>
      </div>
  </template>
  <script>
7c15ac9e   梁灏   add Message compo...
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
      import Notice from './notice.vue';
  
      const prefixCls = 'ivu-notification';
      let seed = 0;
      const now = Date.now();
  
      function getUuid () {
          return 'ivuNotification_' + now + '_' + (seed++);
      }
  
      export default {
          components: { Notice },
          props: {
              prefixCls: {
                  type: String,
                  default: prefixCls
              },
6cadeba4   梁灏   support Message
36
              styles: {
7c15ac9e   梁灏   add Message compo...
37
38
39
40
41
                  type: Object,
                  default: function () {
                      return {
                          top: '65px',
                          left: '50%'
b0893113   jingsam   :art: add eslint
42
                      };
7c15ac9e   梁灏   add Message compo...
43
44
45
46
47
48
49
                  }
              },
              content: {
                  type: String
              },
              className: {
                  type: String
40f8606f   梁灏   add Notice component
50
              }
7c15ac9e   梁灏   add Message compo...
51
52
53
54
          },
          data () {
              return {
                  notices: []
b0893113   jingsam   :art: add eslint
55
              };
7c15ac9e   梁灏   add Message compo...
56
57
58
59
60
61
62
63
          },
          computed: {
              classes () {
                  return [
                      `${this.prefixCls}`,
                      {
                          [`${this.className}`]: !!this.className
                      }
b0893113   jingsam   :art: add eslint
64
                  ];
7c15ac9e   梁灏   add Message compo...
65
66
67
68
              }
          },
          methods: {
              add (notice) {
6cadeba4   梁灏   support Message
69
                  const name = notice.name || getUuid();
7c15ac9e   梁灏   add Message compo...
70
71
  
                  let _notice = Object.assign({
6cadeba4   梁灏   support Message
72
                      styles: {
7c15ac9e   梁灏   add Message compo...
73
74
75
76
77
                          right: '50%'
                      },
                      content: '',
                      duration: 1.5,
                      closable: false,
6cadeba4   梁灏   support Message
78
                      name: name
7c15ac9e   梁灏   add Message compo...
79
80
81
82
                  }, notice);
  
                  this.notices.push(_notice);
              },
6cadeba4   梁灏   support Message
83
              close (name) {
7c15ac9e   梁灏   add Message compo...
84
                  const notices = this.notices;
7c15ac9e   梁灏   add Message compo...
85
                  for (let i = 0; i < notices.length; i++) {
6cadeba4   梁灏   support Message
86
                      if (notices[i].name === name) {
7c15ac9e   梁灏   add Message compo...
87
88
89
90
                          this.notices.splice(i, 1);
                          break;
                      }
                  }
17628aab   Lawrence Lee   bugfix on message
91
92
93
              },
              closeAll () {
                  this.notices = [];
7c15ac9e   梁灏   add Message compo...
94
95
              }
          }
b0893113   jingsam   :art: add eslint
96
97
      };
  </script>