yy-vue-easytable 2.27.2

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 (205) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +187 -0
  3. package/libs/font/demo.css +539 -0
  4. package/libs/font/demo_index.html +400 -0
  5. package/libs/font/iconfont.css +57 -0
  6. package/libs/font/iconfont.eot +0 -0
  7. package/libs/font/iconfont.js +1 -0
  8. package/libs/font/iconfont.json +79 -0
  9. package/libs/font/iconfont.svg +56 -0
  10. package/libs/font/iconfont.ttf +0 -0
  11. package/libs/font/iconfont.woff +0 -0
  12. package/libs/font/iconfont.woff2 +0 -0
  13. package/libs/locale/lang/af-ZA.js +48 -0
  14. package/libs/locale/lang/en-US.js +48 -0
  15. package/libs/locale/lang/fr-FR.js +48 -0
  16. package/libs/locale/lang/ko-KR.js +48 -0
  17. package/libs/locale/lang/pt-BR.js +48 -0
  18. package/libs/locale/lang/ru-RU.js +48 -0
  19. package/libs/locale/lang/zh-CN.js +48 -0
  20. package/libs/locale/lang/zh-TW.js +48 -0
  21. package/libs/locale/lang/zu-ZA.js +48 -0
  22. package/libs/main.js +1 -0
  23. package/libs/theme-dark/base.css +1 -0
  24. package/libs/theme-dark/index.css +1253 -0
  25. package/libs/theme-dark/var.css +7 -0
  26. package/libs/theme-dark/ve-checkbox.css +150 -0
  27. package/libs/theme-dark/ve-contextmenu.css +71 -0
  28. package/libs/theme-dark/ve-dropdown.css +177 -0
  29. package/libs/theme-dark/ve-icon.css +10 -0
  30. package/libs/theme-dark/ve-loading.css +218 -0
  31. package/libs/theme-dark/ve-pagination.css +136 -0
  32. package/libs/theme-dark/ve-radio.css +111 -0
  33. package/libs/theme-dark/ve-select.css +50 -0
  34. package/libs/theme-dark/ve-table.css +385 -0
  35. package/libs/theme-default/base.css +1 -0
  36. package/libs/theme-default/index.css +1253 -0
  37. package/libs/theme-default/var.css +7 -0
  38. package/libs/theme-default/ve-checkbox.css +150 -0
  39. package/libs/theme-default/ve-contextmenu.css +71 -0
  40. package/libs/theme-default/ve-dropdown.css +177 -0
  41. package/libs/theme-default/ve-icon.css +10 -0
  42. package/libs/theme-default/ve-loading.css +218 -0
  43. package/libs/theme-default/ve-pagination.css +136 -0
  44. package/libs/theme-default/ve-radio.css +111 -0
  45. package/libs/theme-default/ve-select.css +50 -0
  46. package/libs/theme-default/ve-table.css +385 -0
  47. package/libs/umd/index.js +9 -0
  48. package/libs/ve-checkbox-group.js +1 -0
  49. package/libs/ve-checkbox.js +1 -0
  50. package/libs/ve-contextmenu.js +1 -0
  51. package/libs/ve-dropdown.js +1 -0
  52. package/libs/ve-icon.js +1 -0
  53. package/libs/ve-loading.js +1 -0
  54. package/libs/ve-locale.js +1 -0
  55. package/libs/ve-pagination.js +1 -0
  56. package/libs/ve-radio.js +1 -0
  57. package/libs/ve-select.js +1 -0
  58. package/libs/ve-table.js +1 -0
  59. package/package.json +142 -0
  60. package/packages/font/demo.css +539 -0
  61. package/packages/font/demo_index.html +400 -0
  62. package/packages/font/iconfont.css +57 -0
  63. package/packages/font/iconfont.eot +0 -0
  64. package/packages/font/iconfont.js +1 -0
  65. package/packages/font/iconfont.json +79 -0
  66. package/packages/font/iconfont.svg +56 -0
  67. package/packages/font/iconfont.ttf +0 -0
  68. package/packages/font/iconfont.woff +0 -0
  69. package/packages/font/iconfont.woff2 +0 -0
  70. package/packages/index.js +75 -0
  71. package/packages/src/comps/resize-observer/index.js +2 -0
  72. package/packages/src/comps/resize-observer/src/index.jsx +38 -0
  73. package/packages/src/directives/clickoutside.js +31 -0
  74. package/packages/src/directives/events-outside.js +79 -0
  75. package/packages/src/directives/focus.js +28 -0
  76. package/packages/src/locale/index.js +27 -0
  77. package/packages/src/locale/lang/af-ZA.js +29 -0
  78. package/packages/src/locale/lang/en-US.js +30 -0
  79. package/packages/src/locale/lang/fr-FR.js +29 -0
  80. package/packages/src/locale/lang/ko-KR.js +29 -0
  81. package/packages/src/locale/lang/pt-BR.js +29 -0
  82. package/packages/src/locale/lang/ru-RU.js +29 -0
  83. package/packages/src/locale/lang/zh-CN.js +30 -0
  84. package/packages/src/locale/lang/zh-TW.js +29 -0
  85. package/packages/src/locale/lang/zu-ZA.js +29 -0
  86. package/packages/src/mixins/emitter.js +39 -0
  87. package/packages/src/utils/animation-frame.js +39 -0
  88. package/packages/src/utils/auto-resize.js +179 -0
  89. package/packages/src/utils/constant.js +42 -0
  90. package/packages/src/utils/dom.js +239 -0
  91. package/packages/src/utils/event-key-codes.js +53 -0
  92. package/packages/src/utils/hooks-manager.js +76 -0
  93. package/packages/src/utils/index.js +161 -0
  94. package/packages/src/utils/mouse-event.js +24 -0
  95. package/packages/src/utils/random.js +6 -0
  96. package/packages/src/utils/request-animation-timeout.js +36 -0
  97. package/packages/src/utils/resize-event.js +40 -0
  98. package/packages/src/utils/scroll-bar.js +27 -0
  99. package/packages/style/ve-checkbox.less +179 -0
  100. package/packages/style/ve-contextmenu.less +76 -0
  101. package/packages/style/ve-dropdown.less +204 -0
  102. package/packages/style/ve-icon.less +3 -0
  103. package/packages/style/ve-loading.less +242 -0
  104. package/packages/style/ve-pagination.less +153 -0
  105. package/packages/style/ve-radio.less +126 -0
  106. package/packages/style/ve-select.less +48 -0
  107. package/packages/style/ve-table.less +539 -0
  108. package/packages/theme-dark/base.less +1 -0
  109. package/packages/theme-dark/index.less +12 -0
  110. package/packages/theme-dark/var.less +111 -0
  111. package/packages/theme-dark/ve-checkbox.less +2 -0
  112. package/packages/theme-dark/ve-contextmenu.less +2 -0
  113. package/packages/theme-dark/ve-dropdown.less +2 -0
  114. package/packages/theme-dark/ve-icon.less +2 -0
  115. package/packages/theme-dark/ve-loading.less +2 -0
  116. package/packages/theme-dark/ve-pagination.less +2 -0
  117. package/packages/theme-dark/ve-radio.less +2 -0
  118. package/packages/theme-dark/ve-select.less +2 -0
  119. package/packages/theme-dark/ve-table.less +2 -0
  120. package/packages/theme-default/base.less +1 -0
  121. package/packages/theme-default/index.less +12 -0
  122. package/packages/theme-default/var.less +111 -0
  123. package/packages/theme-default/ve-checkbox.less +2 -0
  124. package/packages/theme-default/ve-contextmenu.less +2 -0
  125. package/packages/theme-default/ve-dropdown.less +2 -0
  126. package/packages/theme-default/ve-icon.less +2 -0
  127. package/packages/theme-default/ve-loading.less +2 -0
  128. package/packages/theme-default/ve-pagination.less +2 -0
  129. package/packages/theme-default/ve-radio.less +2 -0
  130. package/packages/theme-default/ve-select.less +2 -0
  131. package/packages/theme-default/ve-table.less +2 -0
  132. package/packages/ve-checkbox/index.js +7 -0
  133. package/packages/ve-checkbox/src/index.jsx +175 -0
  134. package/packages/ve-checkbox/src/util/constant.js +14 -0
  135. package/packages/ve-checkbox/src/util/index.js +10 -0
  136. package/packages/ve-checkbox-group/index.js +7 -0
  137. package/packages/ve-checkbox-group/src/index.jsx +53 -0
  138. package/packages/ve-checkbox-group/src/util/constant.js +14 -0
  139. package/packages/ve-checkbox-group/src/util/index.js +10 -0
  140. package/packages/ve-contextmenu/index.js +7 -0
  141. package/packages/ve-contextmenu/src/index.jsx +731 -0
  142. package/packages/ve-contextmenu/src/util/constant.js +29 -0
  143. package/packages/ve-contextmenu/src/util/index.js +10 -0
  144. package/packages/ve-dropdown/index.js +7 -0
  145. package/packages/ve-dropdown/src/index.jsx +720 -0
  146. package/packages/ve-dropdown/src/util/constant.js +15 -0
  147. package/packages/ve-dropdown/src/util/index.js +10 -0
  148. package/packages/ve-icon/index.js +7 -0
  149. package/packages/ve-icon/src/index.jsx +52 -0
  150. package/packages/ve-icon/src/util/constant.js +10 -0
  151. package/packages/ve-icon/src/util/index.js +10 -0
  152. package/packages/ve-loading/index.js +8 -0
  153. package/packages/ve-loading/src/bounce.jsx +50 -0
  154. package/packages/ve-loading/src/flow.jsx +51 -0
  155. package/packages/ve-loading/src/grid.jsx +57 -0
  156. package/packages/ve-loading/src/index.js +106 -0
  157. package/packages/ve-loading/src/loading.jsx +63 -0
  158. package/packages/ve-loading/src/plane.jsx +38 -0
  159. package/packages/ve-loading/src/pulse.jsx +38 -0
  160. package/packages/ve-loading/src/util/constant.js +31 -0
  161. package/packages/ve-loading/src/util/index.js +10 -0
  162. package/packages/ve-loading/src/wave.jsx +53 -0
  163. package/packages/ve-locale/index.js +28 -0
  164. package/packages/ve-pagination/index.js +7 -0
  165. package/packages/ve-pagination/src/index.jsx +304 -0
  166. package/packages/ve-pagination/src/pager.jsx +166 -0
  167. package/packages/ve-pagination/src/util/constant.js +16 -0
  168. package/packages/ve-pagination/src/util/index.js +10 -0
  169. package/packages/ve-radio/index.js +7 -0
  170. package/packages/ve-radio/src/index.jsx +121 -0
  171. package/packages/ve-radio/src/util/constant.js +13 -0
  172. package/packages/ve-radio/src/util/index.js +10 -0
  173. package/packages/ve-select/index.js +7 -0
  174. package/packages/ve-select/src/index.jsx +193 -0
  175. package/packages/ve-select/src/util/constant.js +13 -0
  176. package/packages/ve-select/src/util/index.js +10 -0
  177. package/packages/ve-table/index.js +7 -0
  178. package/packages/ve-table/src/body/body-checkbox-content.jsx +126 -0
  179. package/packages/ve-table/src/body/body-radio-content.jsx +113 -0
  180. package/packages/ve-table/src/body/body-td.jsx +671 -0
  181. package/packages/ve-table/src/body/body-tr-scrolling.jsx +38 -0
  182. package/packages/ve-table/src/body/body-tr.jsx +383 -0
  183. package/packages/ve-table/src/body/expand-tr-icon.jsx +80 -0
  184. package/packages/ve-table/src/body/expand-tr.jsx +147 -0
  185. package/packages/ve-table/src/body/index.jsx +943 -0
  186. package/packages/ve-table/src/colgroup/index.jsx +48 -0
  187. package/packages/ve-table/src/column-resizer/index.jsx +318 -0
  188. package/packages/ve-table/src/editor/constant.js +5 -0
  189. package/packages/ve-table/src/editor/index.jsx +533 -0
  190. package/packages/ve-table/src/footer/footer-td.jsx +396 -0
  191. package/packages/ve-table/src/footer/footer-tr.jsx +249 -0
  192. package/packages/ve-table/src/footer/index.jsx +108 -0
  193. package/packages/ve-table/src/header/header-checkbox-content.jsx +69 -0
  194. package/packages/ve-table/src/header/header-filter-content.jsx +100 -0
  195. package/packages/ve-table/src/header/header-filter-custom-content.jsx +110 -0
  196. package/packages/ve-table/src/header/header-th.jsx +664 -0
  197. package/packages/ve-table/src/header/header-tr.jsx +255 -0
  198. package/packages/ve-table/src/header/index.jsx +195 -0
  199. package/packages/ve-table/src/index.jsx +4196 -0
  200. package/packages/ve-table/src/selection/constant.js +5 -0
  201. package/packages/ve-table/src/selection/index.jsx +1643 -0
  202. package/packages/ve-table/src/util/clipboard.js +428 -0
  203. package/packages/ve-table/src/util/constant.js +269 -0
  204. package/packages/ve-table/src/util/index.js +1585 -0
  205. package/packages/ve-table/src/util/store.js +14 -0
