@whitesev/pops 1.6.0 → 1.6.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 (62) hide show
  1. package/dist/index.amd.js +3666 -3125
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.cjs.js +3666 -3125
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.esm.js +3666 -3125
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.iife.js +3666 -3125
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.system.js +3666 -3125
  10. package/dist/index.system.js.map +1 -1
  11. package/dist/index.umd.js +3666 -3125
  12. package/dist/index.umd.js.map +1 -1
  13. package/dist/types/src/Pops.d.ts +56 -7
  14. package/dist/types/src/components/alert/config.d.ts +2 -0
  15. package/dist/types/src/components/confirm/config.d.ts +2 -0
  16. package/dist/types/src/components/drawer/config.d.ts +2 -0
  17. package/dist/types/src/components/folder/config.d.ts +2 -0
  18. package/dist/types/src/components/iframe/config.d.ts +2 -0
  19. package/dist/types/src/components/loading/config.d.ts +2 -0
  20. package/dist/types/src/components/panel/PanelHandleContentDetails.d.ts +149 -0
  21. package/dist/types/src/components/panel/config.d.ts +2 -0
  22. package/dist/types/src/components/panel/selectMultipleType.d.ts +49 -24
  23. package/dist/types/src/components/prompt/config.d.ts +2 -0
  24. package/dist/types/src/components/rightClickMenu/config.d.ts +2 -0
  25. package/dist/types/src/components/searchSuggestion/config.d.ts +2 -0
  26. package/dist/types/src/components/searchSuggestion/indexType.d.ts +56 -32
  27. package/dist/types/src/components/tooltip/config.d.ts +2 -0
  28. package/dist/types/src/utils/PopsDOMUtils.d.ts +42 -13
  29. package/dist/types/src/utils/PopsInstanceUtils.d.ts +22 -0
  30. package/package.json +4 -1
  31. package/src/Pops.ts +8 -2
  32. package/src/components/alert/config.ts +59 -0
  33. package/src/components/alert/index.ts +2 -57
  34. package/src/components/confirm/config.ts +94 -0
  35. package/src/components/confirm/index.ts +4 -94
  36. package/src/components/drawer/config.ts +90 -0
  37. package/src/components/drawer/index.ts +2 -88
  38. package/src/components/folder/config.ts +130 -0
  39. package/src/components/folder/index.ts +3 -129
  40. package/src/components/iframe/config.ts +58 -0
  41. package/src/components/iframe/index.ts +2 -56
  42. package/src/components/loading/config.ts +27 -0
  43. package/src/components/loading/index.ts +2 -25
  44. package/src/components/panel/PanelHandleContentDetails.ts +2612 -0
  45. package/src/components/panel/config.ts +348 -0
  46. package/src/components/panel/index.css +191 -5
  47. package/src/components/panel/index.ts +10 -2521
  48. package/src/components/panel/selectMultipleType.ts +52 -25
  49. package/src/components/prompt/config.ts +102 -0
  50. package/src/components/prompt/index.ts +2 -100
  51. package/src/components/rightClickMenu/config.ts +122 -0
  52. package/src/components/rightClickMenu/index.css +78 -0
  53. package/src/components/rightClickMenu/index.ts +26 -202
  54. package/src/components/searchSuggestion/config.ts +55 -0
  55. package/src/components/searchSuggestion/index.ts +228 -205
  56. package/src/components/searchSuggestion/indexType.ts +56 -32
  57. package/src/components/tooltip/config.ts +29 -0
  58. package/src/components/tooltip/index.ts +2 -27
  59. package/src/css/animation.css +22 -0
  60. package/src/utils/PopsDOMUtils.ts +108 -29
  61. package/src/utils/PopsInstanceUtils.ts +80 -0
  62. package/src/components/searchSuggestion/index.css +0 -0
