@whitesev/pops 2.2.8 → 2.2.9
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.
- package/dist/index.amd.js +2815 -3010
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +2815 -3010
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +2815 -3010
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +2815 -3010
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +2815 -3010
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +2815 -3010
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Pops.d.ts +11 -11
- package/dist/types/src/PopsIcon.d.ts +2 -2
- package/dist/types/src/components/rightClickMenu/index.d.ts +2 -2
- package/dist/types/src/components/tooltip/index.d.ts +2 -2
- package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +256 -259
- package/dist/types/src/types/animation.d.ts +19 -19
- package/dist/types/src/types/button.d.ts +187 -196
- package/dist/types/src/types/components.d.ts +213 -229
- package/dist/types/src/types/event.d.ts +63 -63
- package/dist/types/src/types/global.d.ts +20 -20
- package/dist/types/src/types/icon.d.ts +32 -32
- package/dist/types/src/types/inst.d.ts +24 -24
- package/dist/types/src/types/main.d.ts +114 -122
- package/dist/types/src/types/mask.d.ts +49 -49
- package/dist/types/src/types/position.d.ts +60 -60
- package/package.json +61 -56
- package/LICENSE +0 -674
- package/src/Pops.ts +0 -209
- package/src/PopsAnimation.ts +0 -32
- package/src/PopsCSS.ts +0 -51
- package/src/PopsCore.ts +0 -44
- package/src/PopsIcon.ts +0 -95
- package/src/PopsInst.ts +0 -21
- package/src/components/alert/config.ts +0 -62
- package/src/components/alert/index.css +0 -0
- package/src/components/alert/index.ts +0 -181
- package/src/components/alert/types/index.ts +0 -30
- package/src/components/confirm/config.ts +0 -90
- package/src/components/confirm/index.css +0 -0
- package/src/components/confirm/index.ts +0 -192
- package/src/components/confirm/types/index.ts +0 -17
- package/src/components/drawer/config.ts +0 -89
- package/src/components/drawer/index.css +0 -35
- package/src/components/drawer/index.ts +0 -260
- package/src/components/drawer/types/index.ts +0 -61
- package/src/components/folder/config.ts +0 -147
- package/src/components/folder/folderIcon.ts +0 -28
- package/src/components/folder/index.css +0 -314
- package/src/components/folder/index.ts +0 -1050
- package/src/components/folder/types/index.ts +0 -101
- package/src/components/iframe/config.ts +0 -60
- package/src/components/iframe/index.css +0 -75
- package/src/components/iframe/index.ts +0 -351
- package/src/components/iframe/types/index.ts +0 -146
- package/src/components/loading/config.ts +0 -29
- package/src/components/loading/index.css +0 -66
- package/src/components/loading/index.ts +0 -114
- package/src/components/loading/types/index.ts +0 -40
- package/src/components/panel/config.ts +0 -550
- package/src/components/panel/handlerComponents.ts +0 -3277
- package/src/components/panel/index.css +0 -1292
- package/src/components/panel/index.ts +0 -213
- package/src/components/panel/types/components-button.ts +0 -69
- package/src/components/panel/types/components-common.ts +0 -55
- package/src/components/panel/types/components-deepMenu.ts +0 -85
- package/src/components/panel/types/components-forms.ts +0 -45
- package/src/components/panel/types/components-input.ts +0 -82
- package/src/components/panel/types/components-own.ts +0 -31
- package/src/components/panel/types/components-select.ts +0 -101
- package/src/components/panel/types/components-selectMultiple.ts +0 -133
- package/src/components/panel/types/components-slider.ts +0 -78
- package/src/components/panel/types/components-switch.ts +0 -57
- package/src/components/panel/types/components-textarea.ts +0 -69
- package/src/components/panel/types/index.ts +0 -177
- package/src/components/prompt/config.ts +0 -94
- package/src/components/prompt/index.css +0 -34
- package/src/components/prompt/index.ts +0 -222
- package/src/components/prompt/types/index.ts +0 -55
- package/src/components/rightClickMenu/config.ts +0 -130
- package/src/components/rightClickMenu/index.css +0 -88
- package/src/components/rightClickMenu/index.ts +0 -689
- package/src/components/rightClickMenu/types/index.ts +0 -91
- package/src/components/searchSuggestion/config.ts +0 -59
- package/src/components/searchSuggestion/index.ts +0 -708
- package/src/components/searchSuggestion/types/index.ts +0 -147
- package/src/components/tooltip/config.ts +0 -34
- package/src/components/tooltip/index.css +0 -196
- package/src/components/tooltip/index.ts +0 -655
- package/src/components/tooltip/types/index.ts +0 -125
- package/src/config/CommonCSSClassName.ts +0 -17
- package/src/config/GlobalConfig.ts +0 -80
- package/src/css/animation.css +0 -2245
- package/src/css/button.css +0 -542
- package/src/css/common.css +0 -52
- package/src/css/index.css +0 -254
- package/src/css/ninePalaceGridPosition.css +0 -50
- package/src/css/scrollbar.css +0 -22
- package/src/handler/PopsElementHandler.ts +0 -325
- package/src/handler/PopsHandler.ts +0 -719
- package/src/svg/arrowLeft.svg +0 -4
- package/src/svg/arrowRight.svg +0 -4
- package/src/svg/chromeFilled.svg +0 -14
- package/src/svg/circleClose.svg +0 -8
- package/src/svg/close.svg +0 -5
- package/src/svg/cpu.svg +0 -8
- package/src/svg/delete.svg +0 -5
- package/src/svg/documentCopy.svg +0 -5
- package/src/svg/edit.svg +0 -8
- package/src/svg/eleme.svg +0 -5
- package/src/svg/elemePlus.svg +0 -5
- package/src/svg/headset.svg +0 -5
- package/src/svg/hide.svg +0 -8
- package/src/svg/keyboard.svg +0 -8
- package/src/svg/loading.svg +0 -5
- package/src/svg/max.svg +0 -5
- package/src/svg/min.svg +0 -5
- package/src/svg/mise.svg +0 -5
- package/src/svg/monitor.svg +0 -5
- package/src/svg/next.svg +0 -5
- package/src/svg/picture.svg +0 -8
- package/src/svg/prev.svg +0 -5
- package/src/svg/search.svg +0 -5
- package/src/svg/share.svg +0 -5
- package/src/svg/upload.svg +0 -5
- package/src/svg/videoPause.svg +0 -5
- package/src/svg/videoPlay.svg +0 -5
- package/src/svg/view.svg +0 -5
- package/src/types/PopsDOMUtilsEventType.d.ts +0 -259
- package/src/types/animation.d.ts +0 -19
- package/src/types/button.d.ts +0 -196
- package/src/types/components.d.ts +0 -229
- package/src/types/event.d.ts +0 -63
- package/src/types/global.d.ts +0 -20
- package/src/types/icon.d.ts +0 -32
- package/src/types/inst.d.ts +0 -24
- package/src/types/main.d.ts +0 -122
- package/src/types/mask.d.ts +0 -49
- package/src/types/position.d.ts +0 -60
- package/src/utils/PopsDOMUtils.ts +0 -2649
- package/src/utils/PopsDOMUtilsEventsConfig.ts +0 -6
- package/src/utils/PopsInstanceUtils.ts +0 -801
- package/src/utils/PopsMathUtils.ts +0 -77
- package/src/utils/PopsSafeUtils.ts +0 -24
- package/src/utils/PopsUtils.ts +0 -430
|
@@ -1,3277 +0,0 @@
|
|
|
1
|
-
import { PopsIcon } from "../../PopsIcon";
|
|
2
|
-
import { popsDOMUtils } from "../../utils/PopsDOMUtils";
|
|
3
|
-
import { PopsInstanceUtils } from "../../utils/PopsInstanceUtils";
|
|
4
|
-
import { PopsMathFloatUtils } from "../../utils/PopsMathUtils";
|
|
5
|
-
import { PopsSafeUtils } from "../../utils/PopsSafeUtils";
|
|
6
|
-
import { popsUtils } from "../../utils/PopsUtils";
|
|
7
|
-
import { PopsAlert } from "../alert";
|
|
8
|
-
import type { PopsAlertDetails } from "../alert/types";
|
|
9
|
-
import { PopsTooltip } from "../tooltip";
|
|
10
|
-
import type { PopsPanelButtonDetails } from "./types/components-button";
|
|
11
|
-
import type { PopsPanelRightAsideContainerOptions } from "./types/components-common";
|
|
12
|
-
import type { PopsPanelDeepMenuDetails } from "./types/components-deepMenu";
|
|
13
|
-
import type { PopsPanelFormsDetails } from "./types/components-forms";
|
|
14
|
-
import type {
|
|
15
|
-
PopsPanelContentConfig,
|
|
16
|
-
PopsPanelDetails,
|
|
17
|
-
PopsPanelEventType,
|
|
18
|
-
PopsPanelFormsTotalDetails,
|
|
19
|
-
} from "./types";
|
|
20
|
-
import type { PopsPanelInputDetails } from "./types/components-input";
|
|
21
|
-
import type { PopsPanelOwnDetails } from "./types/components-own";
|
|
22
|
-
import type {
|
|
23
|
-
PopsPanelSelectMultipleDataOption,
|
|
24
|
-
PopsPanelSelectMultipleDetails,
|
|
25
|
-
} from "./types/components-selectMultiple";
|
|
26
|
-
import type { PopsPanelSelectDetails } from "./types/components-select";
|
|
27
|
-
import type { PopsPanelSliderDetails } from "./types/components-slider";
|
|
28
|
-
import type { PopsPanelSwitchDetails } from "./types/components-switch";
|
|
29
|
-
import type { PopsPanelTextAreaDetails } from "./types/components-textarea";
|
|
30
|
-
import { PopsCommonCSSClassName } from "../../config/CommonCSSClassName";
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 处理组件(把组件配置转为组件元素)
|
|
34
|
-
*/
|
|
35
|
-
export const PanelHandlerComponents = () => {
|
|
36
|
-
return {
|
|
37
|
-
/**
|
|
38
|
-
* 左侧上方的的ul容器
|
|
39
|
-
*/
|
|
40
|
-
asideULElement: null as any as HTMLUListElement,
|
|
41
|
-
/**
|
|
42
|
-
* 左侧下方的ul容器
|
|
43
|
-
*/
|
|
44
|
-
asideBottomULElement: null as any as HTMLUListElement,
|
|
45
|
-
/**
|
|
46
|
-
* 右侧主内容的顶部文字ul容器
|
|
47
|
-
*/
|
|
48
|
-
sectionContainerHeaderULElement: null as any as HTMLUListElement,
|
|
49
|
-
/**
|
|
50
|
-
* 右侧主内容的ul容器
|
|
51
|
-
*/
|
|
52
|
-
sectionContainerULElement: null as any as HTMLUListElement,
|
|
53
|
-
/**
|
|
54
|
-
* 元素
|
|
55
|
-
*/
|
|
56
|
-
$el: {
|
|
57
|
-
/** pops主元素 */
|
|
58
|
-
$pops: null as any as HTMLElement,
|
|
59
|
-
/** 内容 */
|
|
60
|
-
$content: null as any as HTMLElement,
|
|
61
|
-
/** 左侧容器 */
|
|
62
|
-
$contentAside: null as any as HTMLElement,
|
|
63
|
-
/** 右侧容器 */
|
|
64
|
-
$contentSectionContainer: null as any as HTMLElement,
|
|
65
|
-
},
|
|
66
|
-
/**
|
|
67
|
-
* 初始化
|
|
68
|
-
* @param details
|
|
69
|
-
*/
|
|
70
|
-
init(details: {
|
|
71
|
-
config: Required<PopsPanelDetails>;
|
|
72
|
-
$el: {
|
|
73
|
-
$pops: HTMLElement;
|
|
74
|
-
$content: HTMLElement;
|
|
75
|
-
$contentAside: HTMLElement;
|
|
76
|
-
$contentSectionContainer: HTMLElement;
|
|
77
|
-
};
|
|
78
|
-
}) {
|
|
79
|
-
const PopsType = "panel";
|
|
80
|
-
this.$el = {
|
|
81
|
-
...details.$el,
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
this.asideULElement =
|
|
85
|
-
this.$el.$contentAside.querySelector<HTMLUListElement>(
|
|
86
|
-
`ul.pops-${PopsType}-aside-top-container`
|
|
87
|
-
)!;
|
|
88
|
-
this.asideBottomULElement =
|
|
89
|
-
this.$el.$contentAside.querySelector<HTMLUListElement>(
|
|
90
|
-
`ul.pops-${PopsType}-aside-bottom-container`
|
|
91
|
-
)!;
|
|
92
|
-
this.sectionContainerHeaderULElement =
|
|
93
|
-
this.$el.$contentSectionContainer.querySelector<HTMLUListElement>(
|
|
94
|
-
`ul.pops-${PopsType}-container-header-ul`
|
|
95
|
-
)!;
|
|
96
|
-
this.sectionContainerULElement =
|
|
97
|
-
this.$el.$contentSectionContainer.querySelector<HTMLUListElement>(
|
|
98
|
-
`ul.pops-${PopsType}-container-main-ul`
|
|
99
|
-
)!;
|
|
100
|
-
/**
|
|
101
|
-
* 默认点击的左侧容器项
|
|
102
|
-
*/
|
|
103
|
-
let $defaultAsideItem: HTMLLIElement | null = null;
|
|
104
|
-
/** 是否滚动到默认位置(第一个项) */
|
|
105
|
-
let isScrollToDefaultView = false;
|
|
106
|
-
// 初始化配置
|
|
107
|
-
details.config.content.forEach((asideItemConfig) => {
|
|
108
|
-
let $asideLiElement = this.createAsideItem(asideItemConfig);
|
|
109
|
-
this.setAsideItemClickEvent($asideLiElement, asideItemConfig);
|
|
110
|
-
// 是否处于底部
|
|
111
|
-
let isBottom =
|
|
112
|
-
typeof asideItemConfig.isBottom === "function"
|
|
113
|
-
? asideItemConfig.isBottom()
|
|
114
|
-
: asideItemConfig.isBottom;
|
|
115
|
-
if (isBottom) {
|
|
116
|
-
this.asideBottomULElement.appendChild($asideLiElement);
|
|
117
|
-
} else {
|
|
118
|
-
this.asideULElement.appendChild($asideLiElement);
|
|
119
|
-
}
|
|
120
|
-
if ($defaultAsideItem == null) {
|
|
121
|
-
let flag = false;
|
|
122
|
-
if (typeof asideItemConfig.isDefault === "function") {
|
|
123
|
-
flag = Boolean(asideItemConfig.isDefault());
|
|
124
|
-
} else {
|
|
125
|
-
flag = Boolean(asideItemConfig.isDefault);
|
|
126
|
-
}
|
|
127
|
-
if (flag) {
|
|
128
|
-
$defaultAsideItem = $asideLiElement;
|
|
129
|
-
isScrollToDefaultView = Boolean(
|
|
130
|
-
asideItemConfig.scrollToDefaultView
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if (typeof asideItemConfig.afterRender === "function") {
|
|
135
|
-
// 执行渲染完毕的回调
|
|
136
|
-
asideItemConfig.afterRender({
|
|
137
|
-
asideConfig: asideItemConfig,
|
|
138
|
-
$asideLiElement: $asideLiElement,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
/* 点击左侧列表 */
|
|
144
|
-
if ($defaultAsideItem == null && this.asideULElement.children.length) {
|
|
145
|
-
/* 默认第一个 */
|
|
146
|
-
$defaultAsideItem = <HTMLLIElement>this.asideULElement.children[0];
|
|
147
|
-
}
|
|
148
|
-
if ($defaultAsideItem) {
|
|
149
|
-
/* 点击选择的那一项 */
|
|
150
|
-
$defaultAsideItem.click();
|
|
151
|
-
if (isScrollToDefaultView) {
|
|
152
|
-
$defaultAsideItem?.scrollIntoView();
|
|
153
|
-
}
|
|
154
|
-
} else {
|
|
155
|
-
console.error("pops.panel:左侧容器没有项");
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
/**
|
|
159
|
-
* 清空container容器的元素
|
|
160
|
-
*/
|
|
161
|
-
clearContainer() {
|
|
162
|
-
Reflect.deleteProperty(
|
|
163
|
-
this.$el.$contentSectionContainer,
|
|
164
|
-
"__formConfig__"
|
|
165
|
-
);
|
|
166
|
-
PopsSafeUtils.setSafeHTML(this.sectionContainerHeaderULElement, "");
|
|
167
|
-
PopsSafeUtils.setSafeHTML(this.sectionContainerULElement, "");
|
|
168
|
-
this.$el.$content
|
|
169
|
-
?.querySelectorAll("section.pops-panel-deepMenu-container")
|
|
170
|
-
.forEach(($el) => $el.remove());
|
|
171
|
-
},
|
|
172
|
-
/**
|
|
173
|
-
* 清空左侧容器已访问记录
|
|
174
|
-
*/
|
|
175
|
-
clearAsideItemIsVisited() {
|
|
176
|
-
this.$el.$contentAside
|
|
177
|
-
.querySelectorAll<HTMLDivElement>(".pops-is-visited")
|
|
178
|
-
.forEach(($el) => {
|
|
179
|
-
popsDOMUtils.removeClassName($el, "pops-is-visited");
|
|
180
|
-
});
|
|
181
|
-
},
|
|
182
|
-
/**
|
|
183
|
-
* 设置左侧容器已访问记录
|
|
184
|
-
* @param element
|
|
185
|
-
*/
|
|
186
|
-
setAsideItemIsVisited(element: HTMLElement) {
|
|
187
|
-
popsDOMUtils.addClassName(element, "pops-is-visited");
|
|
188
|
-
},
|
|
189
|
-
/**
|
|
190
|
-
* 为元素添加自定义属性
|
|
191
|
-
* @param element
|
|
192
|
-
* @param attributes
|
|
193
|
-
*/
|
|
194
|
-
setElementAttributes(element: HTMLElement, attributes?: any) {
|
|
195
|
-
if (attributes == null) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
if (Array.isArray(attributes)) {
|
|
199
|
-
attributes.forEach((attrObject) => {
|
|
200
|
-
this.setElementAttributes(element, attrObject);
|
|
201
|
-
});
|
|
202
|
-
} else {
|
|
203
|
-
Object.keys(attributes).forEach((attributeName) => {
|
|
204
|
-
element.setAttribute(attributeName, attributes[attributeName]);
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
/**
|
|
209
|
-
* 为元素设置(自定义)属性
|
|
210
|
-
* @param element
|
|
211
|
-
* @param props
|
|
212
|
-
*/
|
|
213
|
-
setElementProps(element: HTMLElement, props?: any) {
|
|
214
|
-
if (props == null) {
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
Object.keys(props).forEach((propName) => {
|
|
218
|
-
let value = props[propName];
|
|
219
|
-
if (propName === "innerHTML") {
|
|
220
|
-
PopsSafeUtils.setSafeHTML(element, value);
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
Reflect.set(element, propName, value);
|
|
224
|
-
});
|
|
225
|
-
},
|
|
226
|
-
/**
|
|
227
|
-
* 为元素设置classname
|
|
228
|
-
* @param element
|
|
229
|
-
* @param className
|
|
230
|
-
*/
|
|
231
|
-
setElementClassName(
|
|
232
|
-
element: HTMLElement,
|
|
233
|
-
className?: string | string[] | (() => string | string[])
|
|
234
|
-
) {
|
|
235
|
-
if (className == null) {
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
if (typeof className === "function") {
|
|
239
|
-
className = className();
|
|
240
|
-
}
|
|
241
|
-
if (typeof className === "string") {
|
|
242
|
-
let splitClassName = className.split(" ");
|
|
243
|
-
splitClassName.forEach((classNameStr) => {
|
|
244
|
-
element.classList.add(classNameStr);
|
|
245
|
-
});
|
|
246
|
-
} else if (Array.isArray(className)) {
|
|
247
|
-
className.forEach((classNameStr) => {
|
|
248
|
-
this.setElementClassName(element, classNameStr);
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
/**
|
|
253
|
-
* 创建左侧容器元素<li>
|
|
254
|
-
* @param asideConfig
|
|
255
|
-
*/
|
|
256
|
-
createAsideItem(asideConfig: PopsPanelContentConfig) {
|
|
257
|
-
let $li = document.createElement("li");
|
|
258
|
-
$li.id = asideConfig.id;
|
|
259
|
-
Reflect.set($li, "__forms__", asideConfig.forms);
|
|
260
|
-
let title =
|
|
261
|
-
typeof asideConfig.title === "function"
|
|
262
|
-
? asideConfig.title()
|
|
263
|
-
: asideConfig.title;
|
|
264
|
-
PopsSafeUtils.setSafeHTML($li, title);
|
|
265
|
-
/* 处理className */
|
|
266
|
-
this.setElementClassName($li, "pops-panel-aside-item");
|
|
267
|
-
this.setElementClassName($li, asideConfig.className);
|
|
268
|
-
this.setElementAttributes($li, asideConfig.attributes);
|
|
269
|
-
this.setElementProps($li, asideConfig.props);
|
|
270
|
-
/** 禁用左侧项的hover的CSS样式的类名 */
|
|
271
|
-
const disableAsideItemHoverCSSClassName =
|
|
272
|
-
"pops-panel-disabled-aside-hover-css";
|
|
273
|
-
/** 是否禁用左侧项的hover的CSS样式 */
|
|
274
|
-
let disableAsideItemHoverCSS =
|
|
275
|
-
typeof asideConfig.disableAsideItemHoverCSS === "function"
|
|
276
|
-
? asideConfig.disableAsideItemHoverCSS()
|
|
277
|
-
: asideConfig.disableAsideItemHoverCSS;
|
|
278
|
-
if (disableAsideItemHoverCSS) {
|
|
279
|
-
$li.classList.add(disableAsideItemHoverCSSClassName);
|
|
280
|
-
} else {
|
|
281
|
-
$li.classList.remove(disableAsideItemHoverCSSClassName);
|
|
282
|
-
}
|
|
283
|
-
return $li;
|
|
284
|
-
},
|
|
285
|
-
/**
|
|
286
|
-
* type ==> switch
|
|
287
|
-
* 创建中间容器的元素<li>
|
|
288
|
-
* @param formConfig
|
|
289
|
-
*/
|
|
290
|
-
createSectionContainerItem_switch(formConfig: PopsPanelSwitchDetails) {
|
|
291
|
-
let $li = document.createElement("li");
|
|
292
|
-
Reflect.set($li, "__formConfig__", formConfig);
|
|
293
|
-
this.setElementClassName($li, formConfig.className);
|
|
294
|
-
this.setElementAttributes($li, formConfig.attributes);
|
|
295
|
-
this.setElementProps($li, formConfig.props);
|
|
296
|
-
/* 左边底部的描述的文字 */
|
|
297
|
-
let leftDescriptionText = "";
|
|
298
|
-
if (Boolean(formConfig.description)) {
|
|
299
|
-
leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
|
|
300
|
-
}
|
|
301
|
-
PopsSafeUtils.setSafeHTML(
|
|
302
|
-
$li,
|
|
303
|
-
/*html*/ `
|
|
304
|
-
<div class="pops-panel-item-left-text">
|
|
305
|
-
<p class="pops-panel-item-left-main-text">${formConfig.text}</p>${leftDescriptionText}</div>
|
|
306
|
-
<div class="pops-panel-switch">
|
|
307
|
-
<input class="pops-panel-switch__input" type="checkbox">
|
|
308
|
-
<span class="pops-panel-switch__core">
|
|
309
|
-
<div class="pops-panel-switch__action">
|
|
310
|
-
</div>
|
|
311
|
-
</span>
|
|
312
|
-
</div>`
|
|
313
|
-
);
|
|
314
|
-
const PopsPanelSwitch = {
|
|
315
|
-
[Symbol.toStringTag]: "PopsPanelSwitch",
|
|
316
|
-
$data: {
|
|
317
|
-
value: Boolean(formConfig.getValue()),
|
|
318
|
-
},
|
|
319
|
-
$ele: {
|
|
320
|
-
itemLeftTextContainer: $li.querySelector<HTMLElement>(
|
|
321
|
-
".pops-panel-item-left-text"
|
|
322
|
-
),
|
|
323
|
-
switch: $li.querySelector<HTMLDivElement>(".pops-panel-switch")!,
|
|
324
|
-
input: $li.querySelector<HTMLInputElement>(
|
|
325
|
-
".pops-panel-switch__input"
|
|
326
|
-
)!,
|
|
327
|
-
core: $li.querySelector<HTMLSpanElement>(".pops-panel-switch__core")!,
|
|
328
|
-
},
|
|
329
|
-
init() {
|
|
330
|
-
this.setStatus(this.$data.value);
|
|
331
|
-
let disabled =
|
|
332
|
-
typeof formConfig.disabled === "function"
|
|
333
|
-
? formConfig.disabled()
|
|
334
|
-
: formConfig.disabled;
|
|
335
|
-
if (disabled) {
|
|
336
|
-
this.disable();
|
|
337
|
-
}
|
|
338
|
-
this.setClickEvent();
|
|
339
|
-
},
|
|
340
|
-
/**
|
|
341
|
-
* 设置点击事件
|
|
342
|
-
*/
|
|
343
|
-
setClickEvent() {
|
|
344
|
-
let that = this;
|
|
345
|
-
popsDOMUtils.on(this.$ele.core, "click", function (event) {
|
|
346
|
-
if (
|
|
347
|
-
that.$ele.input.disabled ||
|
|
348
|
-
that.$ele.switch.hasAttribute("data-disabled")
|
|
349
|
-
) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
that.$data.value = that.getStatus();
|
|
353
|
-
that.setStatus(that.$data.value);
|
|
354
|
-
if (typeof formConfig.callback === "function") {
|
|
355
|
-
formConfig.callback(event, that.$data.value);
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
},
|
|
359
|
-
/**
|
|
360
|
-
* 设置状态
|
|
361
|
-
*/
|
|
362
|
-
setStatus(isChecked = false) {
|
|
363
|
-
isChecked = Boolean(isChecked);
|
|
364
|
-
this.$ele.input.checked = isChecked;
|
|
365
|
-
if (isChecked) {
|
|
366
|
-
popsDOMUtils.addClassName(
|
|
367
|
-
this.$ele.switch,
|
|
368
|
-
"pops-panel-switch-is-checked"
|
|
369
|
-
);
|
|
370
|
-
} else {
|
|
371
|
-
popsDOMUtils.removeClassName(
|
|
372
|
-
this.$ele.switch,
|
|
373
|
-
"pops-panel-switch-is-checked"
|
|
374
|
-
);
|
|
375
|
-
}
|
|
376
|
-
},
|
|
377
|
-
/**
|
|
378
|
-
* 根据className来获取逆反值
|
|
379
|
-
*/
|
|
380
|
-
getStatus() {
|
|
381
|
-
let checkedValue = false;
|
|
382
|
-
if (
|
|
383
|
-
!popsDOMUtils.containsClassName(
|
|
384
|
-
this.$ele.switch,
|
|
385
|
-
"pops-panel-switch-is-checked"
|
|
386
|
-
)
|
|
387
|
-
) {
|
|
388
|
-
checkedValue = true;
|
|
389
|
-
}
|
|
390
|
-
return checkedValue;
|
|
391
|
-
},
|
|
392
|
-
/**
|
|
393
|
-
* 禁用复选框
|
|
394
|
-
*/
|
|
395
|
-
disable() {
|
|
396
|
-
this.$ele.input.disabled = true;
|
|
397
|
-
this.$ele.switch.setAttribute("data-disabled", "true");
|
|
398
|
-
popsDOMUtils.addClassName(
|
|
399
|
-
this.$ele.itemLeftTextContainer,
|
|
400
|
-
PopsCommonCSSClassName.textIsDisabled
|
|
401
|
-
);
|
|
402
|
-
},
|
|
403
|
-
/**
|
|
404
|
-
* 取消禁用复选框
|
|
405
|
-
*/
|
|
406
|
-
notDisable() {
|
|
407
|
-
this.$ele.input.disabled = false;
|
|
408
|
-
this.$ele.switch.removeAttribute("data-disabled");
|
|
409
|
-
popsDOMUtils.removeClassName(
|
|
410
|
-
this.$ele.itemLeftTextContainer,
|
|
411
|
-
PopsCommonCSSClassName.textIsDisabled
|
|
412
|
-
);
|
|
413
|
-
},
|
|
414
|
-
};
|
|
415
|
-
|
|
416
|
-
PopsPanelSwitch.init();
|
|
417
|
-
Reflect.set($li, "data-switch", PopsPanelSwitch);
|
|
418
|
-
return $li;
|
|
419
|
-
},
|
|
420
|
-
/**
|
|
421
|
-
* type ==> slider
|
|
422
|
-
* 获取中间容器的元素<li>
|
|
423
|
-
* @param formConfig
|
|
424
|
-
*/
|
|
425
|
-
createSectionContainerItem_slider(formConfig: PopsPanelSliderDetails) {
|
|
426
|
-
let $li = document.createElement("li");
|
|
427
|
-
Reflect.set($li, "__formConfig__", formConfig);
|
|
428
|
-
this.setElementClassName($li, formConfig.className);
|
|
429
|
-
this.setElementAttributes($li, formConfig.attributes);
|
|
430
|
-
this.setElementProps($li, formConfig.props);
|
|
431
|
-
/* 左边底部的描述的文字 */
|
|
432
|
-
let leftDescriptionText = "";
|
|
433
|
-
if (Boolean(formConfig.description)) {
|
|
434
|
-
leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
|
|
435
|
-
}
|
|
436
|
-
PopsSafeUtils.setSafeHTML(
|
|
437
|
-
$li,
|
|
438
|
-
/*html*/ `
|
|
439
|
-
<div class="pops-panel-item-left-text">
|
|
440
|
-
<p class="pops-panel-item-left-main-text">${formConfig.text}</p>${leftDescriptionText}</div>
|
|
441
|
-
<div class="pops-panel-slider">
|
|
442
|
-
<input type="range" min="${formConfig.min}" max="${formConfig.max}">
|
|
443
|
-
</div>
|
|
444
|
-
`
|
|
445
|
-
);
|
|
446
|
-
let $rangeInput = $li.querySelector<HTMLInputElement>(
|
|
447
|
-
".pops-panel-slider input[type=range]"
|
|
448
|
-
)!;
|
|
449
|
-
if (formConfig.step) {
|
|
450
|
-
$rangeInput.setAttribute("step", formConfig.step.toString());
|
|
451
|
-
}
|
|
452
|
-
$rangeInput.value = formConfig.getValue().toString();
|
|
453
|
-
/**
|
|
454
|
-
* 获取提示的内容
|
|
455
|
-
* @param value
|
|
456
|
-
*/
|
|
457
|
-
let getToolTipContent = function (value: number | string) {
|
|
458
|
-
if (typeof formConfig.getToolTipContent === "function") {
|
|
459
|
-
return formConfig.getToolTipContent(value as number);
|
|
460
|
-
} else {
|
|
461
|
-
return value as string;
|
|
462
|
-
}
|
|
463
|
-
};
|
|
464
|
-
let tooltip = PopsTooltip.init({
|
|
465
|
-
target: $rangeInput.parentElement!,
|
|
466
|
-
content: () => {
|
|
467
|
-
return getToolTipContent($rangeInput.value);
|
|
468
|
-
},
|
|
469
|
-
zIndex: () => {
|
|
470
|
-
return PopsInstanceUtils.getPopsMaxZIndex().zIndex;
|
|
471
|
-
},
|
|
472
|
-
className: "github-tooltip",
|
|
473
|
-
alwaysShow: false,
|
|
474
|
-
only: false,
|
|
475
|
-
position: "top",
|
|
476
|
-
arrowDistance: 10,
|
|
477
|
-
});
|
|
478
|
-
popsDOMUtils.on<InputEvent>(
|
|
479
|
-
$rangeInput,
|
|
480
|
-
["input", "propertychange"],
|
|
481
|
-
void 0,
|
|
482
|
-
function (event) {
|
|
483
|
-
tooltip.toolTip.changeContent(getToolTipContent($rangeInput.value));
|
|
484
|
-
if (typeof formConfig.callback === "function") {
|
|
485
|
-
formConfig.callback(event, $rangeInput.valueAsNumber);
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
);
|
|
489
|
-
return $li;
|
|
490
|
-
},
|
|
491
|
-
/**
|
|
492
|
-
* type ==> slider
|
|
493
|
-
* 获取中间容器的元素<li>
|
|
494
|
-
* @param formConfig
|
|
495
|
-
*/
|
|
496
|
-
createSectionContainerItem_slider_new(formConfig: PopsPanelSliderDetails) {
|
|
497
|
-
let $li = document.createElement("li");
|
|
498
|
-
Reflect.set($li, "__formConfig__", formConfig);
|
|
499
|
-
this.setElementClassName($li, formConfig.className);
|
|
500
|
-
this.setElementAttributes($li, formConfig.attributes);
|
|
501
|
-
this.setElementProps($li, formConfig.props);
|
|
502
|
-
/* 左边底部的描述的文字 */
|
|
503
|
-
let leftDescriptionText = "";
|
|
504
|
-
if (Boolean(formConfig.description)) {
|
|
505
|
-
leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
|
|
506
|
-
}
|
|
507
|
-
PopsSafeUtils.setSafeHTML(
|
|
508
|
-
$li,
|
|
509
|
-
/*html*/ `
|
|
510
|
-
<div class="pops-panel-item-left-text" style="flex: 1;">
|
|
511
|
-
<p class="pops-panel-item-left-main-text">${formConfig.text}</p>${leftDescriptionText}</div>
|
|
512
|
-
<div class="pops-slider pops-slider-width">
|
|
513
|
-
<div class="pops-slider__runway">
|
|
514
|
-
<div class="pops-slider__bar" style="width: 0%; left: 0%"></div>
|
|
515
|
-
<div class="pops-slider__button-wrapper" style="left: 0%">
|
|
516
|
-
<div class="pops-slider__button"></div>
|
|
517
|
-
</div>
|
|
518
|
-
</div>
|
|
519
|
-
</div>`
|
|
520
|
-
);
|
|
521
|
-
const PopsPanelSlider = {
|
|
522
|
-
[Symbol.toStringTag]: "PopsPanelSlider",
|
|
523
|
-
/**
|
|
524
|
-
* 值
|
|
525
|
-
*/
|
|
526
|
-
value: formConfig.getValue(),
|
|
527
|
-
/**
|
|
528
|
-
* 最小值
|
|
529
|
-
*/
|
|
530
|
-
min: formConfig.min,
|
|
531
|
-
/**
|
|
532
|
-
* 最大值
|
|
533
|
-
*/
|
|
534
|
-
max: formConfig.max,
|
|
535
|
-
/**
|
|
536
|
-
* 间隔
|
|
537
|
-
*/
|
|
538
|
-
step: formConfig.step || 1,
|
|
539
|
-
$data: {
|
|
540
|
-
/**
|
|
541
|
-
* 是否正在移动
|
|
542
|
-
*/
|
|
543
|
-
isMove: false,
|
|
544
|
-
/**
|
|
545
|
-
* 是否已初始化已拖拽的距离
|
|
546
|
-
*/
|
|
547
|
-
isInitDragPosition: false,
|
|
548
|
-
/**
|
|
549
|
-
* 是否正在检测是否停止拖拽
|
|
550
|
-
*/
|
|
551
|
-
isCheckingStopDragMove: false,
|
|
552
|
-
/**
|
|
553
|
-
* 总宽度(px)
|
|
554
|
-
*/
|
|
555
|
-
totalWidth: 0,
|
|
556
|
-
/**
|
|
557
|
-
* 每一块的间隔(px)
|
|
558
|
-
*/
|
|
559
|
-
stepPx: 0,
|
|
560
|
-
/**
|
|
561
|
-
* 已拖拽的距离(px)
|
|
562
|
-
*/
|
|
563
|
-
dragWidth: 0,
|
|
564
|
-
/**
|
|
565
|
-
* 已拖拽的百分比
|
|
566
|
-
*/
|
|
567
|
-
dragPercent: 0,
|
|
568
|
-
/**
|
|
569
|
-
* 每一次块的信息
|
|
570
|
-
* 例如:当最小值是2,最大值是10,step为2
|
|
571
|
-
* 那么生成[2,4,6,8,10] 共计5个
|
|
572
|
-
* 又获取到当前滑块总长度是200px
|
|
573
|
-
* 那么生成映射
|
|
574
|
-
* 2 => 0px~40px
|
|
575
|
-
* 4 => 40px~80px
|
|
576
|
-
* 6 => 80px~120px
|
|
577
|
-
* 8 => 120px~160px
|
|
578
|
-
* 10 => 160px~200px
|
|
579
|
-
*/
|
|
580
|
-
stepBlockMap: new Map<
|
|
581
|
-
number,
|
|
582
|
-
{
|
|
583
|
-
value: number;
|
|
584
|
-
px: number;
|
|
585
|
-
pxLeft: number;
|
|
586
|
-
pxRight: number;
|
|
587
|
-
percent: number;
|
|
588
|
-
}
|
|
589
|
-
>(),
|
|
590
|
-
tooltip: null as any as ReturnType<typeof PopsTooltip.init>,
|
|
591
|
-
},
|
|
592
|
-
$ele: {
|
|
593
|
-
itemLeftTextContainer: $li.querySelector<HTMLElement>(
|
|
594
|
-
".pops-panel-item-left-text"
|
|
595
|
-
),
|
|
596
|
-
slider: $li.querySelector<HTMLElement>(".pops-slider")!,
|
|
597
|
-
runAway: $li.querySelector<HTMLElement>(".pops-slider__runway")!,
|
|
598
|
-
bar: $li.querySelector<HTMLElement>(".pops-slider__bar")!,
|
|
599
|
-
buttonWrapper: $li.querySelector<HTMLElement>(
|
|
600
|
-
".pops-slider__button-wrapper"
|
|
601
|
-
)!,
|
|
602
|
-
button: $li.querySelector<HTMLElement>(".pops-slider__button")!,
|
|
603
|
-
},
|
|
604
|
-
$interval: {
|
|
605
|
-
isCheck: false,
|
|
606
|
-
},
|
|
607
|
-
$tooltip: null as any as ReturnType<
|
|
608
|
-
typeof popsUtils.AnyTouch
|
|
609
|
-
>["prototype"],
|
|
610
|
-
init() {
|
|
611
|
-
this.initEleData();
|
|
612
|
-
this.setToolTipEvent();
|
|
613
|
-
this.setPanEvent();
|
|
614
|
-
this.setRunAwayClickEvent();
|
|
615
|
-
this.intervalInit();
|
|
616
|
-
if (this.isFormConfigDisabledDrag()) {
|
|
617
|
-
this.disableDrag();
|
|
618
|
-
}
|
|
619
|
-
},
|
|
620
|
-
/**
|
|
621
|
-
* 10s内循环获取slider的宽度等信息
|
|
622
|
-
* 获取到了就可以初始化left的值
|
|
623
|
-
* @param [checkStepTime=200] 每次检测的间隔时间
|
|
624
|
-
* @param [maxTime=10000] 最大的检测时间
|
|
625
|
-
*/
|
|
626
|
-
intervalInit(checkStepTime = 200, maxTime = 10000) {
|
|
627
|
-
if (this.$interval.isCheck) {
|
|
628
|
-
return;
|
|
629
|
-
}
|
|
630
|
-
this.$interval.isCheck = true;
|
|
631
|
-
let isSuccess = false;
|
|
632
|
-
let oldTotalWidth = this.$data.totalWidth;
|
|
633
|
-
let timer: number | undefined = void 0;
|
|
634
|
-
let interval = setInterval(() => {
|
|
635
|
-
if (isSuccess) {
|
|
636
|
-
this.$interval.isCheck = false;
|
|
637
|
-
clearTimeout(timer);
|
|
638
|
-
clearInterval(interval);
|
|
639
|
-
} else {
|
|
640
|
-
this.initTotalWidth();
|
|
641
|
-
if (this.$data.totalWidth !== 0) {
|
|
642
|
-
isSuccess = true;
|
|
643
|
-
if (this.$data.totalWidth !== oldTotalWidth) {
|
|
644
|
-
/* slider的总宽度改变了 */
|
|
645
|
-
if (PopsMathFloatUtils.isFloat(this.step)) {
|
|
646
|
-
this.initFloatStepMap();
|
|
647
|
-
} else {
|
|
648
|
-
this.initStepMap();
|
|
649
|
-
}
|
|
650
|
-
this.initSliderPosition();
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
}, checkStepTime);
|
|
655
|
-
/* 最长检测时间是10s */
|
|
656
|
-
timer = setTimeout(() => {
|
|
657
|
-
clearInterval(interval);
|
|
658
|
-
}, maxTime);
|
|
659
|
-
},
|
|
660
|
-
/**
|
|
661
|
-
* 把数据添加到元素上
|
|
662
|
-
*/
|
|
663
|
-
initEleData() {
|
|
664
|
-
this.$ele.slider.setAttribute("data-min", this.min.toString());
|
|
665
|
-
this.$ele.slider.setAttribute("data-max", this.max.toString());
|
|
666
|
-
this.$ele.slider.setAttribute("data-value", this.value.toString());
|
|
667
|
-
this.$ele.slider.setAttribute("data-step", this.step.toString());
|
|
668
|
-
Reflect.set(this.$ele.slider, "data-min", this.min);
|
|
669
|
-
Reflect.set(this.$ele.slider, "data-max", this.max);
|
|
670
|
-
Reflect.set(this.$ele.slider, "data-value", this.value);
|
|
671
|
-
Reflect.set(this.$ele.slider, "data-step", this.step);
|
|
672
|
-
},
|
|
673
|
-
/**
|
|
674
|
-
* 初始化滑块的总长度的数据(px)
|
|
675
|
-
*/
|
|
676
|
-
initTotalWidth() {
|
|
677
|
-
this.$data.totalWidth = popsDOMUtils.width(this.$ele.runAway);
|
|
678
|
-
},
|
|
679
|
-
/**
|
|
680
|
-
* 初始化每一个块的具体数据信息
|
|
681
|
-
*/
|
|
682
|
-
initStepMap() {
|
|
683
|
-
let index = 0;
|
|
684
|
-
// 计算出份数
|
|
685
|
-
let blockNums = (this.max - this.min) / this.step;
|
|
686
|
-
// 计算出每一份占据的px
|
|
687
|
-
this.$data.stepPx = this.$data.totalWidth / blockNums;
|
|
688
|
-
let widthPx = 0;
|
|
689
|
-
for (
|
|
690
|
-
let stepValue = this.min;
|
|
691
|
-
stepValue <= this.max;
|
|
692
|
-
stepValue += this.step
|
|
693
|
-
) {
|
|
694
|
-
let value = this.formatValue(stepValue);
|
|
695
|
-
let info;
|
|
696
|
-
if (value === this.min) {
|
|
697
|
-
/* 起始 */
|
|
698
|
-
info = {
|
|
699
|
-
value: value,
|
|
700
|
-
px: 0,
|
|
701
|
-
pxLeft: 0,
|
|
702
|
-
pxRight: this.$data.stepPx / 2,
|
|
703
|
-
percent: 0,
|
|
704
|
-
};
|
|
705
|
-
} else {
|
|
706
|
-
info = {
|
|
707
|
-
value: value,
|
|
708
|
-
px: widthPx,
|
|
709
|
-
pxLeft: widthPx - this.$data.stepPx / 2,
|
|
710
|
-
pxRight: widthPx + this.$data.stepPx / 2,
|
|
711
|
-
percent: widthPx / this.$data.totalWidth,
|
|
712
|
-
};
|
|
713
|
-
//if (value === this.max) {
|
|
714
|
-
// info["pxLeft"] = this.$data.stepBlockMap.get(
|
|
715
|
-
// index - 1
|
|
716
|
-
// ).pxRight;
|
|
717
|
-
// info["pxRight"] = this.$data.totalWidth;
|
|
718
|
-
//}
|
|
719
|
-
}
|
|
720
|
-
this.$data.stepBlockMap.set(index, info);
|
|
721
|
-
index++;
|
|
722
|
-
widthPx += this.$data.stepPx;
|
|
723
|
-
}
|
|
724
|
-
},
|
|
725
|
-
/**
|
|
726
|
-
* 初始化每一个块的具体数据信息(浮点)
|
|
727
|
-
*/
|
|
728
|
-
initFloatStepMap() {
|
|
729
|
-
let index = 0;
|
|
730
|
-
// 计算出份数
|
|
731
|
-
let blockNums = (this.max - this.min) / this.step;
|
|
732
|
-
// 计算出每一份占据的px
|
|
733
|
-
this.$data.stepPx = this.$data.totalWidth / blockNums;
|
|
734
|
-
let widthPx = 0;
|
|
735
|
-
for (
|
|
736
|
-
let stepValue = this.min;
|
|
737
|
-
stepValue <= this.max;
|
|
738
|
-
stepValue = PopsMathFloatUtils.add(stepValue, this.step)
|
|
739
|
-
) {
|
|
740
|
-
let value = this.formatValue(stepValue);
|
|
741
|
-
let info;
|
|
742
|
-
if (value === this.min) {
|
|
743
|
-
/* 起始 */
|
|
744
|
-
info = {
|
|
745
|
-
value: value,
|
|
746
|
-
px: 0,
|
|
747
|
-
pxLeft: 0,
|
|
748
|
-
pxRight: this.$data.stepPx / 2,
|
|
749
|
-
percent: 0,
|
|
750
|
-
};
|
|
751
|
-
} else {
|
|
752
|
-
info = {
|
|
753
|
-
value: value,
|
|
754
|
-
px: widthPx,
|
|
755
|
-
pxLeft: widthPx - this.$data.stepPx / 2,
|
|
756
|
-
pxRight: widthPx + this.$data.stepPx / 2,
|
|
757
|
-
percent: widthPx / this.$data.totalWidth,
|
|
758
|
-
};
|
|
759
|
-
//if (value === this.max) {
|
|
760
|
-
// info["pxLeft"] = this.$data.stepBlockMap.get(
|
|
761
|
-
// index - 1
|
|
762
|
-
// ).pxRight;
|
|
763
|
-
// info["pxRight"] = this.$data.totalWidth;
|
|
764
|
-
//}
|
|
765
|
-
}
|
|
766
|
-
this.$data.stepBlockMap.set(index, info);
|
|
767
|
-
index++;
|
|
768
|
-
widthPx += this.$data.stepPx;
|
|
769
|
-
}
|
|
770
|
-
},
|
|
771
|
-
/**
|
|
772
|
-
* 初始化slider的默认起始left的百分比值
|
|
773
|
-
*/
|
|
774
|
-
initSliderPosition() {
|
|
775
|
-
/* 设置起始默认style的left值 */
|
|
776
|
-
let percent = 0;
|
|
777
|
-
for (const [, stepBlockInfo] of this.$data.stepBlockMap.entries()) {
|
|
778
|
-
/* 判断值是否和区域内的值相等 */
|
|
779
|
-
if (stepBlockInfo.value == this.value) {
|
|
780
|
-
percent = stepBlockInfo.percent;
|
|
781
|
-
this.$data.dragWidth = stepBlockInfo.px;
|
|
782
|
-
break;
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
percent = this.formatValue(percent * 100);
|
|
786
|
-
this.setSliderPosition(percent);
|
|
787
|
-
},
|
|
788
|
-
/**
|
|
789
|
-
* 判断数字是否是浮点数
|
|
790
|
-
* @param num
|
|
791
|
-
*/
|
|
792
|
-
isFloat(num: number) {
|
|
793
|
-
return Number(num) === num && num % 1 !== 0;
|
|
794
|
-
},
|
|
795
|
-
/**
|
|
796
|
-
* 值改变的回调
|
|
797
|
-
* @param event
|
|
798
|
-
* @param value
|
|
799
|
-
*/
|
|
800
|
-
valueChangeCallBack(event: any, value: number) {
|
|
801
|
-
if (typeof formConfig.callback === "function") {
|
|
802
|
-
formConfig.callback(event, value);
|
|
803
|
-
}
|
|
804
|
-
},
|
|
805
|
-
/**
|
|
806
|
-
* 根据拖拽距离获取滑块应该在的区间和值
|
|
807
|
-
* @param dragX
|
|
808
|
-
*/
|
|
809
|
-
getDragInfo(dragX: number) {
|
|
810
|
-
let result = this.$data.stepBlockMap.get(0);
|
|
811
|
-
for (const [, stepBlockInfo] of this.$data.stepBlockMap.entries()) {
|
|
812
|
-
if (
|
|
813
|
-
stepBlockInfo.pxLeft <= dragX &&
|
|
814
|
-
dragX < stepBlockInfo.pxRight
|
|
815
|
-
) {
|
|
816
|
-
result = stepBlockInfo;
|
|
817
|
-
break;
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
return result;
|
|
821
|
-
},
|
|
822
|
-
/**
|
|
823
|
-
* 获取滑块的当前脱拖拽占据的百分比
|
|
824
|
-
* @param dragWidth
|
|
825
|
-
*/
|
|
826
|
-
getSliderPositonPercent(dragWidth: number) {
|
|
827
|
-
return dragWidth / this.$data.totalWidth;
|
|
828
|
-
},
|
|
829
|
-
/**
|
|
830
|
-
* 根据step格式化value
|
|
831
|
-
* @param num
|
|
832
|
-
*/
|
|
833
|
-
formatValue(num: number) {
|
|
834
|
-
if (PopsMathFloatUtils.isFloat(this.step)) {
|
|
835
|
-
num = parseFloat(num.toFixed(2));
|
|
836
|
-
} else {
|
|
837
|
-
num = parseInt(num.toString());
|
|
838
|
-
}
|
|
839
|
-
return num;
|
|
840
|
-
},
|
|
841
|
-
/**
|
|
842
|
-
* 设置滑块的位置偏移(left)
|
|
843
|
-
* @param percent 百分比
|
|
844
|
-
*/
|
|
845
|
-
setSliderPosition(percent: number) {
|
|
846
|
-
if (parseInt(percent.toString()) === 1) {
|
|
847
|
-
percent = 1;
|
|
848
|
-
}
|
|
849
|
-
if (percent > 1) {
|
|
850
|
-
percent = percent / 100;
|
|
851
|
-
}
|
|
852
|
-
/* 滑块按钮的偏移 */
|
|
853
|
-
this.$ele.buttonWrapper.style.left = `${percent * 100}%`;
|
|
854
|
-
/* 滑块进度的宽度 */
|
|
855
|
-
this.$ele.bar.style.width = `${percent * 100}%`;
|
|
856
|
-
},
|
|
857
|
-
/**
|
|
858
|
-
* 禁止拖拽
|
|
859
|
-
*/
|
|
860
|
-
disableDrag() {
|
|
861
|
-
popsDOMUtils.addClassName(
|
|
862
|
-
this.$ele.runAway,
|
|
863
|
-
"pops-slider-is-disabled"
|
|
864
|
-
);
|
|
865
|
-
popsDOMUtils.addClassName(
|
|
866
|
-
this.$ele.runAway,
|
|
867
|
-
PopsCommonCSSClassName.textIsDisabled
|
|
868
|
-
);
|
|
869
|
-
},
|
|
870
|
-
/**
|
|
871
|
-
* 允许拖拽
|
|
872
|
-
*/
|
|
873
|
-
allowDrag() {
|
|
874
|
-
popsDOMUtils.removeClassName(
|
|
875
|
-
this.$ele.runAway,
|
|
876
|
-
"pops-slider-is-disabled"
|
|
877
|
-
);
|
|
878
|
-
popsDOMUtils.removeClassName(
|
|
879
|
-
this.$ele.runAway,
|
|
880
|
-
PopsCommonCSSClassName.textIsDisabled
|
|
881
|
-
);
|
|
882
|
-
},
|
|
883
|
-
/**
|
|
884
|
-
* 判断当前滑块是否被禁用
|
|
885
|
-
*/
|
|
886
|
-
isDisabledDrag() {
|
|
887
|
-
return popsDOMUtils.containsClassName(
|
|
888
|
-
this.$ele.runAway,
|
|
889
|
-
"pops-slider-is-disabled"
|
|
890
|
-
);
|
|
891
|
-
},
|
|
892
|
-
/**
|
|
893
|
-
* 判断当前滑块是否被禁用(配置中判断)
|
|
894
|
-
*/
|
|
895
|
-
isFormConfigDisabledDrag() {
|
|
896
|
-
let isDisabled =
|
|
897
|
-
typeof formConfig.disabled === "function"
|
|
898
|
-
? formConfig.disabled()
|
|
899
|
-
: formConfig.disabled;
|
|
900
|
-
if (typeof isDisabled === "boolean") {
|
|
901
|
-
return isDisabled;
|
|
902
|
-
} else {
|
|
903
|
-
return false;
|
|
904
|
-
}
|
|
905
|
-
},
|
|
906
|
-
/**
|
|
907
|
-
* 设置进度条点击定位的事件
|
|
908
|
-
*/
|
|
909
|
-
setRunAwayClickEvent() {
|
|
910
|
-
popsDOMUtils.on<PointerEvent | MouseEvent>(
|
|
911
|
-
this.$ele.runAway,
|
|
912
|
-
"click",
|
|
913
|
-
(event) => {
|
|
914
|
-
if (
|
|
915
|
-
event.target !== this.$ele.runAway &&
|
|
916
|
-
event.target !== this.$ele.bar
|
|
917
|
-
) {
|
|
918
|
-
return;
|
|
919
|
-
}
|
|
920
|
-
let clickX = parseFloat(event.offsetX.toString());
|
|
921
|
-
let dragStartResult = this.dragStartCallBack();
|
|
922
|
-
if (!dragStartResult) {
|
|
923
|
-
return;
|
|
924
|
-
}
|
|
925
|
-
this.dragMoveCallBack(event, clickX, this.value);
|
|
926
|
-
this.dragEndCallBack(clickX);
|
|
927
|
-
},
|
|
928
|
-
{
|
|
929
|
-
capture: false,
|
|
930
|
-
}
|
|
931
|
-
);
|
|
932
|
-
},
|
|
933
|
-
/**
|
|
934
|
-
* 拖拽开始的回调,如果返回false,禁止拖拽
|
|
935
|
-
*/
|
|
936
|
-
dragStartCallBack() {
|
|
937
|
-
if (this.isFormConfigDisabledDrag()) {
|
|
938
|
-
// 禁止
|
|
939
|
-
this.disableDrag();
|
|
940
|
-
return false;
|
|
941
|
-
}
|
|
942
|
-
if (!this.$data.isMove) {
|
|
943
|
-
// 非移动中
|
|
944
|
-
if (this.isDisabledDrag()) {
|
|
945
|
-
// 允许
|
|
946
|
-
this.allowDrag();
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
this.$data.isMove = true;
|
|
950
|
-
}
|
|
951
|
-
return true;
|
|
952
|
-
},
|
|
953
|
-
/**
|
|
954
|
-
* 拖拽中的回调
|
|
955
|
-
* @param event 事件
|
|
956
|
-
* @param dragX 当前拖拽的距离
|
|
957
|
-
* @param oldValue 旧的值
|
|
958
|
-
*/
|
|
959
|
-
dragMoveCallBack(event: any, dragX: number, oldValue: number) {
|
|
960
|
-
let dragPercent = 0;
|
|
961
|
-
if (dragX <= 0) {
|
|
962
|
-
dragPercent = 0;
|
|
963
|
-
this.value = this.min;
|
|
964
|
-
} else if (dragX >= this.$data.totalWidth) {
|
|
965
|
-
dragPercent = 1;
|
|
966
|
-
this.value = this.max;
|
|
967
|
-
} else {
|
|
968
|
-
const dragInfo = this.getDragInfo(dragX)!;
|
|
969
|
-
dragPercent = dragInfo.percent;
|
|
970
|
-
this.value = this.formatValue(dragInfo.value);
|
|
971
|
-
}
|
|
972
|
-
this.$data.dragPercent = dragPercent;
|
|
973
|
-
this.setSliderPosition(this.$data.dragPercent);
|
|
974
|
-
this.showToolTip();
|
|
975
|
-
if (oldValue !== this.value) {
|
|
976
|
-
this.valueChangeCallBack(event, this.value);
|
|
977
|
-
}
|
|
978
|
-
},
|
|
979
|
-
/**
|
|
980
|
-
* 拖拽结束的回调
|
|
981
|
-
*/
|
|
982
|
-
dragEndCallBack(dragX: number) {
|
|
983
|
-
this.$data.isMove = false;
|
|
984
|
-
if (dragX <= 0) {
|
|
985
|
-
this.$data.dragWidth = 0;
|
|
986
|
-
} else if (dragX >= this.$data.totalWidth) {
|
|
987
|
-
this.$data.dragWidth = this.$data.totalWidth;
|
|
988
|
-
} else {
|
|
989
|
-
this.$data.dragWidth = dragX;
|
|
990
|
-
}
|
|
991
|
-
this.closeToolTip();
|
|
992
|
-
},
|
|
993
|
-
/**
|
|
994
|
-
* 设置点击拖拽事件
|
|
995
|
-
*/
|
|
996
|
-
setPanEvent() {
|
|
997
|
-
const AnyTouch = popsUtils.AnyTouch();
|
|
998
|
-
this.$tooltip = new AnyTouch(this.$ele.button, {
|
|
999
|
-
preventDefault() {
|
|
1000
|
-
return false;
|
|
1001
|
-
},
|
|
1002
|
-
});
|
|
1003
|
-
/**
|
|
1004
|
-
* 当前的拖拽的距离px
|
|
1005
|
-
*/
|
|
1006
|
-
let currentDragX = 0;
|
|
1007
|
-
/* 监听拖拽 */
|
|
1008
|
-
this.$tooltip.on("at:move", (event) => {
|
|
1009
|
-
if (!this.dragStartCallBack()) {
|
|
1010
|
-
return;
|
|
1011
|
-
}
|
|
1012
|
-
let oldValue = this.value;
|
|
1013
|
-
const runAwayRect = this.$ele.runAway.getBoundingClientRect();
|
|
1014
|
-
let displacementX =
|
|
1015
|
-
event.x - (runAwayRect.left + globalThis.screenX);
|
|
1016
|
-
if (displacementX <= 0) {
|
|
1017
|
-
displacementX = 0;
|
|
1018
|
-
} else if (displacementX >= runAwayRect.width) {
|
|
1019
|
-
displacementX = runAwayRect.width;
|
|
1020
|
-
}
|
|
1021
|
-
currentDragX = displacementX;
|
|
1022
|
-
/* 拖拽移动 */
|
|
1023
|
-
this.dragMoveCallBack(event, currentDragX, oldValue);
|
|
1024
|
-
});
|
|
1025
|
-
/* 监听触点离开,处理某些情况下,拖拽松开,但是未触发pan事件,可以通过设置这个来关闭tooltip */
|
|
1026
|
-
this.$tooltip.on("at:end", (event) => {
|
|
1027
|
-
this.dragEndCallBack(currentDragX);
|
|
1028
|
-
});
|
|
1029
|
-
},
|
|
1030
|
-
/**
|
|
1031
|
-
* 显示悬浮的
|
|
1032
|
-
*/
|
|
1033
|
-
showToolTip() {
|
|
1034
|
-
this.$data.tooltip.toolTip.show();
|
|
1035
|
-
},
|
|
1036
|
-
/**
|
|
1037
|
-
* 关闭悬浮的
|
|
1038
|
-
*/
|
|
1039
|
-
closeToolTip() {
|
|
1040
|
-
this.$data.tooltip.toolTip.close();
|
|
1041
|
-
},
|
|
1042
|
-
/**
|
|
1043
|
-
* 检测在1000ms内,是否停止了拖拽
|
|
1044
|
-
*/
|
|
1045
|
-
checkStopDragMove() {
|
|
1046
|
-
if (this.$data.isCheckingStopDragMove) {
|
|
1047
|
-
return;
|
|
1048
|
-
}
|
|
1049
|
-
this.$data.isCheckingStopDragMove = true;
|
|
1050
|
-
let interval = setInterval(() => {
|
|
1051
|
-
if (!this.$data.isMove) {
|
|
1052
|
-
this.$data.isCheckingStopDragMove = false;
|
|
1053
|
-
this.closeToolTip();
|
|
1054
|
-
clearInterval(interval);
|
|
1055
|
-
}
|
|
1056
|
-
}, 200);
|
|
1057
|
-
setTimeout(() => {
|
|
1058
|
-
this.$data.isCheckingStopDragMove = false;
|
|
1059
|
-
clearInterval(interval);
|
|
1060
|
-
}, 2000);
|
|
1061
|
-
},
|
|
1062
|
-
/**
|
|
1063
|
-
* 设置拖拽按钮的悬浮事件
|
|
1064
|
-
*/
|
|
1065
|
-
setToolTipEvent() {
|
|
1066
|
-
/**
|
|
1067
|
-
* 获取提示的内容
|
|
1068
|
-
*/
|
|
1069
|
-
function getToolTipContent() {
|
|
1070
|
-
if (typeof formConfig.getToolTipContent === "function") {
|
|
1071
|
-
return formConfig.getToolTipContent(PopsPanelSlider.value);
|
|
1072
|
-
} else {
|
|
1073
|
-
return PopsPanelSlider.value.toString();
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
let tooltip = PopsTooltip.init({
|
|
1078
|
-
target: this.$ele.button,
|
|
1079
|
-
content: getToolTipContent,
|
|
1080
|
-
zIndex: () => {
|
|
1081
|
-
return PopsInstanceUtils.getPopsMaxZIndex().zIndex;
|
|
1082
|
-
},
|
|
1083
|
-
isFixed: true,
|
|
1084
|
-
className: "github-tooltip",
|
|
1085
|
-
only: false,
|
|
1086
|
-
eventOption: {
|
|
1087
|
-
capture: true,
|
|
1088
|
-
passive: true,
|
|
1089
|
-
},
|
|
1090
|
-
showBeforeCallBack: () => {
|
|
1091
|
-
let isShowHoverTip =
|
|
1092
|
-
typeof formConfig.isShowHoverTip === "function"
|
|
1093
|
-
? formConfig.isShowHoverTip()
|
|
1094
|
-
: typeof formConfig.isShowHoverTip === "boolean"
|
|
1095
|
-
? formConfig.isShowHoverTip
|
|
1096
|
-
: true;
|
|
1097
|
-
if (!isShowHoverTip) {
|
|
1098
|
-
return false;
|
|
1099
|
-
}
|
|
1100
|
-
this.intervalInit();
|
|
1101
|
-
},
|
|
1102
|
-
showAfterCallBack: (toolTipNode) => {
|
|
1103
|
-
tooltip.toolTip.changeContent(getToolTipContent());
|
|
1104
|
-
},
|
|
1105
|
-
closeBeforeCallBack: () => {
|
|
1106
|
-
if (this.$data.isMove) {
|
|
1107
|
-
this.checkStopDragMove();
|
|
1108
|
-
return false;
|
|
1109
|
-
} else {
|
|
1110
|
-
}
|
|
1111
|
-
},
|
|
1112
|
-
alwaysShow: false,
|
|
1113
|
-
position: "top",
|
|
1114
|
-
arrowDistance: 10,
|
|
1115
|
-
});
|
|
1116
|
-
this.$data.tooltip = tooltip;
|
|
1117
|
-
},
|
|
1118
|
-
};
|
|
1119
|
-
PopsPanelSlider.init();
|
|
1120
|
-
Reflect.set($li, "data-slider", PopsPanelSlider);
|
|
1121
|
-
return $li;
|
|
1122
|
-
},
|
|
1123
|
-
/**
|
|
1124
|
-
* type ==> input
|
|
1125
|
-
* 获取中间容器的元素<li>
|
|
1126
|
-
* @param formConfig
|
|
1127
|
-
*/
|
|
1128
|
-
createSectionContainerItem_input(formConfig: PopsPanelInputDetails) {
|
|
1129
|
-
let $li = document.createElement("li");
|
|
1130
|
-
Reflect.set($li, "__formConfig__", formConfig);
|
|
1131
|
-
this.setElementClassName($li, formConfig.className);
|
|
1132
|
-
this.setElementAttributes($li, formConfig.attributes);
|
|
1133
|
-
this.setElementProps($li, formConfig.props);
|
|
1134
|
-
let inputType = "text";
|
|
1135
|
-
if (formConfig.isPassword) {
|
|
1136
|
-
inputType = "password";
|
|
1137
|
-
} else if (formConfig.isNumber) {
|
|
1138
|
-
inputType = "number";
|
|
1139
|
-
}
|
|
1140
|
-
/* 左边底部的描述的文字 */
|
|
1141
|
-
let leftDescriptionText = "";
|
|
1142
|
-
if (Boolean(formConfig.description)) {
|
|
1143
|
-
leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
|
|
1144
|
-
}
|
|
1145
|
-
PopsSafeUtils.setSafeHTML(
|
|
1146
|
-
$li,
|
|
1147
|
-
/*html*/ `
|
|
1148
|
-
<div class="pops-panel-item-left-text">
|
|
1149
|
-
<p class="pops-panel-item-left-main-text">${
|
|
1150
|
-
formConfig.text
|
|
1151
|
-
}</p>${leftDescriptionText}</div>
|
|
1152
|
-
<div class="pops-panel-input">
|
|
1153
|
-
<input type="${inputType}" placeholder="${formConfig.placeholder ?? ""}">
|
|
1154
|
-
</div>
|
|
1155
|
-
`
|
|
1156
|
-
);
|
|
1157
|
-
const PopsPanelInput = {
|
|
1158
|
-
[Symbol.toStringTag]: "PopsPanelInput",
|
|
1159
|
-
$ele: {
|
|
1160
|
-
itemLeftTextContainer: $li.querySelector<HTMLElement>(
|
|
1161
|
-
".pops-panel-item-left-text"
|
|
1162
|
-
),
|
|
1163
|
-
panelInput: $li.querySelector<HTMLDivElement>(".pops-panel-input")!,
|
|
1164
|
-
input: $li.querySelector<HTMLInputElement>("input")!,
|
|
1165
|
-
inputSpanIcon: document.createElement("span"),
|
|
1166
|
-
inputSpanIconInner: null as any as HTMLSpanElement,
|
|
1167
|
-
icon: null as any as HTMLElement,
|
|
1168
|
-
},
|
|
1169
|
-
$data: {
|
|
1170
|
-
value: formConfig.getValue(),
|
|
1171
|
-
isView: false,
|
|
1172
|
-
},
|
|
1173
|
-
init() {
|
|
1174
|
-
this.initEle();
|
|
1175
|
-
this.setInputValue(this.$data.value);
|
|
1176
|
-
/* 如果是密码框,放进图标 */
|
|
1177
|
-
if (formConfig.isPassword) {
|
|
1178
|
-
this.setCircleIcon(PopsIcon.getIcon("view")!);
|
|
1179
|
-
this.setCircleIconClickEvent();
|
|
1180
|
-
} else {
|
|
1181
|
-
/* 先判断预设值是否为空,不为空添加清空图标按钮 */
|
|
1182
|
-
if (this.$ele.input.value != "") {
|
|
1183
|
-
this.setCircleIcon(PopsIcon.getIcon("circleClose")!);
|
|
1184
|
-
this.setCircleIconClickEvent();
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
this.setInputChangeEvent();
|
|
1189
|
-
// 是否禁用复选框
|
|
1190
|
-
let disabled =
|
|
1191
|
-
typeof formConfig.disabled === "function"
|
|
1192
|
-
? formConfig.disabled()
|
|
1193
|
-
: formConfig.disabled;
|
|
1194
|
-
if (disabled) {
|
|
1195
|
-
this.disable();
|
|
1196
|
-
}
|
|
1197
|
-
if (typeof formConfig.handlerCallBack === "function") {
|
|
1198
|
-
formConfig.handlerCallBack($li, this.$ele.input);
|
|
1199
|
-
}
|
|
1200
|
-
},
|
|
1201
|
-
/**
|
|
1202
|
-
* 初始化$ele的配置
|
|
1203
|
-
*/
|
|
1204
|
-
initEle() {
|
|
1205
|
-
this.$ele.input.parentElement!.insertBefore(
|
|
1206
|
-
this.$ele.inputSpanIcon,
|
|
1207
|
-
this.$ele.input.nextSibling
|
|
1208
|
-
);
|
|
1209
|
-
this.$ele.inputSpanIcon.className = "pops-panel-input__suffix";
|
|
1210
|
-
PopsSafeUtils.setSafeHTML(
|
|
1211
|
-
this.$ele.inputSpanIcon,
|
|
1212
|
-
/*html*/ `
|
|
1213
|
-
<span class="pops-panel-input__suffix-inner">
|
|
1214
|
-
<i class="pops-panel-icon"></i>
|
|
1215
|
-
</span>
|
|
1216
|
-
`
|
|
1217
|
-
);
|
|
1218
|
-
this.$ele.inputSpanIconInner =
|
|
1219
|
-
this.$ele.inputSpanIcon.querySelector<HTMLElement>(
|
|
1220
|
-
".pops-panel-input__suffix-inner"
|
|
1221
|
-
)!;
|
|
1222
|
-
this.$ele.icon =
|
|
1223
|
-
this.$ele.inputSpanIcon.querySelector<HTMLElement>(
|
|
1224
|
-
".pops-panel-icon"
|
|
1225
|
-
)!;
|
|
1226
|
-
popsDOMUtils.addClassName(
|
|
1227
|
-
this.$ele.panelInput,
|
|
1228
|
-
PopsCommonCSSClassName.userSelectNone
|
|
1229
|
-
);
|
|
1230
|
-
},
|
|
1231
|
-
/**
|
|
1232
|
-
* 禁用
|
|
1233
|
-
*/
|
|
1234
|
-
disable() {
|
|
1235
|
-
this.$ele.input.disabled = true;
|
|
1236
|
-
popsDOMUtils.addClassName(
|
|
1237
|
-
this.$ele.panelInput,
|
|
1238
|
-
"pops-input-disabled"
|
|
1239
|
-
);
|
|
1240
|
-
popsDOMUtils.addClassName(
|
|
1241
|
-
this.$ele.itemLeftTextContainer,
|
|
1242
|
-
PopsCommonCSSClassName.textIsDisabled
|
|
1243
|
-
);
|
|
1244
|
-
},
|
|
1245
|
-
/**
|
|
1246
|
-
* 取消禁用
|
|
1247
|
-
*/
|
|
1248
|
-
notDisable() {
|
|
1249
|
-
this.$ele.input.disabled = false;
|
|
1250
|
-
popsDOMUtils.removeClassName(
|
|
1251
|
-
this.$ele.panelInput,
|
|
1252
|
-
"pops-input-disabled"
|
|
1253
|
-
);
|
|
1254
|
-
popsDOMUtils.removeClassName(
|
|
1255
|
-
this.$ele.itemLeftTextContainer,
|
|
1256
|
-
PopsCommonCSSClassName.textIsDisabled
|
|
1257
|
-
);
|
|
1258
|
-
},
|
|
1259
|
-
/**
|
|
1260
|
-
* 判断是否已被禁用
|
|
1261
|
-
*/
|
|
1262
|
-
isDisabled() {
|
|
1263
|
-
return this.$ele.input.disabled;
|
|
1264
|
-
},
|
|
1265
|
-
/**
|
|
1266
|
-
* 设置输入框内容
|
|
1267
|
-
* @param {string} [value=""] 值
|
|
1268
|
-
*/
|
|
1269
|
-
setInputValue(value = "") {
|
|
1270
|
-
this.$ele.input.value = value;
|
|
1271
|
-
},
|
|
1272
|
-
/**
|
|
1273
|
-
* 设置input元素的type
|
|
1274
|
-
* @param [typeValue="text"] type值
|
|
1275
|
-
*/
|
|
1276
|
-
setInputType(typeValue = "text") {
|
|
1277
|
-
this.$ele.input.setAttribute("type", typeValue);
|
|
1278
|
-
},
|
|
1279
|
-
/**
|
|
1280
|
-
* 删除图标按钮
|
|
1281
|
-
*/
|
|
1282
|
-
removeCircleIcon() {
|
|
1283
|
-
PopsSafeUtils.setSafeHTML(this.$ele.icon, "");
|
|
1284
|
-
},
|
|
1285
|
-
/**
|
|
1286
|
-
* 添加清空图标按钮
|
|
1287
|
-
* @param [svgHTML=PopsIcon.getIcon("circleClose")] svg图标,默认为清空的图标
|
|
1288
|
-
*/
|
|
1289
|
-
setCircleIcon(svgHTML = PopsIcon.getIcon("circleClose")!) {
|
|
1290
|
-
PopsSafeUtils.setSafeHTML(this.$ele.icon, svgHTML);
|
|
1291
|
-
},
|
|
1292
|
-
/**
|
|
1293
|
-
* 添加图标按钮的点击事件
|
|
1294
|
-
*/
|
|
1295
|
-
setCircleIconClickEvent() {
|
|
1296
|
-
popsDOMUtils.on(this.$ele.icon, "click", void 0, () => {
|
|
1297
|
-
if (this.isDisabled()) {
|
|
1298
|
-
return;
|
|
1299
|
-
}
|
|
1300
|
-
/* 删除图标 */
|
|
1301
|
-
this.removeCircleIcon();
|
|
1302
|
-
if (formConfig.isPassword) {
|
|
1303
|
-
/* 密码输入框 */
|
|
1304
|
-
if (this.$data.isView) {
|
|
1305
|
-
/* 当前可见 => 点击改变为隐藏 */
|
|
1306
|
-
this.$data.isView = false;
|
|
1307
|
-
/* 显示输入框内容,且更换图标为隐藏图标 */
|
|
1308
|
-
this.setInputType("text");
|
|
1309
|
-
this.setCircleIcon(PopsIcon.getIcon("hide")!);
|
|
1310
|
-
} else {
|
|
1311
|
-
/* 当前不可见 => 点击改变为显示 */
|
|
1312
|
-
this.$data.isView = true;
|
|
1313
|
-
/* 隐藏输入框内容,且更换图标为显示图标 */
|
|
1314
|
-
this.setInputType("password");
|
|
1315
|
-
this.setCircleIcon(PopsIcon.getIcon("view")!);
|
|
1316
|
-
}
|
|
1317
|
-
} else {
|
|
1318
|
-
/* 普通输入框 */
|
|
1319
|
-
/* 清空内容 */
|
|
1320
|
-
this.setInputValue("");
|
|
1321
|
-
/* 获取焦点 */
|
|
1322
|
-
this.$ele.input.focus();
|
|
1323
|
-
/* 触发内容改变事件 */
|
|
1324
|
-
this.$ele.input.dispatchEvent(new Event("input"));
|
|
1325
|
-
}
|
|
1326
|
-
});
|
|
1327
|
-
},
|
|
1328
|
-
/**
|
|
1329
|
-
* 监听输入框内容改变
|
|
1330
|
-
*/
|
|
1331
|
-
setInputChangeEvent() {
|
|
1332
|
-
popsDOMUtils.on<InputEvent>(
|
|
1333
|
-
this.$ele.input,
|
|
1334
|
-
["input", "propertychange"],
|
|
1335
|
-
void 0,
|
|
1336
|
-
(event) => {
|
|
1337
|
-
this.$data.value = this.$ele.input.value;
|
|
1338
|
-
if (!formConfig.isPassword) {
|
|
1339
|
-
/* 不是密码框 */
|
|
1340
|
-
if (
|
|
1341
|
-
this.$ele.input.value !== "" &&
|
|
1342
|
-
this.$ele.icon.innerHTML === ""
|
|
1343
|
-
) {
|
|
1344
|
-
/* 不为空,显示清空图标 */
|
|
1345
|
-
this.setCircleIcon(PopsIcon.getIcon("circleClose")!);
|
|
1346
|
-
this.setCircleIconClickEvent();
|
|
1347
|
-
} else if (this.$ele.input.value === "") {
|
|
1348
|
-
this.removeCircleIcon();
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
if (typeof formConfig.callback === "function") {
|
|
1352
|
-
if (formConfig.isNumber) {
|
|
1353
|
-
formConfig.callback(
|
|
1354
|
-
event,
|
|
1355
|
-
this.$ele.input.value,
|
|
1356
|
-
this.$ele.input.valueAsNumber
|
|
1357
|
-
);
|
|
1358
|
-
} else {
|
|
1359
|
-
formConfig.callback(event, this.$ele.input.value);
|
|
1360
|
-
}
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
);
|
|
1364
|
-
},
|
|
1365
|
-
};
|
|
1366
|
-
PopsPanelInput.init();
|
|
1367
|
-
Reflect.set($li, "data-input", PopsPanelInput);
|
|
1368
|
-
return $li;
|
|
1369
|
-
},
|
|
1370
|
-
/**
|
|
1371
|
-
* type ==> textarea
|
|
1372
|
-
* 获取中间容器的元素<li>
|
|
1373
|
-
* @param formConfig
|
|
1374
|
-
*/
|
|
1375
|
-
createSectionContainerItem_textarea(formConfig: PopsPanelTextAreaDetails) {
|
|
1376
|
-
let $li = document.createElement("li");
|
|
1377
|
-
Reflect.set($li, "__formConfig__", formConfig);
|
|
1378
|
-
this.setElementClassName($li, formConfig.className);
|
|
1379
|
-
this.setElementAttributes($li, formConfig.attributes);
|
|
1380
|
-
this.setElementProps($li, formConfig.props);
|
|
1381
|
-
|
|
1382
|
-
/* 左边底部的描述的文字 */
|
|
1383
|
-
let leftDescriptionText = "";
|
|
1384
|
-
if (Boolean(formConfig.description)) {
|
|
1385
|
-
leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
|
|
1386
|
-
}
|
|
1387
|
-
PopsSafeUtils.setSafeHTML(
|
|
1388
|
-
$li,
|
|
1389
|
-
/*html*/ `
|
|
1390
|
-
<div class="pops-panel-item-left-text">
|
|
1391
|
-
<p class="pops-panel-item-left-main-text">${
|
|
1392
|
-
formConfig.text
|
|
1393
|
-
}</p>${leftDescriptionText}</div>
|
|
1394
|
-
<div class="pops-panel-textarea">
|
|
1395
|
-
<textarea placeholder="${formConfig.placeholder ?? ""}"></textarea>
|
|
1396
|
-
</div>
|
|
1397
|
-
`
|
|
1398
|
-
);
|
|
1399
|
-
|
|
1400
|
-
const PopsPanelTextArea = {
|
|
1401
|
-
[Symbol.toStringTag]: "PopsPanelTextArea",
|
|
1402
|
-
$ele: {
|
|
1403
|
-
itemLeftTextContainer: $li.querySelector<HTMLElement>(
|
|
1404
|
-
".pops-panel-item-left-text"
|
|
1405
|
-
),
|
|
1406
|
-
panelTextarea: $li.querySelector<HTMLDivElement>(
|
|
1407
|
-
".pops-panel-textarea"
|
|
1408
|
-
)!,
|
|
1409
|
-
textarea: $li.querySelector<HTMLTextAreaElement>(
|
|
1410
|
-
".pops-panel-textarea textarea"
|
|
1411
|
-
)!,
|
|
1412
|
-
},
|
|
1413
|
-
$data: {
|
|
1414
|
-
value: formConfig.getValue(),
|
|
1415
|
-
},
|
|
1416
|
-
init() {
|
|
1417
|
-
this.setValue(this.$data.value);
|
|
1418
|
-
this.setChangeEvent();
|
|
1419
|
-
let disabled =
|
|
1420
|
-
typeof formConfig.disabled === "function"
|
|
1421
|
-
? formConfig.disabled()
|
|
1422
|
-
: formConfig.disabled;
|
|
1423
|
-
if (disabled) {
|
|
1424
|
-
this.disable();
|
|
1425
|
-
}
|
|
1426
|
-
},
|
|
1427
|
-
disable() {
|
|
1428
|
-
this.$ele.textarea.setAttribute("disabled", "true");
|
|
1429
|
-
popsDOMUtils.addClassName(
|
|
1430
|
-
this.$ele.panelTextarea,
|
|
1431
|
-
"pops-panel-textarea-disable"
|
|
1432
|
-
);
|
|
1433
|
-
popsDOMUtils.addClassName(
|
|
1434
|
-
this.$ele.itemLeftTextContainer,
|
|
1435
|
-
PopsCommonCSSClassName.textIsDisabled
|
|
1436
|
-
);
|
|
1437
|
-
},
|
|
1438
|
-
notDisable() {
|
|
1439
|
-
this.$ele.textarea.removeAttribute("disabled");
|
|
1440
|
-
popsDOMUtils.removeClassName(
|
|
1441
|
-
this.$ele.panelTextarea,
|
|
1442
|
-
"pops-panel-textarea-disable"
|
|
1443
|
-
);
|
|
1444
|
-
popsDOMUtils.removeClassName(
|
|
1445
|
-
this.$ele.itemLeftTextContainer,
|
|
1446
|
-
PopsCommonCSSClassName.textIsDisabled
|
|
1447
|
-
);
|
|
1448
|
-
},
|
|
1449
|
-
isDisabled() {
|
|
1450
|
-
return (
|
|
1451
|
-
this.$ele.textarea.hasAttribute("disabled") ||
|
|
1452
|
-
popsDOMUtils.containsClassName(
|
|
1453
|
-
this.$ele.panelTextarea,
|
|
1454
|
-
"pops-panel-textarea-disable"
|
|
1455
|
-
)
|
|
1456
|
-
);
|
|
1457
|
-
},
|
|
1458
|
-
setValue(value: string) {
|
|
1459
|
-
this.$ele.textarea.value = value;
|
|
1460
|
-
},
|
|
1461
|
-
/**
|
|
1462
|
-
* 监听选择内容改变
|
|
1463
|
-
*/
|
|
1464
|
-
setChangeEvent() {
|
|
1465
|
-
popsDOMUtils.on<InputEvent>(
|
|
1466
|
-
this.$ele.textarea,
|
|
1467
|
-
["input", "propertychange"],
|
|
1468
|
-
(event) => {
|
|
1469
|
-
let value = this.$ele.textarea.value;
|
|
1470
|
-
this.$data.value = value;
|
|
1471
|
-
if (typeof formConfig.callback === "function") {
|
|
1472
|
-
formConfig.callback(
|
|
1473
|
-
event as InputEvent & {
|
|
1474
|
-
target: HTMLTextAreaElement;
|
|
1475
|
-
},
|
|
1476
|
-
value
|
|
1477
|
-
);
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
);
|
|
1481
|
-
},
|
|
1482
|
-
};
|
|
1483
|
-
|
|
1484
|
-
PopsPanelTextArea.init();
|
|
1485
|
-
Reflect.set($li, "data-textarea", PopsPanelTextArea);
|
|
1486
|
-
|
|
1487
|
-
return $li;
|
|
1488
|
-
},
|
|
1489
|
-
/**
|
|
1490
|
-
* type ==> select
|
|
1491
|
-
* 获取中间容器的元素<li>
|
|
1492
|
-
* @param formConfig
|
|
1493
|
-
*/
|
|
1494
|
-
createSectionContainerItem_select(formConfig: PopsPanelSelectDetails<any>) {
|
|
1495
|
-
const that = this;
|
|
1496
|
-
let $li = document.createElement("li");
|
|
1497
|
-
Reflect.set($li, "__formConfig__", formConfig);
|
|
1498
|
-
this.setElementClassName($li, formConfig.className);
|
|
1499
|
-
this.setElementAttributes($li, formConfig.attributes);
|
|
1500
|
-
this.setElementProps($li, formConfig.props);
|
|
1501
|
-
/* 左边底部的描述的文字 */
|
|
1502
|
-
let leftDescriptionText = "";
|
|
1503
|
-
if (Boolean(formConfig.description)) {
|
|
1504
|
-
leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
|
|
1505
|
-
}
|
|
1506
|
-
PopsSafeUtils.setSafeHTML(
|
|
1507
|
-
$li,
|
|
1508
|
-
/*html*/ `
|
|
1509
|
-
<div class="pops-panel-item-left-text">
|
|
1510
|
-
<p class="pops-panel-item-left-main-text">${formConfig.text}</p>${leftDescriptionText}</div>
|
|
1511
|
-
<div class="pops-panel-select">
|
|
1512
|
-
<select></select>
|
|
1513
|
-
</div>
|
|
1514
|
-
`
|
|
1515
|
-
);
|
|
1516
|
-
|
|
1517
|
-
const PopsPanelSelect = {
|
|
1518
|
-
[Symbol.toStringTag]: "PopsPanelSelect",
|
|
1519
|
-
$ele: {
|
|
1520
|
-
itemLeftTextContainer: $li.querySelector<HTMLElement>(
|
|
1521
|
-
".pops-panel-item-left-text"
|
|
1522
|
-
),
|
|
1523
|
-
panelSelect: $li.querySelector<HTMLDivElement>(".pops-panel-select")!,
|
|
1524
|
-
select: $li.querySelector<HTMLSelectElement>(
|
|
1525
|
-
".pops-panel-select select"
|
|
1526
|
-
)!,
|
|
1527
|
-
},
|
|
1528
|
-
$eleKey: {
|
|
1529
|
-
disable: "__disable__",
|
|
1530
|
-
value: "__value__",
|
|
1531
|
-
forms: "__forms__",
|
|
1532
|
-
},
|
|
1533
|
-
$data: {
|
|
1534
|
-
defaultValue: formConfig.getValue(),
|
|
1535
|
-
},
|
|
1536
|
-
init() {
|
|
1537
|
-
popsDOMUtils.addClassName(
|
|
1538
|
-
this.$ele.panelSelect,
|
|
1539
|
-
PopsCommonCSSClassName.userSelectNone
|
|
1540
|
-
);
|
|
1541
|
-
this.initOption();
|
|
1542
|
-
this.setChangeEvent();
|
|
1543
|
-
this.setClickEvent();
|
|
1544
|
-
let disabled =
|
|
1545
|
-
typeof formConfig.disabled === "function"
|
|
1546
|
-
? formConfig.disabled()
|
|
1547
|
-
: formConfig.disabled;
|
|
1548
|
-
if (disabled) {
|
|
1549
|
-
this.disable();
|
|
1550
|
-
}
|
|
1551
|
-
},
|
|
1552
|
-
/**
|
|
1553
|
-
* 给option元素设置属性
|
|
1554
|
-
* @param $ele
|
|
1555
|
-
* @param key
|
|
1556
|
-
* @param value
|
|
1557
|
-
*/
|
|
1558
|
-
setNodeValue($ele: HTMLElement, key: string, value: any) {
|
|
1559
|
-
Reflect.set($ele, key, value);
|
|
1560
|
-
},
|
|
1561
|
-
/**
|
|
1562
|
-
* 获取option元素上设置的属性
|
|
1563
|
-
* @param $ele
|
|
1564
|
-
* @param value
|
|
1565
|
-
* @param key
|
|
1566
|
-
*/
|
|
1567
|
-
getNodeValue($ele: HTMLElement, key: string) {
|
|
1568
|
-
return Reflect.get($ele, key);
|
|
1569
|
-
},
|
|
1570
|
-
/**
|
|
1571
|
-
* 禁用选项
|
|
1572
|
-
*/
|
|
1573
|
-
disable() {
|
|
1574
|
-
this.$ele.select.setAttribute("disabled", "true");
|
|
1575
|
-
popsDOMUtils.addClassName(
|
|
1576
|
-
this.$ele.panelSelect,
|
|
1577
|
-
"pops-panel-select-disable"
|
|
1578
|
-
);
|
|
1579
|
-
popsDOMUtils.addClassName(
|
|
1580
|
-
this.$ele.itemLeftTextContainer,
|
|
1581
|
-
PopsCommonCSSClassName.textIsDisabled
|
|
1582
|
-
);
|
|
1583
|
-
},
|
|
1584
|
-
/**
|
|
1585
|
-
* 取消禁用
|
|
1586
|
-
*/
|
|
1587
|
-
notDisable() {
|
|
1588
|
-
this.$ele.select.removeAttribute("disabled");
|
|
1589
|
-
popsDOMUtils.removeClassName(
|
|
1590
|
-
this.$ele.panelSelect,
|
|
1591
|
-
"pops-panel-select-disable"
|
|
1592
|
-
);
|
|
1593
|
-
popsDOMUtils.removeClassName(
|
|
1594
|
-
this.$ele.itemLeftTextContainer,
|
|
1595
|
-
PopsCommonCSSClassName.textIsDisabled
|
|
1596
|
-
);
|
|
1597
|
-
},
|
|
1598
|
-
/**
|
|
1599
|
-
* 判断是否禁用
|
|
1600
|
-
*/
|
|
1601
|
-
isDisabled() {
|
|
1602
|
-
return (
|
|
1603
|
-
this.$ele.select.hasAttribute("disabled") ||
|
|
1604
|
-
popsDOMUtils.containsClassName(
|
|
1605
|
-
this.$ele.panelSelect,
|
|
1606
|
-
"pops-panel-select-disable"
|
|
1607
|
-
)
|
|
1608
|
-
);
|
|
1609
|
-
},
|
|
1610
|
-
/**
|
|
1611
|
-
* 初始化选项
|
|
1612
|
-
*/
|
|
1613
|
-
initOption() {
|
|
1614
|
-
formConfig.data.forEach((dataItem) => {
|
|
1615
|
-
// 初始化默认选中
|
|
1616
|
-
let optionElement = document.createElement("option");
|
|
1617
|
-
this.setNodeValue(
|
|
1618
|
-
optionElement,
|
|
1619
|
-
this.$eleKey.value,
|
|
1620
|
-
dataItem.value
|
|
1621
|
-
);
|
|
1622
|
-
this.setNodeValue(
|
|
1623
|
-
optionElement,
|
|
1624
|
-
this.$eleKey.disable,
|
|
1625
|
-
dataItem.disable
|
|
1626
|
-
);
|
|
1627
|
-
this.setNodeValue(
|
|
1628
|
-
optionElement,
|
|
1629
|
-
this.$eleKey.forms,
|
|
1630
|
-
dataItem.forms
|
|
1631
|
-
);
|
|
1632
|
-
if (dataItem.value === this.$data.defaultValue) {
|
|
1633
|
-
this.setOptionSelected(optionElement);
|
|
1634
|
-
}
|
|
1635
|
-
optionElement.innerText = dataItem.text;
|
|
1636
|
-
this.$ele.select.appendChild(optionElement);
|
|
1637
|
-
});
|
|
1638
|
-
},
|
|
1639
|
-
/**
|
|
1640
|
-
* 设置选项选中
|
|
1641
|
-
*/
|
|
1642
|
-
setOptionSelected($option: HTMLOptionElement) {
|
|
1643
|
-
$option.setAttribute("selected", "true");
|
|
1644
|
-
},
|
|
1645
|
-
/** 检测所有option并设置禁用状态 */
|
|
1646
|
-
setSelectOptionsDisableStatus() {
|
|
1647
|
-
if (this.$ele.select.options && this.$ele.select.options.length) {
|
|
1648
|
-
Array.from(this.$ele.select.options).forEach((optionItem) => {
|
|
1649
|
-
this.setOptionDisableStatus(optionItem);
|
|
1650
|
-
});
|
|
1651
|
-
}
|
|
1652
|
-
},
|
|
1653
|
-
/** 设置禁用状态 */
|
|
1654
|
-
setOptionDisableStatus(optionElement: HTMLOptionElement) {
|
|
1655
|
-
let disable = false;
|
|
1656
|
-
let optionDisableAttr = this.getNodeValue(
|
|
1657
|
-
optionElement,
|
|
1658
|
-
this.$eleKey.disable
|
|
1659
|
-
);
|
|
1660
|
-
if (optionDisableAttr === "function") {
|
|
1661
|
-
let value = this.getNodeValue(optionElement, this.$eleKey.value);
|
|
1662
|
-
disable = Boolean(optionDisableAttr(value));
|
|
1663
|
-
}
|
|
1664
|
-
if (disable) {
|
|
1665
|
-
optionElement.setAttribute("disabled", "true");
|
|
1666
|
-
} else {
|
|
1667
|
-
optionElement.removeAttribute("disabled");
|
|
1668
|
-
}
|
|
1669
|
-
},
|
|
1670
|
-
/** 获取option上的信息 */
|
|
1671
|
-
getSelectOptionInfo($option: HTMLOptionElement) {
|
|
1672
|
-
let optionValue = this.getNodeValue($option, this.$eleKey.value);
|
|
1673
|
-
let optionText = $option.innerText || $option.textContent!;
|
|
1674
|
-
let optionForms = this.getNodeValue(
|
|
1675
|
-
$option,
|
|
1676
|
-
this.$eleKey.forms
|
|
1677
|
-
) as (typeof formConfig.data)[0]["forms"];
|
|
1678
|
-
return {
|
|
1679
|
-
value: optionValue,
|
|
1680
|
-
text: optionText,
|
|
1681
|
-
forms: optionForms,
|
|
1682
|
-
$option: $option,
|
|
1683
|
-
};
|
|
1684
|
-
},
|
|
1685
|
-
/**
|
|
1686
|
-
* 监听选择内容改变
|
|
1687
|
-
*/
|
|
1688
|
-
setChangeEvent() {
|
|
1689
|
-
popsDOMUtils.on<PointerEvent | TouchEvent>(
|
|
1690
|
-
this.$ele.select,
|
|
1691
|
-
"change",
|
|
1692
|
-
void 0,
|
|
1693
|
-
(event) => {
|
|
1694
|
-
let $isSelectedElement = this.$ele.select[
|
|
1695
|
-
this.$ele.select.selectedIndex
|
|
1696
|
-
] as HTMLOptionElement;
|
|
1697
|
-
let selectInfo = this.getSelectOptionInfo($isSelectedElement);
|
|
1698
|
-
this.setSelectOptionsDisableStatus();
|
|
1699
|
-
if (typeof formConfig.callback === "function") {
|
|
1700
|
-
formConfig.callback(event, selectInfo.value, selectInfo.text);
|
|
1701
|
-
}
|
|
1702
|
-
let forms =
|
|
1703
|
-
typeof selectInfo.forms === "function"
|
|
1704
|
-
? selectInfo.forms()
|
|
1705
|
-
: selectInfo.forms;
|
|
1706
|
-
if (Array.isArray(forms)) {
|
|
1707
|
-
/* 如果成功创建,加入到中间容器中 */
|
|
1708
|
-
let childUListClassName = "pops-panel-select-child-forms";
|
|
1709
|
-
// 移除旧的元素
|
|
1710
|
-
while ($li.nextElementSibling) {
|
|
1711
|
-
if (
|
|
1712
|
-
$li.nextElementSibling.classList.contains(
|
|
1713
|
-
childUListClassName
|
|
1714
|
-
)
|
|
1715
|
-
) {
|
|
1716
|
-
$li.nextElementSibling.remove();
|
|
1717
|
-
} else {
|
|
1718
|
-
break;
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
let $childUList = document.createElement("ul");
|
|
1722
|
-
$childUList.className = childUListClassName;
|
|
1723
|
-
popsDOMUtils.after($li, $childUList);
|
|
1724
|
-
that.uListContainerAddItem(formConfig, {
|
|
1725
|
-
ulElement: $childUList,
|
|
1726
|
-
});
|
|
1727
|
-
}
|
|
1728
|
-
}
|
|
1729
|
-
);
|
|
1730
|
-
},
|
|
1731
|
-
/**
|
|
1732
|
-
* 监听点击事件
|
|
1733
|
-
*/
|
|
1734
|
-
setClickEvent() {
|
|
1735
|
-
popsDOMUtils.on(this.$ele.select, "click", void 0, (event) => {
|
|
1736
|
-
this.setSelectOptionsDisableStatus();
|
|
1737
|
-
if (typeof formConfig.clickCallBack === "function") {
|
|
1738
|
-
formConfig.clickCallBack(event, this.$ele.select);
|
|
1739
|
-
}
|
|
1740
|
-
});
|
|
1741
|
-
},
|
|
1742
|
-
};
|
|
1743
|
-
|
|
1744
|
-
PopsPanelSelect.init();
|
|
1745
|
-
Reflect.set($li, "data-select", PopsPanelSelect);
|
|
1746
|
-
return $li;
|
|
1747
|
-
},
|
|
1748
|
-
/**
|
|
1749
|
-
* type ==> select-multiple
|
|
1750
|
-
* 获取中间容器的元素<li>
|
|
1751
|
-
* @param formConfig
|
|
1752
|
-
*/
|
|
1753
|
-
createSectionContainerItem_select_multiple_new(
|
|
1754
|
-
formConfig: PopsPanelSelectMultipleDetails<any>
|
|
1755
|
-
) {
|
|
1756
|
-
let $li = document.createElement("li");
|
|
1757
|
-
Reflect.set($li, "__formConfig__", formConfig);
|
|
1758
|
-
this.setElementClassName($li, formConfig.className);
|
|
1759
|
-
this.setElementAttributes($li, formConfig.attributes);
|
|
1760
|
-
this.setElementProps($li, formConfig.props);
|
|
1761
|
-
/* 左边底部的描述的文字 */
|
|
1762
|
-
let leftDescriptionText = "";
|
|
1763
|
-
if (Boolean(formConfig.description)) {
|
|
1764
|
-
leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
|
|
1765
|
-
}
|
|
1766
|
-
PopsSafeUtils.setSafeHTML(
|
|
1767
|
-
$li,
|
|
1768
|
-
/*html*/ `
|
|
1769
|
-
<div class="pops-panel-item-left-text">
|
|
1770
|
-
<p class="pops-panel-item-left-main-text">${formConfig.text}</p>${leftDescriptionText}</div>
|
|
1771
|
-
<div class="pops-panel-select-multiple">
|
|
1772
|
-
<div class="el-select__wrapper">
|
|
1773
|
-
<div class="el-select__selection">
|
|
1774
|
-
<!-- 这个是用于手动输入的,这里暂不适配 -->
|
|
1775
|
-
<div class="el-select__selected-item el-select__input-wrapper">
|
|
1776
|
-
|
|
1777
|
-
</div>
|
|
1778
|
-
<!-- 这个是placeholder -->
|
|
1779
|
-
<div class="el-select__selected-item el-select__placeholder">
|
|
1780
|
-
</div>
|
|
1781
|
-
</div>
|
|
1782
|
-
<!-- 下拉箭头 -->
|
|
1783
|
-
<div class="el-select__suffix">
|
|
1784
|
-
<i class="el-icon el-select__caret el-select__icon">
|
|
1785
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
|
|
1786
|
-
<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>
|
|
1787
|
-
</svg>
|
|
1788
|
-
</i>
|
|
1789
|
-
</div>
|
|
1790
|
-
</div>
|
|
1791
|
-
</div>
|
|
1792
|
-
`
|
|
1793
|
-
);
|
|
1794
|
-
const PopsPanelSelectMultiple = {
|
|
1795
|
-
[Symbol.toStringTag]: "PopsPanelSelectMultiple",
|
|
1796
|
-
$el: {
|
|
1797
|
-
/** 左侧文本容器 */
|
|
1798
|
-
itemLeftTextContainer: $li.querySelector<HTMLElement>(
|
|
1799
|
-
".pops-panel-item-left-text"
|
|
1800
|
-
),
|
|
1801
|
-
/** 容器 */
|
|
1802
|
-
$container: void 0 as any as HTMLElement,
|
|
1803
|
-
/** 包括的容器 */
|
|
1804
|
-
$wrapper: void 0 as any as HTMLElement,
|
|
1805
|
-
/** 内容区域 */
|
|
1806
|
-
$section: void 0 as any as HTMLElement,
|
|
1807
|
-
/** 手动输入 */
|
|
1808
|
-
$selectedInputWrapper: void 0 as any as HTMLElement,
|
|
1809
|
-
/** 灰色提示语 */
|
|
1810
|
-
$selectedPlaceHolderWrapper: void 0 as any as HTMLElement,
|
|
1811
|
-
/** 下拉箭头区域 */
|
|
1812
|
-
$suffix: void 0 as any as HTMLElement,
|
|
1813
|
-
/** 下拉箭头图标 */
|
|
1814
|
-
$suffixIcon: void 0 as any as HTMLElement,
|
|
1815
|
-
/** 下拉列表弹窗的下拉列表容器 */
|
|
1816
|
-
$selectContainer: void 0 as any as HTMLElement | null,
|
|
1817
|
-
},
|
|
1818
|
-
$data: {
|
|
1819
|
-
/** 默认值 */
|
|
1820
|
-
defaultValue: formConfig.getValue(),
|
|
1821
|
-
selectInfo: [] as any as PopsPanelSelectMultipleDataOption<any>[],
|
|
1822
|
-
},
|
|
1823
|
-
/** 初始化 */
|
|
1824
|
-
init() {
|
|
1825
|
-
this.initDefault();
|
|
1826
|
-
this.inintEl();
|
|
1827
|
-
this.initPlaceHolder();
|
|
1828
|
-
this.initTagElement();
|
|
1829
|
-
this.setSelectContainerClickEvent();
|
|
1830
|
-
|
|
1831
|
-
let disabled =
|
|
1832
|
-
typeof formConfig.disabled === "function"
|
|
1833
|
-
? formConfig.disabled()
|
|
1834
|
-
: formConfig.disabled;
|
|
1835
|
-
if (disabled) {
|
|
1836
|
-
this.disable();
|
|
1837
|
-
}
|
|
1838
|
-
},
|
|
1839
|
-
/** 初始化默认值 */
|
|
1840
|
-
initDefault() {
|
|
1841
|
-
formConfig.data.forEach((dataItem) => {
|
|
1842
|
-
if (this.$data.defaultValue.includes(dataItem.value)) {
|
|
1843
|
-
// 初始化选中的配置
|
|
1844
|
-
this.$data.selectInfo.push({
|
|
1845
|
-
text: dataItem.text,
|
|
1846
|
-
value: dataItem.value,
|
|
1847
|
-
isHTML: Boolean(dataItem.isHTML),
|
|
1848
|
-
disable: dataItem.disable?.bind(dataItem),
|
|
1849
|
-
});
|
|
1850
|
-
}
|
|
1851
|
-
});
|
|
1852
|
-
},
|
|
1853
|
-
/** 初始化$el变量 */
|
|
1854
|
-
inintEl() {
|
|
1855
|
-
this.$el.$container = $li.querySelector<HTMLElement>(
|
|
1856
|
-
".pops-panel-select-multiple"
|
|
1857
|
-
)!;
|
|
1858
|
-
this.$el.$wrapper = $li.querySelector<HTMLElement>(
|
|
1859
|
-
".el-select__wrapper"
|
|
1860
|
-
)!;
|
|
1861
|
-
this.$el.$section = $li.querySelector<HTMLElement>(
|
|
1862
|
-
".el-select__selection"
|
|
1863
|
-
)!;
|
|
1864
|
-
this.$el.$selectedInputWrapper = $li.querySelector<HTMLElement>(
|
|
1865
|
-
".el-select__selected-item.el-select__input-wrapper"
|
|
1866
|
-
)!;
|
|
1867
|
-
this.$el.$selectedPlaceHolderWrapper = $li.querySelector<HTMLElement>(
|
|
1868
|
-
".el-select__selected-item.el-select__placeholder"
|
|
1869
|
-
)!;
|
|
1870
|
-
this.$el.$suffix =
|
|
1871
|
-
$li.querySelector<HTMLElement>(".el-select__suffix")!;
|
|
1872
|
-
this.$el.$suffixIcon = $li.querySelector<HTMLElement>(
|
|
1873
|
-
".el-select__suffix .el-icon"
|
|
1874
|
-
)!;
|
|
1875
|
-
|
|
1876
|
-
// 先把手动输入框隐藏
|
|
1877
|
-
this.hideInputWrapper();
|
|
1878
|
-
},
|
|
1879
|
-
/** 初始化提示文字 */
|
|
1880
|
-
initPlaceHolder() {
|
|
1881
|
-
let placeholder = "";
|
|
1882
|
-
if (typeof formConfig.placeholder === "string") {
|
|
1883
|
-
placeholder = formConfig.placeholder;
|
|
1884
|
-
} else if (typeof formConfig.placeholder === "function") {
|
|
1885
|
-
let placeholderResult = formConfig.placeholder();
|
|
1886
|
-
if (typeof placeholderResult === "string") {
|
|
1887
|
-
placeholder = placeholderResult;
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
let $placeholder = popsDOMUtils.createElement("span", {
|
|
1891
|
-
innerText: placeholder,
|
|
1892
|
-
});
|
|
1893
|
-
this.$el.$selectedPlaceHolderWrapper.appendChild($placeholder);
|
|
1894
|
-
},
|
|
1895
|
-
/** 初始化tag元素 */
|
|
1896
|
-
initTagElement() {
|
|
1897
|
-
// 遍历数据,寻找对应的值
|
|
1898
|
-
formConfig.data.forEach((dataItem) => {
|
|
1899
|
-
let findValue = this.$data.selectInfo.find(
|
|
1900
|
-
(item) => item.value === dataItem.value
|
|
1901
|
-
);
|
|
1902
|
-
if (findValue) {
|
|
1903
|
-
// 存在对应的值
|
|
1904
|
-
let selectedInfo = this.createSelectedTagItem(dataItem);
|
|
1905
|
-
this.addSelectedTagItem(selectedInfo.$tag);
|
|
1906
|
-
this.setSelectedItemCloseIconClickEvent({
|
|
1907
|
-
$tag: selectedInfo.$tag,
|
|
1908
|
-
$closeIcon: selectedInfo.$closeIcon,
|
|
1909
|
-
value: dataItem.value,
|
|
1910
|
-
text: dataItem.text,
|
|
1911
|
-
});
|
|
1912
|
-
}
|
|
1913
|
-
});
|
|
1914
|
-
this.checkTagEmpty();
|
|
1915
|
-
},
|
|
1916
|
-
/**
|
|
1917
|
-
* 生成一个tag项
|
|
1918
|
-
* @param data 配置
|
|
1919
|
-
*/
|
|
1920
|
-
createSelectedTagItem(data: PopsPanelSelectMultipleDataOption<any>) {
|
|
1921
|
-
const $selectedItem = popsDOMUtils.createElement("div", {
|
|
1922
|
-
className: "el-select__selected-item el-select__choose_tag",
|
|
1923
|
-
innerHTML: /*html*/ `
|
|
1924
|
-
<span class="el-tag is-closable el-tag--info el-tag--default el-tag--light">
|
|
1925
|
-
<span class="el-tag__content">
|
|
1926
|
-
<span class="el-select__tags-text"></span>
|
|
1927
|
-
</span>
|
|
1928
|
-
<!-- 关闭tag的图标 -->
|
|
1929
|
-
<i class="el-icon el-tag__close">
|
|
1930
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
|
|
1931
|
-
<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>
|
|
1932
|
-
</svg>
|
|
1933
|
-
</i>
|
|
1934
|
-
</span>
|
|
1935
|
-
`,
|
|
1936
|
-
});
|
|
1937
|
-
/** 标签 */
|
|
1938
|
-
const $tagText = $selectedItem.querySelector<HTMLSpanElement>(
|
|
1939
|
-
".el-select__tags-text"
|
|
1940
|
-
)!;
|
|
1941
|
-
/** 关闭图标 */
|
|
1942
|
-
const $closeIcon = $selectedItem.querySelector<HTMLElement>(
|
|
1943
|
-
".el-icon.el-tag__close"
|
|
1944
|
-
)!;
|
|
1945
|
-
let text =
|
|
1946
|
-
typeof data.text === "function"
|
|
1947
|
-
? data.text(data, this.$data.selectInfo)
|
|
1948
|
-
: data.text;
|
|
1949
|
-
if (data.isHTML) {
|
|
1950
|
-
PopsSafeUtils.setSafeHTML($tagText, text);
|
|
1951
|
-
} else {
|
|
1952
|
-
$tagText.innerText = text;
|
|
1953
|
-
}
|
|
1954
|
-
|
|
1955
|
-
return {
|
|
1956
|
-
$tag: $selectedItem,
|
|
1957
|
-
$tagText: $tagText,
|
|
1958
|
-
$closeIcon: $closeIcon,
|
|
1959
|
-
};
|
|
1960
|
-
},
|
|
1961
|
-
/**
|
|
1962
|
-
* 添加选中项的tag元素
|
|
1963
|
-
* @param $tag 添加的元素
|
|
1964
|
-
*/
|
|
1965
|
-
addSelectedTagItem($tag: HTMLElement) {
|
|
1966
|
-
// 往前添加
|
|
1967
|
-
// 去除前面的空白
|
|
1968
|
-
this.setSectionIsNear();
|
|
1969
|
-
if (this.$el.$section.contains(this.$el.$selectedInputWrapper)) {
|
|
1970
|
-
let $prev = this.$el.$selectedInputWrapper.previousElementSibling;
|
|
1971
|
-
if ($prev) {
|
|
1972
|
-
// 存在前一个元素,添加到前面的元素的后面
|
|
1973
|
-
popsDOMUtils.after($prev, $tag);
|
|
1974
|
-
} else {
|
|
1975
|
-
// 不存在前一个元素,添加到最前面
|
|
1976
|
-
popsDOMUtils.before(this.$el.$selectedInputWrapper, $tag);
|
|
1977
|
-
}
|
|
1978
|
-
} else if (
|
|
1979
|
-
this.$el.$section.contains(this.$el.$selectedPlaceHolderWrapper)
|
|
1980
|
-
) {
|
|
1981
|
-
let $prev =
|
|
1982
|
-
this.$el.$selectedPlaceHolderWrapper.previousElementSibling;
|
|
1983
|
-
if ($prev) {
|
|
1984
|
-
// 存在前一个元素,添加到前面的元素的后面
|
|
1985
|
-
popsDOMUtils.after($prev, $tag);
|
|
1986
|
-
} else {
|
|
1987
|
-
// 不存在前一个元素,添加到最前面
|
|
1988
|
-
popsDOMUtils.before(this.$el.$selectedPlaceHolderWrapper, $tag);
|
|
1989
|
-
}
|
|
1990
|
-
} else {
|
|
1991
|
-
this.$el.$section.appendChild($tag);
|
|
1992
|
-
}
|
|
1993
|
-
// 隐藏元素
|
|
1994
|
-
this.hideInputWrapper();
|
|
1995
|
-
this.hidePlaceHolderWrapper();
|
|
1996
|
-
},
|
|
1997
|
-
/** 更新tag信息 */
|
|
1998
|
-
updateSelectTagItem() {
|
|
1999
|
-
this.$el.$section
|
|
2000
|
-
.querySelectorAll<HTMLElement>(".el-select__choose_tag")
|
|
2001
|
-
.forEach(($ele) => {
|
|
2002
|
-
$ele.remove();
|
|
2003
|
-
});
|
|
2004
|
-
this.initTagElement();
|
|
2005
|
-
},
|
|
2006
|
-
/**
|
|
2007
|
-
* 选中的值改变的回调
|
|
2008
|
-
* @param selectedDataList 当前的选中信息
|
|
2009
|
-
*/
|
|
2010
|
-
selectValueChangeCallBack(
|
|
2011
|
-
selectedDataList?: PopsPanelSelectMultipleDataOption<any>[]
|
|
2012
|
-
) {
|
|
2013
|
-
// 动态更新禁用状态
|
|
2014
|
-
this.updateSelectItem();
|
|
2015
|
-
if (typeof formConfig.callback === "function") {
|
|
2016
|
-
formConfig.callback(selectedDataList || this.$data.selectInfo);
|
|
2017
|
-
}
|
|
2018
|
-
},
|
|
2019
|
-
/**
|
|
2020
|
-
* 更新选项弹窗内的所有选项元素的状态
|
|
2021
|
-
*
|
|
2022
|
-
* + 更新禁用状态
|
|
2023
|
-
* + 更新选中状态
|
|
2024
|
-
*/
|
|
2025
|
-
updateSelectItem() {
|
|
2026
|
-
this.getAllSelectItemInfo(false).forEach(($selectInfo) => {
|
|
2027
|
-
const { data, $select } = $selectInfo;
|
|
2028
|
-
// 更新文字
|
|
2029
|
-
this.setSelectItemText(data, $selectInfo.$select);
|
|
2030
|
-
// 更新禁用状态
|
|
2031
|
-
if (
|
|
2032
|
-
typeof data.disable === "function" &&
|
|
2033
|
-
data.disable(data.value, this.$data.selectInfo)
|
|
2034
|
-
) {
|
|
2035
|
-
// 禁用
|
|
2036
|
-
this.setSelectItemDisabled($select);
|
|
2037
|
-
// 移除选中信息
|
|
2038
|
-
this.removeSelectedInfo(data, false);
|
|
2039
|
-
// 移除选中状态
|
|
2040
|
-
this.removeSelectItemSelected($select);
|
|
2041
|
-
} else {
|
|
2042
|
-
// 取消禁用
|
|
2043
|
-
this.removeSelectItemDisabled($select);
|
|
2044
|
-
}
|
|
2045
|
-
// 更新选中状态
|
|
2046
|
-
let findValue = this.$data.selectInfo.find(
|
|
2047
|
-
(it) => it.value === data.value
|
|
2048
|
-
);
|
|
2049
|
-
if (findValue) {
|
|
2050
|
-
this.setSelectItemSelected($select);
|
|
2051
|
-
} else {
|
|
2052
|
-
this.removeSelectItemSelected($select);
|
|
2053
|
-
}
|
|
2054
|
-
});
|
|
2055
|
-
},
|
|
2056
|
-
/**
|
|
2057
|
-
* 设置选项元素选中
|
|
2058
|
-
* @param $select 选项元素
|
|
2059
|
-
*/
|
|
2060
|
-
setSelectItemSelected($select: HTMLElement) {
|
|
2061
|
-
if (this.isSelectItemSelected($select)) return;
|
|
2062
|
-
$select.classList.add("select-item-is-selected");
|
|
2063
|
-
},
|
|
2064
|
-
/**
|
|
2065
|
-
* 移除选项元素选中
|
|
2066
|
-
* @param $select 选项元素
|
|
2067
|
-
*/
|
|
2068
|
-
removeSelectItemSelected($select: HTMLElement) {
|
|
2069
|
-
$select.classList.remove("select-item-is-selected");
|
|
2070
|
-
},
|
|
2071
|
-
/**
|
|
2072
|
-
* 判断选项元素是否选中
|
|
2073
|
-
* @param $select
|
|
2074
|
-
*/
|
|
2075
|
-
isSelectItemSelected($select: HTMLElement): boolean {
|
|
2076
|
-
return $select.classList.contains("select-item-is-selected");
|
|
2077
|
-
},
|
|
2078
|
-
/**
|
|
2079
|
-
* 添加选中信息
|
|
2080
|
-
* @param dataList 选择项列表的数据
|
|
2081
|
-
* @param $select 选项元素
|
|
2082
|
-
*/
|
|
2083
|
-
addSelectedItemInfo(
|
|
2084
|
-
dataList: PopsPanelSelectMultipleDataOption<any>[],
|
|
2085
|
-
$select: HTMLElement
|
|
2086
|
-
) {
|
|
2087
|
-
let info = this.getSelectedItemInfo($select);
|
|
2088
|
-
let findValue = dataList.find((item) => item.value === info.value);
|
|
2089
|
-
if (!findValue) {
|
|
2090
|
-
dataList.push({
|
|
2091
|
-
value: info.value,
|
|
2092
|
-
text: info.text,
|
|
2093
|
-
isHTML: Boolean(info.isHTML),
|
|
2094
|
-
disable: info.disable?.bind(info),
|
|
2095
|
-
});
|
|
2096
|
-
}
|
|
2097
|
-
this.selectValueChangeCallBack(dataList);
|
|
2098
|
-
},
|
|
2099
|
-
/**
|
|
2100
|
-
* 获取选中的项的信息
|
|
2101
|
-
* @param $select 选项元素
|
|
2102
|
-
*/
|
|
2103
|
-
getSelectedItemInfo($select: HTMLElement) {
|
|
2104
|
-
return Reflect.get(
|
|
2105
|
-
$select,
|
|
2106
|
-
"data-info"
|
|
2107
|
-
) as PopsPanelSelectMultipleDataOption<any>;
|
|
2108
|
-
},
|
|
2109
|
-
/**
|
|
2110
|
-
* 移除选中信息
|
|
2111
|
-
* @param dataList 选择项的数据
|
|
2112
|
-
* @param $select 选项元素
|
|
2113
|
-
*/
|
|
2114
|
-
removeSelectedItemInfo(
|
|
2115
|
-
dataList: PopsPanelSelectMultipleDataOption<any>[],
|
|
2116
|
-
$select: HTMLElement
|
|
2117
|
-
) {
|
|
2118
|
-
let info = this.getSelectedItemInfo($select);
|
|
2119
|
-
let findIndex = dataList.findIndex(
|
|
2120
|
-
(item) => item.value === info.value
|
|
2121
|
-
);
|
|
2122
|
-
if (findIndex !== -1) {
|
|
2123
|
-
dataList.splice(findIndex, 1);
|
|
2124
|
-
}
|
|
2125
|
-
this.selectValueChangeCallBack(dataList);
|
|
2126
|
-
},
|
|
2127
|
-
/**
|
|
2128
|
-
* 获取所有选项的信息
|
|
2129
|
-
* @param [onlySelected=true] 是否仅获取选中的项的信息
|
|
2130
|
-
* + true (默认)仅获取选中项的信息
|
|
2131
|
-
* + false 获取所有选择项的信息
|
|
2132
|
-
*/
|
|
2133
|
-
getAllSelectItemInfo(onlySelected: boolean = true) {
|
|
2134
|
-
return Array.from(
|
|
2135
|
-
this.$el.$selectContainer?.querySelectorAll<HTMLElement>(
|
|
2136
|
-
".select-item"
|
|
2137
|
-
) ?? []
|
|
2138
|
-
)
|
|
2139
|
-
.map(($select) => {
|
|
2140
|
-
let data = this.getSelectedItemInfo($select);
|
|
2141
|
-
let result = {
|
|
2142
|
-
/** 选项信息数据 */
|
|
2143
|
-
data: data,
|
|
2144
|
-
/** 选项元素 */
|
|
2145
|
-
$select: $select,
|
|
2146
|
-
};
|
|
2147
|
-
if (onlySelected) {
|
|
2148
|
-
// 仅选中
|
|
2149
|
-
let isSelected = this.isSelectItemSelected($select);
|
|
2150
|
-
if (isSelected) {
|
|
2151
|
-
return result;
|
|
2152
|
-
}
|
|
2153
|
-
return;
|
|
2154
|
-
} else {
|
|
2155
|
-
return result;
|
|
2156
|
-
}
|
|
2157
|
-
})
|
|
2158
|
-
.filter((item) => {
|
|
2159
|
-
return item != null;
|
|
2160
|
-
});
|
|
2161
|
-
},
|
|
2162
|
-
/**
|
|
2163
|
-
* 创建一个选择项元素
|
|
2164
|
-
* @param data 选择项的数据
|
|
2165
|
-
*/
|
|
2166
|
-
createSelectItemElement(data: PopsPanelSelectMultipleDataOption<any>) {
|
|
2167
|
-
let $select = popsDOMUtils.createElement("li", {
|
|
2168
|
-
className: "select-item",
|
|
2169
|
-
innerHTML: /*html*/ `
|
|
2170
|
-
<span class="select-item-text"></span>
|
|
2171
|
-
`,
|
|
2172
|
-
});
|
|
2173
|
-
this.setSelectItemText(data, $select);
|
|
2174
|
-
Reflect.set($select, "data-info", data);
|
|
2175
|
-
return $select;
|
|
2176
|
-
},
|
|
2177
|
-
/**
|
|
2178
|
-
* 设置选择项的文字
|
|
2179
|
-
* @param data 选择项的数据
|
|
2180
|
-
* @param $select 选择项元素
|
|
2181
|
-
*/
|
|
2182
|
-
setSelectItemText(
|
|
2183
|
-
data: PopsPanelSelectMultipleDataOption<any>,
|
|
2184
|
-
$select: HTMLElement
|
|
2185
|
-
) {
|
|
2186
|
-
let text =
|
|
2187
|
-
typeof data.text === "function"
|
|
2188
|
-
? data.text(data.value, this.$data.selectInfo)
|
|
2189
|
-
: data.text;
|
|
2190
|
-
let $selectSpan =
|
|
2191
|
-
$select.querySelector<HTMLElement>(".select-item-text")!;
|
|
2192
|
-
if (data.isHTML) {
|
|
2193
|
-
PopsSafeUtils.setSafeHTML($selectSpan, text);
|
|
2194
|
-
} else {
|
|
2195
|
-
$selectSpan.innerText = text;
|
|
2196
|
-
}
|
|
2197
|
-
},
|
|
2198
|
-
/**
|
|
2199
|
-
* 设置选择项的禁用状态
|
|
2200
|
-
* @param $select 选择项元素
|
|
2201
|
-
*/
|
|
2202
|
-
setSelectItemDisabled($select: HTMLElement) {
|
|
2203
|
-
$select.setAttribute("aria-disabled", "true");
|
|
2204
|
-
$select.setAttribute("disabled", "true");
|
|
2205
|
-
},
|
|
2206
|
-
/**
|
|
2207
|
-
* 移除选择项的禁用状态
|
|
2208
|
-
* @param $select 选择项元素
|
|
2209
|
-
*/
|
|
2210
|
-
removeSelectItemDisabled($select: HTMLElement) {
|
|
2211
|
-
$select.removeAttribute("aria-disabled");
|
|
2212
|
-
$select.removeAttribute("disabled");
|
|
2213
|
-
},
|
|
2214
|
-
/**
|
|
2215
|
-
* 判断选择项是否禁用
|
|
2216
|
-
* @param $select 选择项元素
|
|
2217
|
-
*/
|
|
2218
|
-
isSelectItemDisabled($select: HTMLElement) {
|
|
2219
|
-
return $select.hasAttribute("disabled") || $select.ariaDisabled;
|
|
2220
|
-
},
|
|
2221
|
-
/**
|
|
2222
|
-
* 设置选择项的点击事件
|
|
2223
|
-
* @param dataList 选中的信息列表
|
|
2224
|
-
* @param $select 选择项元素
|
|
2225
|
-
*/
|
|
2226
|
-
setSelectElementClickEvent(
|
|
2227
|
-
dataList: PopsPanelSelectMultipleDataOption<any>[],
|
|
2228
|
-
$select: HTMLElement
|
|
2229
|
-
) {
|
|
2230
|
-
popsDOMUtils.on<PointerEvent | MouseEvent>(
|
|
2231
|
-
$select,
|
|
2232
|
-
"click",
|
|
2233
|
-
(event) => {
|
|
2234
|
-
popsDOMUtils.preventEvent(event);
|
|
2235
|
-
if (this.isSelectItemDisabled($select)) {
|
|
2236
|
-
return;
|
|
2237
|
-
}
|
|
2238
|
-
if (typeof formConfig.clickCallBack === "function") {
|
|
2239
|
-
let allSelectedInfo = this.getAllSelectItemInfo().map(
|
|
2240
|
-
(it) => it.data
|
|
2241
|
-
);
|
|
2242
|
-
let clickResult = formConfig.clickCallBack(
|
|
2243
|
-
event,
|
|
2244
|
-
allSelectedInfo
|
|
2245
|
-
);
|
|
2246
|
-
if (typeof clickResult === "boolean" && !clickResult) {
|
|
2247
|
-
return;
|
|
2248
|
-
}
|
|
2249
|
-
}
|
|
2250
|
-
// 修改选中状态
|
|
2251
|
-
if (this.isSelectItemSelected($select)) {
|
|
2252
|
-
this.removeSelectItemSelected($select);
|
|
2253
|
-
this.removeSelectedItemInfo(dataList, $select);
|
|
2254
|
-
} else {
|
|
2255
|
-
this.setSelectItemSelected($select);
|
|
2256
|
-
this.addSelectedItemInfo(dataList, $select);
|
|
2257
|
-
}
|
|
2258
|
-
}
|
|
2259
|
-
);
|
|
2260
|
-
},
|
|
2261
|
-
/**
|
|
2262
|
-
* 设置下拉列表的点击事件
|
|
2263
|
-
*/
|
|
2264
|
-
setSelectContainerClickEvent() {
|
|
2265
|
-
const that = this;
|
|
2266
|
-
popsDOMUtils.on(this.$el.$container, "click", (event) => {
|
|
2267
|
-
if (this.isDisabled()) {
|
|
2268
|
-
return;
|
|
2269
|
-
}
|
|
2270
|
-
/** 弹窗的选中的值 */
|
|
2271
|
-
let selectedInfo = that.$data.selectInfo;
|
|
2272
|
-
let { style, ...userConfirmDetails } =
|
|
2273
|
-
formConfig.selectConfirmDialogDetails || {};
|
|
2274
|
-
let confirmDetails = popsUtils.assign(
|
|
2275
|
-
{
|
|
2276
|
-
title: {
|
|
2277
|
-
text: "请勾选需要选择的选项",
|
|
2278
|
-
position: "center",
|
|
2279
|
-
},
|
|
2280
|
-
content: {
|
|
2281
|
-
text: /*html*/ `
|
|
2282
|
-
<ul class="select-container"></ul>
|
|
2283
|
-
`,
|
|
2284
|
-
html: true,
|
|
2285
|
-
},
|
|
2286
|
-
btn: {
|
|
2287
|
-
ok: {
|
|
2288
|
-
enable: false,
|
|
2289
|
-
},
|
|
2290
|
-
close: {
|
|
2291
|
-
enable: true,
|
|
2292
|
-
callback(details, event) {
|
|
2293
|
-
that.$data.selectInfo = [...selectedInfo];
|
|
2294
|
-
that.updateSelectTagItem();
|
|
2295
|
-
that.$el.$selectContainer = null;
|
|
2296
|
-
details.close();
|
|
2297
|
-
},
|
|
2298
|
-
},
|
|
2299
|
-
},
|
|
2300
|
-
mask: {
|
|
2301
|
-
enable: true,
|
|
2302
|
-
clickCallBack(originalRun, config) {
|
|
2303
|
-
originalRun();
|
|
2304
|
-
that.$data.selectInfo = [...selectedInfo];
|
|
2305
|
-
that.updateSelectTagItem();
|
|
2306
|
-
that.$el.$selectContainer = null;
|
|
2307
|
-
},
|
|
2308
|
-
clickEvent: {
|
|
2309
|
-
toClose: true,
|
|
2310
|
-
},
|
|
2311
|
-
},
|
|
2312
|
-
drag: true,
|
|
2313
|
-
dragLimit: true,
|
|
2314
|
-
width: "300px",
|
|
2315
|
-
height: "300px",
|
|
2316
|
-
style: /*css*/ `
|
|
2317
|
-
.select-container{
|
|
2318
|
-
--el-font-size-base: 14px;
|
|
2319
|
-
--el-text-color-regular: #606266;
|
|
2320
|
-
--el-color-primary: #409eff;
|
|
2321
|
-
--el-fill-color-light: #f5f7fa;
|
|
2322
|
-
--el-disable-color: #a8abb2;
|
|
2323
|
-
}
|
|
2324
|
-
.select-item{
|
|
2325
|
-
cursor: pointer;
|
|
2326
|
-
font-size: var(--el-font-size-base);
|
|
2327
|
-
padding: 0 32px 0 20px;
|
|
2328
|
-
position: relative;
|
|
2329
|
-
white-space: nowrap;
|
|
2330
|
-
overflow: hidden;
|
|
2331
|
-
text-overflow: ellipsis;
|
|
2332
|
-
color: var(--el-text-color-regular);
|
|
2333
|
-
height: 34px;
|
|
2334
|
-
line-height: 34px;
|
|
2335
|
-
box-sizing: border-box;
|
|
2336
|
-
}
|
|
2337
|
-
.select-item[aria-disabled],
|
|
2338
|
-
.select-item[disabled]{
|
|
2339
|
-
cursor: not-allowed;
|
|
2340
|
-
color: var(--el-disable-color);
|
|
2341
|
-
background: unset;
|
|
2342
|
-
}
|
|
2343
|
-
.select-item:hover{
|
|
2344
|
-
background-color: var(--el-fill-color-light);
|
|
2345
|
-
}
|
|
2346
|
-
.select-item.select-item-is-selected{
|
|
2347
|
-
color: var(--el-color-primary);
|
|
2348
|
-
font-weight: 700;
|
|
2349
|
-
}
|
|
2350
|
-
.select-item.select-item-is-selected::after{
|
|
2351
|
-
content: "";
|
|
2352
|
-
position: absolute;
|
|
2353
|
-
top: 50%;
|
|
2354
|
-
right: 20px;
|
|
2355
|
-
border-top: none;
|
|
2356
|
-
border-right: none;
|
|
2357
|
-
background-repeat: no-repeat;
|
|
2358
|
-
background-position: center;
|
|
2359
|
-
background-color: var(--el-color-primary);
|
|
2360
|
-
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;
|
|
2361
|
-
mask-size: 100% 100%;
|
|
2362
|
-
-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;
|
|
2363
|
-
-webkit-mask-size: 100% 100%;
|
|
2364
|
-
transform: translateY(-50%);
|
|
2365
|
-
width: 12px;
|
|
2366
|
-
height: 12px;
|
|
2367
|
-
}
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
@media (prefers-color-scheme: dark) {
|
|
2371
|
-
.select-container{
|
|
2372
|
-
--el-text-color-regular: #f2f2f2;
|
|
2373
|
-
--el-disable-color: #8D9095;
|
|
2374
|
-
--el-fill-color-light: #262727;
|
|
2375
|
-
}
|
|
2376
|
-
}
|
|
2377
|
-
|
|
2378
|
-
${style || ""}
|
|
2379
|
-
`,
|
|
2380
|
-
} as PopsAlertDetails,
|
|
2381
|
-
userConfirmDetails
|
|
2382
|
-
);
|
|
2383
|
-
let $dialog = PopsAlert.init(confirmDetails);
|
|
2384
|
-
let $selectContainer =
|
|
2385
|
-
$dialog.$shadowRoot.querySelector<HTMLUListElement>(
|
|
2386
|
-
".select-container"
|
|
2387
|
-
)!;
|
|
2388
|
-
this.$el.$selectContainer = $selectContainer;
|
|
2389
|
-
// 配置选项元素
|
|
2390
|
-
formConfig.data.forEach((item) => {
|
|
2391
|
-
let $select = this.createSelectItemElement(item);
|
|
2392
|
-
// 添加到confirm中
|
|
2393
|
-
$selectContainer.appendChild($select);
|
|
2394
|
-
// 设置每一项的点击事件
|
|
2395
|
-
this.setSelectElementClickEvent(selectedInfo, $select);
|
|
2396
|
-
});
|
|
2397
|
-
// 动态更新禁用状态
|
|
2398
|
-
this.updateSelectItem();
|
|
2399
|
-
});
|
|
2400
|
-
},
|
|
2401
|
-
/**
|
|
2402
|
-
* 设置关闭图标的点击事件
|
|
2403
|
-
* @param data 选中的信息
|
|
2404
|
-
*/
|
|
2405
|
-
setSelectedItemCloseIconClickEvent(data: {
|
|
2406
|
-
/** 关闭图标的元素 */
|
|
2407
|
-
$closeIcon: HTMLElement;
|
|
2408
|
-
/** tag元素 */
|
|
2409
|
-
$tag: HTMLElement;
|
|
2410
|
-
/** 值 */
|
|
2411
|
-
value: PopsPanelSelectMultipleDataOption<any>["value"];
|
|
2412
|
-
/** 显示的文字 */
|
|
2413
|
-
text: PopsPanelSelectMultipleDataOption<any>["text"];
|
|
2414
|
-
}) {
|
|
2415
|
-
popsDOMUtils.on<PointerEvent | MouseEvent>(
|
|
2416
|
-
data.$closeIcon,
|
|
2417
|
-
"click",
|
|
2418
|
-
(event) => {
|
|
2419
|
-
popsDOMUtils.preventEvent(event);
|
|
2420
|
-
if (this.isDisabled()) {
|
|
2421
|
-
return;
|
|
2422
|
-
}
|
|
2423
|
-
if (typeof formConfig.closeIconClickCallBack === "function") {
|
|
2424
|
-
let result = formConfig.closeIconClickCallBack(event, {
|
|
2425
|
-
$tag: data.$tag,
|
|
2426
|
-
$closeIcon: data.$closeIcon,
|
|
2427
|
-
value: data.value,
|
|
2428
|
-
text:
|
|
2429
|
-
typeof data.text === "function"
|
|
2430
|
-
? data.text.bind(data)
|
|
2431
|
-
: data.text,
|
|
2432
|
-
});
|
|
2433
|
-
if (typeof result === "boolean" && !result) {
|
|
2434
|
-
return;
|
|
2435
|
-
}
|
|
2436
|
-
}
|
|
2437
|
-
this.removeSelectedTagItem(data.$tag);
|
|
2438
|
-
this.removeSelectedInfo({
|
|
2439
|
-
value: data.value,
|
|
2440
|
-
text: data.text,
|
|
2441
|
-
});
|
|
2442
|
-
},
|
|
2443
|
-
{
|
|
2444
|
-
capture: true,
|
|
2445
|
-
}
|
|
2446
|
-
);
|
|
2447
|
-
},
|
|
2448
|
-
/**
|
|
2449
|
-
* 检测tag是否为空,为空显示placeholder
|
|
2450
|
-
*/
|
|
2451
|
-
checkTagEmpty() {
|
|
2452
|
-
if (
|
|
2453
|
-
!this.$el.$section.querySelectorAll(".el-select__choose_tag").length
|
|
2454
|
-
) {
|
|
2455
|
-
// 没有tag了
|
|
2456
|
-
// this.showInputWrapper();
|
|
2457
|
-
this.showPlaceHolderWrapper();
|
|
2458
|
-
this.removeSectionIsNear();
|
|
2459
|
-
}
|
|
2460
|
-
},
|
|
2461
|
-
/**
|
|
2462
|
-
* 移除选中项元素
|
|
2463
|
-
*/
|
|
2464
|
-
removeSelectedTagItem($tag: HTMLElement) {
|
|
2465
|
-
$tag.remove();
|
|
2466
|
-
this.checkTagEmpty();
|
|
2467
|
-
},
|
|
2468
|
-
/**
|
|
2469
|
-
* 从保存的已选中的信息列表中移除目标信息
|
|
2470
|
-
* @param data 需要移除的信息
|
|
2471
|
-
* @param [triggerValueChangeCallBack=true] 是否触发值改变的回调
|
|
2472
|
-
* + true (默认)触发值改变的回调
|
|
2473
|
-
* + false 不触发值改变的回调
|
|
2474
|
-
*/
|
|
2475
|
-
removeSelectedInfo(
|
|
2476
|
-
data: PopsPanelSelectMultipleDataOption<any>,
|
|
2477
|
-
triggerValueChangeCallBack: boolean = true
|
|
2478
|
-
) {
|
|
2479
|
-
for (let index = 0; index < this.$data.selectInfo.length; index++) {
|
|
2480
|
-
const selectInfo = this.$data.selectInfo[index];
|
|
2481
|
-
if (selectInfo.value === data.value) {
|
|
2482
|
-
this.$data.selectInfo.splice(index, 1);
|
|
2483
|
-
break;
|
|
2484
|
-
}
|
|
2485
|
-
}
|
|
2486
|
-
triggerValueChangeCallBack && this.selectValueChangeCallBack();
|
|
2487
|
-
},
|
|
2488
|
-
/** 显示输入框 */
|
|
2489
|
-
showInputWrapper() {
|
|
2490
|
-
popsDOMUtils.cssShow(this.$el.$selectedInputWrapper);
|
|
2491
|
-
},
|
|
2492
|
-
/** 隐藏输入框 */
|
|
2493
|
-
hideInputWrapper() {
|
|
2494
|
-
popsDOMUtils.cssHide(this.$el.$selectedInputWrapper, true);
|
|
2495
|
-
},
|
|
2496
|
-
/** 显示palceholder */
|
|
2497
|
-
showPlaceHolderWrapper() {
|
|
2498
|
-
popsDOMUtils.cssShow(this.$el.$selectedPlaceHolderWrapper);
|
|
2499
|
-
},
|
|
2500
|
-
/** 隐藏palceholder */
|
|
2501
|
-
hidePlaceHolderWrapper() {
|
|
2502
|
-
popsDOMUtils.cssHide(this.$el.$selectedPlaceHolderWrapper, true);
|
|
2503
|
-
},
|
|
2504
|
-
/** 设置隐藏section的前面的空白 */
|
|
2505
|
-
setSectionIsNear() {
|
|
2506
|
-
this.$el.$section.classList.add("is-near");
|
|
2507
|
-
},
|
|
2508
|
-
/** 取消设置隐藏section的前面的空白 */
|
|
2509
|
-
removeSectionIsNear() {
|
|
2510
|
-
this.$el.$section.classList.remove("is-near");
|
|
2511
|
-
},
|
|
2512
|
-
/**
|
|
2513
|
-
* 禁用标签
|
|
2514
|
-
*/
|
|
2515
|
-
disable() {
|
|
2516
|
-
popsDOMUtils.addClassName(
|
|
2517
|
-
this.$el.itemLeftTextContainer,
|
|
2518
|
-
PopsCommonCSSClassName.textIsDisabled
|
|
2519
|
-
);
|
|
2520
|
-
popsDOMUtils.addClassName(
|
|
2521
|
-
this.$el.$container,
|
|
2522
|
-
"pops-panel-select-multiple-disable"
|
|
2523
|
-
);
|
|
2524
|
-
},
|
|
2525
|
-
/**
|
|
2526
|
-
* 判断是否被禁用
|
|
2527
|
-
*/
|
|
2528
|
-
isDisabled() {
|
|
2529
|
-
return popsDOMUtils.containsClassName(
|
|
2530
|
-
this.$el.$container,
|
|
2531
|
-
"pops-panel-select-multiple-disable"
|
|
2532
|
-
);
|
|
2533
|
-
},
|
|
2534
|
-
/**
|
|
2535
|
-
* 取消禁用标签
|
|
2536
|
-
*/
|
|
2537
|
-
cancleDisable() {
|
|
2538
|
-
popsDOMUtils.removeClassName(
|
|
2539
|
-
this.$el.itemLeftTextContainer,
|
|
2540
|
-
PopsCommonCSSClassName.textIsDisabled
|
|
2541
|
-
);
|
|
2542
|
-
popsDOMUtils.removeClassName(
|
|
2543
|
-
this.$el.$container,
|
|
2544
|
-
"pops-panel-select-multiple-disable"
|
|
2545
|
-
);
|
|
2546
|
-
},
|
|
2547
|
-
};
|
|
2548
|
-
|
|
2549
|
-
PopsPanelSelectMultiple.init();
|
|
2550
|
-
Reflect.set($li, "data-select-multiple", PopsPanelSelectMultiple);
|
|
2551
|
-
return $li;
|
|
2552
|
-
},
|
|
2553
|
-
/**
|
|
2554
|
-
* type ==> button
|
|
2555
|
-
* 获取中间容器的元素<li>
|
|
2556
|
-
* @param formConfig
|
|
2557
|
-
*/
|
|
2558
|
-
createSectionContainerItem_button(formConfig: PopsPanelButtonDetails) {
|
|
2559
|
-
let $li = document.createElement("li");
|
|
2560
|
-
Reflect.set($li, "__formConfig__", formConfig);
|
|
2561
|
-
this.setElementClassName($li, formConfig.className);
|
|
2562
|
-
this.setElementAttributes($li, formConfig.attributes);
|
|
2563
|
-
this.setElementProps($li, formConfig.props);
|
|
2564
|
-
|
|
2565
|
-
/* 左边底部的描述的文字 */
|
|
2566
|
-
let leftDescriptionText = "";
|
|
2567
|
-
if (Boolean(formConfig.description)) {
|
|
2568
|
-
leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
|
|
2569
|
-
}
|
|
2570
|
-
PopsSafeUtils.setSafeHTML(
|
|
2571
|
-
$li,
|
|
2572
|
-
/*html*/ `
|
|
2573
|
-
<div class="pops-panel-item-left-text">
|
|
2574
|
-
<p class="pops-panel-item-left-main-text">${formConfig.text}</p>${leftDescriptionText}</div>
|
|
2575
|
-
<div class="pops-panel-button">
|
|
2576
|
-
<button class="pops-panel-button_inner" type="button">
|
|
2577
|
-
<i class="pops-bottom-icon"></i>
|
|
2578
|
-
<span class="pops-panel-button-text"></span>
|
|
2579
|
-
</button>
|
|
2580
|
-
</div>
|
|
2581
|
-
`
|
|
2582
|
-
);
|
|
2583
|
-
|
|
2584
|
-
const PopsPanelButton = {
|
|
2585
|
-
[Symbol.toStringTag]: "PopsPanelButton",
|
|
2586
|
-
$ele: {
|
|
2587
|
-
panelButton: $li.querySelector<HTMLDivElement>(".pops-panel-button")!,
|
|
2588
|
-
button: $li.querySelector<HTMLDivElement>(
|
|
2589
|
-
".pops-panel-button .pops-panel-button_inner"
|
|
2590
|
-
)!,
|
|
2591
|
-
icon: $li.querySelector<HTMLDivElement>(
|
|
2592
|
-
".pops-panel-button .pops-bottom-icon"
|
|
2593
|
-
)!,
|
|
2594
|
-
spanText: $li.querySelector<HTMLDivElement>(
|
|
2595
|
-
".pops-panel-button .pops-panel-button-text"
|
|
2596
|
-
)!,
|
|
2597
|
-
},
|
|
2598
|
-
$data: {},
|
|
2599
|
-
init() {
|
|
2600
|
-
this.$ele.panelButton.appendChild(this.$ele.button);
|
|
2601
|
-
this.initButton();
|
|
2602
|
-
this.setClickEvent();
|
|
2603
|
-
},
|
|
2604
|
-
initButton() {
|
|
2605
|
-
if (
|
|
2606
|
-
typeof formConfig.buttonIcon === "string" &&
|
|
2607
|
-
formConfig.buttonIcon.trim() !== ""
|
|
2608
|
-
) {
|
|
2609
|
-
/* 存在icon图标且不为空 */
|
|
2610
|
-
if (PopsIcon.hasIcon(formConfig.buttonIcon)) {
|
|
2611
|
-
this.setIconSVG(PopsIcon.getIcon(formConfig.buttonIcon)!);
|
|
2612
|
-
} else {
|
|
2613
|
-
this.setIconSVG(formConfig.buttonIcon);
|
|
2614
|
-
}
|
|
2615
|
-
this.showIcon();
|
|
2616
|
-
} else {
|
|
2617
|
-
this.hideIcon();
|
|
2618
|
-
}
|
|
2619
|
-
/* 按钮文字 */
|
|
2620
|
-
let buttonText = formConfig.buttonText;
|
|
2621
|
-
if (typeof formConfig.buttonText === "function") {
|
|
2622
|
-
buttonText = formConfig.buttonText();
|
|
2623
|
-
}
|
|
2624
|
-
this.setButtonType(formConfig.buttonType);
|
|
2625
|
-
if (formConfig.buttonIsRightIcon) {
|
|
2626
|
-
this.setIconRight();
|
|
2627
|
-
} else {
|
|
2628
|
-
this.setIconLeft();
|
|
2629
|
-
}
|
|
2630
|
-
if (formConfig.disable) {
|
|
2631
|
-
this.disable();
|
|
2632
|
-
}
|
|
2633
|
-
this.setButtonText(buttonText as string);
|
|
2634
|
-
this.setIconLoadingStatus(formConfig.buttonIconIsLoading);
|
|
2635
|
-
},
|
|
2636
|
-
disable() {
|
|
2637
|
-
this.$ele.button.setAttribute("disabled", "true");
|
|
2638
|
-
},
|
|
2639
|
-
notDisable() {
|
|
2640
|
-
this.$ele.button.removeAttribute("disabled");
|
|
2641
|
-
},
|
|
2642
|
-
/**
|
|
2643
|
-
* 隐藏icon图标
|
|
2644
|
-
*/
|
|
2645
|
-
hideIcon() {
|
|
2646
|
-
this.$ele.panelButton.classList.add("pops-panel-button-no-icon");
|
|
2647
|
-
},
|
|
2648
|
-
/**
|
|
2649
|
-
* 显示icon图标
|
|
2650
|
-
*/
|
|
2651
|
-
showIcon() {
|
|
2652
|
-
this.$ele.panelButton.classList.remove("pops-panel-button-no-icon");
|
|
2653
|
-
},
|
|
2654
|
-
/**
|
|
2655
|
-
* 设置icon图标的svg
|
|
2656
|
-
*/
|
|
2657
|
-
setIconSVG(svgHTML: string) {
|
|
2658
|
-
PopsSafeUtils.setSafeHTML(this.$ele.icon, svgHTML);
|
|
2659
|
-
},
|
|
2660
|
-
/**
|
|
2661
|
-
* 设置icon图标是否旋转
|
|
2662
|
-
* @param status
|
|
2663
|
-
*/
|
|
2664
|
-
setIconLoadingStatus(status: any) {
|
|
2665
|
-
this.$ele.icon.setAttribute("is-loading", Boolean(status).toString());
|
|
2666
|
-
},
|
|
2667
|
-
/**
|
|
2668
|
-
* 设置属性上是否存在icon图标
|
|
2669
|
-
*/
|
|
2670
|
-
setHasIcon(value: any) {
|
|
2671
|
-
this.$ele.button.setAttribute("data-icon", Boolean(value).toString());
|
|
2672
|
-
},
|
|
2673
|
-
/**
|
|
2674
|
-
* 设置按钮类型
|
|
2675
|
-
* @param typeValue
|
|
2676
|
-
*/
|
|
2677
|
-
setButtonType(typeValue: string) {
|
|
2678
|
-
this.$ele.button.setAttribute("data-type", typeValue);
|
|
2679
|
-
},
|
|
2680
|
-
/**
|
|
2681
|
-
* 添加按钮的图标在右边
|
|
2682
|
-
*/
|
|
2683
|
-
setIconRight() {
|
|
2684
|
-
this.$ele.button.classList.add("pops-panel-button-right-icon");
|
|
2685
|
-
},
|
|
2686
|
-
/**
|
|
2687
|
-
* (默认)添加按钮的图标在左边
|
|
2688
|
-
*/
|
|
2689
|
-
setIconLeft() {
|
|
2690
|
-
this.$ele.button.classList.remove("pops-panel-button-right-icon");
|
|
2691
|
-
},
|
|
2692
|
-
/**
|
|
2693
|
-
* 设置按钮文本
|
|
2694
|
-
* @param text
|
|
2695
|
-
*/
|
|
2696
|
-
setButtonText(text: string) {
|
|
2697
|
-
PopsSafeUtils.setSafeHTML(this.$ele.spanText, text);
|
|
2698
|
-
},
|
|
2699
|
-
setClickEvent() {
|
|
2700
|
-
popsDOMUtils.on(this.$ele.button, "click", void 0, (event) => {
|
|
2701
|
-
if (typeof formConfig.callback === "function") {
|
|
2702
|
-
formConfig.callback(event);
|
|
2703
|
-
}
|
|
2704
|
-
});
|
|
2705
|
-
},
|
|
2706
|
-
};
|
|
2707
|
-
PopsPanelButton.init();
|
|
2708
|
-
Reflect.set($li, "data-button", PopsPanelButton);
|
|
2709
|
-
return $li;
|
|
2710
|
-
},
|
|
2711
|
-
/**
|
|
2712
|
-
* type ==> deepMenu
|
|
2713
|
-
* 获取深层容器的元素<li>
|
|
2714
|
-
* @param formConfig
|
|
2715
|
-
*/
|
|
2716
|
-
createSectionContainerItem_deepMenu(formConfig: PopsPanelDeepMenuDetails) {
|
|
2717
|
-
let that = this;
|
|
2718
|
-
let $li = document.createElement("li");
|
|
2719
|
-
popsDOMUtils.addClassName($li, "pops-panel-deepMenu-nav-item");
|
|
2720
|
-
Reflect.set($li, "__formConfig__", formConfig);
|
|
2721
|
-
this.setElementClassName($li, formConfig.className);
|
|
2722
|
-
// 设置属性
|
|
2723
|
-
this.setElementAttributes($li, formConfig.attributes);
|
|
2724
|
-
// 设置元素上的属性
|
|
2725
|
-
this.setElementProps($li, formConfig.props);
|
|
2726
|
-
|
|
2727
|
-
/* 左边底部的描述的文字 */
|
|
2728
|
-
let leftDescriptionText = "";
|
|
2729
|
-
if (Boolean(formConfig.description)) {
|
|
2730
|
-
// 设置描述
|
|
2731
|
-
leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
|
|
2732
|
-
}
|
|
2733
|
-
// 箭头图标
|
|
2734
|
-
let arrowRightIcon =
|
|
2735
|
-
typeof formConfig.arrowRightIcon === "boolean"
|
|
2736
|
-
? formConfig.arrowRightIcon
|
|
2737
|
-
: true;
|
|
2738
|
-
let arrowRightIconHTML = "";
|
|
2739
|
-
if (arrowRightIcon) {
|
|
2740
|
-
arrowRightIconHTML = `<i class="pops-panel-deepMenu-arrowRight-icon">${PopsIcon.getIcon(
|
|
2741
|
-
"arrowRight"
|
|
2742
|
-
)}</i>`;
|
|
2743
|
-
}
|
|
2744
|
-
let rightText = "";
|
|
2745
|
-
if (formConfig.rightText) {
|
|
2746
|
-
rightText = /*html*/ `<p class="pops-panel-item-right-text">${formConfig.rightText}</p>`;
|
|
2747
|
-
}
|
|
2748
|
-
PopsSafeUtils.setSafeHTML(
|
|
2749
|
-
$li,
|
|
2750
|
-
/*html*/ `
|
|
2751
|
-
<div class="pops-panel-item-left-text">
|
|
2752
|
-
<p class="pops-panel-item-left-main-text">${formConfig.text}</p>${leftDescriptionText}</div>
|
|
2753
|
-
<div class="pops-panel-deepMenu">${rightText}${arrowRightIconHTML}</div>
|
|
2754
|
-
`
|
|
2755
|
-
);
|
|
2756
|
-
const PopsPanelDeepMenu = {
|
|
2757
|
-
[Symbol.toStringTag]: "PopsPanelDeepMenu",
|
|
2758
|
-
$ele: {
|
|
2759
|
-
get parentSection() {
|
|
2760
|
-
return that.$el.$contentSectionContainer;
|
|
2761
|
-
},
|
|
2762
|
-
},
|
|
2763
|
-
init() {
|
|
2764
|
-
this.setLiClickEvent();
|
|
2765
|
-
},
|
|
2766
|
-
/**
|
|
2767
|
-
* 生成配置每一项的元素
|
|
2768
|
-
* @param $container
|
|
2769
|
-
* @param formItemConfig
|
|
2770
|
-
*/
|
|
2771
|
-
initFormItem(
|
|
2772
|
-
$container: HTMLElement,
|
|
2773
|
-
formItemConfig: PopsPanelFormsTotalDetails | PopsPanelFormsDetails
|
|
2774
|
-
) {
|
|
2775
|
-
let formConfig_forms = formItemConfig as PopsPanelFormsDetails;
|
|
2776
|
-
if (formConfig_forms.type === "forms") {
|
|
2777
|
-
let childForms = formConfig_forms["forms"];
|
|
2778
|
-
/* 每一项<li>元素 */
|
|
2779
|
-
let formContainerListElement = document.createElement("li");
|
|
2780
|
-
/* 每一项<li>内的子<ul>元素 */
|
|
2781
|
-
let formContainerULElement = document.createElement("ul");
|
|
2782
|
-
formContainerULElement.classList.add(
|
|
2783
|
-
"pops-panel-forms-container-item-formlist"
|
|
2784
|
-
);
|
|
2785
|
-
formContainerListElement.classList.add(
|
|
2786
|
-
"pops-panel-forms-container-item"
|
|
2787
|
-
);
|
|
2788
|
-
/* 区域头部的文字 */
|
|
2789
|
-
let formHeaderDivElement = popsDOMUtils.createElement("div", {
|
|
2790
|
-
className: "pops-panel-forms-container-item-header-text",
|
|
2791
|
-
});
|
|
2792
|
-
PopsSafeUtils.setSafeHTML(
|
|
2793
|
-
formHeaderDivElement,
|
|
2794
|
-
formConfig_forms["text"]
|
|
2795
|
-
);
|
|
2796
|
-
|
|
2797
|
-
if (formConfig_forms.isFold) {
|
|
2798
|
-
/* 添加第一个 */
|
|
2799
|
-
/* 加进容器内 */
|
|
2800
|
-
PopsSafeUtils.setSafeHTML(
|
|
2801
|
-
formHeaderDivElement,
|
|
2802
|
-
/*html*/ `
|
|
2803
|
-
<p>${formConfig_forms.text}</p>
|
|
2804
|
-
<i class="pops-panel-forms-fold-container-icon">
|
|
2805
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
|
|
2806
|
-
<path d="M340.864 149.312a30.592 30.592 0 0 0 0 42.752L652.736 512 340.864 831.872a30.592 30.592 0 0 0 0 42.752 29.12 29.12 0 0 0 41.728 0L714.24 534.336a32 32 0 0 0 0-44.672L382.592 149.376a29.12 29.12 0 0 0-41.728 0z"></path>
|
|
2807
|
-
</svg>
|
|
2808
|
-
</i>
|
|
2809
|
-
`
|
|
2810
|
-
);
|
|
2811
|
-
// 添加点击事件
|
|
2812
|
-
popsDOMUtils.on(formHeaderDivElement, "click", (event) => {
|
|
2813
|
-
if (formContainerListElement.hasAttribute("data-fold-enable")) {
|
|
2814
|
-
formContainerListElement.removeAttribute("data-fold-enable");
|
|
2815
|
-
} else {
|
|
2816
|
-
formContainerListElement.setAttribute("data-fold-enable", "");
|
|
2817
|
-
}
|
|
2818
|
-
});
|
|
2819
|
-
popsDOMUtils.addClassName(
|
|
2820
|
-
formHeaderDivElement,
|
|
2821
|
-
"pops-panel-forms-fold-container"
|
|
2822
|
-
);
|
|
2823
|
-
popsDOMUtils.addClassName(
|
|
2824
|
-
formHeaderDivElement,
|
|
2825
|
-
PopsCommonCSSClassName.userSelectNone
|
|
2826
|
-
);
|
|
2827
|
-
formContainerListElement.setAttribute("data-fold-enable", "");
|
|
2828
|
-
popsDOMUtils.addClassName(
|
|
2829
|
-
formHeaderDivElement,
|
|
2830
|
-
"pops-panel-forms-fold"
|
|
2831
|
-
);
|
|
2832
|
-
formContainerListElement.appendChild(formHeaderDivElement);
|
|
2833
|
-
} else {
|
|
2834
|
-
/* 加进容器内 */
|
|
2835
|
-
formContainerListElement.appendChild(formHeaderDivElement);
|
|
2836
|
-
}
|
|
2837
|
-
|
|
2838
|
-
that.setElementClassName(
|
|
2839
|
-
formContainerListElement,
|
|
2840
|
-
formItemConfig.className
|
|
2841
|
-
);
|
|
2842
|
-
that.setElementAttributes(
|
|
2843
|
-
formContainerListElement,
|
|
2844
|
-
formItemConfig.attributes
|
|
2845
|
-
);
|
|
2846
|
-
that.setElementProps(
|
|
2847
|
-
formContainerListElement,
|
|
2848
|
-
formItemConfig.props
|
|
2849
|
-
);
|
|
2850
|
-
childForms.forEach((childFormConfig) => {
|
|
2851
|
-
that.uListContainerAddItem(childFormConfig, {
|
|
2852
|
-
ulElement: formContainerULElement,
|
|
2853
|
-
sectionContainerULElement: that.sectionContainerULElement,
|
|
2854
|
-
formContainerListElement: formContainerListElement,
|
|
2855
|
-
formHeaderDivElement: formHeaderDivElement,
|
|
2856
|
-
});
|
|
2857
|
-
});
|
|
2858
|
-
formContainerListElement.appendChild(formContainerULElement);
|
|
2859
|
-
$container.appendChild(formContainerListElement);
|
|
2860
|
-
if (
|
|
2861
|
-
typeof formConfig_forms.afterAddToUListCallBack === "function"
|
|
2862
|
-
) {
|
|
2863
|
-
formConfig_forms.afterAddToUListCallBack(
|
|
2864
|
-
formConfig as any as PopsPanelFormsDetails,
|
|
2865
|
-
{
|
|
2866
|
-
target: formContainerListElement,
|
|
2867
|
-
ulElement: formContainerULElement,
|
|
2868
|
-
sectionContainerULElement: that.sectionContainerULElement,
|
|
2869
|
-
formContainerListElement: formContainerListElement,
|
|
2870
|
-
formHeaderDivElement: formHeaderDivElement,
|
|
2871
|
-
}
|
|
2872
|
-
);
|
|
2873
|
-
}
|
|
2874
|
-
} else {
|
|
2875
|
-
/* 如果成功创建,加入到中间容器中 */
|
|
2876
|
-
that.uListContainerAddItem(formConfig, {
|
|
2877
|
-
ulElement: that.sectionContainerULElement,
|
|
2878
|
-
});
|
|
2879
|
-
}
|
|
2880
|
-
},
|
|
2881
|
-
/**
|
|
2882
|
-
* 前往子菜单
|
|
2883
|
-
* @param event 点击事件
|
|
2884
|
-
* @param liElement 当前的<li>元素
|
|
2885
|
-
*/
|
|
2886
|
-
gotoDeepMenu(event: Event, liElement: HTMLLIElement) {
|
|
2887
|
-
/** 当前所在的容器 */
|
|
2888
|
-
let currentSection = liElement.closest<HTMLElement>(
|
|
2889
|
-
"section.pops-panel-container"
|
|
2890
|
-
);
|
|
2891
|
-
if (currentSection) {
|
|
2892
|
-
popsDOMUtils.cssHide(currentSection, true);
|
|
2893
|
-
}
|
|
2894
|
-
// 子菜单的容器
|
|
2895
|
-
let $deepMenuContainer = popsDOMUtils.createElement("section", {
|
|
2896
|
-
className: "pops-panel-container pops-panel-deepMenu-container",
|
|
2897
|
-
});
|
|
2898
|
-
Reflect.set($deepMenuContainer, "__formConfig__", formConfig);
|
|
2899
|
-
let $deepMenuHeaderUL = popsDOMUtils.createElement("ul", {
|
|
2900
|
-
className:
|
|
2901
|
-
"pops-panel-container-header-ul pops-panel-deepMenu-container-header-ul",
|
|
2902
|
-
});
|
|
2903
|
-
let $deepMenuMain = popsDOMUtils.createElement("ul", {
|
|
2904
|
-
className: "pops-panel-container-main-ul",
|
|
2905
|
-
});
|
|
2906
|
-
// 标题文字
|
|
2907
|
-
let headerTitleText = formConfig.headerTitle ?? formConfig.text;
|
|
2908
|
-
let $header = popsDOMUtils.createElement("li", {
|
|
2909
|
-
className:
|
|
2910
|
-
"pops-panel-container-header-title-text pops-panel-deepMenu-container-header",
|
|
2911
|
-
innerHTML: /*html*/ `<p class="pops-panel-deepMenu-container-header-title-text">${headerTitleText}</p>`,
|
|
2912
|
-
});
|
|
2913
|
-
let $headerLeftArrow = popsDOMUtils.createElement("i", {
|
|
2914
|
-
className: "pops-panel-deepMenu-container-left-arrow-icon",
|
|
2915
|
-
innerHTML: PopsIcon.getIcon("arrowLeft")!,
|
|
2916
|
-
});
|
|
2917
|
-
popsDOMUtils.on(
|
|
2918
|
-
$headerLeftArrow,
|
|
2919
|
-
"click",
|
|
2920
|
-
(event) => {
|
|
2921
|
-
popsDOMUtils.preventEvent(event);
|
|
2922
|
-
// 返回上一层菜单
|
|
2923
|
-
let $prev = <HTMLElement>(
|
|
2924
|
-
$deepMenuContainer.previousElementSibling
|
|
2925
|
-
);
|
|
2926
|
-
popsDOMUtils.cssShow($prev);
|
|
2927
|
-
$deepMenuContainer.remove();
|
|
2928
|
-
that.triggerRenderRightContainer($prev);
|
|
2929
|
-
},
|
|
2930
|
-
{
|
|
2931
|
-
once: true,
|
|
2932
|
-
}
|
|
2933
|
-
);
|
|
2934
|
-
$header.firstElementChild?.insertAdjacentElement(
|
|
2935
|
-
"beforebegin",
|
|
2936
|
-
$headerLeftArrow
|
|
2937
|
-
);
|
|
2938
|
-
$deepMenuHeaderUL.appendChild($header);
|
|
2939
|
-
$deepMenuContainer.appendChild($deepMenuHeaderUL);
|
|
2940
|
-
$deepMenuContainer.appendChild($deepMenuMain);
|
|
2941
|
-
|
|
2942
|
-
if (formConfig.forms && Array.isArray(formConfig.forms)) {
|
|
2943
|
-
for (let index = 0; index < formConfig.forms.length; index++) {
|
|
2944
|
-
let formItemConfig = formConfig.forms[index];
|
|
2945
|
-
this.initFormItem($deepMenuMain, formItemConfig);
|
|
2946
|
-
}
|
|
2947
|
-
}
|
|
2948
|
-
that.$el.$content?.appendChild($deepMenuContainer);
|
|
2949
|
-
|
|
2950
|
-
if (typeof formConfig.afterEnterDeepMenuCallBack === "function") {
|
|
2951
|
-
formConfig.afterEnterDeepMenuCallBack(formConfig, {
|
|
2952
|
-
sectionContainer: $deepMenuContainer,
|
|
2953
|
-
sectionContainerHeaderContainer: $deepMenuHeaderUL,
|
|
2954
|
-
sectionContainerHeader: $header,
|
|
2955
|
-
sectionBodyContainer: $deepMenuMain,
|
|
2956
|
-
});
|
|
2957
|
-
}
|
|
2958
|
-
that.triggerRenderRightContainer($deepMenuContainer);
|
|
2959
|
-
},
|
|
2960
|
-
/** 设置项的点击事件 */
|
|
2961
|
-
setLiClickEvent() {
|
|
2962
|
-
popsDOMUtils.on($li, "click", void 0, async (event) => {
|
|
2963
|
-
if (typeof formConfig.clickCallBack === "function") {
|
|
2964
|
-
let result = await formConfig.clickCallBack(event, formConfig);
|
|
2965
|
-
if (result) {
|
|
2966
|
-
return;
|
|
2967
|
-
}
|
|
2968
|
-
}
|
|
2969
|
-
this.gotoDeepMenu(event, $li);
|
|
2970
|
-
});
|
|
2971
|
-
},
|
|
2972
|
-
};
|
|
2973
|
-
|
|
2974
|
-
PopsPanelDeepMenu.init();
|
|
2975
|
-
Reflect.set($li, "data-deepMenu", PopsPanelDeepMenu);
|
|
2976
|
-
|
|
2977
|
-
return $li;
|
|
2978
|
-
},
|
|
2979
|
-
/**
|
|
2980
|
-
* type ===> own
|
|
2981
|
-
* 获取中间容器的元素<li>
|
|
2982
|
-
* @param formConfig
|
|
2983
|
-
*/
|
|
2984
|
-
createSectionContainerItem_own(formConfig: PopsPanelOwnDetails) {
|
|
2985
|
-
let $li = document.createElement("li");
|
|
2986
|
-
Reflect.set($li, "__formConfig__", formConfig);
|
|
2987
|
-
if (formConfig.className) {
|
|
2988
|
-
$li.className = formConfig.className;
|
|
2989
|
-
}
|
|
2990
|
-
$li = formConfig.getLiElementCallBack($li);
|
|
2991
|
-
return $li;
|
|
2992
|
-
},
|
|
2993
|
-
/**
|
|
2994
|
-
* 获取中间容器的元素<li>
|
|
2995
|
-
* @param formConfig
|
|
2996
|
-
*/
|
|
2997
|
-
createSectionContainerItem(formConfig: PopsPanelFormsTotalDetails) {
|
|
2998
|
-
/** 配置项的类型 */
|
|
2999
|
-
let formType = formConfig.type;
|
|
3000
|
-
|
|
3001
|
-
if (formType === "switch") {
|
|
3002
|
-
return this.createSectionContainerItem_switch(
|
|
3003
|
-
formConfig as PopsPanelSwitchDetails
|
|
3004
|
-
);
|
|
3005
|
-
} else if (formType === "slider") {
|
|
3006
|
-
return this.createSectionContainerItem_slider_new(
|
|
3007
|
-
formConfig as PopsPanelSliderDetails
|
|
3008
|
-
);
|
|
3009
|
-
} else if (formType === "input") {
|
|
3010
|
-
return this.createSectionContainerItem_input(
|
|
3011
|
-
formConfig as PopsPanelInputDetails
|
|
3012
|
-
);
|
|
3013
|
-
} else if (formType === "textarea") {
|
|
3014
|
-
return this.createSectionContainerItem_textarea(
|
|
3015
|
-
formConfig as PopsPanelTextAreaDetails
|
|
3016
|
-
);
|
|
3017
|
-
} else if (formType === "select") {
|
|
3018
|
-
return this.createSectionContainerItem_select(
|
|
3019
|
-
formConfig as PopsPanelSelectDetails
|
|
3020
|
-
);
|
|
3021
|
-
} else if (formType === "select-multiple") {
|
|
3022
|
-
return this.createSectionContainerItem_select_multiple_new(
|
|
3023
|
-
formConfig as PopsPanelSelectMultipleDetails<any>
|
|
3024
|
-
);
|
|
3025
|
-
} else if (formType === "button") {
|
|
3026
|
-
return this.createSectionContainerItem_button(
|
|
3027
|
-
formConfig as PopsPanelButtonDetails
|
|
3028
|
-
);
|
|
3029
|
-
} else if (formType === "deepMenu") {
|
|
3030
|
-
return this.createSectionContainerItem_deepMenu(
|
|
3031
|
-
formConfig as PopsPanelDeepMenuDetails
|
|
3032
|
-
);
|
|
3033
|
-
} else if (formType === "own") {
|
|
3034
|
-
return this.createSectionContainerItem_own(
|
|
3035
|
-
formConfig as PopsPanelOwnDetails
|
|
3036
|
-
);
|
|
3037
|
-
} else {
|
|
3038
|
-
console.error("尚未实现的type类型", formConfig);
|
|
3039
|
-
}
|
|
3040
|
-
},
|
|
3041
|
-
/**
|
|
3042
|
-
* 生成配置项forms
|
|
3043
|
-
* 生成配置每一项的元素
|
|
3044
|
-
* @param formConfig
|
|
3045
|
-
*/
|
|
3046
|
-
createSectionContainerItem_forms(
|
|
3047
|
-
formConfig: PopsPanelContentConfig | PopsPanelFormsDetails
|
|
3048
|
-
) {
|
|
3049
|
-
let that = this;
|
|
3050
|
-
let formConfig_forms = formConfig as PopsPanelFormsDetails;
|
|
3051
|
-
if (formConfig_forms.type === "forms") {
|
|
3052
|
-
let childForms = formConfig["forms"];
|
|
3053
|
-
/* 每一项<li>元素 */
|
|
3054
|
-
let formContainerListElement = document.createElement("li");
|
|
3055
|
-
/* 每一项<li>内的子<ul>元素 */
|
|
3056
|
-
let formContainerULElement = document.createElement("ul");
|
|
3057
|
-
formContainerListElement.classList.add(
|
|
3058
|
-
"pops-panel-forms-container-item"
|
|
3059
|
-
);
|
|
3060
|
-
formContainerULElement.classList.add(
|
|
3061
|
-
"pops-panel-forms-container-item-formlist"
|
|
3062
|
-
);
|
|
3063
|
-
/* 区域头部的文字 */
|
|
3064
|
-
let formHeaderDivElement = popsDOMUtils.createElement("div", {
|
|
3065
|
-
className: "pops-panel-forms-container-item-header-text",
|
|
3066
|
-
});
|
|
3067
|
-
PopsSafeUtils.setSafeHTML(
|
|
3068
|
-
formHeaderDivElement,
|
|
3069
|
-
formConfig_forms["text"]
|
|
3070
|
-
);
|
|
3071
|
-
if (formConfig_forms.isFold) {
|
|
3072
|
-
/* 加进容器内 */
|
|
3073
|
-
PopsSafeUtils.setSafeHTML(
|
|
3074
|
-
formHeaderDivElement,
|
|
3075
|
-
/*html*/ `
|
|
3076
|
-
<p>${formConfig_forms.text}</p>
|
|
3077
|
-
<i class="pops-panel-forms-fold-container-icon">
|
|
3078
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
|
|
3079
|
-
<path d="M340.864 149.312a30.592 30.592 0 0 0 0 42.752L652.736 512 340.864 831.872a30.592 30.592 0 0 0 0 42.752 29.12 29.12 0 0 0 41.728 0L714.24 534.336a32 32 0 0 0 0-44.672L382.592 149.376a29.12 29.12 0 0 0-41.728 0z"></path>
|
|
3080
|
-
</svg>
|
|
3081
|
-
</i>
|
|
3082
|
-
`
|
|
3083
|
-
);
|
|
3084
|
-
// 添加点击事件
|
|
3085
|
-
popsDOMUtils.on(formHeaderDivElement, "click", (event) => {
|
|
3086
|
-
if (formContainerListElement.hasAttribute("data-fold-enable")) {
|
|
3087
|
-
formContainerListElement.removeAttribute("data-fold-enable");
|
|
3088
|
-
} else {
|
|
3089
|
-
formContainerListElement.setAttribute("data-fold-enable", "");
|
|
3090
|
-
}
|
|
3091
|
-
});
|
|
3092
|
-
popsDOMUtils.addClassName(
|
|
3093
|
-
formHeaderDivElement,
|
|
3094
|
-
"pops-panel-forms-fold-container"
|
|
3095
|
-
);
|
|
3096
|
-
popsDOMUtils.addClassName(
|
|
3097
|
-
formHeaderDivElement,
|
|
3098
|
-
PopsCommonCSSClassName.userSelectNone
|
|
3099
|
-
);
|
|
3100
|
-
formContainerListElement.setAttribute("data-fold-enable", "");
|
|
3101
|
-
popsDOMUtils.addClassName(
|
|
3102
|
-
formContainerListElement,
|
|
3103
|
-
"pops-panel-forms-fold"
|
|
3104
|
-
);
|
|
3105
|
-
formContainerListElement.appendChild(formHeaderDivElement);
|
|
3106
|
-
} else {
|
|
3107
|
-
/* 加进容器内 */
|
|
3108
|
-
formContainerListElement.appendChild(formHeaderDivElement);
|
|
3109
|
-
}
|
|
3110
|
-
that.setElementClassName(
|
|
3111
|
-
formContainerListElement,
|
|
3112
|
-
formConfig.className
|
|
3113
|
-
);
|
|
3114
|
-
that.setElementAttributes(
|
|
3115
|
-
formContainerListElement,
|
|
3116
|
-
formConfig.attributes
|
|
3117
|
-
);
|
|
3118
|
-
that.setElementProps(formContainerListElement, formConfig.props);
|
|
3119
|
-
childForms.forEach((childFormConfig) => {
|
|
3120
|
-
that.uListContainerAddItem(
|
|
3121
|
-
childFormConfig as PopsPanelFormsTotalDetails,
|
|
3122
|
-
{
|
|
3123
|
-
ulElement: formContainerULElement,
|
|
3124
|
-
sectionContainerULElement: that.sectionContainerULElement,
|
|
3125
|
-
formContainerListElement: formContainerListElement,
|
|
3126
|
-
formHeaderDivElement: formHeaderDivElement,
|
|
3127
|
-
}
|
|
3128
|
-
);
|
|
3129
|
-
});
|
|
3130
|
-
formContainerListElement.appendChild(formContainerULElement);
|
|
3131
|
-
that.sectionContainerULElement.appendChild(formContainerListElement);
|
|
3132
|
-
|
|
3133
|
-
if (typeof formConfig_forms.afterAddToUListCallBack === "function") {
|
|
3134
|
-
formConfig_forms.afterAddToUListCallBack(formConfig_forms, {
|
|
3135
|
-
target: formContainerListElement,
|
|
3136
|
-
ulElement: formContainerULElement,
|
|
3137
|
-
sectionContainerULElement: that.sectionContainerULElement,
|
|
3138
|
-
formContainerListElement: formContainerListElement,
|
|
3139
|
-
formHeaderDivElement: formHeaderDivElement,
|
|
3140
|
-
});
|
|
3141
|
-
}
|
|
3142
|
-
} else {
|
|
3143
|
-
/* 如果成功创建,加入到中间容器中 */
|
|
3144
|
-
that.uListContainerAddItem(
|
|
3145
|
-
formConfig as any as PopsPanelFormsTotalDetails,
|
|
3146
|
-
{
|
|
3147
|
-
ulElement: that.sectionContainerULElement,
|
|
3148
|
-
}
|
|
3149
|
-
);
|
|
3150
|
-
}
|
|
3151
|
-
},
|
|
3152
|
-
/**
|
|
3153
|
-
* 触发触发渲染右侧容器的事件
|
|
3154
|
-
*/
|
|
3155
|
-
triggerRenderRightContainer($container: HTMLElement) {
|
|
3156
|
-
let __formConfig__: PopsPanelEventType["pops:renderRightContainer"]["formConfig"] =
|
|
3157
|
-
Reflect.get($container, "__formConfig__");
|
|
3158
|
-
this.$el.$pops.dispatchEvent(
|
|
3159
|
-
new CustomEvent<PopsPanelEventType["pops:renderRightContainer"]>(
|
|
3160
|
-
<keyof PopsPanelEventType>"pops:renderRightContainer",
|
|
3161
|
-
{
|
|
3162
|
-
detail: {
|
|
3163
|
-
formConfig: __formConfig__,
|
|
3164
|
-
},
|
|
3165
|
-
}
|
|
3166
|
-
)
|
|
3167
|
-
);
|
|
3168
|
-
},
|
|
3169
|
-
/**
|
|
3170
|
-
*
|
|
3171
|
-
* @param formConfig
|
|
3172
|
-
* @param containerOptions
|
|
3173
|
-
*/
|
|
3174
|
-
uListContainerAddItem(
|
|
3175
|
-
formConfig: PopsPanelFormsTotalDetails,
|
|
3176
|
-
containerOptions: Omit<PopsPanelRightAsideContainerOptions, "target">
|
|
3177
|
-
) {
|
|
3178
|
-
let itemLiElement = this.createSectionContainerItem(formConfig);
|
|
3179
|
-
if (itemLiElement) {
|
|
3180
|
-
containerOptions["ulElement"].appendChild(itemLiElement);
|
|
3181
|
-
}
|
|
3182
|
-
if (typeof formConfig.afterAddToUListCallBack === "function") {
|
|
3183
|
-
formConfig.afterAddToUListCallBack(formConfig as any, {
|
|
3184
|
-
...containerOptions,
|
|
3185
|
-
target: itemLiElement,
|
|
3186
|
-
});
|
|
3187
|
-
}
|
|
3188
|
-
},
|
|
3189
|
-
/**
|
|
3190
|
-
* 为左侧容器元素添加点击事件
|
|
3191
|
-
* @param asideLiElement 左侧的容器<li>元素
|
|
3192
|
-
* @param asideConfig 配置
|
|
3193
|
-
*/
|
|
3194
|
-
setAsideItemClickEvent(
|
|
3195
|
-
asideLiElement: HTMLElement,
|
|
3196
|
-
asideConfig: PopsPanelContentConfig
|
|
3197
|
-
) {
|
|
3198
|
-
popsDOMUtils.on<MouseEvent | PointerEvent>(
|
|
3199
|
-
asideLiElement,
|
|
3200
|
-
"click",
|
|
3201
|
-
async (event) => {
|
|
3202
|
-
if (typeof asideConfig.clickFirstCallback === "function") {
|
|
3203
|
-
let clickFirstCallbackResult = await asideConfig.clickFirstCallback(
|
|
3204
|
-
event,
|
|
3205
|
-
this.sectionContainerHeaderULElement,
|
|
3206
|
-
this.sectionContainerULElement
|
|
3207
|
-
);
|
|
3208
|
-
if (
|
|
3209
|
-
typeof clickFirstCallbackResult === "boolean" &&
|
|
3210
|
-
!clickFirstCallbackResult
|
|
3211
|
-
) {
|
|
3212
|
-
return;
|
|
3213
|
-
}
|
|
3214
|
-
}
|
|
3215
|
-
this.clearContainer();
|
|
3216
|
-
let rightContainerFormConfig: PopsPanelContentConfig[] = Reflect.get(
|
|
3217
|
-
asideLiElement,
|
|
3218
|
-
"__forms__"
|
|
3219
|
-
);
|
|
3220
|
-
|
|
3221
|
-
Reflect.set(
|
|
3222
|
-
this.$el.$contentSectionContainer,
|
|
3223
|
-
"__formConfig__",
|
|
3224
|
-
rightContainerFormConfig
|
|
3225
|
-
);
|
|
3226
|
-
popsDOMUtils.cssShow(this.$el.$contentSectionContainer);
|
|
3227
|
-
this.clearAsideItemIsVisited();
|
|
3228
|
-
this.setAsideItemIsVisited(asideLiElement);
|
|
3229
|
-
/* 顶部标题栏,存在就设置 */
|
|
3230
|
-
let title =
|
|
3231
|
-
typeof asideConfig.title === "function"
|
|
3232
|
-
? asideConfig.title()
|
|
3233
|
-
: asideConfig.title;
|
|
3234
|
-
let headerTitleText =
|
|
3235
|
-
typeof asideConfig.headerTitle === "function"
|
|
3236
|
-
? asideConfig.headerTitle()
|
|
3237
|
-
: asideConfig.headerTitle;
|
|
3238
|
-
headerTitleText = headerTitleText ?? title;
|
|
3239
|
-
if (
|
|
3240
|
-
typeof headerTitleText === "string" &&
|
|
3241
|
-
headerTitleText.trim() !== ""
|
|
3242
|
-
) {
|
|
3243
|
-
let $containerHeaderTitle = document.createElement("li");
|
|
3244
|
-
$containerHeaderTitle.classList.add(
|
|
3245
|
-
"pops-panel-container-header-title-text"
|
|
3246
|
-
);
|
|
3247
|
-
Reflect.set($containerHeaderTitle, "__asideConfig__", asideConfig);
|
|
3248
|
-
PopsSafeUtils.setSafeHTML($containerHeaderTitle, headerTitleText);
|
|
3249
|
-
this.sectionContainerHeaderULElement.appendChild(
|
|
3250
|
-
$containerHeaderTitle
|
|
3251
|
-
);
|
|
3252
|
-
}
|
|
3253
|
-
|
|
3254
|
-
rightContainerFormConfig.forEach((formConfig) => {
|
|
3255
|
-
this.createSectionContainerItem_forms(formConfig);
|
|
3256
|
-
});
|
|
3257
|
-
|
|
3258
|
-
if (typeof asideConfig.clickCallback === "function") {
|
|
3259
|
-
/* 执行回调 */
|
|
3260
|
-
let asideClickCallbackResult = await asideConfig.clickCallback(
|
|
3261
|
-
event,
|
|
3262
|
-
this.sectionContainerHeaderULElement,
|
|
3263
|
-
this.sectionContainerULElement
|
|
3264
|
-
);
|
|
3265
|
-
if (
|
|
3266
|
-
typeof asideClickCallbackResult === "boolean" &&
|
|
3267
|
-
!asideClickCallbackResult
|
|
3268
|
-
) {
|
|
3269
|
-
return;
|
|
3270
|
-
}
|
|
3271
|
-
}
|
|
3272
|
-
this.triggerRenderRightContainer(this.$el.$contentSectionContainer);
|
|
3273
|
-
}
|
|
3274
|
-
);
|
|
3275
|
-
},
|
|
3276
|
-
};
|
|
3277
|
-
};
|