Blame view

src/components/base/notification/notification.vue 2.42 KB
7c15ac9e   梁灏   add Message compo...
1
  <template>
6cadeba4   梁灏   support Message
2
3
4
5
      <div :class="classes" :style="styles">
          <Notice
              v-for="notice in notices"
              :key="notice"
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>
6cadeba4   梁灏   support Message
18
      // todo :key="notice"
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
85
86
                  const notices = this.notices;
  
                  for (let i = 0; i < notices.length; i++) {
6cadeba4   梁灏   support Message
87
                      if (notices[i].name === name) {
7c15ac9e   梁灏   add Message compo...
88
89
90
91
92
93
                          this.notices.splice(i, 1);
                          break;
                      }
                  }
              }
          }
b0893113   jingsam   :art: add eslint
94
95
      };
  </script>