@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,942 @@
1
+ <template>
2
+ <base-input
3
+ class="base-date-editor"
4
+ :class="'base-date-editor--' + type"
5
+ :readonly="!editable || readonly || type === 'dates' || type === 'week'"
6
+ :disabled="pickerDisabled"
7
+ :size="pickerSize"
8
+ :ripple="ripple"
9
+ :show-label="false"
10
+ :name="name"
11
+ v-bind="firstInputId"
12
+ v-if="!ranged"
13
+ v-clickoutside="handleClose"
14
+ :placeholder="placeholder"
15
+ @focus="handleFocus"
16
+ @keydown.native="handleKeydown"
17
+ :value="displayValue"
18
+ @input="value => userInput = value"
19
+ @change="handleChange"
20
+ @mouseenter.native="handleMouseEnter"
21
+ @mouseleave.native="showClose = false"
22
+ :validateEvent="false"
23
+ ref="reference">
24
+ <i v-if="prefixIcon"
25
+ slot="prefix"
26
+ class="base-input__icon"
27
+ :class="triggerClass"
28
+ @click="handleFocus">
29
+ </i>
30
+ <i slot="suffix"
31
+ class="base-input__icon"
32
+ @click="handleClickIcon"
33
+ :class="[showClose ? '' + clearIcon : '']"
34
+ v-if="haveTrigger">
35
+ </i>
36
+ </base-input>
37
+ <div
38
+ class="base-date-editor base-range-editor base-input__inner"
39
+ :class="[
40
+ 'base-date-editor--' + type,
41
+ pickerSize ? `base-range-editor--${ pickerSize }` : '',
42
+ pickerDisabled ? 'is-disabled' : '',
43
+ pickerVisible ? 'is-active' : ''
44
+ ]"
45
+ @click="handleRangeClick"
46
+ @mouseenter="handleMouseEnter"
47
+ @mouseleave="showClose = false"
48
+ @keydown="handleKeydown"
49
+ ref="reference"
50
+ v-clickoutside="handleClose"
51
+ v-else>
52
+ <i :class="['base-input__icon', 'base-range__icon', triggerClass]"></i>
53
+ <input
54
+ autocomplete="off"
55
+ :placeholder="startPlaceholder"
56
+ :value="displayValue && displayValue[0]"
57
+ :disabled="pickerDisabled"
58
+ v-bind="firstInputId"
59
+ :readonly="!editable || readonly"
60
+ :name="name && name[0]"
61
+ @input="handleStartInput"
62
+ @change="handleStartChange"
63
+ @focus="handleFocus"
64
+ class="base-range-input">
65
+ <slot name="range-separator">
66
+ <span class="base-range-separator">{{ rangeSeparator }}</span>
67
+ </slot>
68
+ <input
69
+ autocomplete="off"
70
+ :placeholder="endPlaceholder"
71
+ :value="displayValue && displayValue[1]"
72
+ :disabled="pickerDisabled"
73
+ v-bind="secondInputId"
74
+ :readonly="!editable || readonly"
75
+ :name="name && name[1]"
76
+ @input="handleEndInput"
77
+ @change="handleEndChange"
78
+ @focus="handleFocus"
79
+ class="base-range-input">
80
+ <i
81
+ @click="handleClickIcon"
82
+ v-if="haveTrigger"
83
+ :class="[showClose ? '' + clearIcon : '']"
84
+ class="base-input__icon base-range__close-icon">
85
+ </i>
86
+ </div>
87
+ </template>
88
+
89
+ <script>
90
+ import Vue from 'vue';
91
+ import Clickoutside from '../util/clickoutside';
92
+ import { formatDate, parseDate, isDateObject, getWeekNumber } from '../util/date-util';
93
+ import Popper from '../util/vue-popper';
94
+ import Emitter from '../mixin/emitter';
95
+ import BaseInput from '../input/Input';
96
+ import merge from '../util/merge';
97
+
98
+ const NewPopper = {
99
+ props: {
100
+ appendToBody: Popper.props.appendToBody,
101
+ offset: Popper.props.offset,
102
+ boundariesPadding: Popper.props.boundariesPadding,
103
+ arrowOffset: Popper.props.arrowOffset
104
+ },
105
+ methods: Popper.methods,
106
+ data() {
107
+ return merge({ visibleArrow: false }, Popper.data);
108
+ },
109
+ beforeDestroy: Popper.beforeDestroy
110
+ };
111
+
112
+ const DEFAULT_FORMATS = {
113
+ date: 'yyyy-MM-dd',
114
+ month: 'yyyy-MM',
115
+ datetime: 'yyyy-MM-dd HH:mm:ss',
116
+ time: 'HH:mm:ss',
117
+ week: 'yyyywWW',
118
+ timerange: 'HH:mm:ss',
119
+ daterange: 'yyyy-MM-dd',
120
+ monthrange: 'yyyy-MM',
121
+ yearrange: 'yyyy',
122
+ datetimerange: 'yyyy-MM-dd HH:mm:ss',
123
+ year: 'yyyy'
124
+ };
125
+ const HAVE_TRIGGER_TYPES = [
126
+ 'date',
127
+ 'datetime',
128
+ 'time',
129
+ 'time-select',
130
+ 'week',
131
+ 'month',
132
+ 'year',
133
+ 'daterange',
134
+ 'monthrange',
135
+ 'yearrange',
136
+ 'timerange',
137
+ 'datetimerange',
138
+ 'dates'
139
+ ];
140
+ const DATE_FORMATTER = function(value, format) {
141
+ if (format === 'timestamp') return value.getTime();
142
+ return formatDate(value, format);
143
+ };
144
+ const DATE_PARSER = function(text, format) {
145
+ if (format === 'timestamp') return new Date(Number(text));
146
+ return parseDate(text, format);
147
+ };
148
+ const RANGE_FORMATTER = function(value, format) {
149
+ if (Array.isArray(value) && value.length === 2) {
150
+ const start = value[0];
151
+ const end = value[1];
152
+
153
+ if (start && end) {
154
+ return [DATE_FORMATTER(start, format), DATE_FORMATTER(end, format)];
155
+ }
156
+ }
157
+ return '';
158
+ };
159
+ const RANGE_PARSER = function(array, format, separator) {
160
+ if (!Array.isArray(array)) {
161
+ array = array.split(separator);
162
+ }
163
+ if (array.length === 2) {
164
+ const range1 = array[0];
165
+ const range2 = array[1];
166
+
167
+ return [DATE_PARSER(range1, format), DATE_PARSER(range2, format)];
168
+ }
169
+ return [];
170
+ };
171
+ const TYPE_VALUE_RESOLVER_MAP = {
172
+ default: {
173
+ formatter(value) {
174
+ if (!value) return '';
175
+ return '' + value;
176
+ },
177
+ parser(text) {
178
+ if (text === undefined || text === '') return null;
179
+ return text;
180
+ }
181
+ },
182
+ week: {
183
+ formatter(value, format) {
184
+ let week = getWeekNumber(value);
185
+ let month = value.getMonth();
186
+ const trueDate = new Date(value);
187
+ if (week === 1 && month === 11) {
188
+ trueDate.setHours(0, 0, 0, 0);
189
+ trueDate.setDate(trueDate.getDate() + 3 - (trueDate.getDay() + 6) % 7);
190
+ }
191
+ let date = formatDate(trueDate, format);
192
+
193
+ date = /WW/.test(date)
194
+ ? date.replace(/WW/, week < 10 ? '0' + week : week)
195
+ : date.replace(/W/, week);
196
+ return date;
197
+ },
198
+ parser(text, format) {
199
+ // parse as if a normal date
200
+ return TYPE_VALUE_RESOLVER_MAP.date.parser(text, format);
201
+ }
202
+ },
203
+ date: {
204
+ formatter: DATE_FORMATTER,
205
+ parser: DATE_PARSER
206
+ },
207
+ datetime: {
208
+ formatter: DATE_FORMATTER,
209
+ parser: DATE_PARSER
210
+ },
211
+ daterange: {
212
+ formatter: RANGE_FORMATTER,
213
+ parser: RANGE_PARSER
214
+ },
215
+ monthrange: {
216
+ formatter: RANGE_FORMATTER,
217
+ parser: RANGE_PARSER
218
+ },
219
+ yearrange: {
220
+ formatter: RANGE_FORMATTER,
221
+ parser: RANGE_PARSER
222
+ },
223
+ datetimerange: {
224
+ formatter: RANGE_FORMATTER,
225
+ parser: RANGE_PARSER
226
+ },
227
+ timerange: {
228
+ formatter: RANGE_FORMATTER,
229
+ parser: RANGE_PARSER
230
+ },
231
+ time: {
232
+ formatter: DATE_FORMATTER,
233
+ parser: DATE_PARSER
234
+ },
235
+ month: {
236
+ formatter: DATE_FORMATTER,
237
+ parser: DATE_PARSER
238
+ },
239
+ year: {
240
+ formatter: DATE_FORMATTER,
241
+ parser: DATE_PARSER
242
+ },
243
+ number: {
244
+ formatter(value) {
245
+ if (!value) return '';
246
+ return '' + value;
247
+ },
248
+ parser(text) {
249
+ let result = Number(text);
250
+
251
+ if (!isNaN(text)) {
252
+ return result;
253
+ } else {
254
+ return null;
255
+ }
256
+ }
257
+ },
258
+ dates: {
259
+ formatter(value, format) {
260
+ return value.map(date => DATE_FORMATTER(date, format));
261
+ },
262
+ parser(value, format) {
263
+ return (typeof value === 'string' ? value.split(', ') : value)
264
+ .map(date => date instanceof Date ? date : DATE_PARSER(date, format));
265
+ }
266
+ }
267
+ };
268
+ const PLACEMENT_MAP = {
269
+ left: 'bottom-start',
270
+ center: 'bottom',
271
+ right: 'bottom-end'
272
+ };
273
+
274
+ const parseAsFormatAndType = (value, customFormat, type, rangeSeparator = '-') => {
275
+ if (!value) return null;
276
+ const parser = (
277
+ TYPE_VALUE_RESOLVER_MAP[type] ||
278
+ TYPE_VALUE_RESOLVER_MAP['default']
279
+ ).parser;
280
+ const format = customFormat || DEFAULT_FORMATS[type];
281
+ return parser(value, format, rangeSeparator);
282
+ };
283
+
284
+ const formatAsFormatAndType = (value, customFormat, type) => {
285
+ if (!value) return null;
286
+ const formatter = (
287
+ TYPE_VALUE_RESOLVER_MAP[type] ||
288
+ TYPE_VALUE_RESOLVER_MAP['default']
289
+ ).formatter;
290
+ const format = customFormat || DEFAULT_FORMATS[type];
291
+ return formatter(value, format);
292
+ };
293
+
294
+ /*
295
+ * Considers:
296
+ * 1. Date object
297
+ * 2. date string
298
+ * 3. array of 1 or 2
299
+ */
300
+ const valueEquals = function(a, b) {
301
+ // considers Date object and string
302
+ const dateEquals = function(a, b) {
303
+ const aIsDate = a instanceof Date;
304
+ const bIsDate = b instanceof Date;
305
+ if (aIsDate && bIsDate) {
306
+ return a.getTime() === b.getTime();
307
+ }
308
+ if (!aIsDate && !bIsDate) {
309
+ return a === b;
310
+ }
311
+ return false;
312
+ };
313
+
314
+ const aIsArray = a instanceof Array;
315
+ const bIsArray = b instanceof Array;
316
+ if (aIsArray && bIsArray) {
317
+ if (a.length !== b.length) {
318
+ return false;
319
+ }
320
+ return a.every((item, index) => dateEquals(item, b[index]));
321
+ }
322
+ if (!aIsArray && !bIsArray) {
323
+ return dateEquals(a, b);
324
+ }
325
+ return false;
326
+ };
327
+
328
+ const isString = function(val) {
329
+ return typeof val === 'string' || val instanceof String;
330
+ };
331
+
332
+ const validator = function(val) {
333
+ // either: String, Array of String, null / undefined
334
+ return (
335
+ val === null ||
336
+ val === undefined ||
337
+ isString(val) ||
338
+ (Array.isArray(val) && val.length === 2 && val.every(isString))
339
+ );
340
+ };
341
+
342
+ export default {
343
+ mixins: [Emitter, NewPopper],
344
+
345
+ inject: {
346
+ baseForm: {
347
+ default: ''
348
+ },
349
+ baseFormItem: {
350
+ default: ''
351
+ }
352
+ },
353
+
354
+ props: {
355
+ size: String,
356
+ format: String,
357
+ valueFormat: String,
358
+ readonly: Boolean,
359
+ placeholder: String,
360
+ startPlaceholder: String,
361
+ endPlaceholder: String,
362
+ prefixIcon: String,
363
+ clearIcon: {
364
+ type: String,
365
+ default: 'base-icon-circle-close'
366
+ },
367
+ name: {
368
+ default: '',
369
+ validator
370
+ },
371
+ disabled: Boolean,
372
+ clearable: {
373
+ type: Boolean,
374
+ default: true
375
+ },
376
+ id: {
377
+ default: '',
378
+ validator
379
+ },
380
+ popperClass: String,
381
+ editable: {
382
+ type: Boolean,
383
+ default: true
384
+ },
385
+ ripple: {
386
+ type: Boolean,
387
+ default: true
388
+ },
389
+ align: {
390
+ type: String,
391
+ default: 'left'
392
+ },
393
+ value: {},
394
+ defaultValue: {},
395
+ defaultTime: {},
396
+ rangeSeparator: {
397
+ default: '-'
398
+ },
399
+ pickerOptions: {},
400
+ unlinkPanels: Boolean,
401
+ validateEvent: {
402
+ type: Boolean,
403
+ default: true
404
+ }
405
+ },
406
+
407
+ components: { BaseInput },
408
+
409
+ directives: { Clickoutside },
410
+
411
+ data() {
412
+ return {
413
+ pickerVisible: false,
414
+ showClose: false,
415
+ userInput: null,
416
+ valueOnOpen: null, // value when picker opens, used to determine whether to emit change
417
+ unwatchPickerOptions: null
418
+ };
419
+ },
420
+
421
+ watch: {
422
+ pickerVisible(val) {
423
+ if (this.readonly || this.pickerDisabled) return;
424
+ if (val) {
425
+ this.showPicker();
426
+ this.valueOnOpen = Array.isArray(this.value) ? [...this.value] : this.value;
427
+ } else {
428
+ this.hidePicker();
429
+ this.emitChange(this.value);
430
+ this.userInput = null;
431
+ if (this.validateEvent) {
432
+ this.dispatch('BaseFormItem', 'base.form.blur');
433
+ }
434
+ this.$emit('blur', this);
435
+ this.blur();
436
+ }
437
+ },
438
+ parsedValue: {
439
+ immediate: true,
440
+ handler(val) {
441
+ if (this.picker) {
442
+ this.picker.value = val;
443
+ }
444
+ }
445
+ },
446
+ defaultValue(val) {
447
+ // NOTE: should eventually move to jsx style picker + panel ?
448
+ if (this.picker) {
449
+ this.picker.defaultValue = val;
450
+ }
451
+ },
452
+ value(val, oldVal) {
453
+ if (!valueEquals(val, oldVal) && !this.pickerVisible && this.validateEvent) {
454
+ this.dispatch('BaseFormItem', 'base.form.change', val);
455
+ }
456
+ }
457
+ },
458
+
459
+ computed: {
460
+ ranged() {
461
+ return this.type.indexOf('range') > -1;
462
+ },
463
+
464
+ reference() {
465
+ const reference = this.$refs.reference;
466
+ return reference.$el || reference;
467
+ },
468
+
469
+ refInput() {
470
+ if (this.reference) {
471
+ return [].slice.call(this.reference.querySelectorAll('input'));
472
+ }
473
+ return [];
474
+ },
475
+
476
+ valueIsEmpty() {
477
+ const val = this.value;
478
+ if (Array.isArray(val)) {
479
+ for (let i = 0, len = val.length; i < len; i++) {
480
+ if (val[i]) {
481
+ return false;
482
+ }
483
+ }
484
+ } else {
485
+ if (val) {
486
+ return false;
487
+ }
488
+ }
489
+ return true;
490
+ },
491
+
492
+ triggerClass() {
493
+ return this.prefixIcon || (this.type.indexOf('time') !== -1 ? 'base-icon-time' : 'base-icon-date');
494
+ },
495
+
496
+ selectionMode() {
497
+ if (this.type === 'week') {
498
+ return 'week';
499
+ } else if (this.type === 'month') {
500
+ return 'month';
501
+ } else if (this.type === 'year') {
502
+ return 'year';
503
+ } else if (this.type === 'dates') {
504
+ return 'dates';
505
+ }
506
+
507
+ return 'day';
508
+ },
509
+
510
+ haveTrigger() {
511
+ if (typeof this.showTrigger !== 'undefined') {
512
+ return this.showTrigger;
513
+ }
514
+ return HAVE_TRIGGER_TYPES.indexOf(this.type) !== -1;
515
+ },
516
+
517
+ displayValue() {
518
+ const formattedValue = formatAsFormatAndType(this.parsedValue, this.format, this.type, this.rangeSeparator);
519
+ if (Array.isArray(this.userInput)) {
520
+ return [
521
+ this.userInput[0] || (formattedValue && formattedValue[0]) || '',
522
+ this.userInput[1] || (formattedValue && formattedValue[1]) || ''
523
+ ];
524
+ } else if (this.userInput !== null) {
525
+ return this.userInput;
526
+ } else if (formattedValue) {
527
+ return this.type === 'dates'
528
+ ? formattedValue.join(', ')
529
+ : formattedValue;
530
+ } else {
531
+ return '';
532
+ }
533
+ },
534
+
535
+ parsedValue() {
536
+ if (!this.value) return this.value; // component value is not set
537
+ if (this.type === 'time-select') return this.value; // time-select does not require parsing, this might change in next major version
538
+
539
+ const valueIsDateObject = isDateObject(this.value) || (Array.isArray(this.value) && this.value.every(isDateObject));
540
+ if (valueIsDateObject) {
541
+ return this.value;
542
+ }
543
+
544
+ if (this.valueFormat) {
545
+ return parseAsFormatAndType(this.value, this.valueFormat, this.type, this.rangeSeparator) || this.value;
546
+ }
547
+
548
+ // NOTE: deal with common but incorrect usage, should remove in next major version
549
+ // user might provide string / timestamp without value-format, coerce them into date (or array of date)
550
+ return Array.isArray(this.value) ? this.value.map(val => new Date(val)) : new Date(this.value);
551
+ },
552
+
553
+ _baseFormItemSize() {
554
+ return (this.baseFormItem || {}).baseFormItemSize;
555
+ },
556
+
557
+ pickerSize() {
558
+ return this.size || this._baseFormItemSize || (this.$ELEMENT || {}).size;
559
+ },
560
+
561
+ pickerDisabled() {
562
+ return this.disabled || (this.baseForm || {}).disabled;
563
+ },
564
+
565
+ firstInputId() {
566
+ const obj = {};
567
+ let id;
568
+ if (this.ranged) {
569
+ id = this.id && this.id[0];
570
+ } else {
571
+ id = this.id;
572
+ }
573
+ if (id) obj.id = id;
574
+ return obj;
575
+ },
576
+
577
+ secondInputId() {
578
+ const obj = {};
579
+ let id;
580
+ if (this.ranged) {
581
+ id = this.id && this.id[1];
582
+ }
583
+ if (id) obj.id = id;
584
+ return obj;
585
+ }
586
+ },
587
+
588
+ created() {
589
+ // vue-popper
590
+ this.popperOptions = {
591
+ boundariesPadding: 0,
592
+ gpuAcceleration: false
593
+ };
594
+ this.placement = PLACEMENT_MAP[this.align] || PLACEMENT_MAP.left;
595
+
596
+ this.$on('fieldReset', this.handleFieldReset);
597
+ },
598
+
599
+ methods: {
600
+ focus() {
601
+ if (!this.ranged) {
602
+ this.$refs.reference.focus();
603
+ } else {
604
+ this.handleFocus();
605
+ }
606
+ },
607
+
608
+ blur() {
609
+ this.refInput.forEach(input => input.blur());
610
+ },
611
+
612
+ // {parse, formatTo} Value deals maps component value with internal Date
613
+ parseValue(value) {
614
+ const isParsed = isDateObject(value) || (Array.isArray(value) && value.every(isDateObject));
615
+ if (this.valueFormat && !isParsed) {
616
+ return parseAsFormatAndType(value, this.valueFormat, this.type, this.rangeSeparator) || value;
617
+ } else {
618
+ return value;
619
+ }
620
+ },
621
+
622
+ formatToValue(date) {
623
+ const isFormattable = isDateObject(date) || (Array.isArray(date) && date.every(isDateObject));
624
+ if (this.valueFormat && isFormattable) {
625
+ return formatAsFormatAndType(date, this.valueFormat, this.type, this.rangeSeparator);
626
+ } else {
627
+ return formatAsFormatAndType(date, null, this.type, this.rangeSeparator);
628
+ }
629
+ },
630
+
631
+ // {parse, formatTo} String deals with user input
632
+ parseString(value) {
633
+ const type = Array.isArray(value) ? this.type : this.type.replace('range', '');
634
+ return parseAsFormatAndType(value, this.format, type);
635
+ },
636
+
637
+ formatToString(value) {
638
+ const type = Array.isArray(value) ? this.type : this.type.replace('range', '');
639
+ return formatAsFormatAndType(value, this.format, type);
640
+ },
641
+
642
+ handleMouseEnter() {
643
+ if (this.readonly || this.pickerDisabled) return;
644
+ if (!this.valueIsEmpty && this.clearable) {
645
+ this.showClose = true;
646
+ }
647
+ },
648
+
649
+ handleChange() {
650
+ if (this.userInput) {
651
+ const value = this.parseString(this.displayValue);
652
+ if (value) {
653
+ this.picker.value = value;
654
+ if (this.isValidValue(value)) {
655
+ this.emitInput(value);
656
+ this.userInput = null;
657
+ }
658
+ }
659
+ }
660
+ if (this.userInput === '') {
661
+ this.emitInput(null);
662
+ this.emitChange(null);
663
+ this.userInput = null;
664
+ }
665
+ },
666
+
667
+ handleStartInput(event) {
668
+ if (this.userInput) {
669
+ this.userInput = [event.target.value, this.userInput[1]];
670
+ } else {
671
+ this.userInput = [event.target.value, null];
672
+ }
673
+ },
674
+
675
+ handleEndInput(event) {
676
+ if (this.userInput) {
677
+ this.userInput = [this.userInput[0], event.target.value];
678
+ } else {
679
+ this.userInput = [null, event.target.value];
680
+ }
681
+ },
682
+
683
+ handleStartChange(event) {
684
+ const value = this.parseString(this.userInput && this.userInput[0]);
685
+ if (value) {
686
+ this.userInput = [this.formatToString(value), this.displayValue[1]];
687
+ const newValue = [value, this.picker.value && this.picker.value[1]];
688
+ this.picker.value = newValue;
689
+ if (this.isValidValue(newValue)) {
690
+ this.emitInput(newValue);
691
+ this.userInput = null;
692
+ }
693
+ }
694
+ },
695
+
696
+ handleEndChange(event) {
697
+ const value = this.parseString(this.userInput && this.userInput[1]);
698
+ if (value) {
699
+ this.userInput = [this.displayValue[0], this.formatToString(value)];
700
+ const newValue = [this.picker.value && this.picker.value[0], value];
701
+ this.picker.value = newValue;
702
+ if (this.isValidValue(newValue)) {
703
+ this.emitInput(newValue);
704
+ this.userInput = null;
705
+ }
706
+ }
707
+ },
708
+
709
+ handleClickIcon(event) {
710
+ if (this.readonly || this.pickerDisabled) return;
711
+ if (this.showClose) {
712
+ this.valueOnOpen = this.value;
713
+ event.stopPropagation();
714
+ this.emitInput(null);
715
+ this.emitChange(null);
716
+ this.showClose = false;
717
+ if (this.picker && typeof this.picker.handleClear === 'function') {
718
+ this.picker.handleClear();
719
+ }
720
+ } else {
721
+ this.pickerVisible = !this.pickerVisible;
722
+ }
723
+ },
724
+
725
+ handleClose() {
726
+ if (!this.pickerVisible) return;
727
+ this.pickerVisible = false;
728
+
729
+ if (this.type === 'dates') {
730
+ // restore to former value
731
+ const oldValue = parseAsFormatAndType(this.valueOnOpen, this.valueFormat, this.type, this.rangeSeparator) || this.valueOnOpen;
732
+ this.emitInput(oldValue);
733
+ }
734
+ },
735
+
736
+ handleFieldReset(initialValue) {
737
+ this.userInput = initialValue === '' ? null : initialValue;
738
+ },
739
+
740
+ handleFocus() {
741
+ const type = this.type;
742
+
743
+ if (HAVE_TRIGGER_TYPES.indexOf(type) !== -1 && !this.pickerVisible) {
744
+ this.pickerVisible = true;
745
+ }
746
+ this.$emit('focus', this);
747
+ },
748
+
749
+ handleKeydown(event) {
750
+ const keyCode = event.keyCode;
751
+
752
+ // ESC
753
+ if (keyCode === 27) {
754
+ this.pickerVisible = false;
755
+ event.stopPropagation();
756
+ return;
757
+ }
758
+
759
+ // Tab
760
+ if (keyCode === 9) {
761
+ if (!this.ranged) {
762
+ this.handleChange();
763
+ this.pickerVisible = this.picker.visible = false;
764
+ this.blur();
765
+ event.stopPropagation();
766
+ } else {
767
+ // user may change focus between two input
768
+ setTimeout(() => {
769
+ if (this.refInput.indexOf(document.activeElement) === -1) {
770
+ this.pickerVisible = false;
771
+ this.blur();
772
+ event.stopPropagation();
773
+ }
774
+ }, 0);
775
+ }
776
+ return;
777
+ }
778
+
779
+ // Enter
780
+ if (keyCode === 13) {
781
+ if (this.userInput === '' || this.isValidValue(this.parseString(this.displayValue))) {
782
+ this.handleChange();
783
+ this.pickerVisible = this.picker.visible = false;
784
+ this.blur();
785
+ }
786
+ event.stopPropagation();
787
+ return;
788
+ }
789
+
790
+ // if user is typing, do not let picker handle key input
791
+ if (this.userInput) {
792
+ event.stopPropagation();
793
+ return;
794
+ }
795
+
796
+ // delegate other keys to panel
797
+ if (this.picker && this.picker.handleKeydown) {
798
+ this.picker.handleKeydown(event);
799
+ }
800
+ },
801
+
802
+ handleRangeClick() {
803
+ const type = this.type;
804
+
805
+ if (HAVE_TRIGGER_TYPES.indexOf(type) !== -1 && !this.pickerVisible) {
806
+ this.pickerVisible = true;
807
+ }
808
+ this.$emit('focus', this);
809
+ },
810
+
811
+ hidePicker() {
812
+ if (this.picker) {
813
+ this.picker.resetView && this.picker.resetView();
814
+ this.pickerVisible = this.picker.visible = false;
815
+ this.destroyPopper();
816
+ }
817
+ },
818
+
819
+ showPicker() {
820
+ if (this.$isServer) return;
821
+ if (!this.picker) {
822
+ this.mountPicker();
823
+ }
824
+ this.pickerVisible = this.picker.visible = true;
825
+
826
+ this.updatePopper();
827
+
828
+ this.picker.value = this.parsedValue;
829
+ this.picker.resetView && this.picker.resetView();
830
+
831
+ this.$nextTick(() => {
832
+ this.picker.adjustSpinners && this.picker.adjustSpinners();
833
+ });
834
+ },
835
+
836
+ mountPicker() {
837
+ this.picker = new Vue(this.panel).$mount();
838
+ this.picker.defaultValue = this.defaultValue;
839
+ this.picker.defaultTime = this.defaultTime;
840
+ this.picker.popperClass = this.popperClass;
841
+ this.popperElm = this.picker.$el;
842
+ this.picker.width = this.reference.getBoundingClientRect().width;
843
+ this.picker.showTime = this.type === 'datetime' || this.type === 'datetimerange';
844
+ this.picker.selectionMode = this.selectionMode;
845
+ this.picker.unlinkPanels = this.unlinkPanels;
846
+ this.picker.arrowControl = this.arrowControl || this.timeArrowControl || false;
847
+ this.$watch('format', (format) => {
848
+ this.picker.format = format;
849
+ });
850
+
851
+ const updateOptions = () => {
852
+ const options = this.pickerOptions;
853
+
854
+ if (options && options.selectableRange) {
855
+ let ranges = options.selectableRange;
856
+ const parser = TYPE_VALUE_RESOLVER_MAP.datetimerange.parser;
857
+ const format = DEFAULT_FORMATS.timerange;
858
+
859
+ ranges = Array.isArray(ranges) ? ranges : [ranges];
860
+ this.picker.selectableRange = ranges.map(range => parser(range, format, this.rangeSeparator));
861
+ }
862
+
863
+ for (const option in options) {
864
+ if (options.hasOwnProperty(option) &&
865
+ // 忽略 time-picker 的该配置项
866
+ option !== 'selectableRange') {
867
+ this.picker[option] = options[option];
868
+ }
869
+ }
870
+
871
+ // main format must prevail over undocumented pickerOptions.format
872
+ if (this.format) {
873
+ this.picker.format = this.format;
874
+ }
875
+ };
876
+ updateOptions();
877
+ this.unwatchPickerOptions = this.$watch('pickerOptions', () => updateOptions(), { deep: true });
878
+ this.$el.appendChild(this.picker.$el);
879
+ this.picker.resetView && this.picker.resetView();
880
+
881
+ this.picker.$on('dodestroy', this.doDestroy);
882
+ this.picker.$on('pick', (date = '', visible = false) => {
883
+ this.userInput = null;
884
+ this.pickerVisible = this.picker.visible = visible;
885
+ this.emitInput(date);
886
+ this.picker.resetView && this.picker.resetView();
887
+ });
888
+
889
+ this.picker.$on('select-range', (start, end, pos) => {
890
+ if (this.refInput.length === 0) return;
891
+ if (!pos || pos === 'min') {
892
+ this.refInput[0].setSelectionRange(start, end);
893
+ this.refInput[0].focus();
894
+ } else if (pos === 'max') {
895
+ this.refInput[1].setSelectionRange(start, end);
896
+ this.refInput[1].focus();
897
+ }
898
+ });
899
+ },
900
+
901
+ unmountPicker() {
902
+ if (this.picker) {
903
+ this.picker.$destroy();
904
+ this.picker.$off();
905
+ if (typeof this.unwatchPickerOptions === 'function') {
906
+ this.unwatchPickerOptions();
907
+ }
908
+ this.picker.$el.parentNode.removeChild(this.picker.$el);
909
+ }
910
+ },
911
+
912
+ emitChange(val) {
913
+ // determine user real change only
914
+ if (!valueEquals(val, this.valueOnOpen)) {
915
+ this.$emit('change', val);
916
+ this.valueOnOpen = val;
917
+ if (this.validateEvent) {
918
+ this.dispatch('BaseFormItem', 'base.form.change', val);
919
+ }
920
+ }
921
+ },
922
+
923
+ emitInput(val) {
924
+ const formatted = this.formatToValue(val);
925
+ if (!valueEquals(this.value, formatted)) {
926
+ this.$emit('input', formatted);
927
+ }
928
+ },
929
+
930
+ isValidValue(value) {
931
+ if (!this.picker) {
932
+ this.mountPicker();
933
+ }
934
+ if (this.picker.isValidValue) {
935
+ return value && this.picker.isValidValue(value);
936
+ } else {
937
+ return true;
938
+ }
939
+ }
940
+ }
941
+ };
942
+ </script>