Blame view

src/components/base/notification/notice.vue 5.6 KB
7c15ac9e   梁灏   add Message compo...
1
  <template>
36a91579   梁灏   fixed #1881
2
      <transition :name="transitionName" @enter="handleEnter" @leave="handleLeave">
6cadeba4   梁灏   support Message
3
          <div :class="classes" :style="styles">
e0bd31a6   Aresn   update Message
4
              <template v-if="type === 'notice'">
b24be35a   zhigang.li   make Message and ...
5
                  <div :class="contentClasses" ref="content" v-html="content"></div>
c7cd8bdd   zhigang.li   update
6
                  <div :class="contentWithIcon">
b24be35a   zhigang.li   make Message and ...
7
8
9
10
                      <render-cell
                          :render="renderFunc"
                      ></render-cell>
                  </div>
e0bd31a6   Aresn   update Message
11
12
13
14
15
16
17
                  <a :class="[baseClass + '-close']" @click="close" v-if="closable">
                      <i class="ivu-icon ivu-icon-ios-close-empty"></i>
                  </a>
              </template>
              <template v-if="type === 'message'">
                  <div :class="[baseClass + '-content']" ref="content">
                      <div :class="[baseClass + '-content-text']" v-html="content"></div>
b24be35a   zhigang.li   make Message and ...
18
19
20
21
22
                      <div :class="[baseClass + '-content-text']">
                          <render-cell
                              :render="renderFunc"
                          ></render-cell>
                      </div>
e0bd31a6   Aresn   update Message
23
24
25
26
27
                      <a :class="[baseClass + '-close']" @click="close" v-if="closable">
                          <i class="ivu-icon ivu-icon-ios-close-empty"></i>
                      </a>
                  </div>
              </template>
6cadeba4   梁灏   support Message
28
29
          </div>
      </transition>
7c15ac9e   梁灏   add Message compo...
30
31
  </template>
  <script>
b24be35a   zhigang.li   make Message and ...
32
      import RenderCell from '../render';
