Blame view

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