Blame view

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