7c15ac9e   梁灏   add Message compo...
33
      export default {
b24be35a   zhigang.li   make Message and ...
34
35
36
          components: {
              RenderCell
          },
7c15ac9e   梁灏   add Message compo...
37
38
39
40
41
42
43
44
45
          props: {
              prefixCls: {
                  type: String,
                  default: ''
              },
              duration: {
                  type: Number,
                  default: 1.5
              },
e0bd31a6   Aresn   update Message
46
47
48
              type: {
                  type: String
              },
7c15ac9e   梁灏   add Message compo...
49
50
51
52
              content: {
                  type: String,
                  default: ''
              },
b24be35a   zhigang.li   make Message and ...
53
54
55
56
              withIcon: Boolean,
              render: {
                  type: Function
              },
6cadeba4   梁灏   support Message
57
              styles: {
7c15ac9e   梁灏   add Message compo...
58
59
60
61
                  type: Object,
                  default: function() {
                      return {
                          right: '50%'
b0893113   jingsam   :art: add eslint
62
                      };
7c15ac9e   梁灏   add Message compo...
63
64
65
66
67
68
69
70
71
                  }
              },
              closable: {
                  type: Boolean,
                  default: false
              },
              className: {
                  type: String
              },
6cadeba4   梁灏   support Message
72
              name: {
7c15ac9e   梁灏   add Message compo...
73
74
75
76
77
                  type: String,
                  required: true
              },
              onClose: {
                  type: Function
40f8606f   梁灏   add Notice component
78
79
80
              },
              transitionName: {
                  type: String
7c15ac9e   梁灏   add Message compo...
81
82
              }
          },
03441255   梁灏   optimize Notice s...
83
84
85
          data () {
              return {
                  withDesc: false
b0893113   jingsam   :art: add eslint
86
              };
03441255   梁灏   optimize Notice s...
87
          },
7c15ac9e   梁灏   add Message compo...
88
89
90
91
          computed: {
              baseClass () {
                  return `${this.prefixCls}-notice`;
              },
b24be35a   zhigang.li   make Message and ...
92
93
94
              renderFunc () {
                  return this.render || function () {};
              },
7c15ac9e   梁灏   add Message compo...
95
96
97
98
99
              classes () {
                  return [
                      this.baseClass,
                      {
                          [`${this.className}`]: !!this.className,
03441255   梁灏   optimize Notice s...
100
101
                          [`${this.baseClass}-closable`]: this.closable,
                          [`${this.baseClass}-with-desc`]: this.withDesc
7c15ac9e   梁灏   add Message compo...
102
                      }
b0893113   jingsam   :art: add eslint
103
                  ];
7c15ac9e   梁灏   add Message compo...
104
105
              },
              contentClasses () {
b24be35a   zhigang.li   make Message and ...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
                  return [
                      `${this.baseClass}-content`,
                      this.render !== undefined ? `${this.baseClass}-content-with-render` : ''
                  ];
              },
              contentWithIcon () {
                  return [
                      this.withIcon ? `${this.prefixCls}-content-with-icon` : '',
                      this.render && !this.title && this.withIcon ? `${this.prefixCls}-content-with-render-notitle` : ''
                  ];
              },
              messageClasses () {
                  return [
                      `${this.baseClass}-content`,
                      this.render !== undefined ? `${this.baseClass}-content-with-render` : ''
                  ];
7c15ac9e   梁灏   add Message compo...
122
123
124
125
126
127
128
129
130
131
132
133
              }
          },
          methods: {
              clearCloseTimer () {
                  if (this.closeTimer) {
                      clearTimeout(this.closeTimer);
                      this.closeTimer = null;
                  }
              },
              close () {
                  this.clearCloseTimer();
                  this.onClose();
6cadeba4   梁灏   support Message
134
                  this.$parent.close(this.name);
36a91579   梁灏   fixed #1881
135
136
137
138
139
140
141
142
              },
              handleEnter (el) {
                  if (this.type === 'message') {
                      el.style.height = el.scrollHeight + 'px';
                  }
              },
              handleLeave (el) {
                  if (this.type === 'message') {
e7ad4154   梁灏   update Message st...
143
144
145
146
147
148
                      // 优化一下,如果当前只有一个 Message,则不使用 js 过渡动画,这样更优美
                      if (document.getElementsByClassName('ivu-message-notice').length !== 1) {
                          el.style.height = 0;
                          el.style.paddingTop = 0;
                          el.style.paddingBottom = 0;
                      }
36a91579   梁灏   fixed #1881
149
                  }
7c15ac9e   梁灏   add Message compo...
150
151
              }
          },
833501a4   梁灏   support Notice
152
          mounted () {
7c15ac9e   梁灏   add Message compo...
153
154
155
156
157
              this.clearCloseTimer();
  
              if (this.duration !== 0) {
                  this.closeTimer = setTimeout(() => {
                      this.close();
b0893113   jingsam   :art: add eslint
158
                  }, this.duration * 1000);
7c15ac9e   梁灏   add Message compo...
159
              }
03441255   梁灏   optimize Notice s...
160
161
162
  
              // check if with desc in Notice component
              if (this.prefixCls === 'ivu-notice') {
b24be35a   zhigang.li   make Message and ...
163
164
                  let desc = this.$refs.content.querySelectorAll(`.${this.prefixCls}-desc`)[0];
                  this.withDesc = this.render ? true : (desc ? desc.innerHTML !== '' : false);
03441255   梁灏   optimize Notice s...
165
              }
7c15ac9e   梁灏   add Message compo...
166
167
168
169
          },
          beforeDestroy () {
              this.clearCloseTimer();
          }
b0893113   jingsam   :art: add eslint
170
      };
d6342fe1   jingsam   fixed ie bug
171
  </script>