iov-design 2.15.60 → 2.15.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. package/README.md +148 -148
  2. package/lib/alert.js +24 -105
  3. package/lib/aside.js +24 -34
  4. package/lib/autocomplete.js +36 -240
  5. package/lib/avatar.js +21 -20
  6. package/lib/backtop.js +27 -52
  7. package/lib/badge.js +30 -58
  8. package/lib/breadcrumb-item.js +24 -53
  9. package/lib/breadcrumb.js +24 -37
  10. package/lib/button-group.js +24 -29
  11. package/lib/button.js +38 -60
  12. package/lib/calendar.js +29 -146
  13. package/lib/card.js +24 -51
  14. package/lib/carousel-item.js +30 -68
  15. package/lib/carousel.js +27 -159
  16. package/lib/cascader-panel.js +41 -64
  17. package/lib/cascader.js +37 -470
  18. package/lib/checkbox-button.js +28 -164
  19. package/lib/checkbox-group.js +24 -37
  20. package/lib/checkbox.js +35 -189
  21. package/lib/col.js +1 -0
  22. package/lib/collapse-item.js +27 -125
  23. package/lib/collapse.js +24 -37
  24. package/lib/color-picker.js +104 -424
  25. package/lib/container.js +24 -34
  26. package/lib/date-picker.js +126 -1981
  27. package/lib/descriptions-item.js +1 -0
  28. package/lib/descriptions.js +1 -0
  29. package/lib/dialog.js +24 -137
  30. package/lib/divider.js +29 -64
  31. package/lib/drawer.js +24 -139
  32. package/lib/dropdown-item.js +27 -45
  33. package/lib/dropdown-menu.js +24 -51
  34. package/lib/dropdown.js +21 -20
  35. package/lib/empty.js +24 -61
  36. package/lib/footer.js +24 -34
  37. package/lib/form-item.js +42 -128
  38. package/lib/form.js +27 -40
  39. package/lib/header.js +24 -34
  40. package/lib/icon.js +24 -29
  41. package/lib/image.js +36 -220
  42. package/lib/index.js +1 -1
  43. package/lib/infinite-scroll.js +1 -0
  44. package/lib/input-number.js +30 -163
  45. package/lib/input.js +42 -274
  46. package/lib/iov-design.common.js +1635 -11132
  47. package/lib/link.js +31 -56
  48. package/lib/loading.js +24 -77
  49. package/lib/locale/format.js +10 -10
  50. package/lib/main.js +24 -29
  51. package/lib/menu-item-group.js +24 -40
  52. package/lib/menu-item.js +27 -83
  53. package/lib/menu.js +21 -20
  54. package/lib/message-box.js +24 -321
  55. package/lib/message.js +30 -82
  56. package/lib/mixins/migrating.js +20 -20
  57. package/lib/notification.js +24 -109
  58. package/lib/option-group.js +24 -50
  59. package/lib/option.js +27 -76
  60. package/lib/page-header.js +24 -56
  61. package/lib/pagination.js +24 -97
  62. package/lib/popconfirm.js +24 -97
  63. package/lib/popover.js +24 -89
  64. package/lib/progress.js +30 -133
  65. package/lib/radio-button.js +29 -111
  66. package/lib/radio-group.js +24 -39
  67. package/lib/radio.js +36 -152
  68. package/lib/rate.js +24 -94
  69. package/lib/result.js +72 -187
  70. package/lib/row.js +1 -0
  71. package/lib/scrollbar.js +1 -0
  72. package/lib/select.js +48 -637
  73. package/lib/skeleton-item.js +36 -68
  74. package/lib/skeleton.js +28 -70
  75. package/lib/slider.js +36 -267
  76. package/lib/spinner.js +24 -51
  77. package/lib/statistic.js +24 -76
  78. package/lib/step.js +29 -118
  79. package/lib/steps.js +27 -40
  80. package/lib/submenu.js +21 -20
  81. package/lib/switch.js +24 -130
  82. package/lib/tab-pane.js +24 -52
  83. package/lib/table-column.js +1 -0
  84. package/lib/table.js +93 -633
  85. package/lib/tabs.js +34 -49
  86. package/lib/tag.js +21 -20
  87. package/lib/theme-chalk/autocomplete.css +1 -1
  88. package/lib/theme-chalk/base.css +1 -1
  89. package/lib/theme-chalk/cascader.css +1 -1
  90. package/lib/theme-chalk/date-picker.css +1 -1
  91. package/lib/theme-chalk/index.css +1 -1
  92. package/lib/theme-chalk/input-number.css +1 -1
  93. package/lib/theme-chalk/input.css +1 -1
  94. package/lib/theme-chalk/iovfont.css +1 -1
  95. package/lib/theme-chalk/link.css +1 -1
  96. package/lib/theme-chalk/message-box.css +1 -1
  97. package/lib/theme-chalk/pagination.css +1 -1
  98. package/lib/theme-chalk/select.css +1 -1
  99. package/lib/theme-chalk/slider.css +1 -1
  100. package/lib/theme-chalk/time-picker.css +1 -1
  101. package/lib/theme-chalk/transfer.css +1 -1
  102. package/lib/time-picker.js +58 -820
  103. package/lib/time-select.js +42 -303
  104. package/lib/timeline-item.js +29 -75
  105. package/lib/timeline.js +21 -20
  106. package/lib/tooltip.js +1 -0
  107. package/lib/transfer.js +36 -299
  108. package/lib/tree.js +54 -243
  109. package/lib/upload.js +86 -654
  110. package/lib/utils/clickoutside.js +7 -7
  111. package/lib/utils/vue-popper.js +7 -7
  112. package/package.json +154 -154
  113. package/packages/autocomplete/src/autocomplete-suggestions.vue +76 -76
  114. package/packages/autocomplete/src/autocomplete.vue +285 -285
  115. package/packages/button/src/button.vue +90 -90
  116. package/packages/calendar/src/date-table.vue +200 -200
  117. package/packages/calendar/src/main.vue +280 -280
  118. package/packages/carousel/src/item.vue +138 -138
  119. package/packages/carousel/src/main.vue +315 -315
  120. package/packages/cascader/src/cascader.vue +776 -776
  121. package/packages/cascader-panel/src/cascader-menu.vue +138 -138
  122. package/packages/cascader-panel/src/cascader-node.vue +246 -246
  123. package/packages/cascader-panel/src/cascader-panel.vue +391 -391
  124. package/packages/cascader-panel/src/node.js +166 -166
  125. package/packages/cascader-panel/src/store.js +58 -58
  126. package/packages/checkbox/src/checkbox-button.vue +199 -199
  127. package/packages/checkbox/src/checkbox-group.vue +49 -49
  128. package/packages/checkbox/src/checkbox.vue +225 -225
  129. package/packages/collapse/src/collapse-item.vue +114 -114
  130. package/packages/color-picker/src/components/picker-dropdown.vue +121 -121
  131. package/packages/color-picker/src/main.vue +188 -188
  132. package/packages/date-picker/src/basic/date-table.vue +441 -441
  133. package/packages/date-picker/src/basic/month-table.vue +269 -269
  134. package/packages/date-picker/src/basic/time-spinner.vue +304 -304
  135. package/packages/date-picker/src/basic/year-table.vue +111 -111
  136. package/packages/date-picker/src/panel/date-range.vue +680 -680
  137. package/packages/date-picker/src/panel/date.vue +609 -609
  138. package/packages/date-picker/src/panel/month-range.vue +289 -289
  139. package/packages/date-picker/src/panel/time-range.vue +248 -248
  140. package/packages/date-picker/src/panel/time-select.vue +178 -178
  141. package/packages/date-picker/src/panel/time.vue +186 -186
  142. package/packages/date-picker/src/picker.vue +967 -967
  143. package/packages/descriptions/src/index.js +180 -180
  144. package/packages/dialog/src/component.vue +262 -262
  145. package/packages/drawer/src/main.vue +205 -205
  146. package/packages/dropdown/src/dropdown-item.vue +37 -37
  147. package/packages/dropdown/src/dropdown-menu.vue +63 -63
  148. package/packages/dropdown/src/dropdown.vue +293 -293
  149. package/packages/empty/src/index.vue +70 -70
  150. package/packages/form/src/form-item.vue +324 -324
  151. package/packages/form/src/form.vue +182 -182
  152. package/packages/image/src/image-viewer.vue +330 -330
  153. package/packages/image/src/main.vue +249 -249
  154. package/packages/infinite-scroll/src/main.js +150 -150
  155. package/packages/input/src/input.vue +477 -477
  156. package/packages/input-number/src/input-number.vue +283 -283
  157. package/packages/loading/src/directive.js +133 -133
  158. package/packages/loading/src/index.js +106 -106
  159. package/packages/menu/src/menu-item.vue +112 -112
  160. package/packages/menu/src/menu.vue +325 -325
  161. package/packages/menu/src/submenu.vue +349 -349
  162. package/packages/message/src/main.js +91 -91
  163. package/packages/message-box/src/main.js +216 -216
  164. package/packages/message-box/src/main.vue +333 -333
  165. package/packages/notification/src/main.js +94 -94
  166. package/packages/page-header/src/main.vue +30 -30
  167. package/packages/pagination/src/pagination.js +390 -390
  168. package/packages/popconfirm/src/main.vue +104 -104
  169. package/packages/popover/src/main.vue +239 -239
  170. package/packages/radio/src/radio-button.vue +115 -115
  171. package/packages/radio/src/radio-group.vue +115 -115
  172. package/packages/radio/src/radio.vue +148 -148
  173. package/packages/rate/src/main.vue +348 -348
  174. package/packages/scrollbar/src/bar.js +92 -92
  175. package/packages/scrollbar/src/main.js +130 -130
  176. package/packages/select/src/option-group.vue +60 -60
  177. package/packages/select/src/option.vue +171 -171
  178. package/packages/select/src/select-dropdown.vue +74 -74
  179. package/packages/select/src/select.vue +979 -979
  180. package/packages/slider/src/button.vue +238 -238
  181. package/packages/slider/src/main.vue +427 -427
  182. package/packages/statistic/src/main.vue +204 -204
  183. package/packages/steps/src/steps.vue +68 -68
  184. package/packages/switch/src/component.vue +182 -182
  185. package/packages/table/src/config.js +153 -153
  186. package/packages/table/src/filter-panel.vue +194 -194
  187. package/packages/table/src/store/current.js +76 -76
  188. package/packages/table/src/store/helper.js +41 -41
  189. package/packages/table/src/store/index.js +147 -147
  190. package/packages/table/src/store/watcher.js +502 -502
  191. package/packages/table/src/table-body.js +469 -469
  192. package/packages/table/src/table-column.js +328 -328
  193. package/packages/table/src/table-header.js +571 -571
  194. package/packages/table/src/table-layout.js +249 -249
  195. package/packages/table/src/table-row.js +101 -101
  196. package/packages/table/src/table.vue +740 -740
  197. package/packages/table/src/util.js +273 -273
  198. package/packages/tabs/src/tab-bar.vue +57 -57
  199. package/packages/tabs/src/tab-nav.vue +294 -294
  200. package/packages/tabs/src/tabs.vue +201 -201
  201. package/packages/theme-chalk/src/button.scss +416 -416
  202. package/packages/theme-chalk/src/cascader.scss +252 -252
  203. package/packages/theme-chalk/src/checkbox.scss +419 -419
  204. package/packages/theme-chalk/src/common/var.scss +795 -795
  205. package/packages/theme-chalk/src/form.scss +201 -201
  206. package/packages/theme-chalk/src/input.scss +591 -591
  207. package/packages/theme-chalk/src/iovfont.scss +818 -803
  208. package/packages/theme-chalk/src/link.scss +8 -8
  209. package/packages/theme-chalk/src/message-box.scss +207 -207
  210. package/packages/theme-chalk/src/mixins/_button.scss +136 -136
  211. package/packages/theme-chalk/src/mixins/mixins.scss +190 -190
  212. package/packages/theme-chalk/src/radio-button.scss +115 -115
  213. package/packages/theme-chalk/src/select.scss +270 -270
  214. package/packages/theme-chalk/src/tabs.scss +755 -755
  215. package/packages/theme-chalk/src/upload.scss +568 -568
  216. package/packages/tooltip/src/main.js +242 -242
  217. package/packages/transfer/src/main.vue +231 -231
  218. package/packages/transfer/src/transfer-panel.vue +251 -251
  219. package/packages/tree/src/model/node.js +484 -484
  220. package/packages/tree/src/tree-node.vue +279 -279
  221. package/packages/tree/src/tree.vue +496 -496
  222. package/packages/upload/src/index.vue +420 -420
  223. package/packages/upload/src/upload-file.vue +98 -98
  224. package/packages/upload/src/upload-list.vue +115 -115
  225. package/packages/upload/src/upload-picture.vue +98 -98
  226. package/packages/upload/src/upload.vue +231 -231
  227. package/packages/upload/src/utils.js +31 -31
  228. package/src/directives/repeat-click.js +26 -26
  229. package/src/index.js +259 -259
  230. package/src/locale/format.js +46 -46
  231. package/src/locale/index.js +48 -48
  232. package/src/locale/lang/lo-LA.js +126 -126
  233. package/src/mixins/locale.js +9 -9
  234. package/src/mixins/migrating.js +54 -54
  235. package/src/transitions/collapse-transition.js +77 -77
  236. package/src/utils/clickoutside.js +76 -76
  237. package/src/utils/date-util.js +282 -282
  238. package/src/utils/popup/index.js +218 -218
  239. package/src/utils/popup/popup-manager.js +194 -194
  240. package/src/utils/util.js +245 -245
  241. package/src/utils/vdom.js +5 -5
  242. package/src/utils/vue-popper.js +198 -198
