@whitesev/pops 1.6.2 → 1.6.4

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