@@ -0,0 +1,2612 @@
1
+ import { pops } from "../../Pops";
2
+ import { popsDOMUtils } from "../../utils/PopsDOMUtils";
3
+ import { PopsMathFloatUtils } from "../../utils/PopsMathUtils";
4
+ import { popsUtils } from "../../utils/PopsUtils";
5
+ import type { PopsAlertDetails } from "../alert/indexType";
6
+ import type { PopsToolTipDetails } from "../tooltip/indexType";
7
+ import type { PopsPanelButtonDetails } from "./buttonType";
8
+ import type { PopsPanelRightAsideContainerOptions } from "./commonType";
9
+ import type { PopsPanelDeepMenuDetails } from "./deepMenuType";
10
+ import type { PopsPanelFormsDetails } from "./formsType";
11
+ import type {
12
+ PopsPanelContentConfig,
13
+ PopsPanelDetails,
14
+ PopsPanelFormsTotalDetails,
15
+ } from "./indexType";
16
+ import type { PopsPanelInputDetails } from "./inputType";
17
+ import type { PopsPanelOwnDetails } from "./ownType";
18
+ import type {
19
+ PopsPanelSelectMultipleDataOption,
20
+ PopsPanelSelectMultipleDetails,
21
+ } from "./selectMultipleType";
22
+ import type { PopsPanelSelectDetails } from "./selectType";
23
+ import type { PopsPanelSliderDetails } from "./sliderType";
24
+ import type { PopsPanelSwitchDetails } from "./switchType";
25
+ import type { PopsPanelTextAreaDetails } from "./textareaType";
26
+
27
+ export const PanelHandleContentDetails = {
28
+ /**
29
+ * 左侧的ul容器
30
+ */
31
+ asideULElement: null as any as HTMLUListElement,
32
+ /**
33
+ * 右侧主内容的顶部文字ul容器
34
+ */
35
+ sectionContainerHeaderULElement: null as any as HTMLUListElement,
36
+ /**
37
+ * 右侧主内容的ul容器
38
+ */
39
+ sectionContainerULElement: null as any as HTMLUListElement,
40
+ $el: {
41
+ $content: null as any as HTMLDivElement,
42
+ $contentAside: null as any as HTMLDivElement,
43
+ $contentSectionContainer: null as any as HTMLDivElement,
44
+ },
45
+ init(details: {
46
+ config: Required<PopsPanelDetails>;
47
+ $el: {
48
+ $content: HTMLDivElement;
49
+ $contentAside: HTMLDivElement;
50
+ $contentSectionContainer: HTMLDivElement;
51
+ };
52
+ }) {
53
+ // @ts-ignore
54
+ this.$el = null;
55
+ this.$el = {
56
+ ...details.$el,
57
+ };
58
+
59
+ this.asideULElement =
60
+ this.$el.$contentAside.querySelector<HTMLUListElement>("ul")!;
61
+ this.sectionContainerHeaderULElement =
62
+ this.$el.$contentSectionContainer.querySelectorAll<HTMLUListElement>(
63
+ "ul"
64
+ )[0];
65
+ this.sectionContainerULElement =
66
+ this.$el.$contentSectionContainer.querySelectorAll<HTMLUListElement>(
67
+ "ul"
68
+ )[1];
69
+ /**
70
+ * 默认点击的左侧容器
71
+ */
72
+ let asideDefaultItemElement: HTMLLIElement | null = null;
73
+ let isScrollToDefaultView = false;
74
+ details.config.content.forEach((asideItem) => {
75
+ let asideLiElement = this.getAsideItem(asideItem);
76
+ this.setAsideItemClickEvent(asideLiElement, asideItem);
77
+ this.asideULElement.appendChild(asideLiElement);
78
+ if (asideDefaultItemElement == null) {
79
+ let flag = false;
80
+ if (typeof asideItem.isDefault === "function") {
81
+ flag = Boolean(asideItem.isDefault());
82
+ } else {
83
+ flag = Boolean(asideItem.isDefault);
84
+ }
85
+ if (flag) {
86
+ asideDefaultItemElement = asideLiElement;
87
+ isScrollToDefaultView = Boolean(asideItem.scrollToDefaultView);
88
+ }
89
+ }
90
+ });
91
+
92
+ /* 点击左侧列表 */
93
+ if (
94
+ asideDefaultItemElement == null &&
95
+ this.asideULElement.children.length
96
+ ) {
97
+ /* 默认第一个 */
98
+ asideDefaultItemElement = this.asideULElement
99
+ .children[0] as HTMLLIElement;
100
+ }
101
+ if (asideDefaultItemElement) {
102
+ /* 点击选择的那一项 */
103
+ asideDefaultItemElement.click();
104
+ if (isScrollToDefaultView) {
105
+ asideDefaultItemElement?.scrollIntoView();
106
+ }
107
+ } else {
108
+ console.error("pops.panel:左侧容器没有项");
109
+ }
110
+ },
111
+ /**
112
+ * 清空container容器的元素
113
+ */
114
+ clearContainer() {
115
+ this.sectionContainerHeaderULElement.innerHTML = "";
116
+ this.sectionContainerULElement.innerHTML = "";
117
+ this.$el.$content
118
+ ?.querySelectorAll("section.pops-panel-deepMenu-container")
119
+ .forEach((ele) => ele.remove());
120
+ },
121
+ /**
122
+ * 清空左侧容器已访问记录
123
+ */
124
+ clearAsideItemIsVisited() {
125
+ this.$el.$contentAside
126
+ .querySelectorAll<HTMLDivElement>(".pops-is-visited")
127
+ .forEach((element) => {
128
+ popsDOMUtils.removeClassName(element, "pops-is-visited");
129
+ });
130
+ },
131
+ /**
132
+ * 设置左侧容器已访问记录
133
+ * @param element
134
+ */
135
+ setAsideItemIsVisited(element: HTMLElement) {
136
+ popsDOMUtils.addClassName(element, "pops-is-visited");
137
+ },
138
+ /**
139
+ * 为元素添加自定义属性
140
+ * @param element
141
+ * @param attributes
142
+ */
143
+ addElementAttributes(element: HTMLElement, attributes?: any) {
144
+ if (attributes == null) {
145
+ return;
146
+ }
147
+ if (Array.isArray(attributes)) {
148
+ attributes.forEach((attrObject) => {
149
+ this.addElementAttributes(element, attrObject);
150
+ });
151
+ } else {
152
+ Object.keys(attributes).forEach((attributeName) => {
153
+ element.setAttribute(attributeName, attributes[attributeName]);
154
+ });
155
+ }
156
+ },
157
+ /**
158
+ * 为元素设置(自定义)属性
159
+ * @param element
160
+ * @param props
161
+ */
162
+ setElementProps(element: HTMLElement, props?: any) {
163
+ if (props == null) {
164
+ return;
165
+ }
166
+ Object.keys(props).forEach((propName) => {
167
+ (element as any)[propName] = props[propName];
168
+ });
169
+ },
170
+ /**
171
+ * 获取左侧容器元素<li>
172
+ * @param asideConfig
173
+ */
174
+ getAsideItem(asideConfig: PopsPanelContentConfig) {
175
+ let liElement = document.createElement("li");
176
+ liElement.id = asideConfig.id;
177
+ (liElement as any)["__forms__"] = asideConfig.forms;
178
+ liElement.innerHTML = asideConfig.title;
179
+ this.addElementAttributes(liElement, asideConfig.attributes);
180
+ this.setElementProps(liElement, asideConfig.props);
181
+ return liElement;
182
+ },
183
+ /**
184
+ * 获取中间容器的元素<li>
185
+ * type ==> switch
186
+ * @param formConfig
187
+ */
188
+ getSectionContainerItem_switch(formConfig: PopsPanelSwitchDetails) {
189
+ let liElement = document.createElement("li");
190
+ (liElement as any)["__formConfig__"] = formConfig;
191
+ if (formConfig.className) {
192
+ liElement.className = formConfig.className;
193
+ }
194
+ this.addElementAttributes(liElement, formConfig.attributes);
195
+ this.setElementProps(liElement, formConfig.props);
196
+ /* 左边底部的描述的文字 */
197
+ let leftDescriptionText = "";
198
+ if (Boolean(formConfig.description)) {
199
+ leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
200
+ }
201
+ liElement.innerHTML = /*html*/ `
202
+ <div class="pops-panel-item-left-text">
203
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
204
+ ${leftDescriptionText}
205
+ </div>
206
+ <div class="pops-panel-switch">
207
+ <input class="pops-panel-switch__input" type="checkbox">
208
+ <span class="pops-panel-switch__core">
209
+ <div class="pops-panel-switch__action">
210
+ </div>
211
+ </span>
212
+ </div>`;
213
+ const PopsPanelSwitch = {
214
+ [Symbol.toStringTag]: "PopsPanelSwitch",
215
+ $data: {
216
+ value: Boolean(formConfig.getValue()),
217
+ },
218
+ $ele: {
219
+ switch: liElement.querySelector<HTMLDivElement>(".pops-panel-switch")!,
220
+ input: liElement.querySelector<HTMLInputElement>(
221
+ ".pops-panel-switch__input"
222
+ )!,
223
+ core: liElement.querySelector<HTMLSpanElement>(
224
+ ".pops-panel-switch__core"
225
+ )!,
226
+ },
227
+ init() {
228
+ this.setStatus(this.$data.value);
229
+ if (formConfig.disabled) {
230
+ this.disable();
231
+ }
232
+ this.setClickEvent();
233
+ },
234
+ setClickEvent() {
235
+ let that = this;
236
+ popsDOMUtils.on(this.$ele.core, "click", void 0, function (event) {
237
+ if (
238
+ that.$ele.input.disabled ||
239
+ that.$ele.switch.hasAttribute("data-disabled")
240
+ ) {
241
+ return;
242
+ }
243
+ that.$data.value = that.getStatus();
244
+ that.setStatus(that.$data.value);
245
+ if (typeof formConfig.callback === "function") {
246
+ formConfig.callback(event, that.$data.value);
247
+ }
248
+ });
249
+ },
250
+ /**
251
+ * 设置状态
252
+ */
253
+ setStatus(isChecked = false) {
254
+ isChecked = Boolean(isChecked);
255
+ this.$ele.input.checked = isChecked;
256
+ if (isChecked) {
257
+ popsDOMUtils.addClassName(
258
+ this.$ele.switch,
259
+ "pops-panel-switch-is-checked"
260
+ );
261
+ } else {
262
+ popsDOMUtils.removeClassName(
263
+ this.$ele.switch,
264
+ "pops-panel-switch-is-checked"
265
+ );
266
+ }
267
+ },
268
+ /**
269
+ * 根据className来获取逆反值
270
+ */
271
+ getStatus() {
272
+ let checkedValue = false;
273
+ if (
274
+ !popsDOMUtils.containsClassName(
275
+ this.$ele.switch,
276
+ "pops-panel-switch-is-checked"
277
+ )
278
+ ) {
279
+ checkedValue = true;
280
+ }
281
+ return checkedValue;
282
+ },
283
+ /**
284
+ * 禁用复选框
285
+ */
286
+ disable() {
287
+ this.$ele.input.disabled = true;
288
+ this.$ele.switch.setAttribute("data-disabled", "true");
289
+ },
290
+ /**
291
+ * 启用复选框
292
+ */
293
+ notDisable() {
294
+ this.$ele.input.disabled = false;
295
+ this.$ele.switch.removeAttribute("data-disabled");
296
+ },
297
+ };
298
+
299
+ PopsPanelSwitch.init();
300
+ (liElement as any)["data-switch"] = PopsPanelSwitch;
301
+ return liElement;
302
+ },
303
+ /**
304
+ * 获取中间容器的元素<li>
305
+ * type ==> slider
306
+ * @param formConfig
307
+ */
308
+ getSectionContainerItem_slider(formConfig: PopsPanelSliderDetails) {
309
+ let liElement = document.createElement("li");
310
+ (liElement as any)["__formConfig__"] = formConfig;
311
+ if (formConfig.className) {
312
+ liElement.className = formConfig.className;
313
+ }
314
+ this.addElementAttributes(liElement, formConfig.attributes);
315
+ this.setElementProps(liElement, formConfig.props);
316
+ /* 左边底部的描述的文字 */
317
+ let leftDescriptionText = "";
318
+ if (Boolean(formConfig.description)) {
319
+ leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
320
+ }
321
+ liElement.innerHTML = `
322
+ <div class="pops-panel-item-left-text">
323
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
324
+ ${leftDescriptionText}
325
+ </div>
326
+ <div class="pops-panel-slider">
327
+ <input type="range" min="${formConfig.min}" max="${formConfig.max}">
328
+ </div>`;
329
+
330
+ let rangeInputElement = liElement.querySelector<HTMLInputElement>(
331
+ ".pops-panel-slider input[type=range]"
332
+ )!;
333
+ if (formConfig.step) {
334
+ rangeInputElement.setAttribute("step", formConfig.step.toString());
335
+ }
336
+ rangeInputElement.value = formConfig.getValue().toString();
337
+ /**
338
+ * 获取提示的内容
339
+ * @param value
340
+ */
341
+ let getToolTipContent = function (value: number | string) {
342
+ if (typeof formConfig.getToolTipContent === "function") {
343
+ return formConfig.getToolTipContent(value as number);
344
+ } else {
345
+ return value as string;
346
+ }
347
+ };
348
+ let tooltip = pops.tooltip({
349
+ target: rangeInputElement.parentElement!,
350
+ content: getToolTipContent(rangeInputElement.value),
351
+ zIndex: 1000000,
352
+ className: "github-tooltip",
353
+ showBeforeCallBack() {
354
+ tooltip.toolTipNode.querySelector("div")!.innerText = getToolTipContent(
355
+ rangeInputElement.value
356
+ );
357
+ },
358
+ alwaysShow: false,
359
+ only: false,
360
+ position: "top",
361
+ arrowDistance: 10,
362
+ });
363
+ popsDOMUtils.on(
364
+ rangeInputElement,
365
+ ["input", "propertychange"],
366
+ void 0,
367
+ function (event) {
368
+ tooltip.toolTipNode.querySelector("div")!.innerText = getToolTipContent(
369
+ rangeInputElement.value
370
+ );
371
+ if (typeof formConfig.callback === "function") {
372
+ formConfig.callback(event as InputEvent, (event as any).target.value);
373
+ }
374
+ }
375
+ );
376
+ return liElement;
377
+ },
378
+ /**
379
+ * 获取中间容器的元素<li>
380
+ * type ==> slider
381
+ * @param formConfig
382
+ */
383
+ getSectionContainerItem_slider_new(formConfig: PopsPanelSliderDetails) {
384
+ let liElement = document.createElement("li");
385
+ (liElement as any)["__formConfig__"] = formConfig;
386
+ if (formConfig.className) {
387
+ liElement.className = formConfig.className;
388
+ }
389
+ this.addElementAttributes(liElement, formConfig.attributes);
390
+ this.setElementProps(liElement, formConfig.props);
391
+ /* 左边底部的描述的文字 */
392
+ let leftDescriptionText = "";
393
+ if (Boolean(formConfig.description)) {
394
+ leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
395
+ }
396
+ liElement.innerHTML = /*html*/ `
397
+ <div class="pops-panel-item-left-text" style="flex: 1;">
398
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
399
+ ${leftDescriptionText}
400
+ </div>
401
+ <div class="pops-slider pops-slider-width">
402
+ <div class="pops-slider__runway">
403
+ <div class="pops-slider__bar" style="width: 0%; left: 0%"></div>
404
+ <div class="pops-slider__button-wrapper" style="left: 0%">
405
+ <div class="pops-slider__button"></div>
406
+ </div>
407
+ </div>
408
+ </div>`;
409
+ const PopsPanelSlider = {
410
+ [Symbol.toStringTag]: "PopsPanelSlider",
411
+ /**
412
+ * 值
413
+ */
414
+ value: formConfig.getValue(),
415
+ /**
416
+ * 最小值
417
+ */
418
+ min: formConfig.min,
419
+ /**
420
+ * 最大值
421
+ */
422
+ max: formConfig.max,
423
+ /**
424
+ * 间隔
425
+ */
426
+ step: formConfig.step || 1,
427
+ $data: {
428
+ /**
429
+ * 是否正在移动
430
+ */
431
+ isMove: false,
432
+ /**
433
+ * 是否已初始化已拖拽的距离
434
+ */
435
+ isInitDragPosition: false,
436
+ /**
437
+ * 是否正在检测是否停止拖拽
438
+ */
439
+ isCheckingStopDragMove: false,
440
+ /**
441
+ * 总宽度(px)
442
+ */
443
+ totalWidth: 0,
444
+ /**
445
+ * 每一块的间隔(px)
446
+ */
447
+ stepPx: 0,
448
+ /**
449
+ * 已拖拽的距离(px)
450
+ */
451
+ dragWidth: 0,
452
+ /**
453
+ * 已拖拽的百分比
454
+ */
455
+ dragPercent: 0,
456
+ /**
457
+ * 每一次块的信息
458
+ * 例如:当最小值是2,最大值是10,step为2
459
+ * 那么生成[2,4,6,8,10] 共计5个
460
+ * 又获取到当前滑块总长度是200px
461
+ * 那么生成映射
462
+ * 2 => 0px~40px
463
+ * 4 => 40px~80px
464
+ * 6 => 80px~120px
465
+ * 8 => 120px~160px
466
+ * 10 => 160px~200px
467
+ */
468
+ stepBlockMap: new Map<
469
+ number,
470
+ {
471
+ value: number;
472
+ px: number;
473
+ pxLeft: number;
474
+ pxRight: number;
475
+ percent: number;
476
+ }
477
+ >(),
478
+ },
479
+ $ele: {
480
+ slider: liElement.querySelector<HTMLDivElement>(".pops-slider")!,
481
+ runAway: liElement.querySelector<HTMLDivElement>(
482
+ ".pops-slider__runway"
483
+ )!,
484
+ bar: liElement.querySelector<HTMLDivElement>(".pops-slider__bar")!,
485
+ buttonWrapper: liElement.querySelector<HTMLDivElement>(
486
+ ".pops-slider__button-wrapper"
487
+ )!,
488
+ button: liElement.querySelector<HTMLDivElement>(
489
+ ".pops-slider__button"
490
+ )!,
491
+ tooltip: null as any as {
492
+ $shadowContainer: HTMLDivElement;
493
+ $shadowRoot: ShadowRoot;
494
+ guid: string;
495
+ config: Required<PopsToolTipDetails>;
496
+ toolTipNode: HTMLDivElement;
497
+ show: () => void;
498
+ close: () => void;
499
+ off: () => void;
500
+ on: () => void;
501
+ },
502
+ },
503
+ $interval: {
504
+ isCheck: false,
505
+ },
506
+ $tooltip: null as any,
507
+ init() {
508
+ this.initEleData();
509
+ this.setToolTipEvent();
510
+ this.setPanEvent();
511
+ this.setRunAwayClickEvent();
512
+ this.intervalInit();
513
+ if (formConfig.disabled) {
514
+ this.disableDrag();
515
+ }
516
+ },
517
+ /**
518
+ * 10s内循环获取slider的宽度等信息
519
+ * 获取到了就可以初始化left的值
520
+ * @param {number} [checkStepTime=200] 每次检测的间隔时间
521
+ * @param {number} [maxTime=10000] 最大的检测时间
522
+ */
523
+ intervalInit(checkStepTime = 200, maxTime = 10000) {
524
+ if (this.$interval.isCheck) {
525
+ return;
526
+ }
527
+ this.$interval.isCheck = true;
528
+ let isSuccess = false;
529
+ let oldTotalWidth = this.$data.totalWidth;
530
+ let timer: number | undefined = void 0;
531
+ let interval = setInterval(() => {
532
+ if (isSuccess) {
533
+ this.$interval.isCheck = false;
534
+ clearTimeout(timer);
535
+ clearInterval(interval);
536
+ } else {
537
+ this.initTotalWidth();
538
+ if (this.$data.totalWidth !== 0) {
539
+ isSuccess = true;
540
+ if (this.$data.totalWidth !== oldTotalWidth) {
541
+ /* slider的总宽度改变了 */
542
+ if (PopsMathFloatUtils.isFloat(this.step)) {
543
+ this.initFloatStepMap();
544
+ } else {
545
+ this.initStepMap();
546
+ }
547
+ this.initSliderPosition();
548
+ }
549
+ }
550
+ }
551
+ }, checkStepTime);
552
+ /* 最长检测时间是10s */
553
+ timer = setTimeout(() => {
554
+ clearInterval(interval);
555
+ }, maxTime);
556
+ },
557
+ /**
558
+ * 把数据添加到元素上
559
+ */
560
+ initEleData() {
561
+ this.$ele.slider.setAttribute("data-min", this.min.toString());
562
+ this.$ele.slider.setAttribute("data-max", this.max.toString());
563
+ this.$ele.slider.setAttribute("data-value", this.value.toString());
564
+ this.$ele.slider.setAttribute("data-step", this.step.toString());
565
+ (this.$ele.slider as any)["data-min"] = this.min;
566
+ (this.$ele.slider as any)["data-max"] = this.max;
567
+ (this.$ele.slider as any)["data-value"] = this.value;
568
+ (this.$ele.slider as any)["data-step"] = this.step;
569
+ },
570
+ /**
571
+ * 初始化滑块的总长度的数据(px)
572
+ */
573
+ initTotalWidth() {
574
+ this.$data.totalWidth = popsDOMUtils.width(this.$ele.runAway);
575
+ },
576
+ /**
577
+ * 初始化每一个块的具体数据信息
578
+ */
579
+ initStepMap() {
580
+ let index = 0;
581
+ // 计算出份数
582
+ let blockNums = (this.max - this.min) / this.step;
583
+ // 计算出每一份占据的px
584
+ this.$data.stepPx = this.$data.totalWidth / blockNums;
585
+ let widthPx = 0;
586
+ for (
587
+ let stepValue = this.min;
588
+ stepValue <= this.max;
589
+ stepValue += this.step
590
+ ) {
591
+ let value = this.formatValue(stepValue);
592
+ let info = {};
593
+ if (value === this.min) {
594
+ /* 起始 */
595
+ info = {
596
+ value: value,
597
+ px: 0,
598
+ pxLeft: 0,
599
+ pxRight: this.$data.stepPx / 2,
600
+ percent: 0,
601
+ };
602
+ } else {
603
+ info = {
604
+ value: value,
605
+ px: widthPx,
606
+ pxLeft: widthPx - this.$data.stepPx / 2,
607
+ pxRight: widthPx + this.$data.stepPx / 2,
608
+ percent: widthPx / this.$data.totalWidth,
609
+ };
610
+ //if (value === this.max) {
611
+ // info["pxLeft"] = this.$data.stepBlockMap.get(
612
+ // index - 1
613
+ // ).pxRight;
614
+ // info["pxRight"] = this.$data.totalWidth;
615
+ //}
616
+ }
617
+ this.$data.stepBlockMap.set(index, info as any);
618
+ index++;
619
+ widthPx += this.$data.stepPx;
620
+ }
621
+ },
622
+ /**
623
+ * 初始化每一个块的具体数据信息(浮点)
624
+ */
625
+ initFloatStepMap() {
626
+ let index = 0;
627
+ // 计算出份数
628
+ let blockNums = (this.max - this.min) / this.step;
629
+ // 计算出每一份占据的px
630
+ this.$data.stepPx = this.$data.totalWidth / blockNums;
631
+ let widthPx = 0;
632
+ for (
633
+ let stepValue = this.min;
634
+ stepValue <= this.max;
635
+ stepValue = PopsMathFloatUtils.add(stepValue, this.step)
636
+ ) {
637
+ let value = this.formatValue(stepValue);
638
+ let info = {};
639
+ if (value === this.min) {
640
+ /* 起始 */
641
+ info = {
642
+ value: value,
643
+ px: 0,
644
+ pxLeft: 0,
645
+ pxRight: this.$data.stepPx / 2,
646
+ percent: 0,
647
+ };
648
+ } else {
649
+ info = {
650
+ value: value,
651
+ px: widthPx,
652
+ pxLeft: widthPx - this.$data.stepPx / 2,
653
+ pxRight: widthPx + this.$data.stepPx / 2,
654
+ percent: widthPx / this.$data.totalWidth,
655
+ };
656
+ //if (value === this.max) {
657
+ // info["pxLeft"] = this.$data.stepBlockMap.get(
658
+ // index - 1
659
+ // ).pxRight;
660
+ // info["pxRight"] = this.$data.totalWidth;
661
+ //}
662
+ }
663
+ this.$data.stepBlockMap.set(index, info as any);
664
+ index++;
665
+ widthPx += this.$data.stepPx;
666
+ }
667
+ },
668
+ /**
669
+ * 初始化slider的默认起始left的百分比值
670
+ */
671
+ initSliderPosition() {
672
+ /* 设置起始默认style的left值 */
673
+ let percent = 0;
674
+ for (const [, stepBlockInfo] of this.$data.stepBlockMap.entries()) {
675
+ /* 判断值是否和区域内的值相等 */
676
+ if (stepBlockInfo.value == this.value) {
677
+ percent = stepBlockInfo.percent;
678
+ this.$data.dragWidth = stepBlockInfo.px;
679
+ break;
680
+ }
681
+ }
682
+ percent = this.formatValue(percent * 100);
683
+ this.setSliderPosition(percent);
684
+ },
685
+ /**
686
+ * 判断数字是否是浮点数
687
+ * @param num
688
+ * @returns
689
+ */
690
+ isFloat(num: number) {
691
+ return Number(num) === num && num % 1 !== 0;
692
+ },
693
+ /**
694
+ * 值改变的回调
695
+ * @param event
696
+ * @param value
697
+ */
698
+ valueChangeCallBack(event: any, value: number) {
699
+ if (typeof formConfig.callback === "function") {
700
+ formConfig.callback(event, value);
701
+ }
702
+ },
703
+ /**
704
+ * 根据拖拽距离获取滑块应该在的区间和值
705
+ */
706
+ getDragInfo(dragX: number) {
707
+ let result = this.$data.stepBlockMap.get(0);
708
+ for (const [, stepBlockInfo] of this.$data.stepBlockMap.entries()) {
709
+ if (stepBlockInfo.pxLeft <= dragX && dragX < stepBlockInfo.pxRight) {
710
+ result = stepBlockInfo;
711
+ break;
712
+ }
713
+ }
714
+ return result;
715
+ },
716
+ /**
717
+ * 获取滑块的当前脱拖拽占据的百分比
718
+ * @param {number} dragWidth
719
+ */
720
+ getSliderPositonPercent(dragWidth: number) {
721
+ return dragWidth / this.$data.totalWidth;
722
+ },
723
+ /**
724
+ * 根据step格式化value
725
+ * @param num
726
+ */
727
+ formatValue(num: number) {
728
+ if (PopsMathFloatUtils.isFloat(this.step)) {
729
+ num = parseFloat(num.toFixed(2));
730
+ } else {
731
+ num = parseInt(num.toString());
732
+ }
733
+ return num;
734
+ },
735
+ /**
736
+ * 设置滑块的位置偏移(left)
737
+ * @param percent 百分比
738
+ */
739
+ setSliderPosition(percent: number) {
740
+ if (parseInt(percent.toString()) === 1) {
741
+ percent = 1;
742
+ }
743
+ if (percent > 1) {
744
+ percent = percent / 100;
745
+ }
746
+ /* 滑块按钮的偏移 */
747
+ this.$ele.buttonWrapper.style.left = `${percent * 100}%`;
748
+ /* 滑块进度的宽度 */
749
+ this.$ele.bar.style.width = `${percent * 100}%`;
750
+ },
751
+ /**
752
+ * 禁止拖拽
753
+ */
754
+ disableDrag() {
755
+ this.$ele.runAway.classList.add("pops-slider-is-disabled");
756
+ },
757
+ /**
758
+ * 允许拖拽
759
+ */
760
+ allowDrag() {
761
+ this.$ele.runAway.classList.remove("pops-slider-is-disabled");
762
+ },
763
+ /**
764
+ * 判断当前滑块是否被禁用
765
+ */
766
+ isDisabledDrag() {
767
+ return this.$ele.runAway.classList.contains("pops-slider-is-disabled");
768
+ },
769
+ /**
770
+ * 设置进度条点击定位的事件
771
+ */
772
+ setRunAwayClickEvent() {
773
+ popsDOMUtils.on(
774
+ this.$ele.runAway,
775
+ "click",
776
+ void 0,
777
+ (event) => {
778
+ if (
779
+ event.target !== this.$ele.runAway &&
780
+ event.target !== this.$ele.bar
781
+ ) {
782
+ return;
783
+ }
784
+ let clickX = parseFloat((event as any).offsetX);
785
+ this.dragStartCallBack();
786
+ this.dragMoveCallBack(event, clickX, this.value);
787
+ this.dragEndCallBack(clickX);
788
+ },
789
+ {
790
+ capture: false,
791
+ }
792
+ );
793
+ },
794
+ /**
795
+ * 拖拽开始的回调,如果返回false,禁止拖拽
796
+ */
797
+ dragStartCallBack() {
798
+ if (!this.$data.isMove) {
799
+ if (this.isDisabledDrag()) {
800
+ return false;
801
+ }
802
+ this.$data.isMove = true;
803
+ }
804
+ return true;
805
+ },
806
+ /**
807
+ * 拖拽中的回调
808
+ * @param event 事件
809
+ * @param dragX 当前拖拽的距离
810
+ * @param oldValue 旧的值
811
+ */
812
+ dragMoveCallBack(
813
+ event: MouseEvent | TouchEvent,
814
+ dragX: number,
815
+ oldValue: number
816
+ ) {
817
+ let dragPercent = 0;
818
+ if (dragX <= 0) {
819
+ dragPercent = 0;
820
+ this.value = this.min;
821
+ } else if (dragX >= this.$data.totalWidth) {
822
+ dragPercent = 1;
823
+ this.value = this.max;
824
+ } else {
825
+ const dragInfo = this.getDragInfo(dragX)!;
826
+ dragPercent = dragInfo.percent;
827
+ this.value = this.formatValue(dragInfo.value);
828
+ }
829
+ this.$data.dragPercent = dragPercent;
830
+ this.setSliderPosition(this.$data.dragPercent);
831
+ this.showToolTip();
832
+ if (oldValue !== this.value) {
833
+ this.valueChangeCallBack(event, this.value);
834
+ }
835
+ },
836
+ /**
837
+ * 拖拽结束的回调
838
+ */
839
+ dragEndCallBack(dragX: number) {
840
+ this.$data.isMove = false;
841
+ if (dragX <= 0) {
842
+ this.$data.dragWidth = 0;
843
+ } else if (dragX >= this.$data.totalWidth) {
844
+ this.$data.dragWidth = this.$data.totalWidth;
845
+ } else {
846
+ this.$data.dragWidth = dragX;
847
+ }
848
+ this.closeToolTip();
849
+ },
850
+ /**
851
+ * 设置点击拖拽事件
852
+ */
853
+ setPanEvent() {
854
+ const AnyTouch = popsUtils.AnyTouch();
855
+ this.$tooltip = new AnyTouch(this.$ele.button, {
856
+ preventEvent() {
857
+ return false;
858
+ },
859
+ });
860
+ /**
861
+ * 当前的拖拽的距离px
862
+ */
863
+ let currentDragX = 0;
864
+ /* 监听拖拽 */
865
+ this.$tooltip.on("at:move", (event: any) => {
866
+ if (!this.dragStartCallBack()) {
867
+ return;
868
+ }
869
+ let oldValue = this.value;
870
+ const runAwayRect = this.$ele.runAway.getBoundingClientRect();
871
+ let displacementX = event.x - (runAwayRect.left + globalThis.screenX);
872
+ if (displacementX <= 0) {
873
+ displacementX = 0;
874
+ } else if (displacementX >= runAwayRect.width) {
875
+ displacementX = runAwayRect.width;
876
+ }
877
+ currentDragX = displacementX;
878
+ /* 拖拽移动 */
879
+ this.dragMoveCallBack(event, currentDragX, oldValue);
880
+ });
881
+ /* 监听触点离开,处理某些情况下,拖拽松开,但是未触发pan事件,可以通过设置这个来关闭tooltip */
882
+ this.$tooltip.on("at:end", (event: any) => {
883
+ this.dragEndCallBack(currentDragX);
884
+ });
885
+ },
886
+ /**
887
+ * 显示悬浮的
888
+ */
889
+ showToolTip() {
890
+ this.$ele.tooltip.show();
891
+ },
892
+ /**
893
+ * 关闭悬浮的
894
+ */
895
+ closeToolTip() {
896
+ this.$ele.tooltip.close();
897
+ },
898
+ /**
899
+ * 检测在1000ms内,是否停止了拖拽
900
+ */
901
+ checkStopDragMove() {
902
+ if (this.$data.isCheckingStopDragMove) {
903
+ return;
904
+ }
905
+ this.$data.isCheckingStopDragMove = true;
906
+ let interval = setInterval(() => {
907
+ if (!this.$data.isMove) {
908
+ this.$data.isCheckingStopDragMove = false;
909
+ this.closeToolTip();
910
+ clearInterval(interval);
911
+ }
912
+ }, 200);
913
+ setTimeout(() => {
914
+ this.$data.isCheckingStopDragMove = false;
915
+ clearInterval(interval);
916
+ }, 2000);
917
+ },
918
+ /**
919
+ * 设置拖拽按钮的悬浮事件
920
+ */
921
+ setToolTipEvent() {
922
+ /**
923
+ * 获取提示的内容
924
+ */
925
+ function getToolTipContent() {
926
+ if (typeof formConfig.getToolTipContent === "function") {
927
+ return formConfig.getToolTipContent(PopsPanelSlider.value);
928
+ } else {
929
+ return PopsPanelSlider.value as any as string;
930
+ }
931
+ }
932
+ let tooltipContent = null as any as HTMLElement;
933
+
934
+ this.$ele.tooltip = pops.tooltip({
935
+ target: this.$ele.button,
936
+ content: getToolTipContent,
937
+ zIndex: 1000000,
938
+ className: "github-tooltip",
939
+ only: false,
940
+ eventOption: {
941
+ capture: true,
942
+ passive: true,
943
+ },
944
+ showBeforeCallBack: () => {
945
+ this.intervalInit();
946
+ },
947
+ showAfterCallBack: (toolTipNode) => {
948
+ tooltipContent.innerText = getToolTipContent();
949
+ },
950
+ closeBeforeCallBack: () => {
951
+ if (this.$data.isMove) {
952
+ this.checkStopDragMove();
953
+ return false;
954
+ } else {
955
+ }
956
+ },
957
+ alwaysShow: false,
958
+ // only: false,
959
+ position: "top",
960
+ arrowDistance: 10,
961
+ }) as any;
962
+ tooltipContent =
963
+ this.$ele.tooltip.toolTipNode.querySelector<HTMLDivElement>("div")!;
964
+ },
965
+ };
966
+ PopsPanelSlider.init();
967
+ (liElement as any)["data-slider"] = PopsPanelSlider;
968
+ return liElement;
969
+ },
970
+ /**
971
+ * 获取中间容器的元素<li>
972
+ * type ==> input
973
+ * @param formConfig
974
+ */
975
+ getSectionContainerItem_input(formConfig: PopsPanelInputDetails) {
976
+ let liElement = document.createElement("li");
977
+ (liElement as any)["__formConfig__"] = formConfig;
978
+ if (formConfig.className) {
979
+ liElement.className = formConfig.className;
980
+ }
981
+ this.addElementAttributes(liElement, formConfig.attributes);
982
+ this.setElementProps(liElement, formConfig.props);
983
+ let inputType = "text";
984
+ if (formConfig.isPassword) {
985
+ inputType = "password";
986
+ } else if (formConfig.isNumber) {
987
+ inputType = "number";
988
+ }
989
+ /* 左边底部的描述的文字 */
990
+ let leftDescriptionText = "";
991
+ if (Boolean(formConfig.description)) {
992
+ leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
993
+ }
994
+ liElement.innerHTML = `
995
+ <div class="pops-panel-item-left-text">
996
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
997
+ ${leftDescriptionText}
998
+ </div>
999
+ <div class="pops-panel-input">
1000
+ <input type="${inputType}" placeholder="${formConfig.placeholder}">
1001
+ </div>
1002
+ `;
1003
+ const PopsPanelInput = {
1004
+ [Symbol.toStringTag]: "PopsPanelInput",
1005
+ $ele: {
1006
+ panelInput:
1007
+ liElement.querySelector<HTMLDivElement>(".pops-panel-input")!,
1008
+ input: liElement.querySelector<HTMLInputElement>("input")!,
1009
+ inputSpanIcon: document.createElement("span"),
1010
+ inputSpanIconInner: null as any as HTMLSpanElement,
1011
+ icon: null as any as HTMLElement,
1012
+ },
1013
+ $data: {
1014
+ value: formConfig.getValue(),
1015
+ isView: false,
1016
+ },
1017
+ init() {
1018
+ this.initEle();
1019
+ this.setInputValue(this.$data.value);
1020
+ /* 如果是密码框,放进图标 */
1021
+ if (formConfig.isPassword) {
1022
+ this.setCircleIcon(pops.config.iconSVG.view);
1023
+ this.setCircleIconClickEvent();
1024
+ } else {
1025
+ /* 先判断预设值是否为空,不为空添加清空图标按钮 */
1026
+ if (this.$ele.input.value != "") {
1027
+ this.setCircleIcon(pops.config.iconSVG.circleClose);
1028
+ this.setCircleIconClickEvent();
1029
+ }
1030
+ }
1031
+
1032
+ this.setInputChangeEvent();
1033
+ if (formConfig.disabled) {
1034
+ this.disable();
1035
+ }
1036
+ if (typeof formConfig.handlerCallBack === "function") {
1037
+ formConfig.handlerCallBack(liElement, this.$ele.input);
1038
+ }
1039
+ },
1040
+ /**
1041
+ * 初始化$ele的配置
1042
+ */
1043
+ initEle() {
1044
+ this.$ele.input.parentElement!.insertBefore(
1045
+ this.$ele.inputSpanIcon,
1046
+ this.$ele.input.nextSibling
1047
+ );
1048
+ this.$ele.inputSpanIcon.className = "pops-panel-input__suffix";
1049
+ this.$ele.inputSpanIcon.innerHTML = `
1050
+ <span class="pops-panel-input__suffix-inner">
1051
+ <i class="pops-panel-icon"></i>
1052
+ </span>
1053
+ `;
1054
+ this.$ele.inputSpanIconInner =
1055
+ this.$ele.inputSpanIcon.querySelector<HTMLElement>(
1056
+ ".pops-panel-input__suffix-inner"
1057
+ )!;
1058
+ this.$ele.icon =
1059
+ this.$ele.inputSpanIcon.querySelector<HTMLElement>(
1060
+ ".pops-panel-icon"
1061
+ )!;
1062
+ },
1063
+ /**
1064
+ * 禁用
1065
+ */
1066
+ disable() {
1067
+ this.$ele.input.disabled = true;
1068
+ this.$ele.panelInput.classList.add("pops-input-disabled");
1069
+ },
1070
+ /**
1071
+ * 取消禁用
1072
+ */
1073
+ notDisable() {
1074
+ this.$ele.input.disabled = false;
1075
+ this.$ele.panelInput.classList.remove("pops-input-disabled");
1076
+ },
1077
+ /**
1078
+ * 判断是否已被禁用
1079
+ */
1080
+ isDisabled() {
1081
+ return this.$ele.input.disabled;
1082
+ },
1083
+ /**
1084
+ * 设置输入框内容
1085
+ * @param {string} [value=""] 值
1086
+ */
1087
+ setInputValue(value = "") {
1088
+ this.$ele.input.value = value;
1089
+ },
1090
+ /**
1091
+ * 设置input元素的type
1092
+ * @param {string} [typeValue="text"] type值
1093
+ */
1094
+ setInputType(typeValue = "text") {
1095
+ this.$ele.input.setAttribute("type", typeValue);
1096
+ },
1097
+ /**
1098
+ * 删除图标按钮
1099
+ */
1100
+ removeCircleIcon() {
1101
+ this.$ele.icon.innerHTML = "";
1102
+ },
1103
+ /**
1104
+ * 添加清空图标按钮
1105
+ * @param {string} [svgHTML=pops.config.iconSVG.circleClose] svg图标,默认为清空的图标
1106
+ */
1107
+ setCircleIcon(svgHTML = pops.config.iconSVG.circleClose) {
1108
+ this.$ele.icon.innerHTML = svgHTML;
1109
+ },
1110
+ /**
1111
+ * 添加图标按钮的点击事件
1112
+ */
1113
+ setCircleIconClickEvent() {
1114
+ popsDOMUtils.on(this.$ele.icon, "click", void 0, () => {
1115
+ if (this.isDisabled()) {
1116
+ return;
1117
+ }
1118
+ /* 删除图标 */
1119
+ this.removeCircleIcon();
1120
+ if (formConfig.isPassword) {
1121
+ /* 密码输入框 */
1122
+ if (this.$data.isView) {
1123
+ /* 当前可见 => 点击改变为隐藏 */
1124
+ this.$data.isView = false;
1125
+ /* 显示输入框内容,且更换图标为隐藏图标 */
1126
+ this.setInputType("text");
1127
+ this.setCircleIcon(pops.config.iconSVG.hide);
1128
+ } else {
1129
+ /* 当前不可见 => 点击改变为显示 */
1130
+ this.$data.isView = true;
1131
+ /* 隐藏输入框内容,且更换图标为显示图标 */
1132
+ this.setInputType("password");
1133
+ this.setCircleIcon(pops.config.iconSVG.view);
1134
+ }
1135
+ } else {
1136
+ /* 普通输入框 */
1137
+ /* 清空内容 */
1138
+ this.setInputValue("");
1139
+ /* 获取焦点 */
1140
+ this.$ele.input.focus();
1141
+ /* 触发内容改变事件 */
1142
+ this.$ele.input.dispatchEvent(new Event("input"));
1143
+ }
1144
+ });
1145
+ },
1146
+ /**
1147
+ * 监听输入框内容改变
1148
+ */
1149
+ setInputChangeEvent() {
1150
+ popsDOMUtils.on(
1151
+ this.$ele.input,
1152
+ ["input", "propertychange"],
1153
+ void 0,
1154
+ (event) => {
1155
+ this.$data.value = this.$ele.input.value;
1156
+ if (!formConfig.isPassword) {
1157
+ /* 不是密码框 */
1158
+ if (
1159
+ this.$ele.input.value !== "" &&
1160
+ this.$ele.icon.innerHTML === ""
1161
+ ) {
1162
+ /* 不为空,显示清空图标 */
1163
+ this.setCircleIcon(pops.config.iconSVG.circleClose);
1164
+ this.setCircleIconClickEvent();
1165
+ } else if (this.$ele.input.value === "") {
1166
+ this.removeCircleIcon();
1167
+ }
1168
+ }
1169
+ if (typeof formConfig.callback === "function") {
1170
+ if (formConfig.isNumber) {
1171
+ formConfig.callback(
1172
+ event as any,
1173
+ this.$ele.input.value,
1174
+ this.$ele.input.valueAsNumber
1175
+ );
1176
+ } else {
1177
+ formConfig.callback(event as any, this.$ele.input.value);
1178
+ }
1179
+ }
1180
+ }
1181
+ );
1182
+ },
1183
+ };
1184
+ PopsPanelInput.init();
1185
+ (liElement as any)["data-input"] = PopsPanelInput;
1186
+ return liElement;
1187
+ },
1188
+ /**
1189
+ * 获取中间容器的元素<li>
1190
+ * type ==> textarea
1191
+ * @param formConfig
1192
+ */
1193
+ getSectionContainerItem_textarea(formConfig: PopsPanelTextAreaDetails) {
1194
+ let liElement = document.createElement("li");
1195
+ (liElement as any)["__formConfig__"] = formConfig;
1196
+ if (formConfig.className) {
1197
+ liElement.className = formConfig.className;
1198
+ }
1199
+ this.addElementAttributes(liElement, formConfig.attributes);
1200
+ this.setElementProps(liElement, formConfig.props);
1201
+
1202
+ /* 左边底部的描述的文字 */
1203
+ let leftDescriptionText = "";
1204
+ if (Boolean(formConfig.description)) {
1205
+ leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
1206
+ }
1207
+ liElement.innerHTML = `
1208
+ <div class="pops-panel-item-left-text">
1209
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
1210
+ ${leftDescriptionText}
1211
+ </div>
1212
+ <div class="pops-panel-textarea">
1213
+ <textarea placeholder="${formConfig.placeholder ?? ""}">
1214
+ </textarea>
1215
+ </div>
1216
+ `;
1217
+
1218
+ const PopsPanelTextArea = {
1219
+ [Symbol.toStringTag]: "PopsPanelTextArea",
1220
+ $ele: {
1221
+ panelTextarea: liElement.querySelector<HTMLDivElement>(
1222
+ ".pops-panel-textarea"
1223
+ )!,
1224
+ textarea: liElement.querySelector<HTMLTextAreaElement>(
1225
+ ".pops-panel-textarea textarea"
1226
+ )!,
1227
+ },
1228
+ $data: {
1229
+ value: formConfig.getValue(),
1230
+ },
1231
+ init() {
1232
+ this.setValue(this.$data.value);
1233
+ this.setChangeEvent();
1234
+ if (formConfig.disabled) {
1235
+ this.disable();
1236
+ }
1237
+ },
1238
+ disable() {
1239
+ this.$ele.textarea.setAttribute("disabled", "true");
1240
+ this.$ele.panelTextarea.classList.add("pops-panel-textarea-disable");
1241
+ },
1242
+ notDisable() {
1243
+ this.$ele.textarea.removeAttribute("disabled");
1244
+ this.$ele.panelTextarea.classList.remove("pops-panel-textarea-disable");
1245
+ },
1246
+ isDisabled() {
1247
+ return (
1248
+ this.$ele.textarea.hasAttribute("disabled") ||
1249
+ this.$ele.panelTextarea.classList.contains(
1250
+ "pops-panel-textarea-disable"
1251
+ )
1252
+ );
1253
+ },
1254
+ setValue(value: string) {
1255
+ this.$ele.textarea.value = value;
1256
+ },
1257
+ /**
1258
+ * 监听选择内容改变
1259
+ */
1260
+ setChangeEvent() {
1261
+ popsDOMUtils.on(
1262
+ this.$ele.textarea,
1263
+ ["input", "propertychange"],
1264
+ void 0,
1265
+ (event) => {
1266
+ this.$data.value = (event as any).target.value;
1267
+ if (typeof formConfig.callback === "function") {
1268
+ formConfig.callback(event as any, (event as any).target.value);
1269
+ }
1270
+ }
1271
+ );
1272
+ },
1273
+ };
1274
+
1275
+ PopsPanelTextArea.init();
1276
+ (liElement as any)["data-textarea"] = PopsPanelTextArea;
1277
+
1278
+ return liElement;
1279
+ },
1280
+ /**
1281
+ * 获取中间容器的元素<li>
1282
+ * type ==> select
1283
+ * @param formConfig
1284
+ */
1285
+ getSectionContainerItem_select(formConfig: PopsPanelSelectDetails<any>) {
1286
+ let liElement = document.createElement("li");
1287
+ (liElement as any)["__formConfig__"] = formConfig;
1288
+ if (formConfig.className) {
1289
+ liElement.className = formConfig.className;
1290
+ }
1291
+ this.addElementAttributes(liElement, formConfig.attributes);
1292
+ this.setElementProps(liElement, formConfig.props);
1293
+ /* 左边底部的描述的文字 */
1294
+ let leftDescriptionText = "";
1295
+ if (Boolean(formConfig.description)) {
1296
+ leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
1297
+ }
1298
+ liElement.innerHTML = /*html*/ `
1299
+ <div class="pops-panel-item-left-text">
1300
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
1301
+ ${leftDescriptionText}
1302
+ </div>
1303
+ <div class="pops-panel-select">
1304
+ <select></select>
1305
+ </div>
1306
+ `;
1307
+
1308
+ const PopsPanelSelect = {
1309
+ [Symbol.toStringTag]: "PopsPanelSelect",
1310
+ $ele: {
1311
+ panelSelect:
1312
+ liElement.querySelector<HTMLDivElement>(".pops-panel-select")!,
1313
+ select: liElement.querySelector<HTMLSelectElement>(
1314
+ ".pops-panel-select select"
1315
+ )!,
1316
+ },
1317
+ $eleKey: {
1318
+ disable: "__disable__",
1319
+ value: "__value__",
1320
+ },
1321
+ $data: {
1322
+ defaultValue: formConfig.getValue(),
1323
+ },
1324
+ init() {
1325
+ this.initOption();
1326
+ this.setChangeEvent();
1327
+ this.setClickEvent();
1328
+ if (formConfig.disabled) {
1329
+ this.disable();
1330
+ }
1331
+ },
1332
+ /**
1333
+ * 给option元素设置属性
1334
+ * @param $ele
1335
+ * @param key
1336
+ * @param value
1337
+ */
1338
+ setNodeValue($ele: HTMLElement, key: string, value: any) {
1339
+ Reflect.set($ele, key, value);
1340
+ },
1341
+ /**
1342
+ * 获取option元素上设置的属性
1343
+ * @param $ele
1344
+ * @param value
1345
+ * @param key
1346
+ */
1347
+ getNodeValue($ele: HTMLElement, key: string) {
1348
+ return Reflect.get($ele, key);
1349
+ },
1350
+ disable() {
1351
+ this.$ele.select.setAttribute("disabled", "true");
1352
+ this.$ele.panelSelect.classList.add("pops-panel-select-disable");
1353
+ },
1354
+ notDisable() {
1355
+ this.$ele.select.removeAttribute("disabled");
1356
+ this.$ele.panelSelect.classList.remove("pops-panel-select-disable");
1357
+ },
1358
+ isDisabled() {
1359
+ return (
1360
+ this.$ele.select.hasAttribute("disabled") ||
1361
+ this.$ele.panelSelect.classList.contains("pops-panel-select-disable")
1362
+ );
1363
+ },
1364
+ initOption() {
1365
+ formConfig.data.forEach((dataItem) => {
1366
+ // 初始化默认选中
1367
+ let optionElement = document.createElement("option");
1368
+ this.setNodeValue(optionElement, this.$eleKey.value, dataItem.value);
1369
+ this.setNodeValue(
1370
+ optionElement,
1371
+ this.$eleKey.disable,
1372
+ dataItem.disable
1373
+ );
1374
+ if (dataItem.value === this.$data.defaultValue) {
1375
+ optionElement.setAttribute("selected", "true");
1376
+ }
1377
+ optionElement.innerText = dataItem.text;
1378
+ this.$ele.select.appendChild(optionElement);
1379
+ });
1380
+ },
1381
+ /** 检测所有option并设置禁用状态 */
1382
+ setSelectOptionsDisableStatus() {
1383
+ if (this.$ele.select.options && this.$ele.select.options.length) {
1384
+ Array.from(this.$ele.select.options).forEach((optionItem) => {
1385
+ this.setOptionDisableStatus(optionItem);
1386
+ });
1387
+ }
1388
+ },
1389
+ /** 设置禁用状态 */
1390
+ setOptionDisableStatus(optionElement: HTMLOptionElement) {
1391
+ let disable = false;
1392
+ let optionDisableAttr = this.getNodeValue(
1393
+ optionElement,
1394
+ this.$eleKey.disable
1395
+ );
1396
+ if (optionDisableAttr === "function") {
1397
+ let value = this.getNodeValue(optionElement, this.$eleKey.value);
1398
+ disable = Boolean(optionDisableAttr(value));
1399
+ }
1400
+ if (disable) {
1401
+ optionElement.setAttribute("disabled", "true");
1402
+ } else {
1403
+ optionElement.removeAttribute("disabled");
1404
+ }
1405
+ },
1406
+ /** 获取option上的信息 */
1407
+ getSelectOptionInfo($option: HTMLOptionElement) {
1408
+ let optionValue = this.getNodeValue($option, this.$eleKey.value);
1409
+ let optionText = $option.innerText || $option.textContent!;
1410
+ return {
1411
+ value: optionValue,
1412
+ text: optionText,
1413
+ $option: $option,
1414
+ };
1415
+ },
1416
+ /**
1417
+ * 监听选择内容改变
1418
+ */
1419
+ setChangeEvent() {
1420
+ popsDOMUtils.on(this.$ele.select, "change", void 0, (event) => {
1421
+ this.setSelectOptionsDisableStatus();
1422
+ if (typeof formConfig.callback === "function") {
1423
+ let $isSelectedElement = (event as any).target[
1424
+ (event as any).target.selectedIndex
1425
+ ] as HTMLOptionElement;
1426
+ let selectInfo = this.getSelectOptionInfo($isSelectedElement);
1427
+ formConfig.callback(
1428
+ event as any,
1429
+ selectInfo.value,
1430
+ selectInfo.text
1431
+ );
1432
+ }
1433
+ });
1434
+ },
1435
+ /**
1436
+ * 监听点击事件
1437
+ */
1438
+ setClickEvent() {
1439
+ popsDOMUtils.on(this.$ele.select, "click", void 0, (event) => {
1440
+ this.setSelectOptionsDisableStatus();
1441
+ if (typeof formConfig.clickCallBack === "function") {
1442
+ formConfig.clickCallBack(event, this.$ele.select);
1443
+ }
1444
+ });
1445
+ },
1446
+ };
1447
+
1448
+ PopsPanelSelect.init();
1449
+ Reflect.set(liElement, "data-select", PopsPanelSelect);
1450
+ return liElement;
1451
+ },
1452
+ /**
1453
+ * 获取中间容器的元素<li>
1454
+ * type ==> select-multiple
1455
+ * @param formConfig
1456
+ */
1457
+ getSectionContainerItem_select_multiple_new(
1458
+ formConfig: PopsPanelSelectMultipleDetails<any>
1459
+ ) {
1460
+ let liElement = document.createElement("li");
1461
+ Reflect.set(liElement, "__formConfig__", formConfig);
1462
+ if (formConfig.className) {
1463
+ liElement.className = formConfig.className;
1464
+ }
1465
+ this.addElementAttributes(liElement, formConfig.attributes);
1466
+ this.setElementProps(liElement, formConfig.props);
1467
+ /* 左边底部的描述的文字 */
1468
+ let leftDescriptionText = "";
1469
+ if (Boolean(formConfig.description)) {
1470
+ leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
1471
+ }
1472
+ liElement.innerHTML = /*html*/ `
1473
+ <div class="pops-panel-item-left-text">
1474
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
1475
+ ${leftDescriptionText}
1476
+ </div>
1477
+ <div class="pops-panel-select-multiple">
1478
+ <div class="el-select__wrapper">
1479
+ <div class="el-select__selection">
1480
+ <!-- 这个是用于手动输入的,这里暂不适配 -->
1481
+ <div class="el-select__selected-item el-select__input-wrapper">
1482
+
1483
+ </div>
1484
+ <!-- 这个是placeholder -->
1485
+ <div class="el-select__selected-item el-select__placeholder">
1486
+ </div>
1487
+ </div>
1488
+ <!-- 下拉箭头 -->
1489
+ <div class="el-select__suffix">
1490
+ <i class="el-icon el-select__caret el-select__icon">
1491
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
1492
+ <path fill="currentColor" d="M831.872 340.864 512 652.672 192.128 340.864a30.592 30.592 0 0 0-42.752 0 29.12 29.12 0 0 0 0 41.6L489.664 714.24a32 32 0 0 0 44.672 0l340.288-331.712a29.12 29.12 0 0 0 0-41.728 30.592 30.592 0 0 0-42.752 0z"></path>
1493
+ </svg>
1494
+ </i>
1495
+ </div>
1496
+ </div>
1497
+ </div>
1498
+ `;
1499
+
1500
+ const PopsPanelSelectMultiple = {
1501
+ $el: {
1502
+ /** 容器 */
1503
+ $container: void 0 as any as HTMLElement,
1504
+ /** 包括的容器 */
1505
+ $wrapper: void 0 as any as HTMLElement,
1506
+ /** 内容区域 */
1507
+ $section: void 0 as any as HTMLElement,
1508
+ /** 手动输入 */
1509
+ $selectedInputWrapper: void 0 as any as HTMLElement,
1510
+ /** 灰色提示语 */
1511
+ $selectedPlaceHolderWrapper: void 0 as any as HTMLElement,
1512
+ /** 下拉箭头区域 */
1513
+ $suffix: void 0 as any as HTMLElement,
1514
+ /** 下拉箭头图标 */
1515
+ $suffixIcon: void 0 as any as HTMLElement,
1516
+ },
1517
+ $data: {
1518
+ /** 默认值 */
1519
+ defaultValue: formConfig.getValue(),
1520
+ selectInfo: [] as any as PopsPanelSelectMultipleDataOption<any>[],
1521
+ },
1522
+ /** 初始化 */
1523
+ init() {
1524
+ this.initDefault();
1525
+ this.inintEl();
1526
+ this.initPlaceHolder();
1527
+ this.updateTagElement();
1528
+ this.setSelectContainerClickEvent();
1529
+ },
1530
+ /** 初始化默认值 */
1531
+ initDefault() {
1532
+ formConfig.data.forEach((dataItem) => {
1533
+ if (this.$data.defaultValue.includes(dataItem.value)) {
1534
+ // 初始化选中的配置
1535
+ this.$data.selectInfo.push({
1536
+ text: dataItem.text,
1537
+ value: dataItem.value,
1538
+ isHTML: Boolean(dataItem.isHTML),
1539
+ disable: dataItem.disable,
1540
+ });
1541
+ }
1542
+ });
1543
+ },
1544
+ /** 初始化$el变量 */
1545
+ inintEl() {
1546
+ this.$el.$container = liElement.querySelector<HTMLElement>(
1547
+ ".pops-panel-select-multiple"
1548
+ )!;
1549
+ this.$el.$wrapper = liElement.querySelector<HTMLElement>(
1550
+ ".el-select__wrapper"
1551
+ )!;
1552
+ this.$el.$section = liElement.querySelector<HTMLElement>(
1553
+ ".el-select__selection"
1554
+ )!;
1555
+ this.$el.$selectedInputWrapper = liElement.querySelector<HTMLElement>(
1556
+ ".el-select__selected-item.el-select__input-wrapper"
1557
+ )!;
1558
+ this.$el.$selectedPlaceHolderWrapper =
1559
+ liElement.querySelector<HTMLElement>(
1560
+ ".el-select__selected-item.el-select__placeholder"
1561
+ )!;
1562
+ this.$el.$suffix =
1563
+ liElement.querySelector<HTMLElement>(".el-select__suffix")!;
1564
+ this.$el.$suffixIcon = liElement.querySelector<HTMLElement>(
1565
+ ".el-select__suffix .el-icon"
1566
+ )!;
1567
+
1568
+ // 先把手动输入框隐藏
1569
+ this.hideInputWrapper();
1570
+ },
1571
+ /** 初始化提示文字 */
1572
+ initPlaceHolder() {
1573
+ let placeholder = "";
1574
+ if (typeof formConfig.placeholder === "string") {
1575
+ placeholder = formConfig.placeholder;
1576
+ } else if (typeof formConfig.placeholder === "function") {
1577
+ let placeholderResult = formConfig.placeholder();
1578
+ if (typeof placeholderResult === "string") {
1579
+ placeholder = placeholderResult;
1580
+ }
1581
+ }
1582
+ let $placeholder = popsDOMUtils.createElement("span", {
1583
+ innerText: placeholder,
1584
+ });
1585
+ this.$el.$selectedPlaceHolderWrapper.appendChild($placeholder);
1586
+ },
1587
+ /** 初始化tag */
1588
+ updateTagElement() {
1589
+ // 遍历数据,寻找对应的值
1590
+ formConfig.data.forEach((dataItem) => {
1591
+ let findValue = this.$data.selectInfo.find(
1592
+ (item) => item.value === dataItem.value
1593
+ );
1594
+ if (findValue) {
1595
+ // 选中的值和获取的所有的值相同
1596
+ let selectedInfo = this.createSelectedItem({
1597
+ text: dataItem.text,
1598
+ isHTML: dataItem.isHTML,
1599
+ });
1600
+ this.addSelectedItem(selectedInfo.$tag);
1601
+ this.setSelectedItemCloseIconClickEvent({
1602
+ $tag: selectedInfo.$tag,
1603
+ $closeIcon: selectedInfo.$closeIcon,
1604
+ value: dataItem.value,
1605
+ text: dataItem.text,
1606
+ });
1607
+ }
1608
+ });
1609
+ this.checkTagEmpty();
1610
+ },
1611
+ /**
1612
+ * 生成一个tag项
1613
+ * @param data 配置
1614
+ */
1615
+ createSelectedItem(data: {
1616
+ /** tag的文本 */
1617
+ text: string;
1618
+ isHTML?: boolean;
1619
+ }) {
1620
+ const $selectedItem = popsDOMUtils.createElement("div", {
1621
+ className: "el-select__selected-item el-select__choose_tag",
1622
+ innerHTML: /*html*/ `
1623
+ <span class="el-tag is-closable el-tag--info el-tag--default el-tag--light">
1624
+ <span class="el-tag__content">
1625
+ <span class="el-select__tags-text"></span>
1626
+ </span>
1627
+ <!-- 关闭tag的图标 -->
1628
+ <i class="el-icon el-tag__close">
1629
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
1630
+ <path fill="currentColor" d="M764.288 214.592 512 466.88 259.712 214.592a31.936 31.936 0 0 0-45.12 45.12L466.752 512 214.528 764.224a31.936 31.936 0 1 0 45.12 45.184L512 557.184l252.288 252.288a31.936 31.936 0 0 0 45.12-45.12L557.12 512.064l252.288-252.352a31.936 31.936 0 1 0-45.12-45.184z"></path>
1631
+ </svg>
1632
+ </i>
1633
+ </span>
1634
+ `,
1635
+ });
1636
+ /** 标签 */
1637
+ const $tagText = $selectedItem.querySelector<HTMLSpanElement>(
1638
+ ".el-select__tags-text"
1639
+ )!;
1640
+ /** 关闭图标 */
1641
+ const $closeIcon = $selectedItem.querySelector<HTMLElement>(
1642
+ ".el-icon.el-tag__close"
1643
+ )!;
1644
+ if (data.isHTML) {
1645
+ $tagText.innerHTML = data.text;
1646
+ } else {
1647
+ $tagText.innerText = data.text;
1648
+ }
1649
+
1650
+ return {
1651
+ $tag: $selectedItem,
1652
+ $tagText: $tagText,
1653
+ $closeIcon: $closeIcon,
1654
+ };
1655
+ },
1656
+ /**
1657
+ * 添加选中项元素
1658
+ */
1659
+ addSelectedItem($ele: HTMLElement) {
1660
+ // 往前添加
1661
+ // 去除前面的空白
1662
+ this.setSectionIsNear();
1663
+ if (this.$el.$section.contains(this.$el.$selectedInputWrapper)) {
1664
+ let $prev = this.$el.$selectedInputWrapper.previousElementSibling;
1665
+ if ($prev) {
1666
+ // 存在前一个元素,添加到前面的元素的后面
1667
+ popsDOMUtils.after($prev, $ele);
1668
+ } else {
1669
+ // 不存在前一个元素,添加到最前面
1670
+ popsDOMUtils.before(this.$el.$selectedInputWrapper, $ele);
1671
+ }
1672
+ } else if (
1673
+ this.$el.$section.contains(this.$el.$selectedPlaceHolderWrapper)
1674
+ ) {
1675
+ let $prev =
1676
+ this.$el.$selectedPlaceHolderWrapper.previousElementSibling;
1677
+ if ($prev) {
1678
+ // 存在前一个元素,添加到前面的元素的后面
1679
+ popsDOMUtils.after($prev, $ele);
1680
+ } else {
1681
+ // 不存在前一个元素,添加到最前面
1682
+ popsDOMUtils.before(this.$el.$selectedPlaceHolderWrapper, $ele);
1683
+ }
1684
+ } else {
1685
+ this.$el.$section.appendChild($ele);
1686
+ }
1687
+ // 隐藏元素
1688
+ this.hideInputWrapper();
1689
+ this.hidePlaceHolderWrapper();
1690
+ },
1691
+ /** 更新tag信息 */
1692
+ updateSelectTagItem() {
1693
+ this.$el.$section
1694
+ .querySelectorAll<HTMLElement>(".el-select__choose_tag")
1695
+ .forEach(($ele) => {
1696
+ $ele.remove();
1697
+ });
1698
+ this.updateTagElement();
1699
+ },
1700
+ /**
1701
+ * 选中的值改变的回调
1702
+ * @param currentSelectInfo 当前的选中信息
1703
+ */
1704
+ selectValueChangeCallBack(
1705
+ currentSelectInfo?: PopsPanelSelectMultipleDataOption<any>[]
1706
+ ) {
1707
+ if (typeof formConfig.callback === "function") {
1708
+ formConfig.callback(currentSelectInfo || this.$data.selectInfo);
1709
+ }
1710
+ },
1711
+ /** 设置下拉列表的点击事件 */
1712
+ setSelectContainerClickEvent() {
1713
+ const that = this;
1714
+ popsDOMUtils.on(this.$el.$container, "click", (event) => {
1715
+ /** 弹窗的选中的值 */
1716
+ let selectedInfo: PopsPanelSelectMultipleDataOption<any>[] = [];
1717
+ selectedInfo = selectedInfo.concat(that.$data.selectInfo);
1718
+ /**
1719
+ * 设置项选中
1720
+ * @param $ele
1721
+ */
1722
+ function setItemSelected($ele: HTMLElement) {
1723
+ $ele.classList.add("select-item-is-selected");
1724
+ }
1725
+ /**
1726
+ * 设置项取消选中
1727
+ * @param $ele
1728
+ */
1729
+ function removeItemSelected($ele: HTMLElement) {
1730
+ $ele.classList.remove("select-item-is-selected");
1731
+ }
1732
+ /**
1733
+ * 添加选中信息
1734
+ */
1735
+ function addSelectedInfo($ele: HTMLElement) {
1736
+ let info = getSelectedInfo($ele);
1737
+ let findValue = selectedInfo.find(
1738
+ (item) => item.value === info.value
1739
+ );
1740
+ if (!findValue) {
1741
+ selectedInfo.push({
1742
+ value: info.value,
1743
+ text: info.text,
1744
+ isHTML: Boolean(info.isHTML),
1745
+ disable: info.disable,
1746
+ });
1747
+ }
1748
+ that.selectValueChangeCallBack(selectedInfo);
1749
+ }
1750
+ /**
1751
+ * 移除选中信息
1752
+ */
1753
+ function removeSelectedInfo($ele: HTMLElement) {
1754
+ let info = getSelectedInfo($ele);
1755
+ let findIndex = selectedInfo.findIndex(
1756
+ (item) => item.value === info.value
1757
+ );
1758
+ if (findIndex !== -1) {
1759
+ selectedInfo.splice(findIndex, 1);
1760
+ }
1761
+ that.selectValueChangeCallBack(selectedInfo);
1762
+ }
1763
+ /**
1764
+ * 判断该项是否选中
1765
+ * @param $ele
1766
+ */
1767
+ function isSelected($ele: HTMLElement): boolean {
1768
+ return $ele.classList.contains("select-item-is-selected");
1769
+ }
1770
+ /**
1771
+ * 获取选中的项的信息
1772
+ */
1773
+ function getSelectedInfo($ele: HTMLElement) {
1774
+ return Reflect.get($ele, "data-info") as {
1775
+ value: any;
1776
+ text: string;
1777
+ isHTML?: boolean;
1778
+ disable?(value: any): boolean;
1779
+ };
1780
+ }
1781
+ /**
1782
+ * 获取所有选中的项的信息
1783
+ */
1784
+ function getAllSelectedInfo() {
1785
+ return Array.from(
1786
+ $selectContainer.querySelectorAll<HTMLElement>(".select-item")
1787
+ )
1788
+ .map(($ele) => {
1789
+ if (isSelected($ele)) {
1790
+ return getSelectedInfo($ele);
1791
+ }
1792
+ })
1793
+ .filter((item) => {
1794
+ return item != null;
1795
+ });
1796
+ }
1797
+ /**
1798
+ * 创建一个选择项元素
1799
+ */
1800
+ function createSelectItemElement(dataInfo: { text: string }) {
1801
+ let $item = popsDOMUtils.createElement("li", {
1802
+ className: "select-item",
1803
+ innerHTML: /*html*/ `
1804
+ <span>${dataInfo.text}</span>
1805
+ `,
1806
+ });
1807
+ Reflect.set($item, "data-info", dataInfo);
1808
+ return $item;
1809
+ }
1810
+ /**
1811
+ * 设置选择项的点击事件
1812
+ */
1813
+ function setSelectElementClickEvent($ele: HTMLElement) {
1814
+ popsDOMUtils.on<PointerEvent | MouseEvent>(
1815
+ $ele,
1816
+ "click",
1817
+ (event) => {
1818
+ popsDOMUtils.preventEvent(event);
1819
+ if (typeof formConfig.clickCallBack === "function") {
1820
+ let clickResult = formConfig.clickCallBack(
1821
+ event,
1822
+ getAllSelectedInfo()
1823
+ );
1824
+ if (typeof clickResult === "boolean" && !clickResult) {
1825
+ return;
1826
+ }
1827
+ }
1828
+ // 修改选中状态
1829
+ if (isSelected($ele)) {
1830
+ removeItemSelected($ele);
1831
+ removeSelectedInfo($ele);
1832
+ } else {
1833
+ setItemSelected($ele);
1834
+ addSelectedInfo($ele);
1835
+ }
1836
+ }
1837
+ );
1838
+ }
1839
+ let { style, ...userConfirmDetails } =
1840
+ formConfig.selectConfirmDialogDetails || {};
1841
+ let confirmDetails = Object.assign(
1842
+ {
1843
+ title: {
1844
+ text: "请勾选需要选择的选项",
1845
+ position: "center",
1846
+ },
1847
+ content: {
1848
+ text: /*html*/ `
1849
+ <ul class="select-container"></ul>
1850
+ `,
1851
+ html: true,
1852
+ },
1853
+ btn: {
1854
+ ok: {
1855
+ enable: false,
1856
+ },
1857
+ close: {
1858
+ enable: true,
1859
+ callback(details, event) {
1860
+ that.$data.selectInfo = [...selectedInfo];
1861
+ that.updateSelectTagItem();
1862
+ },
1863
+ },
1864
+ },
1865
+ mask: {
1866
+ enable: true,
1867
+ clickCallBack(originalRun, config) {
1868
+ originalRun();
1869
+ that.$data.selectInfo = [...selectedInfo];
1870
+ that.updateSelectTagItem();
1871
+ },
1872
+ clickEvent: {
1873
+ toClose: true,
1874
+ },
1875
+ },
1876
+ drag: true,
1877
+ dragLimit: true,
1878
+ width: "300px",
1879
+ height: "300px",
1880
+ style: /*css*/ `
1881
+ .select-container{
1882
+ --el-font-size-base: 14px;
1883
+ --el-text-color-regular: #606266;
1884
+ --el-color-primary: #409eff;
1885
+ --el-fill-color-light: #f5f7fa;
1886
+ }
1887
+ .select-item{
1888
+ cursor: pointer;
1889
+ cursor: pointer;
1890
+ font-size: var(--el-font-size-base);
1891
+ padding: 0 32px 0 20px;
1892
+ position: relative;
1893
+ white-space: nowrap;
1894
+ overflow: hidden;
1895
+ text-overflow: ellipsis;
1896
+ color: var(--el-text-color-regular);
1897
+ height: 34px;
1898
+ line-height: 34px;
1899
+ box-sizing: border-box;
1900
+ }
1901
+ .select-item:hover{
1902
+ background-color: var(--el-fill-color-light);
1903
+ }
1904
+ .select-item.select-item-is-selected{
1905
+ color: var(--el-color-primary);
1906
+ font-weight: 700;
1907
+ }
1908
+ .select-item.select-item-is-selected::after{
1909
+ content: "";
1910
+ position: absolute;
1911
+ top: 50%;
1912
+ right: 20px;
1913
+ border-top: none;
1914
+ border-right: none;
1915
+ background-repeat: no-repeat;
1916
+ background-position: center;
1917
+ background-color: var(--el-color-primary);
1918
+ mask: url("data:image/svg+xml;utf8,%3Csvg class='icon' width='200' height='200' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='currentColor' d='M406.656 706.944L195.84 496.256a32 32 0 10-45.248 45.248l256 256 512-512a32 32 0 00-45.248-45.248L406.592 706.944z'%3E%3C/path%3E%3C/svg%3E") no-repeat;
1919
+ mask-size: 100% 100%;
1920
+ -webkit-mask: url("data:image/svg+xml;utf8,%3Csvg class='icon' width='200' height='200' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='currentColor' d='M406.656 706.944L195.84 496.256a32 32 0 10-45.248 45.248l256 256 512-512a32 32 0 00-45.248-45.248L406.592 706.944z'%3E%3C/path%3E%3C/svg%3E") no-repeat;
1921
+ -webkit-mask-size: 100% 100%;
1922
+ transform: translateY(-50%);
1923
+ width: 12px;
1924
+ height: 12px;
1925
+ }
1926
+ ${style || ""}
1927
+ `,
1928
+ } as PopsAlertDetails,
1929
+ userConfirmDetails
1930
+ );
1931
+ let $dialog = pops.alert(confirmDetails);
1932
+ let $selectContainer =
1933
+ $dialog.$shadowRoot.querySelector<HTMLUListElement>(
1934
+ ".select-container"
1935
+ )!;
1936
+ // 配置选项元素
1937
+ formConfig.data.forEach((item) => {
1938
+ let $select = createSelectItemElement(item);
1939
+ // 添加到confirm中
1940
+ $selectContainer.appendChild($select);
1941
+ // 设置每一项的点击事件
1942
+ setSelectElementClickEvent($select);
1943
+ let findValue = selectedInfo.find(
1944
+ (value) => value.value === item.value
1945
+ );
1946
+ if (findValue) {
1947
+ setItemSelected($select);
1948
+ }
1949
+ });
1950
+ });
1951
+ },
1952
+ /** 设置关闭图标的点击事件 */
1953
+ setSelectedItemCloseIconClickEvent(data: {
1954
+ /** 关闭图标的元素 */
1955
+ $closeIcon: HTMLElement;
1956
+ /** tag元素 */
1957
+ $tag: HTMLElement;
1958
+ /** 值 */
1959
+ value: any;
1960
+ /** 显示的文字 */
1961
+ text: string;
1962
+ }) {
1963
+ popsDOMUtils.on<PointerEvent | MouseEvent>(
1964
+ data.$closeIcon,
1965
+ "click",
1966
+ (event) => {
1967
+ popsDOMUtils.preventEvent(event);
1968
+ if (typeof formConfig.closeIconClickCallBack === "function") {
1969
+ let result = formConfig.closeIconClickCallBack(event, {
1970
+ $tag: data.$tag,
1971
+ $closeIcon: data.$closeIcon,
1972
+ value: data.value,
1973
+ text: data.text,
1974
+ });
1975
+ if (typeof result === "boolean" && !result) {
1976
+ return;
1977
+ }
1978
+ }
1979
+ this.removeSelectedItem(data.$tag);
1980
+ this.removeSelectedInfo({
1981
+ value: data.value,
1982
+ text: data.text,
1983
+ });
1984
+ },
1985
+ {
1986
+ capture: true,
1987
+ }
1988
+ );
1989
+ },
1990
+ /**
1991
+ * 检测tag是否为空,为空显示placeholder
1992
+ */
1993
+ checkTagEmpty() {
1994
+ if (
1995
+ !this.$el.$section.querySelectorAll(".el-select__choose_tag").length
1996
+ ) {
1997
+ // 没有tag了
1998
+ // this.showInputWrapper();
1999
+ this.showPlaceHolderWrapper();
2000
+ this.removeSectionIsNear();
2001
+ }
2002
+ },
2003
+ /** 移除选中项元素 */
2004
+ removeSelectedItem($ele: HTMLElement) {
2005
+ $ele.remove();
2006
+ this.checkTagEmpty();
2007
+ },
2008
+ /** 移除选中的信息 */
2009
+ removeSelectedInfo(data: { value: any; text: string }) {
2010
+ for (let index = 0; index < this.$data.selectInfo.length; index++) {
2011
+ const selectInfo = this.$data.selectInfo[index];
2012
+ if (selectInfo.value === data.value) {
2013
+ this.$data.selectInfo.splice(index, 1);
2014
+ break;
2015
+ }
2016
+ }
2017
+ this.selectValueChangeCallBack();
2018
+ },
2019
+ /** 显示输入框 */
2020
+ showInputWrapper() {
2021
+ popsDOMUtils.cssShow(this.$el.$selectedInputWrapper);
2022
+ },
2023
+ /** 隐藏输入框 */
2024
+ hideInputWrapper() {
2025
+ popsDOMUtils.cssHide(this.$el.$selectedInputWrapper, true);
2026
+ },
2027
+ /** 显示palceholder */
2028
+ showPlaceHolderWrapper() {
2029
+ popsDOMUtils.cssShow(this.$el.$selectedPlaceHolderWrapper);
2030
+ },
2031
+ /** 隐藏palceholder */
2032
+ hidePlaceHolderWrapper() {
2033
+ popsDOMUtils.cssHide(this.$el.$selectedPlaceHolderWrapper, true);
2034
+ },
2035
+ /** 设置隐藏section的前面的空白 */
2036
+ setSectionIsNear() {
2037
+ this.$el.$section.classList.add("is-near");
2038
+ },
2039
+ /** 取消设置隐藏section的前面的空白 */
2040
+ removeSectionIsNear() {
2041
+ this.$el.$section.classList.remove("is-near");
2042
+ },
2043
+ };
2044
+
2045
+ PopsPanelSelectMultiple.init();
2046
+ Reflect.set(liElement, "data-select", PopsPanelSelectMultiple);
2047
+ return liElement;
2048
+ },
2049
+ /**
2050
+ * 获取中间容器的元素<li>
2051
+ * type ==> button
2052
+ * @param formConfig
2053
+ */
2054
+ getSectionContainerItem_button(formConfig: PopsPanelButtonDetails) {
2055
+ let liElement = document.createElement("li");
2056
+ (liElement as any)["__formConfig__"] = formConfig;
2057
+ if (formConfig.className) {
2058
+ liElement.className = formConfig.className;
2059
+ }
2060
+ this.addElementAttributes(liElement, formConfig.attributes);
2061
+ this.setElementProps(liElement, formConfig.props);
2062
+
2063
+ /* 左边底部的描述的文字 */
2064
+ let leftDescriptionText = "";
2065
+ if (Boolean(formConfig.description)) {
2066
+ leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
2067
+ }
2068
+ liElement.innerHTML = /*html*/ `
2069
+ <div class="pops-panel-item-left-text">
2070
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
2071
+ ${leftDescriptionText}
2072
+ </div>
2073
+ <div class="pops-panel-button">
2074
+ <button class="pops-panel-button_inner">
2075
+ <i class="pops-bottom-icon"></i>
2076
+ <span class="pops-panel-button-text"></span>
2077
+ </button>
2078
+ </div>
2079
+ `;
2080
+
2081
+ const PopsPanelButton = {
2082
+ [Symbol.toStringTag]: "PopsPanelButton",
2083
+ $ele: {
2084
+ panelButton:
2085
+ liElement.querySelector<HTMLDivElement>(".pops-panel-button")!,
2086
+ button: liElement.querySelector<HTMLDivElement>(
2087
+ ".pops-panel-button .pops-panel-button_inner"
2088
+ )!,
2089
+ icon: liElement.querySelector<HTMLDivElement>(
2090
+ ".pops-panel-button .pops-bottom-icon"
2091
+ )!,
2092
+ spanText: liElement.querySelector<HTMLDivElement>(
2093
+ ".pops-panel-button .pops-panel-button-text"
2094
+ )!,
2095
+ },
2096
+ $data: {},
2097
+ init() {
2098
+ this.$ele.panelButton.appendChild(this.$ele.button);
2099
+ this.initButton();
2100
+ this.setClickEvent();
2101
+ },
2102
+ initButton() {
2103
+ if (
2104
+ typeof formConfig.buttonIcon === "string" &&
2105
+ formConfig.buttonIcon.trim() !== ""
2106
+ ) {
2107
+ /* 存在icon图标且不为空 */
2108
+ if (formConfig.buttonIcon in pops.config.iconSVG) {
2109
+ this.setIconSVG(pops.config.iconSVG[formConfig.buttonIcon]);
2110
+ } else {
2111
+ this.setIconSVG(formConfig.buttonIcon);
2112
+ }
2113
+ this.showIcon();
2114
+ } else {
2115
+ this.hideIcon();
2116
+ }
2117
+ /* 按钮文字 */
2118
+ let buttonText = formConfig.buttonText;
2119
+ if (typeof formConfig.buttonText === "function") {
2120
+ buttonText = formConfig.buttonText();
2121
+ }
2122
+ this.setButtonType(formConfig.buttonType);
2123
+ if (formConfig.buttonIsRightIcon) {
2124
+ this.setIconRight();
2125
+ } else {
2126
+ this.setIconLeft();
2127
+ }
2128
+ if (formConfig.disable) {
2129
+ this.disable();
2130
+ }
2131
+ this.setButtonText(buttonText as string);
2132
+ this.setIconLoadingStatus(formConfig.buttonIconIsLoading);
2133
+ },
2134
+ disable() {
2135
+ this.$ele.button.setAttribute("disabled", "true");
2136
+ },
2137
+ notDisable() {
2138
+ this.$ele.button.removeAttribute("disabled");
2139
+ },
2140
+ /**
2141
+ * 隐藏icon图标
2142
+ */
2143
+ hideIcon() {
2144
+ this.$ele.panelButton.classList.add("pops-panel-button-no-icon");
2145
+ },
2146
+ /**
2147
+ * 显示icon图标
2148
+ */
2149
+ showIcon() {
2150
+ this.$ele.panelButton.classList.remove("pops-panel-button-no-icon");
2151
+ },
2152
+ /**
2153
+ * 设置icon图标的svg
2154
+ */
2155
+ setIconSVG(svgHTML: string) {
2156
+ this.$ele.icon.innerHTML = svgHTML;
2157
+ },
2158
+ /**
2159
+ * 设置icon图标是否旋转
2160
+ * @param status
2161
+ */
2162
+ setIconLoadingStatus(status: any) {
2163
+ this.$ele.icon.setAttribute("is-loading", Boolean(status).toString());
2164
+ },
2165
+ /**
2166
+ * 设置属性上是否存在icon图标
2167
+ */
2168
+ setHasIcon(value: any) {
2169
+ this.$ele.button.setAttribute("data-icon", Boolean(value).toString());
2170
+ },
2171
+ /**
2172
+ * 设置按钮类型
2173
+ * @param typeValue
2174
+ */
2175
+ setButtonType(typeValue: string) {
2176
+ this.$ele.button.setAttribute("type", typeValue);
2177
+ },
2178
+ /**
2179
+ * 添加按钮的图标在右边
2180
+ */
2181
+ setIconRight() {
2182
+ this.$ele.button.classList.add("pops-panel-button-right-icon");
2183
+ },
2184
+ /**
2185
+ * (默认)添加按钮的图标在左边
2186
+ */
2187
+ setIconLeft() {
2188
+ this.$ele.button.classList.remove("pops-panel-button-right-icon");
2189
+ },
2190
+ /**
2191
+ * 设置按钮文本
2192
+ * @param text
2193
+ */
2194
+ setButtonText(text: string) {
2195
+ this.$ele.spanText.innerHTML = text;
2196
+ },
2197
+ setClickEvent() {
2198
+ popsDOMUtils.on(this.$ele.button, "click", void 0, (event) => {
2199
+ if (typeof formConfig.callback === "function") {
2200
+ formConfig.callback(event);
2201
+ }
2202
+ });
2203
+ },
2204
+ };
2205
+ PopsPanelButton.init();
2206
+ (liElement as any)["data-button"] = PopsPanelButton;
2207
+ return liElement;
2208
+ },
2209
+ /**
2210
+ * 获取深层容器的元素<li>
2211
+ * @param formConfig
2212
+ */
2213
+ getSectionContainerItem_deepMenu(formConfig: PopsPanelDeepMenuDetails) {
2214
+ let that = this;
2215
+ let liElement = document.createElement("li");
2216
+ liElement.classList.add("pops-panel-deepMenu-nav-item");
2217
+ (liElement as any)["__formConfig__"] = formConfig;
2218
+ if (formConfig.className) {
2219
+ liElement.classList.add(formConfig.className);
2220
+ }
2221
+ // 设置属性
2222
+ this.addElementAttributes(liElement, formConfig.attributes);
2223
+ // 设置元素上的属性
2224
+ this.setElementProps(liElement, formConfig.props);
2225
+
2226
+ /* 左边底部的描述的文字 */
2227
+ let leftDescriptionText = "";
2228
+ if (Boolean(formConfig.description)) {
2229
+ // 设置描述
2230
+ leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
2231
+ }
2232
+ // 箭头图标
2233
+ let arrowRightIcon =
2234
+ typeof formConfig.arrowRightIcon === "boolean"
2235
+ ? formConfig.arrowRightIcon
2236
+ : true;
2237
+ let arrowRightIconHTML = "";
2238
+ if (arrowRightIcon) {
2239
+ arrowRightIconHTML = `<i class="pops-panel-deepMenu-arrowRight-icon">${pops.config.iconSVG.arrowRight}</i>`;
2240
+ }
2241
+ let rightText = "";
2242
+ if (formConfig.rightText) {
2243
+ rightText = /*html*/ `<p class="pops-panel-item-right-text">${formConfig.rightText}</p>`;
2244
+ }
2245
+ liElement.innerHTML = /*html*/ `
2246
+ <div class="pops-panel-item-left-text">
2247
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
2248
+ ${leftDescriptionText}
2249
+ </div>
2250
+ <div class="pops-panel-deepMenu">
2251
+ ${rightText}
2252
+ ${arrowRightIconHTML}
2253
+ </div>
2254
+ `;
2255
+ const PopsPanelDeepMenu = {
2256
+ [Symbol.toStringTag]: "PopsPanelDeepMenu",
2257
+ $ele: {
2258
+ get parentSection() {
2259
+ return that.$el.$contentSectionContainer;
2260
+ },
2261
+ },
2262
+ init() {
2263
+ this.setLiClickEvent();
2264
+ },
2265
+ /**
2266
+ * 生成配置每一项的元素
2267
+ * @param $container
2268
+ * @param formItemConfig
2269
+ */
2270
+ initFormItem(
2271
+ $container: HTMLElement,
2272
+ formItemConfig: PopsPanelFormsTotalDetails | PopsPanelFormsDetails
2273
+ ) {
2274
+ if (formItemConfig["type"] === "forms") {
2275
+ let childForms = formItemConfig["forms"];
2276
+ /* 每一项<li>元素 */
2277
+ let formContainerListElement = document.createElement("li");
2278
+ /* 每一项<li>内的子<ul>元素 */
2279
+ let formContainerULElement = document.createElement("ul");
2280
+ formContainerListElement.className =
2281
+ "pops-panel-forms-container-item";
2282
+ /* 区域头部的文字 */
2283
+ let formHeaderDivElement = popsDOMUtils.createElement("div", {
2284
+ className: "pops-panel-forms-container-item-header-text",
2285
+ });
2286
+ formHeaderDivElement.innerHTML = formItemConfig["text"];
2287
+ /* 加进容器内 */
2288
+ formContainerListElement.appendChild(formHeaderDivElement);
2289
+ if (formItemConfig.className) {
2290
+ popsDOMUtils.addClassName(
2291
+ formContainerListElement,
2292
+ formItemConfig.className
2293
+ );
2294
+ }
2295
+ that.addElementAttributes(
2296
+ formContainerListElement,
2297
+ formItemConfig.attributes
2298
+ );
2299
+ that.setElementProps(formContainerListElement, formItemConfig.props);
2300
+ childForms.forEach((childFormConfig) => {
2301
+ that.uListContainerAddItem(childFormConfig, {
2302
+ ulElement: formContainerULElement,
2303
+ sectionContainerULElement: that.sectionContainerULElement,
2304
+ formContainerListElement: formContainerListElement,
2305
+ formHeaderDivElement: formHeaderDivElement,
2306
+ });
2307
+ });
2308
+ formContainerListElement.appendChild(formContainerULElement);
2309
+ $container.appendChild(formContainerListElement);
2310
+ } else {
2311
+ /* 如果成功创建,加入到中间容器中 */
2312
+ that.uListContainerAddItem(formConfig, {
2313
+ ulElement: that.sectionContainerULElement,
2314
+ });
2315
+ }
2316
+ },
2317
+ /**
2318
+ * 前往子菜单
2319
+ * @param event 点击事件
2320
+ * @param liElement 当前的<li>元素
2321
+ */
2322
+ gotoDeepMenu(event: Event, liElement: HTMLLIElement) {
2323
+ /** 当前所在的容器 */
2324
+ let currentSection = liElement.closest(
2325
+ "section.pops-panel-container"
2326
+ ) as HTMLElement | null;
2327
+ if (currentSection) {
2328
+ popsDOMUtils.cssHide(currentSection);
2329
+ }
2330
+ // 子菜单的容器
2331
+ let $deepMenuContainer = popsDOMUtils.createElement("section", {
2332
+ className: "pops-panel-container pops-panel-deepMenu-container",
2333
+ });
2334
+ let $deepMenuHeaderUL = popsDOMUtils.createElement("ul", {
2335
+ className: "pops-panel-deepMenu-container-header-ul",
2336
+ });
2337
+ let $deepMenuChildMenuUL = popsDOMUtils.createElement("ul");
2338
+ // 标题文字
2339
+ let headerTitleText = formConfig.headerTitle ?? formConfig.text;
2340
+ let $header = popsDOMUtils.createElement("div", {
2341
+ className: "pops-panel-deepMenu-container-header",
2342
+ innerHTML: `<p>${headerTitleText}</p>`,
2343
+ });
2344
+ let $headerLeftArrow = popsDOMUtils.createElement("i", {
2345
+ className: "pops-panel-deepMenu-container-left-arrow-icon",
2346
+ innerHTML: pops.config.iconSVG.arrowLeft,
2347
+ });
2348
+ popsDOMUtils.on(
2349
+ $headerLeftArrow,
2350
+ "click",
2351
+ void 0,
2352
+ (event) => {
2353
+ event?.preventDefault();
2354
+ event?.stopPropagation();
2355
+ // 返回上一层菜单
2356
+ let $prev = $deepMenuContainer.previousElementSibling;
2357
+ popsDOMUtils.cssShow($prev);
2358
+ $deepMenuContainer.remove();
2359
+ },
2360
+ {
2361
+ once: true,
2362
+ }
2363
+ );
2364
+ $header.firstElementChild?.insertAdjacentElement(
2365
+ "beforebegin",
2366
+ $headerLeftArrow
2367
+ );
2368
+ $deepMenuHeaderUL.appendChild($header);
2369
+ $deepMenuContainer.appendChild($deepMenuHeaderUL);
2370
+ $deepMenuContainer.appendChild($deepMenuChildMenuUL);
2371
+
2372
+ if (formConfig.forms && Array.isArray(formConfig.forms)) {
2373
+ for (let index = 0; index < formConfig.forms.length; index++) {
2374
+ let formItemConfig = formConfig.forms[index];
2375
+ this.initFormItem($deepMenuChildMenuUL, formItemConfig);
2376
+ }
2377
+ }
2378
+ that.$el.$content?.appendChild($deepMenuContainer);
2379
+
2380
+ /* 根据标题的高度来自适应内容高度,默认开启 */
2381
+ /* 中间容器的偏移量,看设置的section.pops-panel-container的padding,默认0 */
2382
+ let contentContainerOffset = 0;
2383
+ /* 获取标题的<ul>元素的高度 */
2384
+ let sectionContainerHeaderULElementHeight =
2385
+ popsDOMUtils.height($deepMenuHeaderUL);
2386
+ $deepMenuChildMenuUL.style.setProperty(
2387
+ "height",
2388
+ `calc( 100% - ${
2389
+ sectionContainerHeaderULElementHeight + contentContainerOffset
2390
+ }px )`
2391
+ );
2392
+ },
2393
+ /** 设置项的点击事件 */
2394
+ setLiClickEvent() {
2395
+ popsDOMUtils.on(liElement, "click", void 0, async (event) => {
2396
+ if (typeof formConfig.clickCallBack === "function") {
2397
+ let result = await formConfig.clickCallBack(event, formConfig);
2398
+ if (result) {
2399
+ return;
2400
+ }
2401
+ }
2402
+ this.gotoDeepMenu(event, liElement);
2403
+ });
2404
+ },
2405
+ };
2406
+
2407
+ PopsPanelDeepMenu.init();
2408
+ (liElement as any)["data-deepMenu"] = PopsPanelDeepMenu;
2409
+
2410
+ return liElement;
2411
+ },
2412
+ /**
2413
+ * 获取中间容器的元素<li>
2414
+ * type ===> own
2415
+ * @param formConfig
2416
+ */
2417
+ getSectionContainerItem_own(formConfig: PopsPanelOwnDetails) {
2418
+ let liElement = document.createElement("li");
2419
+ (liElement as any)["__formConfig__"] = formConfig;
2420
+ if (formConfig.className) {
2421
+ liElement.className = formConfig.className;
2422
+ }
2423
+ liElement = formConfig.getLiElementCallBack(liElement);
2424
+ return liElement;
2425
+ },
2426
+ /**
2427
+ * 获取中间容器的元素<li>
2428
+ * @param formConfig
2429
+ */
2430
+ getSectionContainerItem(formConfig: PopsPanelFormsTotalDetails) {
2431
+ /** 配置项的类型 */
2432
+ let formType = formConfig["type"];
2433
+
2434
+ if (formType === "switch") {
2435
+ return this.getSectionContainerItem_switch(
2436
+ formConfig as PopsPanelSwitchDetails
2437
+ );
2438
+ } else if (formType === "slider") {
2439
+ return this.getSectionContainerItem_slider_new(
2440
+ formConfig as PopsPanelSliderDetails
2441
+ );
2442
+ } else if (formType === "input") {
2443
+ return this.getSectionContainerItem_input(
2444
+ formConfig as PopsPanelInputDetails
2445
+ );
2446
+ } else if (formType === "textarea") {
2447
+ return this.getSectionContainerItem_textarea(
2448
+ formConfig as PopsPanelTextAreaDetails
2449
+ );
2450
+ } else if (formType === "select") {
2451
+ return this.getSectionContainerItem_select(
2452
+ formConfig as PopsPanelSelectDetails
2453
+ );
2454
+ } else if (formType === "select-multiple") {
2455
+ return this.getSectionContainerItem_select_multiple_new(
2456
+ formConfig as PopsPanelSelectMultipleDetails
2457
+ );
2458
+ } else if (formType === "button") {
2459
+ return this.getSectionContainerItem_button(
2460
+ formConfig as PopsPanelButtonDetails
2461
+ );
2462
+ } else if (formType === "deepMenu") {
2463
+ return this.getSectionContainerItem_deepMenu(
2464
+ formConfig as PopsPanelDeepMenuDetails
2465
+ );
2466
+ } else if (formType === "own") {
2467
+ return this.getSectionContainerItem_own(
2468
+ formConfig as PopsPanelOwnDetails
2469
+ );
2470
+ } else {
2471
+ console.error("尚未实现的type类型", formConfig);
2472
+ }
2473
+ },
2474
+ /**
2475
+ * 生成配置每一项的元素
2476
+ * @param formConfig
2477
+ */
2478
+ initFormItem(formConfig: PopsPanelContentConfig) {
2479
+ let that = this;
2480
+ if ((formConfig as any)["type"] === "forms") {
2481
+ let __formConfig_forms = formConfig as any as PopsPanelFormsDetails;
2482
+ let childForms = formConfig["forms"];
2483
+ /* 每一项<li>元素 */
2484
+ let formContainerListElement = document.createElement("li");
2485
+ /* 每一项<li>内的子<ul>元素 */
2486
+ let formContainerULElement = document.createElement("ul");
2487
+ formContainerListElement.className = "pops-panel-forms-container-item";
2488
+ /* 区域头部的文字 */
2489
+ let formHeaderDivElement = popsDOMUtils.createElement("div", {
2490
+ className: "pops-panel-forms-container-item-header-text",
2491
+ });
2492
+ formHeaderDivElement.innerHTML = __formConfig_forms["text"];
2493
+ /* 加进容器内 */
2494
+ formContainerListElement.appendChild(formHeaderDivElement);
2495
+ if (__formConfig_forms.className) {
2496
+ popsDOMUtils.addClassName(
2497
+ formContainerListElement,
2498
+ __formConfig_forms.className
2499
+ );
2500
+ }
2501
+ that.addElementAttributes(
2502
+ formContainerListElement,
2503
+ formConfig.attributes
2504
+ );
2505
+ that.setElementProps(formContainerListElement, formConfig.props);
2506
+ childForms.forEach((childFormConfig) => {
2507
+ that.uListContainerAddItem(childFormConfig as any, {
2508
+ ulElement: formContainerULElement,
2509
+ sectionContainerULElement: that.sectionContainerULElement,
2510
+ formContainerListElement: formContainerListElement,
2511
+ formHeaderDivElement: formHeaderDivElement,
2512
+ });
2513
+ });
2514
+ formContainerListElement.appendChild(formContainerULElement);
2515
+ that.sectionContainerULElement.appendChild(formContainerListElement);
2516
+ } else {
2517
+ /* 如果成功创建,加入到中间容器中 */
2518
+ that.uListContainerAddItem(formConfig as any, {
2519
+ ulElement: that.sectionContainerULElement,
2520
+ });
2521
+ }
2522
+ },
2523
+ /**
2524
+ *
2525
+ * @param formConfig
2526
+ * @param containerOptions
2527
+ */
2528
+ uListContainerAddItem(
2529
+ formConfig: PopsPanelFormsTotalDetails,
2530
+ containerOptions: PopsPanelRightAsideContainerOptions
2531
+ ) {
2532
+ let itemLiElement = this.getSectionContainerItem(formConfig);
2533
+ if (itemLiElement) {
2534
+ containerOptions["ulElement"].appendChild(itemLiElement);
2535
+ }
2536
+ if (typeof formConfig.afterAddToUListCallBack === "function") {
2537
+ formConfig.afterAddToUListCallBack(formConfig, containerOptions);
2538
+ }
2539
+ },
2540
+ /**
2541
+ * 为左侧容器元素添加点击事件
2542
+ * @param asideLiElement 左侧的容器<li>元素
2543
+ * @param asideConfig 配置
2544
+ */
2545
+ setAsideItemClickEvent(
2546
+ asideLiElement: HTMLElement,
2547
+ asideConfig: PopsPanelContentConfig
2548
+ ) {
2549
+ const that = this;
2550
+ popsDOMUtils.on<MouseEvent | PointerEvent>(
2551
+ asideLiElement,
2552
+ "click",
2553
+ void 0,
2554
+ (event) => {
2555
+ this.clearContainer();
2556
+ popsDOMUtils.cssShow(that.$el.$contentSectionContainer);
2557
+ this.clearAsideItemIsVisited();
2558
+ this.setAsideItemIsVisited(asideLiElement);
2559
+ /* 顶部标题栏,存在就设置 */
2560
+ let headerTitleText = asideConfig.headerTitle ?? asideConfig.title;
2561
+ if (
2562
+ typeof headerTitleText === "string" &&
2563
+ headerTitleText.trim() !== ""
2564
+ ) {
2565
+ let containerHeaderTitleLIElement = document.createElement("li");
2566
+ (containerHeaderTitleLIElement as any)["__asideConfig__"] =
2567
+ asideConfig;
2568
+ containerHeaderTitleLIElement.innerHTML = headerTitleText;
2569
+ this.sectionContainerHeaderULElement.appendChild(
2570
+ containerHeaderTitleLIElement
2571
+ );
2572
+ }
2573
+
2574
+ let __forms__ = (asideLiElement as any)[
2575
+ "__forms__"
2576
+ ] as PopsPanelContentConfig[];
2577
+
2578
+ __forms__.forEach((formConfig) => {
2579
+ this.initFormItem(formConfig);
2580
+ });
2581
+
2582
+ let autoAdaptionContentHeight =
2583
+ asideConfig.autoAdaptionContentHeight ?? true;
2584
+ if (autoAdaptionContentHeight) {
2585
+ /* 根据标题的高度来自适应内容高度,默认开启 */
2586
+ /* 中间容器的偏移量,看设置的section.pops-panel-container的padding,默认0 */
2587
+ let contentContainerOffset =
2588
+ (asideConfig as any).contentContainerOffset ?? 0;
2589
+ /* 获取标题的<ul>元素的高度 */
2590
+ let sectionContainerHeaderULElementHeight = popsDOMUtils.height(
2591
+ this.sectionContainerHeaderULElement
2592
+ );
2593
+ this.sectionContainerULElement.style.setProperty(
2594
+ "height",
2595
+ `calc( 100% - ${
2596
+ sectionContainerHeaderULElementHeight + contentContainerOffset
2597
+ }px )`
2598
+ );
2599
+ }
2600
+
2601
+ if (typeof asideConfig.callback === "function") {
2602
+ /* 执行回调 */
2603
+ asideConfig.callback(
2604
+ event,
2605
+ this.sectionContainerHeaderULElement,
2606
+ this.sectionContainerULElement
2607
+ );
2608
+ }
2609
+ }
2610
+ );
2611
+ },
2612
+ };