Blame view

src/components/base/notification/notice.vue 2.88 KB
7c15ac9e   梁灏   add Message compo...
1
  <template>
40f8606f   梁灏   add Notice component
2
      <div :class="classes" :style="style" :transition="transitionName">
d6342fe1   jingsam   fixed ie bug
3
          <div :class="[baseClass + '-content']" v-el:content>{{{ content }}}</div>
e3a12bd3   梁灏   bug fixed
4
          <a :class="[baseClass + '-close']" @click="close" v-if="closable">
40f8606f   梁灏   add Notice component
5
6
              <i class="ivu-icon ivu-icon-ios-close-empty"></i>
          </a>
7c15ac9e   梁灏   add Message compo...
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
      </div>
  </template>
  <script>
      export default {
          props: {
              prefixCls: {
                  type: String,
                  default: ''
              },
              duration: {
                  type: Number,
                  default: 1.5
              },
              content: {
                  type: String,
                  default: ''
              },
              style: {
                  type: Object,
                  default: function() {
                      return {
                          right: '50%'
                      }
                  }
              },
              closable: {
                  type: Boolean,
                  default: false
              },
              className: {
                  type: String
              },
              key: {
                  type: String,
                  required: true
              },
              onClose: {
                  type: Function
40f8606f   梁灏   add Notice component
45
46
47
              },
              transitionName: {
                  type: String
7c15ac9e   梁灏   add Message compo...
48
49
              }
          },
03441255   梁灏   optimize Notice s...
50
51
52
53
54
          data () {
              return {
                  withDesc: false
              }
          },
7c15ac9e   梁灏   add Message compo...
55
56
57
58
59
60
61
62
63
          computed: {
              baseClass () {
                  return `${this.prefixCls}-notice`;
              },
              classes () {
                  return [
                      this.baseClass,
                      {
                          [`${this.className}`]: !!this.className,
03441255   梁灏   optimize Notice s...
64
65
                          [`${this.baseClass}-closable`]: this.closable,
                          [`${this.baseClass}-with-desc`]: this.withDesc
7c15ac9e   梁灏   add Message compo...
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
                      }
                  ]
              },
              contentClasses () {
                  return `${this.baseClass}-content`;
              }
          },
          methods: {
              clearCloseTimer () {
                  if (this.closeTimer) {
                      clearTimeout(this.closeTimer);
                      this.closeTimer = null;
                  }
              },
              close () {
                  this.clearCloseTimer();
                  this.onClose();
                  this.$parent.close(this.key);
              }
          },
          compiled () {
              this.clearCloseTimer();
  
              if (this.duration !== 0) {
                  this.closeTimer = setTimeout(() => {
                      this.close();
                  }, this.duration * 1000)
              }
03441255   梁灏   optimize Notice s...
94
95
96
97
98
  
              // check if with desc in Notice component
              if (this.prefixCls === 'ivu-notice') {
                  this.withDesc = this.$els.content.querySelectorAll(`.${this.prefixCls}-desc`)[0].innerHTML !== '';
              }
7c15ac9e   梁灏   add Message compo...
99
100
101
102
103
          },
          beforeDestroy () {
              this.clearCloseTimer();
          }
      }
d6342fe1   jingsam   fixed ie bug
104
  </script>