Blame view

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