Blame view

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