@@ -1,333 +1,333 @@
1
- <template>
2
- <transition name="msgbox-fade">
3
- <div
4
- class="el-message-box__wrapper"
5
- tabindex="-1"
6
- v-show="visible"
7
- @click.self="handleWrapperClick"
8
- role="dialog"
9
- aria-modal="true"
10
- :aria-label="title || 'dialog'">
11
- <div class="el-message-box" :class="[customClass, showTitleIcon && 'el-message-box--title-icon']">
12
- <div class="el-message-box__header" v-if="title !== null">
13
- <div class="el-message-box__title">
14
- <div
15
- :class="['el-message-box__status', icon]"
16
- v-if="icon && showTitleIcon">
17
- </div>
18
- <span>{{ title }}</span>
19
- </div>
20
- <span
21
- type="button"
22
- class="el-message-box__headerbtn"
23
- aria-label="Close"
24
- v-if="showClose"
25
- @click="handleAction(distinguishCancelAndClose ? 'close' : 'cancel')"
26
- @keydown.enter="handleAction(distinguishCancelAndClose ? 'close' : 'cancel')">
27
- <i class="el-message-box__close iov-icon-close"></i>
28
- </span>
29
- </div>
30
- <div class="el-message-box__content" v-if="message !== ''">
31
- <div class="el-message-box__container">
32
- <div
33
- :class="['el-message-box__status', icon]"
34
- v-if="icon && !showTitleIcon && message !== ''">
35
- </div>
36
- <div class="el-message-box__message" :class="[!icon && 'no-type']" v-if="message !== ''">
37
- <slot>
38
- <p v-if="!dangerouslyUseHTMLString">{{ message }}</p>
39
- <p v-else v-html="message"></p>
40
- </slot>
41
- </div>
42
- </div>
43
- <div class="el-message-box__input" v-show="showInput">
44
- <el-input
45
- v-model="inputValue"
46
- size="small"
47
- :type="inputType"
48
- @keydown.enter.native="handleInputEnter"
49
- :placeholder="inputPlaceholder"
50
- ref="input"></el-input>
51
- <div class="el-message-box__errormsg" :style="{ visibility: !!editorErrorMessage ? 'visible' : 'hidden' }">{{ editorErrorMessage }}</div>
52
- </div>
53
- </div>
54
- <div class="el-message-box__btns">
55
- <el-button
56
- :loading="cancelButtonLoading"
57
- :class="[ cancelButtonClasses ]"
58
- v-if="showCancelButton"
59
- :round="roundButton"
60
- size="small"
61
- @click.native="handleAction('cancel')"
62
- @keydown.enter="handleAction('cancel')">
63
- {{ cancelButtonText || t('el.messagebox.cancel') }}
64
- </el-button>
65
- <el-button
66
- :loading="confirmButtonLoading"
67
- ref="confirm"
68
- :class="[ confirmButtonClasses ]"
69
- v-show="showConfirmButton"
70
- :round="roundButton"
71
- size="small"
72
- @click.native="handleAction('confirm')"
73
- @keydown.enter="handleAction('confirm')">
74
- {{ confirmButtonText || t('el.messagebox.confirm') }}
75
- </el-button>
76
- </div>
77
- </div>
78
- </div>
79
- </transition>
80
- </template>
81
-
82
- <script type="text/babel">
83
- import Popup from 'iov-design/src/utils/popup';
84
- import Locale from 'iov-design/src/mixins/locale';
85
- import ElInput from 'iov-design/packages/input';
86
- import ElButton from 'iov-design/packages/button';
87
- import { addClass, removeClass } from 'iov-design/src/utils/dom';
88
- import { t } from 'iov-design/src/locale';
89
- import Dialog from 'iov-design/src/utils/aria-dialog';
90
-
91
- let messageBox;
92
- let typeMap = {
93
- success: 'success',
94
- info: 'explain',
95
- warning: 'warning',
96
- error: 'fail'
97
- };
98
-
99
- export default {
100
- mixins: [Popup, Locale],
101
-
102
- props: {
103
- modal: {
104
- default: true
105
- },
106
- lockScroll: {
107
- default: true
108
- },
109
- showClose: {
110
- type: Boolean,
111
- default: true
112
- },
113
- closeOnClickModal: {
114
- default: true
115
- },
116
- closeOnPressEscape: {
117
- default: true
118
- },
119
- closeOnHashChange: {
120
- default: true
121
- },
122
- showTitleIcon: {
123
- default: false,
124
- type: Boolean
125
- },
126
- roundButton: {
127
- default: true,
128
- type: Boolean
129
- }
130
- },
131
-
132
- components: {
133
- ElInput,
134
- ElButton
135
- },
136
-
137
- computed: {
138
- icon() {
139
- const { type, iconClass } = this;
140
- return iconClass || (type && typeMap[type] ? `iov-icon-fill-${ typeMap[type] }` : '');
141
- },
142
-
143
- confirmButtonClasses() {
144
- return `el-button--primary ${ this.confirmButtonClass }`;
145
- },
146
- cancelButtonClasses() {
147
- return `${ this.cancelButtonClass }`;
148
- }
149
- },
150
-
151
- methods: {
152
- getSafeClose() {
153
- const currentId = this.uid;
154
- return () => {
155
- this.$nextTick(() => {
156
- if (currentId === this.uid) this.doClose();
157
- });
158
- };
159
- },
160
- doClose() {
161
- if (!this.visible) return;
162
- this.visible = false;
163
- this._closing = true;
164
-
165
- this.onClose && this.onClose();
166
- messageBox.closeDialog(); // 解绑
167
- if (this.lockScroll) {
168
- setTimeout(this.restoreBodyStyle, 200);
169
- }
170
- this.opened = false;
171
- this.doAfterClose();
172
- setTimeout(() => {
173
- if (this.action) this.callback(this.action, this);
174
- });
175
- },
176
-
177
- handleWrapperClick() {
178
- if (this.closeOnClickModal) {
179
- this.handleAction(this.distinguishCancelAndClose ? 'close' : 'cancel');
180
- }
181
- },
182
-
183
- handleInputEnter() {
184
- if (this.inputType !== 'textarea') {
185
- return this.handleAction('confirm');
186
- }
187
- },
188
-
189
- handleAction(action) {
190
- if (this.$type === 'prompt' && action === 'confirm' && !this.validate()) {
191
- return;
192
- }
193
- this.action = action;
194
- if (typeof this.beforeClose === 'function') {
195
- this.close = this.getSafeClose();
196
- this.beforeClose(action, this, this.close);
197
- } else {
198
- this.doClose();
199
- }
200
- },
201
-
202
- validate() {
203
- if (this.$type === 'prompt') {
204
- const inputPattern = this.inputPattern;
205
- if (inputPattern && !inputPattern.test(this.inputValue || '')) {
206
- this.editorErrorMessage = this.inputErrorMessage || t('el.messagebox.error');
207
- addClass(this.getInputElement(), 'invalid');
208
- return false;
209
- }
210
- const inputValidator = this.inputValidator;
211
- if (typeof inputValidator === 'function') {
212
- const validateResult = inputValidator(this.inputValue);
213
- if (validateResult === false) {
214
- this.editorErrorMessage = this.inputErrorMessage || t('el.messagebox.error');
215
- addClass(this.getInputElement(), 'invalid');
216
- return false;
217
- }
218
- if (typeof validateResult === 'string') {
219
- this.editorErrorMessage = validateResult;
220
- addClass(this.getInputElement(), 'invalid');
221
- return false;
222
- }
223
- }
224
- }
225
- this.editorErrorMessage = '';
226
- removeClass(this.getInputElement(), 'invalid');
227
- return true;
228
- },
229
- getFirstFocus() {
230
- const btn = this.$el.querySelector('.el-message-box__btns .el-button');
231
- const title = this.$el.querySelector('.el-message-box__btns .el-message-box__title');
232
- return btn || title;
233
- },
234
- getInputElement() {
235
- const inputRefs = this.$refs.input.$refs;
236
- return inputRefs.input || inputRefs.textarea;
237
- },
238
- handleClose() {
239
- this.handleAction('close');
240
- }
241
- },
242
-
243
- watch: {
244
- inputValue: {
245
- immediate: true,
246
- handler(val) {
247
- this.$nextTick(_ => {
248
- if (this.$type === 'prompt' && val !== null) {
249
- this.validate();
250
- }
251
- });
252
- }
253
- },
254
-
255
- visible(val) {
256
- if (val) {
257
- this.uid++;
258
- if (this.$type === 'alert' || this.$type === 'confirm') {
259
- this.$nextTick(() => {
260
- this.$refs.confirm.$el.focus();
261
- });
262
- }
263
- this.focusAfterClosed = document.activeElement;
264
- messageBox = new Dialog(this.$el, this.focusAfterClosed, this.getFirstFocus());
265
- }
266
-
267
- // prompt
268
- if (this.$type !== 'prompt') return;
269
- if (val) {
270
- setTimeout(() => {
271
- if (this.$refs.input && this.$refs.input.$el) {
272
- this.getInputElement().focus();
273
- }
274
- }, 500);
275
- } else {
276
- this.editorErrorMessage = '';
277
- removeClass(this.getInputElement(), 'invalid');
278
- }
279
- }
280
- },
281
-
282
- mounted() {
283
- this.$nextTick(() => {
284
- if (this.closeOnHashChange) {
285
- window.addEventListener('hashchange', this.close);
286
- }
287
- });
288
- },
289
-
290
- beforeDestroy() {
291
- if (this.closeOnHashChange) {
292
- window.removeEventListener('hashchange', this.close);
293
- }
294
- setTimeout(() => {
295
- messageBox.closeDialog();
296
- });
297
- },
298
-
299
- data() {
300
- return {
301
- uid: 1,
302
- title: undefined,
303
- message: '',
304
- type: '',
305
- iconClass: '',
306
- customClass: '',
307
- showInput: false,
308
- inputValue: null,
309
- inputPlaceholder: '',
310
- inputType: 'text',
311
- inputPattern: null,
312
- inputValidator: null,
313
- inputErrorMessage: '',
314
- showConfirmButton: true,
315
- showCancelButton: false,
316
- action: '',
317
- confirmButtonText: '',
318
- cancelButtonText: '',
319
- confirmButtonLoading: false,
320
- cancelButtonLoading: false,
321
- confirmButtonClass: '',
322
- confirmButtonDisabled: false,
323
- cancelButtonClass: '',
324
- editorErrorMessage: null,
325
- callback: null,
326
- dangerouslyUseHTMLString: false,
327
- focusAfterClosed: null,
328
- isOnComposition: false,
329
- distinguishCancelAndClose: false
330
- };
331
- }
332
- };
333
- </script>
1
+ <template>
2
+ <transition name="msgbox-fade">
3
+ <div
4
+ class="el-message-box__wrapper"
5
+ tabindex="-1"
6
+ v-show="visible"
7
+ @click.self="handleWrapperClick"
8
+ role="dialog"
9
+ aria-modal="true"
10
+ :aria-label="title || 'dialog'">
11
+ <div class="el-message-box" :class="[customClass, showTitleIcon && 'el-message-box--title-icon']">
12
+ <div class="el-message-box__header" v-if="title !== null">
13
+ <div class="el-message-box__title">
14
+ <div
15
+ :class="['el-message-box__status', icon]"
16
+ v-if="icon && showTitleIcon">
17
+ </div>
18
+ <span>{{ title }}</span>
19
+ </div>
20
+ <span
21
+ type="button"
22
+ class="el-message-box__headerbtn"
23
+ aria-label="Close"
24
+ v-if="showClose"
25
+ @click="handleAction(distinguishCancelAndClose ? 'close' : 'cancel')"
26
+ @keydown.enter="handleAction(distinguishCancelAndClose ? 'close' : 'cancel')">
27
+ <i class="el-message-box__close iov-icon-close"></i>
28
+ </span>
29
+ </div>
30
+ <div class="el-message-box__content" v-if="message !== ''">
31
+ <div class="el-message-box__container">
32
+ <div
33
+ :class="['el-message-box__status', icon]"
34
+ v-if="icon && !showTitleIcon && message !== ''">
35
+ </div>
36
+ <div class="el-message-box__message" :class="[!icon && 'no-type']" v-if="message !== ''">
37
+ <slot>
38
+ <p v-if="!dangerouslyUseHTMLString">{{ message }}</p>
39
+ <p v-else v-html="message"></p>
40
+ </slot>
41
+ </div>
42
+ </div>
43
+ <div class="el-message-box__input" v-show="showInput">
44
+ <el-input
45
+ v-model="inputValue"
46
+ size="small"
47
+ :type="inputType"
48
+ @keydown.enter.native="handleInputEnter"
49
+ :placeholder="inputPlaceholder"
50
+ ref="input"></el-input>
51
+ <div class="el-message-box__errormsg" :style="{ visibility: !!editorErrorMessage ? 'visible' : 'hidden' }">{{ editorErrorMessage }}</div>
52
+ </div>
53
+ </div>
54
+ <div class="el-message-box__btns">
55
+ <el-button
56
+ :loading="cancelButtonLoading"
57
+ :class="[ cancelButtonClasses ]"
58
+ v-if="showCancelButton"
59
+ :round="roundButton"
60
+ size="small"
61
+ @click.native="handleAction('cancel')"
62
+ @keydown.enter="handleAction('cancel')">
63
+ {{ cancelButtonText || t('el.messagebox.cancel') }}
64
+ </el-button>
65
+ <el-button
66
+ :loading="confirmButtonLoading"
67
+ ref="confirm"
68
+ :class="[ confirmButtonClasses ]"
69
+ v-show="showConfirmButton"
70
+ :round="roundButton"
71
+ size="small"
72
+ @click.native="handleAction('confirm')"
73
+ @keydown.enter="handleAction('confirm')">
74
+ {{ confirmButtonText || t('el.messagebox.confirm') }}
75
+ </el-button>
76
+ </div>
77
+ </div>
78
+ </div>
79
+ </transition>
80
+ </template>
81
+
82
+ <script type="text/babel">
83
+ import Popup from 'iov-design/src/utils/popup';
84
+ import Locale from 'iov-design/src/mixins/locale';
85
+ import ElInput from 'iov-design/packages/input';
86
+ import ElButton from 'iov-design/packages/button';
87
+ import { addClass, removeClass } from 'iov-design/src/utils/dom';
88
+ import { t } from 'iov-design/src/locale';
89
+ import Dialog from 'iov-design/src/utils/aria-dialog';
90
+
91
+ let messageBox;
92
+ let typeMap = {
93
+ success: 'success',
94
+ info: 'explain',
95
+ warning: 'warning',
96
+ error: 'fail'
97
+ };
98
+
99
+ export default {
100
+ mixins: [Popup, Locale],
101
+
102
+ props: {
103
+ modal: {
104
+ default: true
105
+ },
106
+ lockScroll: {
107
+ default: true
108
+ },
109
+ showClose: {
110
+ type: Boolean,
111
+ default: true
112
+ },
113
+ closeOnClickModal: {
114
+ default: true
115
+ },
116
+ closeOnPressEscape: {
117
+ default: true
118
+ },
119
+ closeOnHashChange: {
120
+ default: true
121
+ },
122
+ showTitleIcon: {
123
+ default: false,
124
+ type: Boolean
125
+ },
126
+ roundButton: {
127
+ default: true,
128
+ type: Boolean
129
+ }
130
+ },
131
+
132
+ components: {
133
+ ElInput,
134
+ ElButton
135
+ },
136
+
137
+ computed: {
138
+ icon() {
139
+ const { type, iconClass } = this;
140
+ return iconClass || (type && typeMap[type] ? `iov-icon-fill-${ typeMap[type] }` : '');
141
+ },
142
+
143
+ confirmButtonClasses() {
144
+ return `el-button--primary ${ this.confirmButtonClass }`;
145
+ },
146
+ cancelButtonClasses() {
147
+ return `${ this.cancelButtonClass }`;
148
+ }
149
+ },
150
+
151
+ methods: {
152
+ getSafeClose() {
153
+ const currentId = this.uid;
154
+ return () => {
155
+ this.$nextTick(() => {
156
+ if (currentId === this.uid) this.doClose();
157
+ });
158
+ };
159
+ },
160
+ doClose() {
161
+ if (!this.visible) return;
162
+ this.visible = false;
163
+ this._closing = true;
164
+
165
+ this.onClose && this.onClose();
166
+ messageBox.closeDialog(); // 解绑
167
+ if (this.lockScroll) {
168
+ setTimeout(this.restoreBodyStyle, 200);
169
+ }
170
+ this.opened = false;
171
+ this.doAfterClose();
172
+ setTimeout(() => {
173
+ if (this.action) this.callback(this.action, this);
174
+ });
175
+ },
176
+
177
+ handleWrapperClick() {
178
+ if (this.closeOnClickModal) {
179
+ this.handleAction(this.distinguishCancelAndClose ? 'close' : 'cancel');
180
+ }
181
+ },
182
+
183
+ handleInputEnter() {
184
+ if (this.inputType !== 'textarea') {
185
+ return this.handleAction('confirm');
186
+ }
187
+ },
188
+
189
+ handleAction(action) {
190
+ if (this.$type === 'prompt' && action === 'confirm' && !this.validate()) {
191
+ return;
192
+ }
193
+ this.action = action;
194
+ if (typeof this.beforeClose === 'function') {
195
+ this.close = this.getSafeClose();
196
+ this.beforeClose(action, this, this.close);
197
+ } else {
198
+ this.doClose();
199
+ }
200
+ },
201
+
202
+ validate() {
203
+ if (this.$type === 'prompt') {
204
+ const inputPattern = this.inputPattern;
205
+ if (inputPattern && !inputPattern.test(this.inputValue || '')) {
206
+ this.editorErrorMessage = this.inputErrorMessage || t('el.messagebox.error');
207
+ addClass(this.getInputElement(), 'invalid');
208
+ return false;
209
+ }
210
+ const inputValidator = this.inputValidator;
211
+ if (typeof inputValidator === 'function') {
212
+ const validateResult = inputValidator(this.inputValue);
213
+ if (validateResult === false) {
214
+ this.editorErrorMessage = this.inputErrorMessage || t('el.messagebox.error');
215
+ addClass(this.getInputElement(), 'invalid');
216
+ return false;
217
+ }
218
+ if (typeof validateResult === 'string') {
219
+ this.editorErrorMessage = validateResult;
220
+ addClass(this.getInputElement(), 'invalid');
221
+ return false;
222
+ }
223
+ }
224
+ }
225
+ this.editorErrorMessage = '';
226
+ removeClass(this.getInputElement(), 'invalid');
227
+ return true;
228
+ },
229
+ getFirstFocus() {
230
+ const btn = this.$el.querySelector('.el-message-box__btns .el-button');
231
+ const title = this.$el.querySelector('.el-message-box__btns .el-message-box__title');
232
+ return btn || title;
233
+ },
234
+ getInputElement() {
235
+ const inputRefs = this.$refs.input.$refs;
236
+ return inputRefs.input || inputRefs.textarea;
237
+ },
238
+ handleClose() {
239
+ this.handleAction('close');
240
+ }
241
+ },
242
+
243
+ watch: {
244
+ inputValue: {
245
+ immediate: true,
246
+ handler(val) {
247
+ this.$nextTick(_ => {
248
+ if (this.$type === 'prompt' && val !== null) {
249
+ this.validate();
250
+ }
251
+ });
252
+ }
253
+ },
254
+
255
+ visible(val) {
256
+ if (val) {
257
+ this.uid++;
258
+ if (this.$type === 'alert' || this.$type === 'confirm') {
259
+ this.$nextTick(() => {
260
+ this.$refs.confirm.$el.focus();
261
+ });
262
+ }
263
+ this.focusAfterClosed = document.activeElement;
264
+ messageBox = new Dialog(this.$el, this.focusAfterClosed, this.getFirstFocus());
265
+ }
266
+
267
+ // prompt
268
+ if (this.$type !== 'prompt') return;
269
+ if (val) {
270
+ setTimeout(() => {
271
+ if (this.$refs.input && this.$refs.input.$el) {
272
+ this.getInputElement().focus();
273
+ }
274
+ }, 500);
275
+ } else {
276
+ this.editorErrorMessage = '';
277
+ removeClass(this.getInputElement(), 'invalid');
278
+ }
279
+ }
280
+ },
281
+
282
+ mounted() {
283
+ this.$nextTick(() => {
284
+ if (this.closeOnHashChange) {
285
+ window.addEventListener('hashchange', this.close);
286
+ }
287
+ });
288
+ },
289
+
290
+ beforeDestroy() {
291
+ if (this.closeOnHashChange) {
292
+ window.removeEventListener('hashchange', this.close);
293
+ }
294
+ setTimeout(() => {
295
+ messageBox.closeDialog();
296
+ });
297
+ },
298
+
299
+ data() {
300
+ return {
301
+ uid: 1,
302
+ title: undefined,
303
+ message: '',
304
+ type: '',
305
+ iconClass: '',
306
+ customClass: '',
307
+ showInput: false,
308
+ inputValue: null,
309
+ inputPlaceholder: '',
310
+ inputType: 'text',
311
+ inputPattern: null,
312
+ inputValidator: null,
313
+ inputErrorMessage: '',
314
+ showConfirmButton: true,
315
+ showCancelButton: false,
316
+ action: '',
317
+ confirmButtonText: '',
318
+ cancelButtonText: '',
319
+ confirmButtonLoading: false,
320
+ cancelButtonLoading: false,
321
+ confirmButtonClass: '',
322
+ confirmButtonDisabled: false,
323
+ cancelButtonClass: '',
324
+ editorErrorMessage: null,
325
+ callback: null,
326
+ dangerouslyUseHTMLString: false,
327
+ focusAfterClosed: null,
328
+ isOnComposition: false,
329
+ distinguishCancelAndClose: false
330
+ };
331
+ }
332
+ };
333
+ </script>