@zkwq/business 0.0.1

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 (231) hide show
  1. package/dist/index.css +1 -0
  2. package/dist/index.js +21861 -0
  3. package/dist/index.umd.cjs +46 -0
  4. package/package.json +27 -0
  5. package/src/components/base/ui/alert/Alert.vue +94 -0
  6. package/src/components/base/ui/autocomplete/autocomplete-suggestions.vue +77 -0
  7. package/src/components/base/ui/autocomplete/autocomplete.vue +305 -0
  8. package/src/components/base/ui/backtop/main.vue +112 -0
  9. package/src/components/base/ui/button/Button.vue +84 -0
  10. package/src/components/base/ui/button/ButtonGroup.vue +10 -0
  11. package/src/components/base/ui/carousel/Carousel.vue +304 -0
  12. package/src/components/base/ui/carousel/CarouselItem.vue +137 -0
  13. package/src/components/base/ui/cascader/cascader.vue +650 -0
  14. package/src/components/base/ui/cascader-panel/cascader-menu.vue +138 -0
  15. package/src/components/base/ui/cascader-panel/cascader-node.vue +246 -0
  16. package/src/components/base/ui/cascader-panel/cascader-panel.vue +382 -0
  17. package/src/components/base/ui/cascader-panel/node.js +166 -0
  18. package/src/components/base/ui/cascader-panel/store.js +62 -0
  19. package/src/components/base/ui/checkbox/checkbox-button.vue +199 -0
  20. package/src/components/base/ui/checkbox/checkbox-group.vue +48 -0
  21. package/src/components/base/ui/checkbox/checkbox.vue +222 -0
  22. package/src/components/base/ui/col/col.js +71 -0
  23. package/src/components/base/ui/collapse/collapse-item.vue +180 -0
  24. package/src/components/base/ui/collapse/collapse.vue +73 -0
  25. package/src/components/base/ui/color-picker/color.js +317 -0
  26. package/src/components/base/ui/color-picker/components/alpha-slider.vue +132 -0
  27. package/src/components/base/ui/color-picker/components/hue-slider.vue +123 -0
  28. package/src/components/base/ui/color-picker/components/picker-dropdown.vue +119 -0
  29. package/src/components/base/ui/color-picker/components/predefine.vue +61 -0
  30. package/src/components/base/ui/color-picker/components/sv-panel.vue +100 -0
  31. package/src/components/base/ui/color-picker/draggable.js +36 -0
  32. package/src/components/base/ui/color-picker/index.js +2 -0
  33. package/src/components/base/ui/color-picker/main.vue +188 -0
  34. package/src/components/base/ui/date-picker/basic/date-table.vue +441 -0
  35. package/src/components/base/ui/date-picker/basic/month-table.vue +254 -0
  36. package/src/components/base/ui/date-picker/basic/time-spinner.vue +304 -0
  37. package/src/components/base/ui/date-picker/basic/year-table.vue +101 -0
  38. package/src/components/base/ui/date-picker/panel/date-range.vue +680 -0
  39. package/src/components/base/ui/date-picker/panel/date.vue +597 -0
  40. package/src/components/base/ui/date-picker/panel/month-range.vue +289 -0
  41. package/src/components/base/ui/date-picker/panel/time-range.vue +248 -0
  42. package/src/components/base/ui/date-picker/panel/time-select.vue +178 -0
  43. package/src/components/base/ui/date-picker/panel/time.vue +186 -0
  44. package/src/components/base/ui/date-picker/picker/date-picker.js +43 -0
  45. package/src/components/base/ui/date-picker/picker/time-picker.js +39 -0
  46. package/src/components/base/ui/date-picker/picker/time-select.js +21 -0
  47. package/src/components/base/ui/date-picker/picker.vue +942 -0
  48. package/src/components/base/ui/dialog/Index.vue +212 -0
  49. package/src/components/base/ui/directive/repeat-click.js +24 -0
  50. package/src/components/base/ui/directive/ripple.js +303 -0
  51. package/src/components/base/ui/divider/Divider.vue +37 -0
  52. package/src/components/base/ui/drawer/Drawer.vue +202 -0
  53. package/src/components/base/ui/dropdown/dropdown-item.vue +39 -0
  54. package/src/components/base/ui/dropdown/dropdown-menu.vue +63 -0
  55. package/src/components/base/ui/dropdown/dropdown.vue +308 -0
  56. package/src/components/base/ui/form/Form.vue +167 -0
  57. package/src/components/base/ui/form/FormItem.vue +334 -0
  58. package/src/components/base/ui/form/LabelWrap.vue +69 -0
  59. package/src/components/base/ui/icon/icon.vue +13 -0
  60. package/src/components/base/ui/image/image-viewer.vue +302 -0
  61. package/src/components/base/ui/image/main.vue +248 -0
  62. package/src/components/base/ui/index.js +189 -0
  63. package/src/components/base/ui/input/Input.vue +438 -0
  64. package/src/components/base/ui/input/calcTextareaHeight.js +104 -0
  65. package/src/components/base/ui/input-number/input-number.vue +285 -0
  66. package/src/components/base/ui/locale/format.js +32 -0
  67. package/src/components/base/ui/locale/index.js +48 -0
  68. package/src/components/base/ui/locale/lang/zh-CN.js +120 -0
  69. package/src/components/base/ui/menu/menu-item-group.vue +45 -0
  70. package/src/components/base/ui/menu/menu-item.vue +112 -0
  71. package/src/components/base/ui/menu/menu-mixin.js +44 -0
  72. package/src/components/base/ui/menu/menu.vue +312 -0
  73. package/src/components/base/ui/menu/submenu.vue +408 -0
  74. package/src/components/base/ui/message/index.js +2 -0
  75. package/src/components/base/ui/message/main.js +87 -0
  76. package/src/components/base/ui/message/main.vue +110 -0
  77. package/src/components/base/ui/message-box/main.js +216 -0
  78. package/src/components/base/ui/message-box/main.vue +323 -0
  79. package/src/components/base/ui/mixin/emitter.js +31 -0
  80. package/src/components/base/ui/mixin/focus.js +9 -0
  81. package/src/components/base/ui/mixin/locale.js +9 -0
  82. package/src/components/base/ui/mixin/migrating.js +33 -0
  83. package/src/components/base/ui/pagination/pager.vue +163 -0
  84. package/src/components/base/ui/pagination/pagination.jsx +391 -0
  85. package/src/components/base/ui/popover/directive.js +20 -0
  86. package/src/components/base/ui/popover/index.js +14 -0
  87. package/src/components/base/ui/popover/main.vue +236 -0
  88. package/src/components/base/ui/progress/Progress.vue +227 -0
  89. package/src/components/base/ui/radio/radio-button.vue +114 -0
  90. package/src/components/base/ui/radio/radio-group.vue +111 -0
  91. package/src/components/base/ui/radio/radio.vue +134 -0
  92. package/src/components/base/ui/row/row.js +47 -0
  93. package/src/components/base/ui/scrollbar/bar.jsx +91 -0
  94. package/src/components/base/ui/scrollbar/index.jsx +203 -0
  95. package/src/components/base/ui/scrollbar/util.js +32 -0
  96. package/src/components/base/ui/select/Option.vue +168 -0
  97. package/src/components/base/ui/select/OptionGroup.vue +60 -0
  98. package/src/components/base/ui/select/Select.vue +920 -0
  99. package/src/components/base/ui/select/SelectDropdown.vue +74 -0
  100. package/src/components/base/ui/select/navigation-mixin.js +54 -0
  101. package/src/components/base/ui/skeleton/index.js +8 -0
  102. package/src/components/base/ui/skeleton/src/img-placeholder.vue +16 -0
  103. package/src/components/base/ui/skeleton/src/index.vue +80 -0
  104. package/src/components/base/ui/skeleton/src/item.vue +22 -0
  105. package/src/components/base/ui/skeleton-item/index.js +8 -0
  106. package/src/components/base/ui/slider/button.vue +238 -0
  107. package/src/components/base/ui/slider/main.vue +427 -0
  108. package/src/components/base/ui/slider/marker.js +18 -0
  109. package/src/components/base/ui/style/alert.scss +147 -0
  110. package/src/components/base/ui/style/animations.scss +65 -0
  111. package/src/components/base/ui/style/autocomplete.scss +81 -0
  112. package/src/components/base/ui/style/backtop.scss +20 -0
  113. package/src/components/base/ui/style/button-group.scss +0 -0
  114. package/src/components/base/ui/style/button.scss +380 -0
  115. package/src/components/base/ui/style/carousel-item.scss +50 -0
  116. package/src/components/base/ui/style/carousel.scss +161 -0
  117. package/src/components/base/ui/style/cascader-panel.scss +120 -0
  118. package/src/components/base/ui/style/cascader.scss +185 -0
  119. package/src/components/base/ui/style/checkbox-button.scss +0 -0
  120. package/src/components/base/ui/style/checkbox-group.scss +0 -0
  121. package/src/components/base/ui/style/checkbox.scss +360 -0
  122. package/src/components/base/ui/style/col.scss +156 -0
  123. package/src/components/base/ui/style/collapse-item.scss +0 -0
  124. package/src/components/base/ui/style/collapse.scss +114 -0
  125. package/src/components/base/ui/style/color-picker.scss +387 -0
  126. package/src/components/base/ui/style/config.scss +4 -0
  127. package/src/components/base/ui/style/date-picker/date-picker.scss +97 -0
  128. package/src/components/base/ui/style/date-picker/date-range-picker.scss +101 -0
  129. package/src/components/base/ui/style/date-picker/date-table.scss +151 -0
  130. package/src/components/base/ui/style/date-picker/month-table.scss +82 -0
  131. package/src/components/base/ui/style/date-picker/picker-panel.scss +117 -0
  132. package/src/components/base/ui/style/date-picker/picker.scss +197 -0
  133. package/src/components/base/ui/style/date-picker/time-picker.scss +85 -0
  134. package/src/components/base/ui/style/date-picker/time-range-picker.scss +31 -0
  135. package/src/components/base/ui/style/date-picker/time-spinner.scss +110 -0
  136. package/src/components/base/ui/style/date-picker/year-table.scss +51 -0
  137. package/src/components/base/ui/style/date-picker.scss +12 -0
  138. package/src/components/base/ui/style/dialog.scss +123 -0
  139. package/src/components/base/ui/style/divider.scss +47 -0
  140. package/src/components/base/ui/style/drawer.scss +218 -0
  141. package/src/components/base/ui/style/dropdown-item.scss +0 -0
  142. package/src/components/base/ui/style/dropdown-menu.scss +0 -0
  143. package/src/components/base/ui/style/dropdown.scss +185 -0
  144. package/src/components/base/ui/style/form-item.scss +0 -0
  145. package/src/components/base/ui/style/form.scss +203 -0
  146. package/src/components/base/ui/style/function.scss +43 -0
  147. package/src/components/base/ui/style/icon.scss +1167 -0
  148. package/src/components/base/ui/style/image.scss +184 -0
  149. package/src/components/base/ui/style/index.scss +57 -0
  150. package/src/components/base/ui/style/input-number.scss +187 -0
  151. package/src/components/base/ui/style/input.scss +477 -0
  152. package/src/components/base/ui/style/menu-item-group.scss +0 -0
  153. package/src/components/base/ui/style/menu-item.scss +0 -0
  154. package/src/components/base/ui/style/menu.scss +294 -0
  155. package/src/components/base/ui/style/message-box.scss +231 -0
  156. package/src/components/base/ui/style/message.scss +120 -0
  157. package/src/components/base/ui/style/mixins.scss +196 -0
  158. package/src/components/base/ui/style/option-group.scss +42 -0
  159. package/src/components/base/ui/style/option.scss +36 -0
  160. package/src/components/base/ui/style/pagination.scss +295 -0
  161. package/src/components/base/ui/style/popover.scss +40 -0
  162. package/src/components/base/ui/style/popper.scss +102 -0
  163. package/src/components/base/ui/style/popup.scss +42 -0
  164. package/src/components/base/ui/style/progress.scss +141 -0
  165. package/src/components/base/ui/style/radio-button.scss +113 -0
  166. package/src/components/base/ui/style/radio-group.scss +9 -0
  167. package/src/components/base/ui/style/radio.scss +203 -0
  168. package/src/components/base/ui/style/ripple.scss +35 -0
  169. package/src/components/base/ui/style/row.scss +39 -0
  170. package/src/components/base/ui/style/scrollbar.scss +75 -0
  171. package/src/components/base/ui/style/select-dropdown.scss +59 -0
  172. package/src/components/base/ui/style/select.scss +154 -0
  173. package/src/components/base/ui/style/skeleton-item.scss +84 -0
  174. package/src/components/base/ui/style/skeleton.scss +40 -0
  175. package/src/components/base/ui/style/slider.scss +250 -0
  176. package/src/components/base/ui/style/switch.scss +116 -0
  177. package/src/components/base/ui/style/tabs.scss +602 -0
  178. package/src/components/base/ui/style/tag.scss +174 -0
  179. package/src/components/base/ui/style/tooltip.scss +146 -0
  180. package/src/components/base/ui/style/transition.scss +138 -0
  181. package/src/components/base/ui/style/upload.scss +603 -0
  182. package/src/components/base/ui/style/utils.scss +39 -0
  183. package/src/components/base/ui/style/var.scss +1007 -0
  184. package/src/components/base/ui/switch/index.vue +174 -0
  185. package/src/components/base/ui/tabs/tab-bar.vue +57 -0
  186. package/src/components/base/ui/tabs/tab-nav.vue +294 -0
  187. package/src/components/base/ui/tabs/tab-pane.vue +56 -0
  188. package/src/components/base/ui/tabs/tabs.vue +191 -0
  189. package/src/components/base/ui/tag/Tag.vue +60 -0
  190. package/src/components/base/ui/tooltip/tooltip.jsx +234 -0
  191. package/src/components/base/ui/upload/Index.vue +340 -0
  192. package/src/components/base/ui/upload/Upload.vue +216 -0
  193. package/src/components/base/ui/upload/UploadDragger.vue +70 -0
  194. package/src/components/base/ui/upload/UploadList.vue +100 -0
  195. package/src/components/base/ui/upload/ajax.js +85 -0
  196. package/src/components/base/ui/util/aria-dialog.js +90 -0
  197. package/src/components/base/ui/util/aria-utils.js +122 -0
  198. package/src/components/base/ui/util/clickoutside.js +76 -0
  199. package/src/components/base/ui/util/date-util.js +292 -0
  200. package/src/components/base/ui/util/date.js +370 -0
  201. package/src/components/base/ui/util/debounce.js +21 -0
  202. package/src/components/base/ui/util/deepmerge.js +100 -0
  203. package/src/components/base/ui/util/dom.js +215 -0
  204. package/src/components/base/ui/util/index.js +262 -0
  205. package/src/components/base/ui/util/menu/aria-menubar.js +14 -0
  206. package/src/components/base/ui/util/menu/aria-menuitem.js +49 -0
  207. package/src/components/base/ui/util/menu/aria-submenu.js +59 -0
  208. package/src/components/base/ui/util/merge.js +14 -0
  209. package/src/components/base/ui/util/popper.js +1235 -0
  210. package/src/components/base/ui/util/popup/index.js +218 -0
  211. package/src/components/base/ui/util/popup/popup-manager.js +194 -0
  212. package/src/components/base/ui/util/resize-events.js +32 -0
  213. package/src/components/base/ui/util/scroll-into-view.js +27 -0
  214. package/src/components/base/ui/util/scrollbar-width.js +29 -0
  215. package/src/components/base/ui/util/shared.js +7 -0
  216. package/src/components/base/ui/util/throttle.js +91 -0
  217. package/src/components/base/ui/util/types.js +24 -0
  218. package/src/components/base/ui/util/vdom.js +5 -0
  219. package/src/components/base/ui/util/vue-popper.js +188 -0
  220. package/src/components/normal/AggsItemH.vue +139 -0
  221. package/src/index.js +10 -0
  222. package/src/static/base-icons.ttf +0 -0
  223. package/src/static/base-icons.woff +0 -0
  224. package/src/static/label_bg.png +0 -0
  225. package/src/static/term-label-bg.png +0 -0
  226. package/src/style/app-article.scss +698 -0
  227. package/src/style/app-comment.scss +259 -0
  228. package/src/style/app-recommend.scss +48 -0
  229. package/src/style/app-richtext.scss +176 -0
  230. package/src/style/index.scss +523 -0
  231. package/vite.config.js +38 -0