@@ -0,0 +1,720 @@
1
+ import clickoutside from "../../src/directives/clickoutside.js";
2
+ import VeCheckbox from "vue-easytable/packages/ve-checkbox";
3
+ import VeRadio from "vue-easytable/packages/ve-radio";
4
+ import { COMPS_NAME, EMIT_EVENTS } from "./util/constant";
5
+ import { clsName } from "./util/index";
6
+ import { isFunction, isBoolean } from "../../src/utils";
7
+ import { getRandomId } from "../../src/utils/random";
8
+ import {
9
+ getViewportOffset,
10
+ getViewportOffsetWithinContainer,
11
+ } from "../../src/utils/dom";
12
+
13
+ export default {
14
+ name: COMPS_NAME.VE_DROPDOWN,
15
+ directives: {
16
+ "click-outside": clickoutside,
17
+ },
18
+ props: {
19
+ // 如果是select 组件将特殊处理
20
+ isSelect: {
21
+ type: Boolean,
22
+ default: false,
23
+ },
24
+ showOperation: {
25
+ type: Boolean,
26
+ default: false,
27
+ },
28
+
29
+ width: {
30
+ type: Number,
31
+ default: 90,
32
+ },
33
+
34
+ // select的最大宽度(超出隐藏)
35
+ maxWidth: {
36
+ type: Number,
37
+ default: 0,
38
+ },
39
+ // max height
40
+ maxHeight: {
41
+ type: Number,
42
+ default: 1000,
43
+ },
44
+
45
+ // 如果为true 会包含 checkbox
46
+ isMultiple: {
47
+ type: Boolean,
48
+ default: false,
49
+ },
50
+
51
+ // 用户传入v-model 的值 [{value/label/selected}]
52
+ value: {
53
+ type: [Array],
54
+ default: null,
55
+ },
56
+
57
+ // 文本居中方式 left|center|right
58
+ textAlign: {
59
+ type: String,
60
+ default: "left",
61
+ },
62
+
63
+ // 是否支持输入input
64
+ isInput: {
65
+ type: Boolean,
66
+ default: false,
67
+ },
68
+ // confirm filter text
69
+ confirmFilterText: {
70
+ type: String,
71
+ default: "",
72
+ },
73
+ // confirm filter text
74
+ resetFilterText: {
75
+ type: String,
76
+ default: "",
77
+ },
78
+ // hide by single selection item click
79
+ hideByItemClick: {
80
+ type: Boolean,
81
+ default: false,
82
+ },
83
+ // is show radio when single selection
84
+ showRadio: {
85
+ type: Boolean,
86
+ default: false,
87
+ },
88
+ // 当 isControlled=true ,visible 生效
89
+ visible: {
90
+ type: Boolean,
91
+ default: false,
92
+ },
93
+ // is controlled
94
+ isControlled: {
95
+ type: Boolean,
96
+ default: false,
97
+ },
98
+ // is custom content
99
+ isCustomContent: {
100
+ type: Boolean,
101
+ default: false,
102
+ },
103
+ // instance between dropdown items and trigger element
104
+ defaultInstance: {
105
+ type: Number,
106
+ default: 5,
107
+ },
108
+ // popper append to element
109
+ popperAppendTo: {
110
+ type: [String, HTMLElement],
111
+ default: function () {
112
+ return document.body;
113
+ },
114
+ },
115
+ /*
116
+ before visible change
117
+ 如果返回false 则阻止显示或者关闭
118
+ */
119
+ beforeVisibleChange: {
120
+ type: Function,
121
+ default: null,
122
+ },
123
+ },
124
+ data() {
125
+ return {
126
+ internalVisible: false,
127
+ internalOptions: [],
128
+ inputValue: "",
129
+ // 是否显示触发器被点击了(被点击将忽略 clickOutside 事件)
130
+ isDropdownShowTriggerClicked: false,
131
+ // root id
132
+ rootId: "",
133
+ // dropdown items panel id
134
+ dropdownItemsPanelId: "",
135
+ // 弹出被添加到的目标元素
136
+ popperAppendToEl: null,
137
+ // 弹出被添加到的目标元素标签名称
138
+ appendToElTagName: null,
139
+ };
140
+ },
141
+ computed: {
142
+ // is dropdown visible
143
+ isDropdownVisible() {
144
+ return this.isControlled ? this.visible : this.internalVisible;
145
+ },
146
+
147
+ // 获取最大宽度(不设置则是无穷大)
148
+ getMaxWidth() {
149
+ var result = Infinity,
150
+ maxWidth = this.maxWidth,
151
+ width = this.width;
152
+
153
+ if (maxWidth && maxWidth > 0 && maxWidth > width) {
154
+ result = maxWidth;
155
+ }
156
+
157
+ return result;
158
+ },
159
+ // selected labels
160
+ selectedLabels() {
161
+ return this.internalOptions
162
+ .filter((x) => x.selected)
163
+ .map((x) => {
164
+ if (x.selected) {
165
+ return x.label;
166
+ }
167
+ });
168
+ },
169
+ // operation buttons class
170
+ operationFilterClass() {
171
+ let result = null;
172
+ result = {
173
+ [clsName("filter-disable")]: this.selectedLabels.length === 0,
174
+ };
175
+
176
+ return result;
177
+ },
178
+ // dropdown items class
179
+ dropdownItemsClass() {
180
+ return {
181
+ [clsName("dd")]: true,
182
+ [clsName("dd-show")]: this.isDropdownVisible,
183
+ };
184
+ },
185
+ },
186
+ watch: {
187
+ value: function () {
188
+ this.init();
189
+ },
190
+ visible: {
191
+ handler(visible) {
192
+ const { isControlled, showDropDown, hideDropDown } = this;
193
+ // deal after mounted hook
194
+ setTimeout(() => {
195
+ if (isControlled) {
196
+ if (visible) {
197
+ showDropDown();
198
+ } else {
199
+ hideDropDown();
200
+ }
201
+ }
202
+ });
203
+ },
204
+ immediate: true,
205
+ },
206
+ },
207
+ methods: {
208
+ // 初始化
209
+ init() {
210
+ this.internalOptions = Object.assign([], this.value);
211
+
212
+ if (this.isInput) {
213
+ this.setInputValue();
214
+ }
215
+ },
216
+
217
+ // operation filter confirm
218
+ confirm() {
219
+ // 使用户传入的v-model 生效
220
+ this.$emit("input", this.internalOptions);
221
+ this.$emit(EMIT_EVENTS.FILTER_CONFIRM, this.internalOptions);
222
+ this.hideDropDown();
223
+ },
224
+
225
+ // operation filter reset
226
+ reset() {
227
+ if (this.internalOptions.some((x) => x.selected)) {
228
+ this.internalOptions.map((x) => {
229
+ if (x.selected) {
230
+ x.selected = false;
231
+ }
232
+ return x;
233
+ });
234
+
235
+ // 使用户传入的v-model 生效
236
+ this.$emit("input", this.internalOptions);
237
+
238
+ this.$emit(EMIT_EVENTS.FILTER_RESET, this.internalOptions);
239
+ }
240
+
241
+ this.hideDropDown();
242
+ },
243
+
244
+ // show dropdown
245
+ showDropDown() {
246
+ const { rootId, dropdownItemsPanelId } = this;
247
+
248
+ const nextVisible = true;
249
+
250
+ const allowChange = this.beforeVisibleChangeCallback(nextVisible);
251
+ if (isBoolean(allowChange) && !allowChange) {
252
+ return false;
253
+ }
254
+
255
+ let rootEl = document.querySelector(`#${rootId}`);
256
+
257
+ if (rootEl) {
258
+ // remove first
259
+ rootEl.innerHTML = "";
260
+ rootEl.appendChild(this.$refs[dropdownItemsPanelId]);
261
+
262
+ rootEl.style.position = "absolute";
263
+ rootEl.classList.add(clsName("popper"));
264
+
265
+ this.changDropdownPanelPosition();
266
+ }
267
+
268
+ this.internalVisible = true;
269
+
270
+ this.$emit(EMIT_EVENTS.VISIBLE_CHANGE, nextVisible);
271
+ },
272
+
273
+ // hide dropdown
274
+ hideDropDown() {
275
+ const nextVisible = false;
276
+
277
+ const allowChange = this.beforeVisibleChangeCallback(nextVisible);
278
+ if (isBoolean(allowChange) && !allowChange) {
279
+ return false;
280
+ }
281
+
282
+ this.$emit(EMIT_EVENTS.VISIBLE_CHANGE, nextVisible);
283
+
284
+ setTimeout(() => {
285
+ this.internalVisible = false;
286
+ this.removeOrEmptyRootPanel();
287
+ }, 150);
288
+ },
289
+
290
+ // before visible change callback
291
+ beforeVisibleChangeCallback(nextVisible) {
292
+ const { beforeVisibleChange, isDropdownVisible } = this;
293
+
294
+ if (
295
+ nextVisible !== isDropdownVisible &&
296
+ isFunction(beforeVisibleChange)
297
+ ) {
298
+ // next visible
299
+ return beforeVisibleChange({
300
+ nextVisible,
301
+ });
302
+ }
303
+ },
304
+
305
+ // remove or emoty root panel
306
+ removeOrEmptyRootPanel() {
307
+ const { rootId } = this;
308
+
309
+ let rootEl = document.querySelector(`#${rootId}`);
310
+ if (rootEl) {
311
+ rootEl.innerHTML = "";
312
+ }
313
+ },
314
+
315
+ // change dropdown panel position
316
+ changDropdownPanelPosition() {
317
+ const {
318
+ defaultInstance,
319
+ rootId,
320
+ popperAppendToEl,
321
+ appendToElTagName,
322
+ } = this;
323
+
324
+ let rootEl = document.querySelector(`#${rootId}`);
325
+
326
+ if (rootEl) {
327
+ const { width: currentPanelWidth, height: currentPanelHeight } =
328
+ rootEl.getBoundingClientRect();
329
+
330
+ const triggerEl = this.$el.querySelector(".ve-dropdown-dt");
331
+ const { height: triggerElHeight } =
332
+ triggerEl.getBoundingClientRect();
333
+
334
+ if (!popperAppendToEl) {
335
+ return false;
336
+ }
337
+
338
+ // is append to body
339
+ const isAppendToBody = appendToElTagName === "BODY";
340
+
341
+ const {
342
+ offsetLeft: triggerElLeft,
343
+ offsetTop: triggerElTop,
344
+ right: triggerElRight,
345
+ bottom: triggerElBottom,
346
+ } = isAppendToBody
347
+ ? getViewportOffset(triggerEl)
348
+ : getViewportOffsetWithinContainer(
349
+ triggerEl,
350
+ popperAppendToEl,
351
+ );
352
+
353
+ let panelX = 0;
354
+ let panelY = 0;
355
+
356
+ // 如果不是添加到body 需要考虑外层容器滚动调的影响
357
+ let scrollLeft = 0;
358
+ let scrollTop = 0;
359
+ if (!isAppendToBody) {
360
+ scrollLeft = popperAppendToEl.scrollLeft;
361
+ scrollTop = popperAppendToEl.scrollTop;
362
+ }
363
+
364
+ // 右方宽度够显示
365
+ if (triggerElRight >= currentPanelWidth) {
366
+ panelX = triggerElLeft + scrollLeft;
367
+ }
368
+ // 右方宽度不够显示在鼠标点击左方
369
+ else {
370
+ panelX = triggerElLeft - currentPanelWidth + scrollLeft;
371
+ }
372
+
373
+ // 下方高度够显示
374
+ if (triggerElBottom >= currentPanelHeight) {
375
+ panelY =
376
+ triggerElTop +
377
+ triggerElHeight +
378
+ defaultInstance +
379
+ scrollTop;
380
+ }
381
+ // 下方高度不够显示在鼠标点击上方
382
+ else {
383
+ panelY =
384
+ triggerElTop -
385
+ currentPanelHeight -
386
+ defaultInstance +
387
+ scrollTop;
388
+ }
389
+
390
+ rootEl.style.left = panelX + "px";
391
+ rootEl.style.top = panelY + "px";
392
+ }
393
+ },
394
+
395
+ // 设置文本框的值
396
+ setInputValue() {
397
+ var result, labels;
398
+
399
+ labels = this.selectedLabels;
400
+ if (Array.isArray(labels) && labels.length > 0) {
401
+ result = labels.join();
402
+ }
403
+
404
+ this.inputValue = result;
405
+ },
406
+
407
+ // dropdown panel click
408
+ dropdownPanelClick() {
409
+ this.isDropdownShowTriggerClicked = true;
410
+ this.dropdownShowToggle();
411
+ },
412
+
413
+ // dropdown show toggle
414
+ dropdownShowToggle() {
415
+ if (this.isDropdownVisible) {
416
+ this.hideDropDown();
417
+ } else {
418
+ this.showDropDown();
419
+ }
420
+ },
421
+
422
+ // single select option click
423
+ singleSelectOptionClick(e, item) {
424
+ this.internalOptions = this.internalOptions.map((x) => {
425
+ if (item.label === x.label) {
426
+ x.selected = true;
427
+ } else {
428
+ x.selected = false;
429
+ }
430
+ return x;
431
+ });
432
+
433
+ if (this.hideByItemClick) {
434
+ this.hideDropDown();
435
+ }
436
+
437
+ if (this.isInput) {
438
+ this.setInputValue();
439
+ }
440
+
441
+ // 使用户传入的v-model 生效
442
+ this.$emit("input", this.internalOptions);
443
+
444
+ this.$emit(EMIT_EVENTS.ITEM_SELECT_CHANGE, this.internalOptions);
445
+ },
446
+
447
+ // 获取样式名称
448
+ getTextAlignClass() {
449
+ return clsName(`items-li-a-${this.textAlign}`);
450
+ },
451
+
452
+ // dropdown click outSide
453
+ dropdownClickOutside() {
454
+ /*
455
+ 是否显示触发器被点击了(被点击将忽略 clickOutside 事件)
456
+ */
457
+ setTimeout(() => {
458
+ if (this.isDropdownShowTriggerClicked) {
459
+ this.isDropdownShowTriggerClicked = false;
460
+ } else {
461
+ this.hideDropDown();
462
+ }
463
+ });
464
+ },
465
+
466
+ // checbox 受控属性管理
467
+ checkedChangeControl(item, isChecked) {
468
+ this.internalOptions = this.internalOptions.map((i) => {
469
+ if (i.label === item.label) {
470
+ i.selected = isChecked;
471
+ }
472
+ return i;
473
+ });
474
+
475
+ this.$emit(EMIT_EVENTS.ITEM_SELECT_CHANGE, this.internalOptions);
476
+ },
477
+
478
+ // get random id
479
+ getRandomIdWithPrefix() {
480
+ return clsName(getRandomId());
481
+ },
482
+
483
+ /*
484
+ add root element to element
485
+ 如果不指定则添加到 body
486
+ */
487
+ addRootElementToElement() {
488
+ const { popperAppendTo } = this;
489
+
490
+ this.rootId = this.getRandomIdWithPrefix();
491
+ this.dropdownItemsPanelId = this.getRandomIdWithPrefix();
492
+
493
+ let rootEl = document.querySelector(`#${this.rootId}`);
494
+
495
+ if (rootEl) {
496
+ return false;
497
+ } else {
498
+ // fixed unit test error: [Vue warn]: Error in v-on handler: "TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'."
499
+ this.$nextTick(() => {
500
+ let containerEl = document.createElement("div");
501
+
502
+ containerEl.setAttribute("id", this.rootId);
503
+
504
+ if (
505
+ typeof popperAppendTo === "string" &&
506
+ popperAppendTo.length > 0
507
+ ) {
508
+ this.popperAppendToEl =
509
+ document.querySelector(popperAppendTo);
510
+ } else {
511
+ this.popperAppendToEl = popperAppendTo;
512
+ }
513
+
514
+ this.appendToElTagName = this.popperAppendToEl.tagName;
515
+
516
+ this.popperAppendToEl.appendChild(containerEl);
517
+ });
518
+ }
519
+ },
520
+ },
521
+
522
+ created() {
523
+ this.init();
524
+ },
525
+ mounted() {
526
+ this.addRootElementToElement();
527
+
528
+ this.$nextTick(() => {
529
+ const targetEl =
530
+ this.appendToElTagName === "BODY"
531
+ ? document
532
+ : this.popperAppendToEl;
533
+ targetEl.addEventListener(
534
+ "scroll",
535
+ this.changDropdownPanelPosition,
536
+ );
537
+ });
538
+ window.addEventListener("resize", this.changDropdownPanelPosition);
539
+ },
540
+
541
+ destroyed() {
542
+ this.removeOrEmptyRootPanel();
543
+
544
+ this.$nextTick(() => {
545
+ const targetEl =
546
+ this.appendToElTagName === "BODY"
547
+ ? document
548
+ : this.popperAppendToEl;
549
+ targetEl.removeEventListener(
550
+ "scroll",
551
+ this.changDropdownPanelPosition,
552
+ );
553
+ });
554
+ window.removeEventListener("resize", this.changDropdownPanelPosition);
555
+ },
556
+
557
+ render() {
558
+ const {
559
+ isMultiple,
560
+ getTextAlignClass,
561
+ internalOptions,
562
+ isSelect,
563
+ width,
564
+ maxHeight,
565
+ dropdownPanelClick,
566
+ getMaxWidth,
567
+ reset,
568
+ singleSelectOptionClick,
569
+ showOperation,
570
+ isCustomContent,
571
+ dropdownItemsClass,
572
+ dropdownItemsPanelId,
573
+ } = this;
574
+
575
+ let content = "";
576
+
577
+ if (isMultiple) {
578
+ content = internalOptions.map((item, index) => {
579
+ const checkboxProps = {
580
+ key: item.label,
581
+ props: {
582
+ isControlled: true,
583
+ label: item.label,
584
+ showLine: item.showLine,
585
+ isSelected: item.selected,
586
+ },
587
+ on: {
588
+ "on-checked-change": (isChecked) =>
589
+ this.checkedChangeControl(item, isChecked),
590
+ },
591
+ };
592
+
593
+ return (
594
+ <li
595
+ key={index}
596
+ class={[
597
+ clsName("items-multiple"),
598
+ clsName("items-li"),
599
+ getTextAlignClass(),
600
+ ]}
601
+ >
602
+ <VeCheckbox {...checkboxProps} />
603
+ </li>
604
+ );
605
+ });
606
+ } else {
607
+ content = internalOptions.map((item, index) => {
608
+ const radioProps = {
609
+ props: {
610
+ isControlled: true,
611
+ isSelected: item.selected,
612
+ },
613
+ on: {
614
+ "on-radio-change": () => {},
615
+ },
616
+ };
617
+
618
+ return (
619
+ <li
620
+ key={index}
621
+ class={[
622
+ clsName("items-li"),
623
+ item.selected ? "active" : "",
624
+ ]}
625
+ on-click={(e) => singleSelectOptionClick(e, item)}
626
+ >
627
+ <a
628
+ class={[clsName("items-li-a"), getTextAlignClass()]}
629
+ href="javascript:void(0);"
630
+ >
631
+ {this.showRadio ? (
632
+ <VeRadio {...radioProps}>{item.label}</VeRadio>
633
+ ) : (
634
+ item.label
635
+ )}
636
+ </a>
637
+ </li>
638
+ );
639
+ });
640
+ }
641
+
642
+ const dropdownProps = {
643
+ class: ["ve-dropdown"],
644
+ };
645
+
646
+ const dropdownItemsProps = {
647
+ ref: dropdownItemsPanelId,
648
+ class: dropdownItemsClass,
649
+ directives: [
650
+ {
651
+ name: "click-outside",
652
+ value: this.dropdownClickOutside,
653
+ },
654
+ ],
655
+ };
656
+
657
+ return (
658
+ <dl {...dropdownProps}>
659
+ <dt class="ve-dropdown-dt" on-click={dropdownPanelClick}>
660
+ <a
661
+ class={[isSelect ? clsName("dt-selected") : ""]}
662
+ style={{ width: width + "px" }}
663
+ >
664
+ {this.$slots.default}
665
+ </a>
666
+ </dt>
667
+ <div style={{ display: "none" }}>
668
+ <dd {...dropdownItemsProps}>
669
+ <ul
670
+ class={clsName("items")}
671
+ style={{
672
+ "min-width": width + "px",
673
+ "max-width": getMaxWidth + "px",
674
+ }}
675
+ >
676
+ {/* custome content */}
677
+ {isCustomContent && this.$slots["custom-content"]}
678
+ {/* not custom content */}
679
+ {!isCustomContent && (
680
+ <div>
681
+ <div
682
+ style={{
683
+ "max-height": maxHeight + "px",
684
+ }}
685
+ class={clsName("items-warpper")}
686
+ >
687
+ {content}
688
+ </div>
689
+ {showOperation && (
690
+ <li class={clsName("operation")}>
691
+ <a
692
+ class={[
693
+ clsName("operation-item"),
694
+ this.operationFilterClass,
695
+ ]}
696
+ href="javascript:void(0)"
697
+ on-click={reset}
698
+ >
699
+ {this.resetFilterText}
700
+ </a>
701
+ <a
702
+ class={clsName(
703
+ "operation-item",
704
+ )}
705
+ href="javascript:void(0)"
706
+ on-click={this.confirm}
707
+ >
708
+ {this.confirmFilterText}
709
+ </a>
710
+ </li>
711
+ )}
712
+ </div>
713
+ )}
714
+ </ul>
715
+ </dd>
716
+ </div>
717
+ </dl>
718
+ );
719
+ },
720
+ };