Blame view

src/components/base/notification/notice.vue 5.61 KB
7c15ac9e   梁灏   add Message compo...
1
  <template>
e8a8d889   pyyzcwg2833   fix(notification)...
2
      <transition :name="transitionName" @enter="handleEnter" @leave="handleLeave" appear>
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
                  <a :class="[baseClass + '-close']" @click="close" v-if="closable">
11793743   梁灏   update Message Icons
12
                      <i class="ivu-icon ivu-icon-ios-close"></i>
e0bd31a6   Aresn   update Message
13
14
15
16
17
                  </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
                      <a :class="[baseClass + '-close']" @click="close" v-if="closable">
11793743   梁灏   update Message Icons
24
                          <i class="ivu-icon ivu-icon-ios-close"></i>
e0bd31a6   Aresn   update Message
25
26
27
                      </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
              },
3f7a5f1a   zhigang.li   udpate notice
57
              hasTitle: Boolean,
6cadeba4   梁灏   support Message
58
              styles: {
7c15ac9e   梁灏   add Message compo...
59
60
61
62
                  type: Object,
                  default: function() {
                      return {
                          right: '50%'
b0893113   jingsam   :art: add eslint
63
                      };
7c15ac9e   梁灏   add Message compo...
64
65
66
67
68
69
70
71
72
                  }
              },
              closable: {
                  type: Boolean,
                  default: false
              },
              className: {
                  type: String
              },
6cadeba4   梁灏   support Message
73
              name: {
7c15ac9e   梁灏   add Message compo...
74
75
76
77
78
                  type: String,
                  required: true
              },
              onClose: {
                  type: Function
40f8606f   梁灏   add Notice component
79
80
81
              },
              transitionName: {
                  type: String
7c15ac9e   梁灏   add Message compo...
82
83
              }
          },
03441255   梁灏   optimize Notice s...
84
85
86
          data () {
              return {
                  withDesc: false
b0893113   jingsam   :art: add eslint
87
              };
03441255   梁灏   optimize Notice s...
88
          },
7c15ac9e   梁灏   add Message compo...
89
90
91
92
          computed: {
              baseClass () {
                  return `${this.prefixCls}-notice`;
              },
b24be35a   zhigang.li   make Message and ...
93
94
95
              renderFunc () {
                  return this.render || function () {};
              },
7c15ac9e   梁灏   add Message compo...
96
97
98
99
100
              classes () {
                  return [
                      this.baseClass,
                      {
                          [`${this.className}`]: !!this.className,
03441255   梁灏   optimize Notice s...
101
102
                          [`${this.baseClass}-closable`]: this.closable,
                          [`${this.baseClass}-with-desc`]: this.withDesc
7c15ac9e   梁灏   add Message compo...
103
                      }
b0893113   jingsam   :art: add eslint
104
                  ];
7c15ac9e   梁灏   add Message compo...
105
106
              },
              contentClasses () {
b24be35a   zhigang.li   make Message and ...
107
108
109
110
111
112
113
114
                  return [
                      `${this.baseClass}-content`,
                      this.render !== undefined ? `${this.baseClass}-content-with-render` : ''
                  ];
              },
              contentWithIcon () {
                  return [
                      this.withIcon ? `${this.prefixCls}-content-with-icon` : '',
3f7a5f1a   zhigang.li   udpate notice
115
                      !this.hasTitle && this.withIcon ? `${this.prefixCls}-content-with-render-notitle` : ''
b24be35a   zhigang.li   make Message and ...
116
117
118
119
120
121
122
                  ];
              },
              messageClasses () {
                  return [
                      `${this.baseClass}-content`,
                      this.render !== undefined ? `${this.baseClass}-content-with-render` : ''
                  ];
7c15ac9e   梁灏   add Message compo...
123
124
125
126
127
128
129
130
131
132
133
134
              }
          },
          methods: {
              clearCloseTimer () {
                  if (this.closeTimer) {
                      clearTimeout(this.closeTimer);
                      this.closeTimer = null;
                  }
              },
              close () {
                  this.clearCloseTimer();
                  this.onClose();
6cadeba4   梁灏   support Message
135
                  this.$parent.close(this.name);
36a91579   梁灏   fixed #1881
136
137
138
139
140
141
142
143
              },
              handleEnter (el) {
                  if (this.type === 'message') {
                      el.style.height = el.scrollHeight + 'px';
                  }
              },
              handleLeave (el) {
                  if (this.type === 'message') {
e7ad4154   梁灏   update Message st...
144
145
146
147
148
149
                      // 优化一下,如果当前只有一个 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
150
                  }
7c15ac9e   梁灏   add Message compo...
151
152
              }
          },
833501a4   梁灏   support Notice
153
          mounted () {
7c15ac9e   梁灏   add Message compo...
154
155
156
157
158
              this.clearCloseTimer();
  
              if (this.duration !== 0) {
                  this.closeTimer = setTimeout(() => {
                      this.close();
b0893113   jingsam   :art: add eslint
159
                  }, this.duration * 1000);
7c15ac9e   梁灏   add Message compo...
160
              }
03441255   梁灏   optimize Notice s...
161
162
163
  
              // check if with desc in Notice component
              if (this.prefixCls === 'ivu-notice') {
b24be35a   zhigang.li   make Message and ...
164
165
                  let desc = this.$refs.content.querySelectorAll(`.${this.prefixCls}-desc`)[0];
                  this.withDesc = this.render ? true : (desc ? desc.innerHTML !== '' : false);
03441255   梁灏   optimize Notice s...
166
              }
7c15ac9e   梁灏   add Message compo...
167
168
169
170
          },
          beforeDestroy () {
              this.clearCloseTimer();
          }
b0893113   jingsam   :art: add eslint
171
      };
d6342fe1   jingsam   fixed ie bug
172
  </script>