@@ -0,0 +1,216 @@
1
+ const defaults = {
2
+ title: null,
3
+ message: '',
4
+ type: '',
5
+ iconClass: '',
6
+ showInput: false,
7
+ showClose: false,
8
+ modalFade: true,
9
+ lockScroll: true,
10
+ closeOnClickModal: true,
11
+ closeOnPressEscape: true,
12
+ closeOnHashChange: true,
13
+ inputValue: null,
14
+ inputPlaceholder: '',
15
+ inputType: 'text',
16
+ inputPattern: null,
17
+ inputValidator: null,
18
+ inputErrorMessage: '',
19
+ showConfirmButton: true,
20
+ showCancelButton: false,
21
+ confirmButtonPosition: 'right',
22
+ confirmButtonHighlight: false,
23
+ cancelButtonHighlight: false,
24
+ confirmButtonText: '',
25
+ cancelButtonText: '',
26
+ confirmButtonClass: '',
27
+ cancelButtonClass: '',
28
+ customClass: '',
29
+ beforeClose: null,
30
+ dangerouslyUseHTMLString: false,
31
+ center: true,
32
+ roundButton: false,
33
+ distinguishCancelAndClose: false
34
+ };
35
+
36
+ import Vue from 'vue';
37
+ import msgboxVue from './main.vue';
38
+ import merge from '../util/merge';
39
+ import { isVNode } from '../util/vdom';
40
+
41
+ const MessageBoxConstructor = Vue.extend(msgboxVue);
42
+
43
+ let currentMsg, instance;
44
+ let msgQueue = [];
45
+
46
+ const defaultCallback = action => {
47
+ if (currentMsg) {
48
+ let callback = currentMsg.callback;
49
+ if (typeof callback === 'function') {
50
+ if (instance.showInput) {
51
+ callback(instance.inputValue, action);
52
+ } else {
53
+ callback(action);
54
+ }
55
+ }
56
+ if (currentMsg.resolve) {
57
+ if (action === 'confirm') {
58
+ if (instance.showInput) {
59
+ currentMsg.resolve({ value: instance.inputValue, action });
60
+ } else {
61
+ currentMsg.resolve(action);
62
+ }
63
+ } else if (currentMsg.reject && (action === 'cancel' || action === 'close')) {
64
+ currentMsg.reject(action);
65
+ }
66
+ }
67
+ }
68
+ };
69
+
70
+ const initInstance = () => {
71
+ instance = new MessageBoxConstructor({
72
+ el: document.createElement('div')
73
+ });
74
+
75
+ instance.callback = defaultCallback;
76
+ };
77
+
78
+ const showNextMsg = () => {
79
+ if (!instance) {
80
+ initInstance();
81
+ }
82
+ instance.action = '';
83
+
84
+ if (!instance.visible || instance.closeTimer) {
85
+ if (msgQueue.length > 0) {
86
+ currentMsg = msgQueue.shift();
87
+
88
+ let options = currentMsg.options;
89
+ for (let prop in options) {
90
+ if (options.hasOwnProperty(prop)) {
91
+ instance[prop] = options[prop];
92
+ }
93
+ }
94
+ if (options.callback === undefined) {
95
+ instance.callback = defaultCallback;
96
+ }
97
+
98
+ let oldCb = instance.callback;
99
+ instance.callback = (action, instance) => {
100
+ oldCb(action, instance);
101
+ showNextMsg();
102
+ };
103
+ if (isVNode(instance.message)) {
104
+ instance.$slots.default = [instance.message];
105
+ instance.message = null;
106
+ } else {
107
+ delete instance.$slots.default;
108
+ }
109
+ ['modal', 'showClose', 'closeOnClickModal', 'closeOnPressEscape', 'closeOnHashChange'].forEach(prop => {
110
+ if (instance[prop] === undefined) {
111
+ instance[prop] = true;
112
+ }
113
+ });
114
+ document.body.appendChild(instance.$el);
115
+
116
+ Vue.nextTick(() => {
117
+ instance.visible = true;
118
+ });
119
+ }
120
+ }
121
+ };
122
+
123
+ const MessageBox = function(options, callback) {
124
+ if (Vue.prototype.$isServer) return;
125
+ if (typeof options === 'string' || isVNode(options)) {
126
+ options = {
127
+ message: options
128
+ };
129
+ if (typeof arguments[1] === 'string') {
130
+ options.title = arguments[1];
131
+ }
132
+ } else if (options.callback && !callback) {
133
+ callback = options.callback;
134
+ }
135
+
136
+ if (typeof Promise !== 'undefined') {
137
+ return new Promise((resolve, reject) => { // eslint-disable-line
138
+ msgQueue.push({
139
+ options: merge({}, defaults, MessageBox.defaults, options),
140
+ callback: callback,
141
+ resolve: resolve,
142
+ reject: reject
143
+ });
144
+
145
+ showNextMsg();
146
+ });
147
+ } else {
148
+ msgQueue.push({
149
+ options: merge({}, defaults, MessageBox.defaults, options),
150
+ callback: callback
151
+ });
152
+
153
+ showNextMsg();
154
+ }
155
+ };
156
+
157
+ MessageBox.setDefaults = defaults => {
158
+ MessageBox.defaults = defaults;
159
+ };
160
+
161
+ MessageBox.alert = (message, title, options) => {
162
+ if (typeof title === 'object') {
163
+ options = title;
164
+ title = '';
165
+ } else if (title === undefined) {
166
+ title = '';
167
+ }
168
+ return MessageBox(merge({
169
+ title: title,
170
+ message: message,
171
+ $type: 'alert',
172
+ closeOnPressEscape: false,
173
+ closeOnClickModal: false
174
+ }, options));
175
+ };
176
+
177
+ MessageBox.confirm = (message, title, options) => {
178
+ if (typeof title === 'object') {
179
+ options = title;
180
+ title = '';
181
+ } else if (title === undefined) {
182
+ title = '';
183
+ }
184
+ return MessageBox(merge({
185
+ title: title,
186
+ message: message,
187
+ $type: 'confirm',
188
+ showCancelButton: true
189
+ }, options));
190
+ };
191
+
192
+ MessageBox.prompt = (message, title, options) => {
193
+ if (typeof title === 'object') {
194
+ options = title;
195
+ title = '';
196
+ } else if (title === undefined) {
197
+ title = '';
198
+ }
199
+ return MessageBox(merge({
200
+ title: title,
201
+ message: message,
202
+ showCancelButton: true,
203
+ showInput: true,
204
+ $type: 'prompt'
205
+ }, options));
206
+ };
207
+
208
+ MessageBox.close = () => {
209
+ instance.doClose();
210
+ instance.visible = false;
211
+ msgQueue = [];
212
+ currentMsg = null;
213
+ };
214
+
215
+ export default MessageBox;
216
+ export { MessageBox };
@@ -0,0 +1,323 @@
1
+ <template>
2
+ <transition name="msgbox-fade">
3
+ <div
4
+ class="base-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="base-message-box" :class="[customClass, center && 'base-message-box--center']">
12
+ <div class="base-message-box__header" v-if="title !== null">
13
+ <div class="base-message-box__title">{{ title }}</div>
14
+ <button
15
+ type="button"
16
+ class="base-message-box__headerbtn"
17
+ aria-label="Close"
18
+ v-if="showClose"
19
+ @click="handleAction(distinguishCancelAndClose ? 'close' : 'cancel')"
20
+ @keydown.enter="handleAction(distinguishCancelAndClose ? 'close' : 'cancel')">
21
+ <i class="base-message-box__close base-icon-close"></i>
22
+ </button>
23
+ </div>
24
+ <div class="base-message-box__content">
25
+ <div class="base-message-box__container">
26
+ <div class="base-message-box__message" v-if="message !== ''">
27
+ <slot>
28
+ <p v-if="!dangerouslyUseHTMLString">{{ message }}</p>
29
+ <p v-else v-html="message"></p>
30
+ </slot>
31
+ </div>
32
+ </div>
33
+ <div class="base-message-box__input" v-if="showInput">
34
+ <base-input
35
+ v-model="inputValue"
36
+ :type="inputType"
37
+ @keydown.enter.native="handleInputEnter"
38
+ :placeholder="inputPlaceholder"
39
+ ref="input"></base-input>
40
+ <div class="base-message-box__errormsg" :style="{ visibility: !!editorErrorMessage ? 'visible' : 'hidden' }">{{ editorErrorMessage }}</div>
41
+ </div>
42
+ </div>
43
+ <div class="base-message-box__btns">
44
+ <base-button
45
+ :loading="cancelButtonLoading"
46
+ :class="[ cancelButtonClasses ]"
47
+ v-if="showCancelButton"
48
+ :round="roundButton"
49
+ size="medium"
50
+ light
51
+ @click.native="handleAction('cancel')"
52
+ @keydown.enter="handleAction('cancel')">
53
+ {{ cancelButtonText || t('base.messagebox.cancel') }}
54
+ </base-button>
55
+ <base-button
56
+ :loading="confirmButtonLoading"
57
+ ref="confirm"
58
+ :class="[ confirmButtonClasses ]"
59
+ v-show="showConfirmButton"
60
+ :round="roundButton"
61
+ size="medium"
62
+ @click.native="handleAction('confirm')"
63
+ @keydown.enter="handleAction('confirm')">
64
+ {{ confirmButtonText || t('base.messagebox.confirm') }}
65
+ </base-button>
66
+ </div>
67
+ </div>
68
+ </div>
69
+ </transition>
70
+ </template>
71
+
72
+ <script type="text/babel">
73
+ import Popup from '../util/popup';
74
+ import Locale from '../mixin/locale';
75
+ import BaseInput from '../input/Input';
76
+ import BaseButton from '../button/Button';
77
+ import { addClass, removeClass } from '../util/dom';
78
+ import { t } from '../locale';
79
+ import Dialog from '../util/aria-dialog';
80
+
81
+ let messageBox;
82
+ let typeMap = {
83
+ success: 'success',
84
+ info: 'info',
85
+ warning: 'warning',
86
+ error: 'error'
87
+ };
88
+
89
+ export default {
90
+ mixins: [Popup, Locale],
91
+
92
+ props: {
93
+ modal: {
94
+ default: true
95
+ },
96
+ lockScroll: {
97
+ default: true
98
+ },
99
+ showClose: {
100
+ type: Boolean,
101
+ default: true
102
+ },
103
+ closeOnClickModal: {
104
+ default: true
105
+ },
106
+ closeOnPressEscape: {
107
+ default: true
108
+ },
109
+ closeOnHashChange: {
110
+ default: true
111
+ },
112
+ center: {
113
+ default: false,
114
+ type: Boolean
115
+ },
116
+ roundButton: {
117
+ default: false,
118
+ type: Boolean
119
+ }
120
+ },
121
+
122
+ components: {
123
+ BaseInput,
124
+ BaseButton
125
+ },
126
+
127
+ computed: {
128
+ icon() {
129
+ const { type, iconClass } = this;
130
+ return iconClass || (type && typeMap[type] ? `base-icon-${ typeMap[type] }` : '');
131
+ },
132
+
133
+ confirmButtonClasses() {
134
+ return `base-button--primary ${ this.confirmButtonClass }`;
135
+ },
136
+ cancelButtonClasses() {
137
+ return `${ this.cancelButtonClass }`;
138
+ }
139
+ },
140
+
141
+ methods: {
142
+ getSafeClose() {
143
+ const currentId = this.uid;
144
+ return () => {
145
+ this.$nextTick(() => {
146
+ if (currentId === this.uid) this.doClose();
147
+ });
148
+ };
149
+ },
150
+ doClose() {
151
+ if (!this.visible) return;
152
+ this.visible = false;
153
+ this._closing = true;
154
+
155
+ this.onClose && this.onClose();
156
+ messageBox.closeDialog(); // 解绑
157
+ if (this.lockScroll) {
158
+ setTimeout(this.restoreBodyStyle, 200);
159
+ }
160
+ this.opened = false;
161
+ this.doAfterClose();
162
+ setTimeout(() => {
163
+ if (this.action) this.callback(this.action, this);
164
+ });
165
+ },
166
+
167
+ handleWrapperClick() {
168
+ if (this.closeOnClickModal) {
169
+ this.handleAction(this.distinguishCancelAndClose ? 'close' : 'cancel');
170
+ }
171
+ },
172
+
173
+ handleInputEnter() {
174
+ if (this.inputType !== 'textarea') {
175
+ return this.handleAction('confirm');
176
+ }
177
+ },
178
+
179
+ handleAction(action) {
180
+ if (this.$type === 'prompt' && action === 'confirm' && !this.validate()) {
181
+ return;
182
+ }
183
+ this.action = action;
184
+ if (typeof this.beforeClose === 'function') {
185
+ this.close = this.getSafeClose();
186
+ this.beforeClose(action, this, this.close);
187
+ } else {
188
+ this.doClose();
189
+ }
190
+ },
191
+
192
+ validate() {
193
+ if (this.$type === 'prompt') {
194
+ const inputPattern = this.inputPattern;
195
+ if (inputPattern && !inputPattern.test(this.inputValue || '')) {
196
+ this.editorErrorMessage = this.inputErrorMessage || t('base.messagebox.error');
197
+ addClass(this.getInputElement(), 'invalid');
198
+ return false;
199
+ }
200
+ const inputValidator = this.inputValidator;
201
+ if (typeof inputValidator === 'function') {
202
+ const validateResult = inputValidator(this.inputValue);
203
+ if (validateResult === false) {
204
+ this.editorErrorMessage = this.inputErrorMessage || t('base.messagebox.error');
205
+ addClass(this.getInputElement(), 'invalid');
206
+ return false;
207
+ }
208
+ if (typeof validateResult === 'string') {
209
+ this.editorErrorMessage = validateResult;
210
+ addClass(this.getInputElement(), 'invalid');
211
+ return false;
212
+ }
213
+ }
214
+ }
215
+ this.editorErrorMessage = '';
216
+ removeClass(this.getInputElement(), 'invalid');
217
+ return true;
218
+ },
219
+ getFirstFocus() {
220
+ const btn = this.$el.querySelector('.base-message-box__btns .base-button');
221
+ const title = this.$el.querySelector('.base-message-box__btns .base-message-box__title');
222
+ return btn || title;
223
+ },
224
+ getInputElement() {
225
+ const inputRefs = this.$refs.input.$refs;
226
+ return inputRefs.input || inputRefs.textarea;
227
+ },
228
+ handleClose() {
229
+ this.handleAction('close');
230
+ }
231
+ },
232
+
233
+ watch: {
234
+ inputValue: {
235
+ immediate: true,
236
+ handler(val) {
237
+ this.$nextTick(_ => {
238
+ if (this.$type === 'prompt' && val !== null) {
239
+ this.validate();
240
+ }
241
+ });
242
+ }
243
+ },
244
+
245
+ visible(val) {
246
+ if (val) {
247
+ this.uid++;
248
+ if (this.$type === 'alert' || this.$type === 'confirm') {
249
+ this.$nextTick(() => {
250
+ this.$refs.confirm.$el.focus();
251
+ });
252
+ }
253
+ this.focusAfterClosed = document.activeElement;
254
+ messageBox = new Dialog(this.$el, this.focusAfterClosed, this.getFirstFocus());
255
+ }
256
+
257
+ // prompt
258
+ if (this.$type !== 'prompt') return;
259
+ if (val) {
260
+ setTimeout(() => {
261
+ if (this.$refs.input && this.$refs.input.$el) {
262
+ this.getInputElement().focus();
263
+ }
264
+ }, 500);
265
+ } else {
266
+ this.editorErrorMessage = '';
267
+ removeClass(this.getInputElement(), 'invalid');
268
+ }
269
+ }
270
+ },
271
+
272
+ mounted() {
273
+ this.$nextTick(() => {
274
+ if (this.closeOnHashChange) {
275
+ window.addEventListener('hashchange', this.close);
276
+ }
277
+ });
278
+ },
279
+
280
+ beforeDestroy() {
281
+ if (this.closeOnHashChange) {
282
+ window.removeEventListener('hashchange', this.close);
283
+ }
284
+ setTimeout(() => {
285
+ messageBox.closeDialog();
286
+ });
287
+ },
288
+
289
+ data() {
290
+ return {
291
+ uid: 1,
292
+ title: undefined,
293
+ message: '',
294
+ type: '',
295
+ iconClass: '',
296
+ customClass: '',
297
+ showInput: false,
298
+ inputValue: null,
299
+ inputPlaceholder: '',
300
+ inputType: 'text',
301
+ inputPattern: null,
302
+ inputValidator: null,
303
+ inputErrorMessage: '',
304
+ showConfirmButton: true,
305
+ showCancelButton: false,
306
+ action: '',
307
+ confirmButtonText: '',
308
+ cancelButtonText: '',
309
+ confirmButtonLoading: false,
310
+ cancelButtonLoading: false,
311
+ confirmButtonClass: '',
312
+ confirmButtonDisabled: false,
313
+ cancelButtonClass: '',
314
+ editorErrorMessage: null,
315
+ callback: null,
316
+ dangerouslyUseHTMLString: false,
317
+ focusAfterClosed: null,
318
+ isOnComposition: false,
319
+ distinguishCancelAndClose: false
320
+ };
321
+ }
322
+ };
323
+ </script>
@@ -0,0 +1,31 @@
1
+ function broadcast (componentName, eventName, params) {
2
+ this.$children.forEach(child => {
3
+ let name = child.$options.componentName
4
+ if (name === componentName) {
5
+ child.$emit.apply(child, [eventName].concat(params))
6
+ } else {
7
+ broadcast.apply(child, [componentName, eventName].concat([params]))
8
+ }
9
+ })
10
+ }
11
+ export default {
12
+ methods: {
13
+ dispatch (componentName, eventName, params) {
14
+ let parent = this.$parent || this.$root
15
+ let name = parent.$options.componentName
16
+
17
+ while (parent && (!name || name !== componentName)) {
18
+ parent = parent.$parent
19
+ if (parent) {
20
+ name = parent.$options.componentName
21
+ }
22
+ }
23
+ if (parent) {
24
+ parent.$emit.apply(parent, [eventName].concat(params))
25
+ }
26
+ },
27
+ broadcast (componentName, eventName, params) {
28
+ broadcast.call(this, componentName, eventName, params)
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,9 @@
1
+ export default function(ref) {
2
+ return {
3
+ methods: {
4
+ focus() {
5
+ this.$refs[ref].focus()
6
+ }
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { t } from '../locale/index'
2
+
3
+ export default {
4
+ methods: {
5
+ t(...args) {
6
+ return t.apply(this, args)
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,33 @@
1
+ import { kebabCase } from '../util/index'
2
+ export default {
3
+ mounted() {
4
+ if (process.env.NODE_ENV === 'production') return
5
+ if (!this.$vnode) return
6
+ const { props = {}, events = {} } = this.getMigratingConfig()
7
+ const { data, componentOptions } = this.$vnode
8
+ const definedProps = data.attrs || {}
9
+ const definedEvents = componentOptions.listeners || {}
10
+
11
+ for (let propName in definedProps) {
12
+ propName = kebabCase(propName)
13
+ if (props[propName]) {
14
+ console.warn(`[Element Migrating][${this.$options.name}][Attribute]: ${props[propName]}`)
15
+ }
16
+ }
17
+
18
+ for (let eventName in definedEvents) {
19
+ eventName = kebabCase(eventName)
20
+ if (events[eventName]) {
21
+ console.warn(`[Element Migrating][${this.$options.name}][Event]: ${events[eventName]}`)
22
+ }
23
+ }
24
+ },
25
+ methods: {
26
+ getMigratingConfig() {
27
+ return {
28
+ props: {},
29
+ events: {}
30
+ }
31
+ }
32
+ }
33
+ }