@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,74 @@
1
+ <template>
2
+ <div
3
+ class="base-select-dropdown base-popper"
4
+ :class="[{ 'is-multiple': $parent.multiple }, popperClass]"
5
+ :style="{ minWidth: minWidth }">
6
+ <slot></slot>
7
+ </div>
8
+ </template>
9
+
10
+ <script type="text/babel">
11
+ import Popper from '../util/vue-popper'
12
+
13
+ export default {
14
+ name: 'BaseSelectDropdown',
15
+
16
+ componentName: 'BaseSelectDropdown',
17
+
18
+ mixins: [Popper],
19
+
20
+ props: {
21
+ placement: {
22
+ default: 'bottom-start'
23
+ },
24
+
25
+ boundariesPadding: {
26
+ default: 0
27
+ },
28
+
29
+ popperOptions: {
30
+ default() {
31
+ return {
32
+ gpuAcceleration: false
33
+ }
34
+ }
35
+ },
36
+
37
+ visibleArrow: {
38
+ default: false
39
+ },
40
+
41
+ appendToBody: {
42
+ type: Boolean,
43
+ default: true
44
+ }
45
+ },
46
+
47
+ data() {
48
+ return {
49
+ minWidth: ''
50
+ }
51
+ },
52
+
53
+ computed: {
54
+ popperClass() {
55
+ return this.$parent.popperClass
56
+ }
57
+ },
58
+
59
+ watch: {
60
+ '$parent.inputWidth'() {
61
+ this.minWidth = this.$parent.$el.getBoundingClientRect().width + 'px'
62
+ }
63
+ },
64
+
65
+ mounted() {
66
+ this.referenceElm = this.$parent.$refs.reference.$el
67
+ this.$parent.popperElm = this.popperElm = this.$el
68
+ this.$on('updatePopper', () => {
69
+ if (this.$parent.visible) this.updatePopper()
70
+ })
71
+ this.$on('destroyPopper', this.destroyPopper)
72
+ }
73
+ }
74
+ </script>
@@ -0,0 +1,54 @@
1
+ export default {
2
+ data() {
3
+ return {
4
+ hoverOption: -1
5
+ }
6
+ },
7
+
8
+ computed: {
9
+ optionsAllDisabled() {
10
+ return this.options.filter(option => option.visible).every(option => option.disabled)
11
+ }
12
+ },
13
+
14
+ watch: {
15
+ hoverIndex(val) {
16
+ if (typeof val === 'number' && val > -1) {
17
+ this.hoverOption = this.options[val] || {}
18
+ }
19
+ this.options.forEach(option => {
20
+ option.hover = this.hoverOption === option
21
+ })
22
+ }
23
+ },
24
+
25
+ methods: {
26
+ navigateOptions(direction) {
27
+ if (!this.visible) {
28
+ this.visible = true
29
+ return
30
+ }
31
+ if (this.options.length === 0 || this.filteredOptionsCount === 0) return
32
+ if (!this.optionsAllDisabled) {
33
+ if (direction === 'next') {
34
+ this.hoverIndex++
35
+ if (this.hoverIndex === this.options.length) {
36
+ this.hoverIndex = 0
37
+ }
38
+ } else if (direction === 'prev') {
39
+ this.hoverIndex--
40
+ if (this.hoverIndex < 0) {
41
+ this.hoverIndex = this.options.length - 1
42
+ }
43
+ }
44
+ const option = this.options[this.hoverIndex]
45
+ if (option.disabled === true ||
46
+ option.groupDisabled === true ||
47
+ !option.visible) {
48
+ this.navigateOptions(direction)
49
+ }
50
+ this.$nextTick(() => this.scrollToOption(this.hoverOption))
51
+ }
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,8 @@
1
+ import Skeleton from './src/index.vue';
2
+
3
+ /* istanbul ignore next */
4
+ Skeleton.install = function(Vue) {
5
+ Vue.component(Skeleton.name, Skeleton);
6
+ };
7
+
8
+ export default Skeleton;
@@ -0,0 +1,16 @@
1
+ <template>
2
+ <svg
3
+ viewBox="0 0 1024 1024"
4
+ xmlns="http://www.w3.org/2000/svg"
5
+ >
6
+ <path
7
+ d="M64 896V128h896v768H64z m64-128l192-192 116.352 116.352L640 448l256 307.2V192H128v576z m224-480a96 96 0 1 1-0.064 192.064A96 96 0 0 1 352 288z"
8
+ />
9
+ </svg>
10
+ </template>
11
+
12
+ <script>
13
+ export default {
14
+ name: 'ImgPlaceholder'
15
+ };
16
+ </script>
@@ -0,0 +1,80 @@
1
+ <template>
2
+ <div class="base-skeleton">
3
+ <template v-if="uiLoading">
4
+ <div :class="['base-skeleton', animated ? 'is-animated' : '', ]" v-bind="$attrs">
5
+ <template v-for="i in count">
6
+ <slot v-if="loading" name="template">
7
+ <base-skeleton-item
8
+ v-for="item in rows"
9
+ :key="`${i}-${item}`"
10
+ :class="{
11
+ 'base-skeleton__paragraph': item !== 1,
12
+ 'is-first': item === 1,
13
+ 'is-last': item === rows && rows > 1,
14
+ }"
15
+ variant="p"
16
+ />
17
+ </slot>
18
+ </template>
19
+ </div>
20
+ </template>
21
+ <template v-else>
22
+ <slot v-bind="$attrs"></slot>
23
+ </template>
24
+ </div>
25
+ </template>
26
+ <script>
27
+ import BaseSkeletonItem from './item';
28
+ export default {
29
+ name: 'BaseSkeleton',
30
+ components: {
31
+ BaseSkeletonItem
32
+ },
33
+ props: {
34
+ animated: {
35
+ type: Boolean,
36
+ default: false
37
+ },
38
+ count: {
39
+ type: Number,
40
+ default: 1
41
+ },
42
+ rows: {
43
+ type: Number,
44
+ default: 4
45
+ },
46
+ loading: {
47
+ type: Boolean,
48
+ default: true
49
+ },
50
+ throttle: {
51
+ type: Number,
52
+ default: 0
53
+ }
54
+ },
55
+ watch: {
56
+ loading: {
57
+ handler(loading) {
58
+ if (this.throttle <= 0) {
59
+ this.uiLoading = loading;
60
+ return;
61
+ }
62
+ if (loading) {
63
+ clearTimeout(this.timeoutHandle);
64
+ this.timeoutHandle = setTimeout(() => {
65
+ this.uiLoading = this.loading;
66
+ }, this.throttle);
67
+ } else {
68
+ this.uiLoading = loading;
69
+ }
70
+ },
71
+ immediate: true
72
+ }
73
+ },
74
+ data() {
75
+ return {
76
+ uiLoading: this.throttle <= 0 ? this.loading : false
77
+ };
78
+ }
79
+ };
80
+ </script>
@@ -0,0 +1,22 @@
1
+ <template>
2
+ <div :class="['base-skeleton__item', `base-skeleton__${variant}`]">
3
+ <img-placeholder v-if="variant === 'image'" />
4
+ </div>
5
+ </template>
6
+
7
+ <script>
8
+ import ImgPlaceholder from './img-placeholder';
9
+
10
+ export default {
11
+ name: 'BaseSkeletonItem',
12
+ props: {
13
+ variant: {
14
+ type: String,
15
+ default: 'text'
16
+ }
17
+ },
18
+ components: {
19
+ [ImgPlaceholder.name]: ImgPlaceholder
20
+ }
21
+ };
22
+ </script>
@@ -0,0 +1,8 @@
1
+ import SkeletonItem from '../skeleton/src/item';
2
+
3
+ /* istanbul ignore next */
4
+ SkeletonItem.install = function(Vue) {
5
+ Vue.component(SkeletonItem.name, SkeletonItem);
6
+ };
7
+
8
+ export default SkeletonItem;
@@ -0,0 +1,238 @@
1
+ <template>
2
+ <div
3
+ class="base-slider__button-wrapper"
4
+ @mouseenter="handleMouseEnter"
5
+ @mouseleave="handleMouseLeave"
6
+ @mousedown="onButtonDown"
7
+ @touchstart="onButtonDown"
8
+ :class="{ 'hover': hovering, 'dragging': dragging }"
9
+ :style="wrapperStyle"
10
+ ref="button"
11
+ tabindex="0"
12
+ @focus="handleMouseEnter"
13
+ @blur="handleMouseLeave"
14
+ @keydown.left="onLeftKeyDown"
15
+ @keydown.right="onRightKeyDown"
16
+ @keydown.down.prevent="onLeftKeyDown"
17
+ @keydown.up.prevent="onRightKeyDown"
18
+ >
19
+ <base-tooltip
20
+ placement="top"
21
+ ref="tooltip"
22
+ :popper-class="tooltipClass"
23
+ :disabled="!showTooltip">
24
+ <span slot="content">{{ formatValue }}</span>
25
+ <div class="base-slider__button" :class="{ 'hover': hovering, 'dragging': dragging }"></div>
26
+ </base-tooltip>
27
+ </div>
28
+ </template>
29
+
30
+ <script>
31
+ import BaseTooltip from '../tooltip/tooltip';
32
+
33
+ export default {
34
+ name: 'BaseSliderButton',
35
+
36
+ components: {
37
+ BaseTooltip
38
+ },
39
+
40
+ props: {
41
+ value: {
42
+ type: Number,
43
+ default: 0
44
+ },
45
+ vertical: {
46
+ type: Boolean,
47
+ default: false
48
+ },
49
+ tooltipClass: String
50
+ },
51
+
52
+ data() {
53
+ return {
54
+ hovering: false,
55
+ dragging: false,
56
+ isClick: false,
57
+ startX: 0,
58
+ currentX: 0,
59
+ startY: 0,
60
+ currentY: 0,
61
+ startPosition: 0,
62
+ newPosition: null,
63
+ oldValue: this.value
64
+ };
65
+ },
66
+
67
+ computed: {
68
+ disabled() {
69
+ return this.$parent.sliderDisabled;
70
+ },
71
+
72
+ max() {
73
+ return this.$parent.max;
74
+ },
75
+
76
+ min() {
77
+ return this.$parent.min;
78
+ },
79
+
80
+ step() {
81
+ return this.$parent.step;
82
+ },
83
+
84
+ showTooltip() {
85
+ return this.$parent.showTooltip;
86
+ },
87
+
88
+ precision() {
89
+ return this.$parent.precision;
90
+ },
91
+
92
+ currentPosition() {
93
+ return `${ (this.value - this.min) / (this.max - this.min) * 100 }%`;
94
+ },
95
+
96
+ enableFormat() {
97
+ return this.$parent.formatTooltip instanceof Function;
98
+ },
99
+
100
+ formatValue() {
101
+ return this.enableFormat && this.$parent.formatTooltip(this.value) || this.value;
102
+ },
103
+
104
+ wrapperStyle() {
105
+ return this.vertical ? { bottom: this.currentPosition } : { left: this.currentPosition };
106
+ }
107
+ },
108
+
109
+ watch: {
110
+ dragging(val) {
111
+ this.$parent.dragging = val;
112
+ }
113
+ },
114
+
115
+ methods: {
116
+ displayTooltip() {
117
+ this.$refs.tooltip && (this.$refs.tooltip.showPopper = true);
118
+ },
119
+
120
+ hideTooltip() {
121
+ this.$refs.tooltip && (this.$refs.tooltip.showPopper = false);
122
+ },
123
+
124
+ handleMouseEnter() {
125
+ this.hovering = true;
126
+ this.displayTooltip();
127
+ },
128
+
129
+ handleMouseLeave() {
130
+ this.hovering = false;
131
+ this.hideTooltip();
132
+ },
133
+
134
+ onButtonDown(event) {
135
+ if (this.disabled) return;
136
+ event.preventDefault();
137
+ this.onDragStart(event);
138
+ window.addEventListener('mousemove', this.onDragging);
139
+ window.addEventListener('touchmove', this.onDragging);
140
+ window.addEventListener('mouseup', this.onDragEnd);
141
+ window.addEventListener('touchend', this.onDragEnd);
142
+ window.addEventListener('contextmenu', this.onDragEnd);
143
+ },
144
+ onLeftKeyDown() {
145
+ if (this.disabled) return;
146
+ this.newPosition = parseFloat(this.currentPosition) - this.step / (this.max - this.min) * 100;
147
+ this.setPosition(this.newPosition);
148
+ this.$parent.emitChange();
149
+ },
150
+ onRightKeyDown() {
151
+ if (this.disabled) return;
152
+ this.newPosition = parseFloat(this.currentPosition) + this.step / (this.max - this.min) * 100;
153
+ this.setPosition(this.newPosition);
154
+ this.$parent.emitChange();
155
+ },
156
+ onDragStart(event) {
157
+ this.dragging = true;
158
+ this.isClick = true;
159
+ if (event.type === 'touchstart') {
160
+ event.clientY = event.touches[0].clientY;
161
+ event.clientX = event.touches[0].clientX;
162
+ }
163
+ if (this.vertical) {
164
+ this.startY = event.clientY;
165
+ } else {
166
+ this.startX = event.clientX;
167
+ }
168
+ this.startPosition = parseFloat(this.currentPosition);
169
+ this.newPosition = this.startPosition;
170
+ },
171
+
172
+ onDragging(event) {
173
+ if (this.dragging) {
174
+ this.isClick = false;
175
+ this.displayTooltip();
176
+ this.$parent.resetSize();
177
+ let diff = 0;
178
+ if (event.type === 'touchmove') {
179
+ event.clientY = event.touches[0].clientY;
180
+ event.clientX = event.touches[0].clientX;
181
+ }
182
+ if (this.vertical) {
183
+ this.currentY = event.clientY;
184
+ diff = (this.startY - this.currentY) / this.$parent.sliderSize * 100;
185
+ } else {
186
+ this.currentX = event.clientX;
187
+ diff = (this.currentX - this.startX) / this.$parent.sliderSize * 100;
188
+ }
189
+ this.newPosition = this.startPosition + diff;
190
+ this.setPosition(this.newPosition);
191
+ }
192
+ },
193
+
194
+ onDragEnd() {
195
+ if (this.dragging) {
196
+ /*
197
+ * 防止在 mouseup 后立即触发 click,导致滑块有几率产生一小段位移
198
+ * 不使用 preventDefault 是因为 mouseup 和 click 没有注册在同一个 DOM 上
199
+ */
200
+ setTimeout(() => {
201
+ this.dragging = false;
202
+ this.hideTooltip();
203
+ if (!this.isClick) {
204
+ this.setPosition(this.newPosition);
205
+ this.$parent.emitChange();
206
+ }
207
+ }, 0);
208
+ window.removeEventListener('mousemove', this.onDragging);
209
+ window.removeEventListener('touchmove', this.onDragging);
210
+ window.removeEventListener('mouseup', this.onDragEnd);
211
+ window.removeEventListener('touchend', this.onDragEnd);
212
+ window.removeEventListener('contextmenu', this.onDragEnd);
213
+ }
214
+ },
215
+
216
+ setPosition(newPosition) {
217
+ if (newPosition === null || isNaN(newPosition)) return;
218
+ if (newPosition < 0) {
219
+ newPosition = 0;
220
+ } else if (newPosition > 100) {
221
+ newPosition = 100;
222
+ }
223
+ const lengthPerStep = 100 / ((this.max - this.min) / this.step);
224
+ const steps = Math.round(newPosition / lengthPerStep);
225
+ let value = steps * lengthPerStep * (this.max - this.min) * 0.01 + this.min;
226
+ value = parseFloat(value.toFixed(this.precision));
227
+ this.$emit('input', value);
228
+ this.$nextTick(() => {
229
+ this.displayTooltip();
230
+ this.$refs.tooltip && this.$refs.tooltip.updatePopper();
231
+ });
232
+ if (!this.dragging && this.value !== this.oldValue) {
233
+ this.oldValue = this.value;
234
+ }
235
+ }
236
+ }
237
+ };
238
+ </script>