@whitesev/pops 3.0.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.amd.js +1964 -719
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +1964 -719
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +1964 -719
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +1964 -719
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +1964 -719
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +1964 -719
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Pops.d.ts +413 -22
- package/dist/types/src/PopsCSS.d.ts +3 -1
- package/dist/types/src/PopsIcon.d.ts +1 -1
- package/dist/types/src/components/panel/handlerComponents.d.ts +1103 -21
- package/dist/types/src/components/panel/index.d.ts +2 -2
- package/dist/types/src/components/panel/types/components-button.d.ts +1 -1
- package/dist/types/src/components/panel/types/components-container.d.ts +1 -1
- package/dist/types/src/components/panel/types/components-deepMenu.d.ts +1 -1
- package/dist/types/src/components/panel/types/components-input.d.ts +41 -16
- package/dist/types/src/components/panel/types/components-own.d.ts +3 -3
- package/dist/types/src/components/panel/types/components-select.d.ts +126 -30
- package/dist/types/src/components/panel/types/components-selectMultiple.d.ts +10 -15
- package/dist/types/src/components/panel/types/components-slider.d.ts +2 -3
- package/dist/types/src/components/panel/types/components-switch.d.ts +1 -1
- package/dist/types/src/components/panel/types/components-textarea.d.ts +1 -1
- package/dist/types/src/components/searchSuggestion/index.d.ts +3 -3
- package/dist/types/src/types/global.d.ts +3 -1
- package/package.json +8 -8
- package/src/PopsCSS.ts +4 -1
- package/src/components/panel/css/components-select.css +84 -0
- package/src/components/panel/defaultConfig.ts +473 -213
- package/src/components/panel/handlerComponents.ts +1504 -499
- package/src/components/panel/index.css +149 -14
- package/src/components/panel/types/components-button.ts +1 -1
- package/src/components/panel/types/components-container.ts +1 -1
- package/src/components/panel/types/components-deepMenu.ts +1 -1
- package/src/components/panel/types/components-input.ts +51 -16
- package/src/components/panel/types/components-own.ts +3 -3
- package/src/components/panel/types/components-select.ts +131 -32
- package/src/components/panel/types/components-selectMultiple.ts +11 -16
- package/src/components/panel/types/components-slider.ts +2 -3
- package/src/components/panel/types/components-switch.ts +1 -1
- package/src/components/panel/types/components-textarea.ts +1 -1
- package/src/components/rightClickMenu/index.css +1 -1
- package/src/components/searchSuggestion/index.ts +20 -65
- package/src/css/common.css +4 -4
- package/src/types/global.d.ts +3 -1
|
@@ -19,16 +19,17 @@ import type {
|
|
|
19
19
|
PopsPanelEventType,
|
|
20
20
|
PopsPanelViewConfig,
|
|
21
21
|
} from "./types";
|
|
22
|
-
import type { PopsPanelInputConfig } from "./types/components-input";
|
|
22
|
+
import type { PopsPanelInputConfig, PopsPanelInputType } from "./types/components-input";
|
|
23
23
|
import type { PopsPanelOwnConfig } from "./types/components-own";
|
|
24
24
|
import type {
|
|
25
25
|
PopsPanelSelectMultipleDataOption,
|
|
26
26
|
PopsPanelSelectMultipleConfig,
|
|
27
27
|
} from "./types/components-selectMultiple";
|
|
28
|
-
import type { PopsPanelSelectConfig } from "./types/components-select";
|
|
28
|
+
import type { PopsPanelSelectConfig, PopsPanelSelectDataOption } from "./types/components-select";
|
|
29
29
|
import type { PopsPanelSliderConfig } from "./types/components-slider";
|
|
30
30
|
import type { PopsPanelSwitchConfig } from "./types/components-switch";
|
|
31
31
|
import type { PopsPanelTextAreaConfig } from "./types/components-textarea";
|
|
32
|
+
import { PopsCSS } from "../../PopsCSS";
|
|
32
33
|
/**
|
|
33
34
|
* 处理组件(把组件配置转为组件元素)
|
|
34
35
|
*/
|
|
@@ -118,7 +119,7 @@ export const PanelHandlerComponents = () => {
|
|
|
118
119
|
// 初始化内容配置
|
|
119
120
|
data.config.content.forEach((asideItemConfig) => {
|
|
120
121
|
const $asideLiElement = this.createAsideItem(asideItemConfig);
|
|
121
|
-
this.
|
|
122
|
+
this.onAsideItemClick($asideLiElement, asideItemConfig);
|
|
122
123
|
// 是否处于底部
|
|
123
124
|
const isBottom =
|
|
124
125
|
typeof asideItemConfig.isBottom === "function" ? asideItemConfig.isBottom() : asideItemConfig.isBottom;
|
|
@@ -150,7 +151,7 @@ export const PanelHandlerComponents = () => {
|
|
|
150
151
|
// 初始化底部内容配置
|
|
151
152
|
(data.config?.bottomContentConfig || []).forEach((bottomItemConfig) => {
|
|
152
153
|
const $bottomLiElement = this.createBottomItem(bottomItemConfig);
|
|
153
|
-
this.
|
|
154
|
+
this.onBottomItemClick($bottomLiElement, bottomItemConfig);
|
|
154
155
|
if (bottomItemConfig.position === "left" || bottomItemConfig.position == null) {
|
|
155
156
|
this.$el.$panelBottomLeftContainer.appendChild($bottomLiElement);
|
|
156
157
|
} else if (bottomItemConfig.position === "right") {
|
|
@@ -298,7 +299,7 @@ export const PanelHandlerComponents = () => {
|
|
|
298
299
|
* @param $bottomItem 底部<li>元素
|
|
299
300
|
* @param bottomItemConfig 配置
|
|
300
301
|
*/
|
|
301
|
-
|
|
302
|
+
onBottomItemClick($bottomItem: HTMLElement, bottomItemConfig: PopsPanelBottomContentConfig) {
|
|
302
303
|
popsDOMUtils.on<MouseEvent | PointerEvent>($bottomItem, "click", async (event) => {
|
|
303
304
|
if (typeof bottomItemConfig.clickCallback === "function") {
|
|
304
305
|
// 执行回调
|
|
@@ -388,12 +389,12 @@ export const PanelHandlerComponents = () => {
|
|
|
388
389
|
if (disabled) {
|
|
389
390
|
this.disable();
|
|
390
391
|
}
|
|
391
|
-
this.
|
|
392
|
+
this.onClick();
|
|
392
393
|
},
|
|
393
394
|
/**
|
|
394
395
|
* 设置点击事件
|
|
395
396
|
*/
|
|
396
|
-
|
|
397
|
+
onClick() {
|
|
397
398
|
const that = this;
|
|
398
399
|
popsDOMUtils.on(this.$ele.core, "click", function (event) {
|
|
399
400
|
if (that.$ele.input.disabled || that.$ele.switch.hasAttribute("data-disabled")) {
|
|
@@ -448,78 +449,17 @@ export const PanelHandlerComponents = () => {
|
|
|
448
449
|
|
|
449
450
|
PopsPanelSwitch.init();
|
|
450
451
|
Reflect.set($li, "data-switch", PopsPanelSwitch);
|
|
451
|
-
return
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
* type ==> slider
|
|
455
|
-
* 获取中间容器的元素<li>
|
|
456
|
-
* @param viewConfig
|
|
457
|
-
*/
|
|
458
|
-
createSectionContainerItem_slider(viewConfig: PopsPanelSliderConfig) {
|
|
459
|
-
const $li = popsDOMUtils.createElement("li");
|
|
460
|
-
Reflect.set($li, this.$data.nodeStoreConfigKey, viewConfig);
|
|
461
|
-
this.setElementClassName($li, viewConfig.className);
|
|
462
|
-
this.setElementAttributes($li, viewConfig.attributes);
|
|
463
|
-
this.setElementProps($li, viewConfig.props);
|
|
464
|
-
// 左边底部的描述的文字
|
|
465
|
-
let leftDescriptionText = "";
|
|
466
|
-
if (viewConfig.description) {
|
|
467
|
-
leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${viewConfig.description}</p>`;
|
|
468
|
-
}
|
|
469
|
-
PopsSafeUtils.setSafeHTML(
|
|
470
|
-
$li,
|
|
471
|
-
/*html*/ `
|
|
472
|
-
<div class="pops-panel-item-left-text">
|
|
473
|
-
<p class="pops-panel-item-left-main-text">${viewConfig.text}</p>${leftDescriptionText}</div>
|
|
474
|
-
<div class="pops-panel-slider">
|
|
475
|
-
<input type="range" min="${viewConfig.min}" max="${viewConfig.max}">
|
|
476
|
-
</div>
|
|
477
|
-
`
|
|
478
|
-
);
|
|
479
|
-
const $rangeInput = $li.querySelector<HTMLInputElement>(".pops-panel-slider input[type=range]")!;
|
|
480
|
-
if (viewConfig.step) {
|
|
481
|
-
$rangeInput.setAttribute("step", viewConfig.step.toString());
|
|
482
|
-
}
|
|
483
|
-
$rangeInput.value = viewConfig.getValue().toString();
|
|
484
|
-
/**
|
|
485
|
-
* 获取提示的内容
|
|
486
|
-
* @param value
|
|
487
|
-
*/
|
|
488
|
-
const getToolTipContent = function (value: number | string) {
|
|
489
|
-
if (typeof viewConfig.getToolTipContent === "function") {
|
|
490
|
-
return viewConfig.getToolTipContent(value as number);
|
|
491
|
-
} else {
|
|
492
|
-
return value as string;
|
|
493
|
-
}
|
|
452
|
+
return {
|
|
453
|
+
$el: $li,
|
|
454
|
+
handler: PopsPanelSwitch,
|
|
494
455
|
};
|
|
495
|
-
const tooltip = PopsTooltip.init({
|
|
496
|
-
$target: $rangeInput.parentElement!,
|
|
497
|
-
content: () => {
|
|
498
|
-
return getToolTipContent($rangeInput.value);
|
|
499
|
-
},
|
|
500
|
-
zIndex: () => {
|
|
501
|
-
return PopsInstanceUtils.getPopsMaxZIndex().zIndex;
|
|
502
|
-
},
|
|
503
|
-
className: "github-tooltip",
|
|
504
|
-
alwaysShow: false,
|
|
505
|
-
only: false,
|
|
506
|
-
position: "top",
|
|
507
|
-
arrowDistance: 10,
|
|
508
|
-
});
|
|
509
|
-
popsDOMUtils.on<InputEvent>($rangeInput, ["input", "propertychange"], void 0, function (event) {
|
|
510
|
-
tooltip.toolTip.changeContent(getToolTipContent($rangeInput.value));
|
|
511
|
-
if (typeof viewConfig.callback === "function") {
|
|
512
|
-
viewConfig.callback(event, $rangeInput.valueAsNumber);
|
|
513
|
-
}
|
|
514
|
-
});
|
|
515
|
-
return $li;
|
|
516
456
|
},
|
|
517
457
|
/**
|
|
518
458
|
* type ==> slider
|
|
519
459
|
* 获取中间容器的元素<li>
|
|
520
460
|
* @param viewConfig
|
|
521
461
|
*/
|
|
522
|
-
|
|
462
|
+
createSectionContainerItem_slider(viewConfig: PopsPanelSliderConfig) {
|
|
523
463
|
const $li = popsDOMUtils.createElement("li");
|
|
524
464
|
Reflect.set($li, this.$data.nodeStoreConfigKey, viewConfig);
|
|
525
465
|
this.setElementClassName($li, viewConfig.className);
|
|
@@ -631,7 +571,7 @@ export const PanelHandlerComponents = () => {
|
|
|
631
571
|
this.initEleData();
|
|
632
572
|
this.setToolTipEvent();
|
|
633
573
|
this.setPanEvent();
|
|
634
|
-
this.
|
|
574
|
+
this.onRunAwayClick();
|
|
635
575
|
this.intervalInit();
|
|
636
576
|
if (this.isDisabledDragWithConfig()) {
|
|
637
577
|
this.disableDrag();
|
|
@@ -901,7 +841,7 @@ export const PanelHandlerComponents = () => {
|
|
|
901
841
|
/**
|
|
902
842
|
* 设置进度条点击定位的事件
|
|
903
843
|
*/
|
|
904
|
-
|
|
844
|
+
onRunAwayClick() {
|
|
905
845
|
popsDOMUtils.on<PointerEvent | MouseEvent>(
|
|
906
846
|
this.$ele.runAway,
|
|
907
847
|
"click",
|
|
@@ -1108,7 +1048,10 @@ export const PanelHandlerComponents = () => {
|
|
|
1108
1048
|
};
|
|
1109
1049
|
PopsPanelSlider.init();
|
|
1110
1050
|
Reflect.set($li, "data-slider", PopsPanelSlider);
|
|
1111
|
-
return
|
|
1051
|
+
return {
|
|
1052
|
+
$el: $li,
|
|
1053
|
+
handler: PopsPanelSlider,
|
|
1054
|
+
};
|
|
1112
1055
|
},
|
|
1113
1056
|
/**
|
|
1114
1057
|
* type ==> input
|
|
@@ -1121,12 +1064,8 @@ export const PanelHandlerComponents = () => {
|
|
|
1121
1064
|
this.setElementClassName($li, viewConfig.className);
|
|
1122
1065
|
this.setElementAttributes($li, viewConfig.attributes);
|
|
1123
1066
|
this.setElementProps($li, viewConfig.props);
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
inputType = "password";
|
|
1127
|
-
} else if (viewConfig.isNumber) {
|
|
1128
|
-
inputType = "number";
|
|
1129
|
-
}
|
|
1067
|
+
const defaultInputType: PopsPanelInputType = "text";
|
|
1068
|
+
const inputType = viewConfig.inputType || defaultInputType;
|
|
1130
1069
|
// 左边底部的描述的文字
|
|
1131
1070
|
let leftDescriptionText = "";
|
|
1132
1071
|
if (viewConfig.description) {
|
|
@@ -1138,139 +1077,194 @@ export const PanelHandlerComponents = () => {
|
|
|
1138
1077
|
<div class="pops-panel-item-left-text">
|
|
1139
1078
|
<p class="pops-panel-item-left-main-text">${viewConfig.text}</p>${leftDescriptionText}</div>
|
|
1140
1079
|
<div class="pops-panel-input">
|
|
1141
|
-
|
|
1080
|
+
<div class="pops-panel-input_inner">
|
|
1081
|
+
<input type="${inputType}" placeholder="${viewConfig.placeholder ?? ""}">
|
|
1082
|
+
</div>
|
|
1142
1083
|
</div>
|
|
1143
1084
|
`
|
|
1144
1085
|
);
|
|
1145
1086
|
const PopsPanelInput = {
|
|
1146
1087
|
[Symbol.toStringTag]: "PopsPanelInput",
|
|
1147
|
-
$
|
|
1088
|
+
$el: {
|
|
1148
1089
|
itemLeftTextContainer: $li.querySelector<HTMLElement>(".pops-panel-item-left-text"),
|
|
1149
1090
|
panelInput: $li.querySelector<HTMLDivElement>(".pops-panel-input")!,
|
|
1091
|
+
panelInputInner: $li.querySelector<HTMLDivElement>(".pops-panel-input_inner")!,
|
|
1150
1092
|
input: $li.querySelector<HTMLInputElement>("input")!,
|
|
1151
|
-
|
|
1152
|
-
|
|
1093
|
+
/** span.pops-panel-input__suffix */
|
|
1094
|
+
suffix: popsDOMUtils.createElement("span"),
|
|
1095
|
+
/** span.pops-panel-input__suffix-inner */
|
|
1096
|
+
suffixInner: null as any as HTMLSpanElement,
|
|
1097
|
+
/** i.pops-panel-icon */
|
|
1153
1098
|
icon: null as any as HTMLElement,
|
|
1154
1099
|
},
|
|
1155
1100
|
$data: {
|
|
1156
1101
|
value: viewConfig.getValue(),
|
|
1157
|
-
|
|
1102
|
+
/**
|
|
1103
|
+
* inputType 为 password时使用该值
|
|
1104
|
+
*
|
|
1105
|
+
* 当前内容的可见性
|
|
1106
|
+
*/
|
|
1107
|
+
isVisible: false,
|
|
1158
1108
|
},
|
|
1159
1109
|
init() {
|
|
1160
1110
|
this.initEle();
|
|
1161
1111
|
this.setInputValue(this.$data.value);
|
|
1162
1112
|
// 如果是密码框,放进图标
|
|
1163
|
-
if (viewConfig.
|
|
1113
|
+
if (viewConfig.inputType === "password") {
|
|
1114
|
+
// 显示密码
|
|
1164
1115
|
this.setCircleIcon(PopsIcon.getIcon("view")!);
|
|
1165
|
-
this.
|
|
1116
|
+
this.onIconClick();
|
|
1166
1117
|
} else {
|
|
1167
1118
|
// 先判断预设值是否为空,不为空添加清空图标按钮
|
|
1168
|
-
|
|
1119
|
+
// 且为普通的输入框
|
|
1120
|
+
if (this.$el.input.value != "" && this.isTextInputType()) {
|
|
1121
|
+
// 清除内容的图标
|
|
1169
1122
|
this.setCircleIcon(PopsIcon.getIcon("circleClose")!);
|
|
1170
|
-
this.
|
|
1123
|
+
this.onIconClick();
|
|
1124
|
+
} else {
|
|
1125
|
+
// 隐藏图标
|
|
1126
|
+
this.hideCircleIconWrapper();
|
|
1171
1127
|
}
|
|
1172
1128
|
}
|
|
1173
1129
|
|
|
1174
|
-
this.
|
|
1130
|
+
this.onValueChange();
|
|
1175
1131
|
// 是否禁用复选框
|
|
1176
1132
|
const disabled = typeof viewConfig.disabled === "function" ? viewConfig.disabled() : viewConfig.disabled;
|
|
1177
1133
|
if (disabled) {
|
|
1178
1134
|
this.disable();
|
|
1179
1135
|
}
|
|
1180
1136
|
if (typeof viewConfig.handlerCallBack === "function") {
|
|
1181
|
-
viewConfig.handlerCallBack($li, this.$
|
|
1137
|
+
viewConfig.handlerCallBack($li, this.$el.input);
|
|
1182
1138
|
}
|
|
1183
1139
|
},
|
|
1184
1140
|
/**
|
|
1185
1141
|
* 初始化$ele的配置
|
|
1186
1142
|
*/
|
|
1187
1143
|
initEle() {
|
|
1188
|
-
this.$
|
|
1189
|
-
popsDOMUtils.addClassName(this.$
|
|
1144
|
+
this.$el.input.parentElement!.insertBefore(this.$el.suffix, this.$el.input.nextSibling);
|
|
1145
|
+
popsDOMUtils.addClassName(this.$el.suffix, "pops-panel-input__suffix");
|
|
1190
1146
|
PopsSafeUtils.setSafeHTML(
|
|
1191
|
-
this.$
|
|
1147
|
+
this.$el.suffix,
|
|
1192
1148
|
/*html*/ `
|
|
1193
1149
|
<span class="pops-panel-input__suffix-inner">
|
|
1194
1150
|
<i class="pops-panel-icon"></i>
|
|
1195
1151
|
</span>
|
|
1196
1152
|
`
|
|
1197
1153
|
);
|
|
1198
|
-
this.$
|
|
1199
|
-
|
|
1200
|
-
)
|
|
1201
|
-
|
|
1202
|
-
|
|
1154
|
+
this.$el.suffixInner = this.$el.suffix.querySelector<HTMLElement>(".pops-panel-input__suffix-inner")!;
|
|
1155
|
+
this.$el.icon = this.$el.suffix.querySelector<HTMLElement>(".pops-panel-icon")!;
|
|
1156
|
+
popsDOMUtils.addClassName(this.$el.panelInput, PopsCommonCSSClassName.userSelectNone);
|
|
1157
|
+
},
|
|
1158
|
+
/**
|
|
1159
|
+
* 校验输入框类型是否是字符串输入框类型
|
|
1160
|
+
*/
|
|
1161
|
+
isTextInputType() {
|
|
1162
|
+
const typeList: PopsPanelInputType[] = ["text", "search", "email", "tel", "url"];
|
|
1163
|
+
return typeList.includes(viewConfig.inputType || defaultInputType);
|
|
1164
|
+
},
|
|
1165
|
+
/**
|
|
1166
|
+
* 是否是时间输入框类型
|
|
1167
|
+
*/
|
|
1168
|
+
isDateInputType() {
|
|
1169
|
+
const typeList: PopsPanelInputType[] = ["date", "datetime-local", "month", "time", "week"];
|
|
1170
|
+
return typeList.includes(viewConfig.inputType || defaultInputType);
|
|
1171
|
+
},
|
|
1172
|
+
/**
|
|
1173
|
+
* 是否是数字输入框类型
|
|
1174
|
+
*/
|
|
1175
|
+
isNumberInputType() {
|
|
1176
|
+
const typeList: PopsPanelInputType[] = ["number"];
|
|
1177
|
+
return typeList.includes(viewConfig.inputType || defaultInputType);
|
|
1203
1178
|
},
|
|
1204
1179
|
/**
|
|
1205
1180
|
* 禁用
|
|
1206
1181
|
*/
|
|
1207
1182
|
disable() {
|
|
1208
|
-
this.$
|
|
1209
|
-
popsDOMUtils.addClassName(this.$
|
|
1210
|
-
popsDOMUtils.addClassName(this.$
|
|
1183
|
+
this.$el.input.disabled = true;
|
|
1184
|
+
popsDOMUtils.addClassName(this.$el.panelInput, "pops-input-disabled");
|
|
1185
|
+
popsDOMUtils.addClassName(this.$el.itemLeftTextContainer, PopsCommonCSSClassName.textIsDisabled);
|
|
1211
1186
|
},
|
|
1212
1187
|
/**
|
|
1213
1188
|
* 取消禁用
|
|
1214
1189
|
*/
|
|
1215
1190
|
notDisable() {
|
|
1216
|
-
this.$
|
|
1217
|
-
popsDOMUtils.removeClassName(this.$
|
|
1218
|
-
popsDOMUtils.removeClassName(this.$
|
|
1191
|
+
this.$el.input.disabled = false;
|
|
1192
|
+
popsDOMUtils.removeClassName(this.$el.panelInput, "pops-input-disabled");
|
|
1193
|
+
popsDOMUtils.removeClassName(this.$el.itemLeftTextContainer, PopsCommonCSSClassName.textIsDisabled);
|
|
1219
1194
|
},
|
|
1220
1195
|
/**
|
|
1221
1196
|
* 判断是否已被禁用
|
|
1222
1197
|
*/
|
|
1223
1198
|
isDisabled() {
|
|
1224
|
-
return this.$
|
|
1199
|
+
return this.$el.input.disabled;
|
|
1225
1200
|
},
|
|
1226
1201
|
/**
|
|
1227
1202
|
* 设置输入框内容
|
|
1228
|
-
* @param
|
|
1203
|
+
* @param value 值
|
|
1229
1204
|
*/
|
|
1230
|
-
setInputValue(value = "") {
|
|
1231
|
-
this
|
|
1205
|
+
setInputValue(value: string | number | Date = "") {
|
|
1206
|
+
if (typeof value === "number" && this.isNumberInputType()) {
|
|
1207
|
+
this.$el.input.valueAsNumber = value;
|
|
1208
|
+
} else if (typeof value === "object" && value instanceof Date && this.isDateInputType()) {
|
|
1209
|
+
this.$el.input.valueAsDate = value;
|
|
1210
|
+
} else {
|
|
1211
|
+
this.$el.input.value = value.toString();
|
|
1212
|
+
}
|
|
1232
1213
|
},
|
|
1233
1214
|
/**
|
|
1234
1215
|
* 设置input元素的type
|
|
1235
|
-
* @param
|
|
1216
|
+
* @param typeValue type值
|
|
1236
1217
|
*/
|
|
1237
|
-
setInputType(typeValue = "text") {
|
|
1238
|
-
this.$
|
|
1218
|
+
setInputType(typeValue: PopsPanelInputType = "text") {
|
|
1219
|
+
this.$el.input.setAttribute("type", typeValue);
|
|
1239
1220
|
},
|
|
1240
1221
|
/**
|
|
1241
1222
|
* 删除图标按钮
|
|
1242
1223
|
*/
|
|
1243
1224
|
removeCircleIcon() {
|
|
1244
|
-
PopsSafeUtils.setSafeHTML(this.$
|
|
1225
|
+
PopsSafeUtils.setSafeHTML(this.$el.icon, "");
|
|
1245
1226
|
},
|
|
1246
1227
|
/**
|
|
1247
1228
|
* 添加清空图标按钮
|
|
1248
|
-
* @param
|
|
1229
|
+
* @param svgHTML svg图标,默认为清空的图标
|
|
1249
1230
|
*/
|
|
1250
|
-
setCircleIcon(svgHTML = PopsIcon.getIcon("circleClose")!) {
|
|
1251
|
-
PopsSafeUtils.setSafeHTML(this.$
|
|
1231
|
+
setCircleIcon(svgHTML: string = PopsIcon.getIcon("circleClose")!) {
|
|
1232
|
+
PopsSafeUtils.setSafeHTML(this.$el.icon, svgHTML);
|
|
1233
|
+
},
|
|
1234
|
+
/**
|
|
1235
|
+
* 隐藏图标容器
|
|
1236
|
+
*/
|
|
1237
|
+
hideCircleIconWrapper() {
|
|
1238
|
+
popsDOMUtils.cssHide(this.$el.suffix, true);
|
|
1239
|
+
},
|
|
1240
|
+
/**
|
|
1241
|
+
* 显示图标容器
|
|
1242
|
+
*/
|
|
1243
|
+
showCircleIconWrapper() {
|
|
1244
|
+
popsDOMUtils.cssShow(this.$el.suffix);
|
|
1252
1245
|
},
|
|
1253
1246
|
/**
|
|
1254
1247
|
* 添加图标按钮的点击事件
|
|
1255
1248
|
*/
|
|
1256
|
-
|
|
1257
|
-
popsDOMUtils.on(this.$
|
|
1249
|
+
onIconClick() {
|
|
1250
|
+
popsDOMUtils.on(this.$el.icon, "click", (evt) => {
|
|
1251
|
+
popsDOMUtils.preventEvent(evt);
|
|
1258
1252
|
if (this.isDisabled()) {
|
|
1259
1253
|
return;
|
|
1260
1254
|
}
|
|
1261
1255
|
// 删除图标
|
|
1262
1256
|
this.removeCircleIcon();
|
|
1263
|
-
if (
|
|
1264
|
-
//
|
|
1265
|
-
if (this.$data.
|
|
1257
|
+
if (inputType === "password") {
|
|
1258
|
+
// 配置类型为密码输入框
|
|
1259
|
+
if (this.$data.isVisible) {
|
|
1266
1260
|
// 当前可见 => 点击改变为隐藏
|
|
1267
|
-
this.$data.
|
|
1261
|
+
this.$data.isVisible = false;
|
|
1268
1262
|
// 显示输入框内容,且更换图标为隐藏图标
|
|
1269
1263
|
this.setInputType("text");
|
|
1270
1264
|
this.setCircleIcon(PopsIcon.getIcon("hide")!);
|
|
1271
1265
|
} else {
|
|
1272
1266
|
// 当前不可见 => 点击改变为显示
|
|
1273
|
-
this.$data.
|
|
1267
|
+
this.$data.isVisible = true;
|
|
1274
1268
|
// 隐藏输入框内容,且更换图标为显示图标
|
|
1275
1269
|
this.setInputType("password");
|
|
1276
1270
|
this.setCircleIcon(PopsIcon.getIcon("view")!);
|
|
@@ -1280,41 +1274,98 @@ export const PanelHandlerComponents = () => {
|
|
|
1280
1274
|
// 清空内容
|
|
1281
1275
|
this.setInputValue("");
|
|
1282
1276
|
// 获取焦点
|
|
1283
|
-
this.$
|
|
1277
|
+
this.$el.input.focus();
|
|
1284
1278
|
// 触发内容改变事件
|
|
1285
|
-
this.$
|
|
1279
|
+
this.$el.input.dispatchEvent(new Event("input"));
|
|
1286
1280
|
}
|
|
1287
1281
|
});
|
|
1288
1282
|
},
|
|
1289
1283
|
/**
|
|
1290
1284
|
* 监听输入框内容改变
|
|
1291
1285
|
*/
|
|
1292
|
-
|
|
1293
|
-
popsDOMUtils.on<InputEvent>(this.$
|
|
1294
|
-
this.$data.value = this.$
|
|
1295
|
-
if (
|
|
1286
|
+
onValueChange() {
|
|
1287
|
+
popsDOMUtils.on<InputEvent>(this.$el.input, ["input", "propertychange"], void 0, (event) => {
|
|
1288
|
+
this.$data.value = this.$el.input.value;
|
|
1289
|
+
if (inputType !== "password") {
|
|
1296
1290
|
// 不是密码框
|
|
1297
|
-
if (this.$
|
|
1291
|
+
if (this.$el.input.value !== "" && this.$el.icon.innerHTML === "" && this.isTextInputType()) {
|
|
1298
1292
|
// 不为空,显示清空图标
|
|
1299
1293
|
this.setCircleIcon(PopsIcon.getIcon("circleClose")!);
|
|
1300
|
-
this.
|
|
1301
|
-
|
|
1294
|
+
this.onIconClick();
|
|
1295
|
+
this.showCircleIconWrapper();
|
|
1296
|
+
} else if (this.$el.input.value === "") {
|
|
1302
1297
|
this.removeCircleIcon();
|
|
1303
1298
|
}
|
|
1304
1299
|
}
|
|
1305
1300
|
if (typeof viewConfig.callback === "function") {
|
|
1306
|
-
|
|
1307
|
-
|
|
1301
|
+
let ret;
|
|
1302
|
+
if (viewConfig.inputType === "number") {
|
|
1303
|
+
ret = viewConfig.callback(event, this.$el.input.value, this.$el.input.valueAsNumber);
|
|
1304
|
+
} else if (this.isDateInputType()) {
|
|
1305
|
+
ret = viewConfig.callback(
|
|
1306
|
+
event,
|
|
1307
|
+
this.$el.input.value,
|
|
1308
|
+
this.$el.input.valueAsNumber,
|
|
1309
|
+
this.$el.input.valueAsDate
|
|
1310
|
+
);
|
|
1311
|
+
} else {
|
|
1312
|
+
ret = viewConfig.callback(event, this.$el.input.value);
|
|
1313
|
+
}
|
|
1314
|
+
if (ret) {
|
|
1315
|
+
if (ret.valid) {
|
|
1316
|
+
// 校验通过
|
|
1317
|
+
this.removeValidErrorMsg();
|
|
1318
|
+
} else {
|
|
1319
|
+
// 校验失败
|
|
1320
|
+
// 显示失败提示
|
|
1321
|
+
this.addValidErrorMsg(ret.message);
|
|
1322
|
+
}
|
|
1308
1323
|
} else {
|
|
1309
|
-
|
|
1324
|
+
this.removeValidErrorMsg();
|
|
1310
1325
|
}
|
|
1311
1326
|
}
|
|
1312
1327
|
});
|
|
1313
1328
|
},
|
|
1329
|
+
/**
|
|
1330
|
+
* 主动触发输入框改变事件
|
|
1331
|
+
*/
|
|
1332
|
+
triggerValueChange() {
|
|
1333
|
+
this.$el.input.dispatchEvent(new Event("input"));
|
|
1334
|
+
},
|
|
1335
|
+
/**
|
|
1336
|
+
* 添加校验失败的提示信息
|
|
1337
|
+
* @param msg 提示信息
|
|
1338
|
+
*/
|
|
1339
|
+
addValidErrorMsg(msg?: string) {
|
|
1340
|
+
if (msg == null) return;
|
|
1341
|
+
const $validErrorMsg =
|
|
1342
|
+
this.$el.panelInput.querySelector<HTMLDivElement>(".pops-panel-input-valid-error") ||
|
|
1343
|
+
popsDOMUtils.createElement("div", {
|
|
1344
|
+
className: "pops-panel-input-valid-error",
|
|
1345
|
+
innerHTML: /*html*/ `<span></span>`,
|
|
1346
|
+
});
|
|
1347
|
+
const $validErrorMsgSpan = $validErrorMsg.querySelector("span")!;
|
|
1348
|
+
if ($validErrorMsgSpan.innerHTML !== msg) {
|
|
1349
|
+
PopsSafeUtils.setSafeHTML($validErrorMsgSpan, msg);
|
|
1350
|
+
}
|
|
1351
|
+
if (!$validErrorMsg.parentElement) {
|
|
1352
|
+
popsDOMUtils.after(this.$el.panelInputInner, $validErrorMsg);
|
|
1353
|
+
}
|
|
1354
|
+
},
|
|
1355
|
+
/**
|
|
1356
|
+
* 移除校验失败的提示信息
|
|
1357
|
+
*/
|
|
1358
|
+
removeValidErrorMsg() {
|
|
1359
|
+
const $validErrorMsg = this.$el.panelInput.querySelector(".pops-panel-input-valid-error");
|
|
1360
|
+
$validErrorMsg?.remove();
|
|
1361
|
+
},
|
|
1314
1362
|
};
|
|
1315
1363
|
PopsPanelInput.init();
|
|
1316
1364
|
Reflect.set($li, "data-input", PopsPanelInput);
|
|
1317
|
-
return
|
|
1365
|
+
return {
|
|
1366
|
+
$el: $li,
|
|
1367
|
+
handler: PopsPanelInput,
|
|
1368
|
+
};
|
|
1318
1369
|
},
|
|
1319
1370
|
/**
|
|
1320
1371
|
* type ==> textarea
|
|
@@ -1356,7 +1407,7 @@ export const PanelHandlerComponents = () => {
|
|
|
1356
1407
|
},
|
|
1357
1408
|
init() {
|
|
1358
1409
|
this.setValue(this.$data.value);
|
|
1359
|
-
this.
|
|
1410
|
+
this.onValueChange();
|
|
1360
1411
|
const disabled = typeof viewConfig.disabled === "function" ? viewConfig.disabled() : viewConfig.disabled;
|
|
1361
1412
|
if (disabled) {
|
|
1362
1413
|
this.disable();
|
|
@@ -1384,7 +1435,7 @@ export const PanelHandlerComponents = () => {
|
|
|
1384
1435
|
/**
|
|
1385
1436
|
* 监听选择内容改变
|
|
1386
1437
|
*/
|
|
1387
|
-
|
|
1438
|
+
onValueChange() {
|
|
1388
1439
|
popsDOMUtils.on<InputEvent>(this.$ele.textarea, ["input", "propertychange"], (event) => {
|
|
1389
1440
|
const value = this.$ele.textarea.value;
|
|
1390
1441
|
this.$data.value = value;
|
|
@@ -1403,209 +1454,1214 @@ export const PanelHandlerComponents = () => {
|
|
|
1403
1454
|
PopsPanelTextArea.init();
|
|
1404
1455
|
Reflect.set($li, "data-textarea", PopsPanelTextArea);
|
|
1405
1456
|
|
|
1406
|
-
return
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
this
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1457
|
+
return {
|
|
1458
|
+
$el: $li,
|
|
1459
|
+
handler: PopsPanelTextArea,
|
|
1460
|
+
};
|
|
1461
|
+
},
|
|
1462
|
+
/**
|
|
1463
|
+
* type ==> select
|
|
1464
|
+
* 获取中间容器的元素<li>
|
|
1465
|
+
* @param viewConfig
|
|
1466
|
+
*/
|
|
1467
|
+
createSectionContainerItem_select(viewConfig: PopsPanelSelectConfig<any>) {
|
|
1468
|
+
const that = this;
|
|
1469
|
+
const $li = popsDOMUtils.createElement("li");
|
|
1470
|
+
Reflect.set($li, this.$data.nodeStoreConfigKey, viewConfig);
|
|
1471
|
+
this.setElementClassName($li, viewConfig.className);
|
|
1472
|
+
this.setElementAttributes($li, viewConfig.attributes);
|
|
1473
|
+
this.setElementProps($li, viewConfig.props);
|
|
1474
|
+
// 左边底部的描述的文字
|
|
1475
|
+
let leftDescriptionText = "";
|
|
1476
|
+
if (viewConfig.description) {
|
|
1477
|
+
leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${viewConfig.description}</p>`;
|
|
1478
|
+
}
|
|
1479
|
+
PopsSafeUtils.setSafeHTML(
|
|
1480
|
+
$li,
|
|
1481
|
+
/*html*/ `
|
|
1482
|
+
<div class="pops-panel-item-left-text">
|
|
1483
|
+
<p class="pops-panel-item-left-main-text">${viewConfig.text}</p>${leftDescriptionText}</div>
|
|
1484
|
+
<div class="pops-panel-select">
|
|
1485
|
+
<select></select>
|
|
1486
|
+
</div>
|
|
1487
|
+
`
|
|
1488
|
+
);
|
|
1489
|
+
const $itemLeftContainer = $li.querySelector<HTMLElement>(".pops-panel-item-left-text")!;
|
|
1490
|
+
const $container = $li.querySelector<HTMLElement>(".pops-panel-select")!;
|
|
1491
|
+
const $select = $li.querySelector<HTMLSelectElement>(".pops-panel-select select")!;
|
|
1492
|
+
const width = (typeof viewConfig.width === "number" ? `${viewConfig.width}px` : viewConfig.width) ?? "200px";
|
|
1493
|
+
popsDOMUtils.css($container, "width", width);
|
|
1494
|
+
const mode = viewConfig.mode ?? "native";
|
|
1495
|
+
let handler;
|
|
1496
|
+
if (mode === "native") {
|
|
1497
|
+
const PopsPanelSelectNative = {
|
|
1498
|
+
[Symbol.toStringTag]: "PopsPanelSelectNative",
|
|
1499
|
+
$el: {
|
|
1500
|
+
itemLeftTextContainer: $itemLeftContainer,
|
|
1501
|
+
$container: $container,
|
|
1502
|
+
$select: $select,
|
|
1503
|
+
},
|
|
1504
|
+
$eleKey: {
|
|
1505
|
+
disable: "__disable__",
|
|
1506
|
+
value: "__value__",
|
|
1507
|
+
viewConfig: "data-view-config",
|
|
1508
|
+
},
|
|
1509
|
+
$data: {
|
|
1510
|
+
data: [] as PopsPanelSelectDataOption<any>[],
|
|
1511
|
+
defaultValue: viewConfig.getValue(),
|
|
1512
|
+
},
|
|
1513
|
+
init() {
|
|
1514
|
+
this.$el.$container.setAttribute("data-mode", mode);
|
|
1515
|
+
this.$data.data = typeof viewConfig.data === "function" ? viewConfig.data() : viewConfig.data;
|
|
1516
|
+
popsDOMUtils.addClassName(this.$el.$container, PopsCommonCSSClassName.userSelectNone);
|
|
1517
|
+
this.initOption();
|
|
1518
|
+
this.onValueChange();
|
|
1519
|
+
this.onClick();
|
|
1520
|
+
const disabled = typeof viewConfig.disabled === "function" ? viewConfig.disabled() : viewConfig.disabled;
|
|
1521
|
+
if (disabled) {
|
|
1522
|
+
this.disable();
|
|
1523
|
+
}
|
|
1524
|
+
},
|
|
1525
|
+
/**
|
|
1526
|
+
* 给option元素设置属性
|
|
1527
|
+
* @param $ele
|
|
1528
|
+
* @param key
|
|
1529
|
+
* @param value
|
|
1530
|
+
*/
|
|
1531
|
+
setNodeValue($ele: HTMLElement, key: string, value: any) {
|
|
1532
|
+
Reflect.set($ele, key, value);
|
|
1533
|
+
},
|
|
1534
|
+
/**
|
|
1535
|
+
* 获取option元素上设置的属性
|
|
1536
|
+
* @param $ele
|
|
1537
|
+
* @param value
|
|
1538
|
+
* @param key
|
|
1539
|
+
*/
|
|
1540
|
+
getNodeValue($ele: HTMLElement, key: string) {
|
|
1541
|
+
return Reflect.get($ele, key);
|
|
1542
|
+
},
|
|
1543
|
+
/**
|
|
1544
|
+
* 禁用选项
|
|
1545
|
+
*/
|
|
1546
|
+
disable() {
|
|
1547
|
+
this.$el.$select.setAttribute("disabled", "true");
|
|
1548
|
+
popsDOMUtils.addClassName(this.$el.$container, "pops-panel-select-disable");
|
|
1549
|
+
popsDOMUtils.addClassName(this.$el.itemLeftTextContainer, PopsCommonCSSClassName.textIsDisabled);
|
|
1550
|
+
},
|
|
1551
|
+
/**
|
|
1552
|
+
* 取消禁用
|
|
1553
|
+
*/
|
|
1554
|
+
notDisable() {
|
|
1555
|
+
this.$el.$select.removeAttribute("disabled");
|
|
1556
|
+
popsDOMUtils.removeClassName(this.$el.$container, "pops-panel-select-disable");
|
|
1557
|
+
popsDOMUtils.removeClassName(this.$el.itemLeftTextContainer, PopsCommonCSSClassName.textIsDisabled);
|
|
1558
|
+
},
|
|
1559
|
+
/**
|
|
1560
|
+
* 判断是否禁用
|
|
1561
|
+
*/
|
|
1562
|
+
isDisabled() {
|
|
1563
|
+
return (
|
|
1564
|
+
this.$el.$select.hasAttribute("disabled") ||
|
|
1565
|
+
popsDOMUtils.containsClassName(this.$el.$container, "pops-panel-select-disable")
|
|
1566
|
+
);
|
|
1567
|
+
},
|
|
1568
|
+
/**
|
|
1569
|
+
* 初始化选项
|
|
1570
|
+
*/
|
|
1571
|
+
initOption() {
|
|
1572
|
+
this.$data.data.forEach((dataItem) => {
|
|
1573
|
+
// 初始化默认选中
|
|
1574
|
+
const optionElement = popsDOMUtils.createElement("option");
|
|
1575
|
+
this.setNodeValue(optionElement, this.$eleKey.value, dataItem.value);
|
|
1576
|
+
this.setNodeValue(optionElement, this.$eleKey.disable, dataItem.disable);
|
|
1577
|
+
this.setNodeValue(optionElement, this.$eleKey.viewConfig, dataItem.views);
|
|
1578
|
+
if (dataItem.value === this.$data.defaultValue) {
|
|
1579
|
+
this.setOptionSelected(optionElement);
|
|
1580
|
+
}
|
|
1581
|
+
if (typeof dataItem.text === "function") {
|
|
1582
|
+
optionElement.innerText = dataItem.text(dataItem.value, dataItem);
|
|
1583
|
+
} else {
|
|
1584
|
+
optionElement.innerText = dataItem.text;
|
|
1585
|
+
}
|
|
1586
|
+
this.$el.$select.appendChild(optionElement);
|
|
1587
|
+
});
|
|
1588
|
+
},
|
|
1589
|
+
/**
|
|
1590
|
+
* 设置选项选中
|
|
1591
|
+
* @param $option
|
|
1592
|
+
*/
|
|
1593
|
+
setOptionSelected($option: HTMLOptionElement) {
|
|
1594
|
+
$option.setAttribute("selected", "true");
|
|
1595
|
+
},
|
|
1596
|
+
/**
|
|
1597
|
+
* 检测所有option并设置禁用状态
|
|
1598
|
+
*/
|
|
1599
|
+
setSelectOptionsDisableStatus() {
|
|
1600
|
+
if (this.$el.$select.options && this.$el.$select.options.length) {
|
|
1601
|
+
Array.from(this.$el.$select.options).forEach((optionItem) => {
|
|
1602
|
+
this.setOptionDisableStatus(optionItem);
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
},
|
|
1606
|
+
/**
|
|
1607
|
+
* 设置禁用状态
|
|
1608
|
+
* @param $option
|
|
1609
|
+
*/
|
|
1610
|
+
setOptionDisableStatus($option: HTMLOptionElement) {
|
|
1611
|
+
let disable = false;
|
|
1612
|
+
const optionDisableAttr = this.getNodeValue($option, this.$eleKey.disable);
|
|
1613
|
+
if (optionDisableAttr === "function") {
|
|
1614
|
+
const value = this.getNodeValue($option, this.$eleKey.value);
|
|
1615
|
+
disable = Boolean(optionDisableAttr(value));
|
|
1616
|
+
}
|
|
1617
|
+
if (disable) {
|
|
1618
|
+
$option.setAttribute("disabled", "true");
|
|
1619
|
+
} else {
|
|
1620
|
+
$option.removeAttribute("disabled");
|
|
1621
|
+
}
|
|
1622
|
+
},
|
|
1623
|
+
/**
|
|
1624
|
+
* 获取option上的信息
|
|
1625
|
+
* @param $option
|
|
1626
|
+
*/
|
|
1627
|
+
getSelectOptionInfo($option: HTMLOptionElement) {
|
|
1628
|
+
const optionValue = this.getNodeValue($option, this.$eleKey.value);
|
|
1629
|
+
const optionText = $option.innerText || $option.textContent!;
|
|
1630
|
+
const views = this.getNodeValue($option, this.$eleKey.viewConfig) as NonNullable<
|
|
1631
|
+
PopsPanelSelectDataOption<any>["views"]
|
|
1632
|
+
>;
|
|
1633
|
+
return {
|
|
1634
|
+
value: optionValue,
|
|
1635
|
+
text: optionText,
|
|
1636
|
+
views: views,
|
|
1637
|
+
$option: $option,
|
|
1638
|
+
};
|
|
1639
|
+
},
|
|
1640
|
+
/**
|
|
1641
|
+
* 监听选择内容改变
|
|
1642
|
+
*/
|
|
1643
|
+
onValueChange() {
|
|
1644
|
+
popsDOMUtils.on<PointerEvent | TouchEvent>(this.$el.$select, "change", () => {
|
|
1645
|
+
const $isSelectedElement = this.$el.$select[this.$el.$select.selectedIndex] as HTMLOptionElement;
|
|
1646
|
+
const selectInfo = this.getSelectOptionInfo($isSelectedElement);
|
|
1647
|
+
this.setSelectOptionsDisableStatus();
|
|
1648
|
+
if (typeof viewConfig.callback === "function") {
|
|
1649
|
+
viewConfig.callback(selectInfo);
|
|
1650
|
+
}
|
|
1651
|
+
const views = typeof selectInfo.views === "function" ? selectInfo.views() : selectInfo.views;
|
|
1652
|
+
if (Array.isArray(views)) {
|
|
1653
|
+
// 如果成功创建,加入到中间容器中
|
|
1654
|
+
const childUListClassName = "pops-panel-select-child-forms";
|
|
1655
|
+
// 移除旧的元素
|
|
1656
|
+
while ($li.nextElementSibling) {
|
|
1657
|
+
if ($li.nextElementSibling.classList.contains(childUListClassName)) {
|
|
1658
|
+
$li.nextElementSibling.remove();
|
|
1659
|
+
} else {
|
|
1660
|
+
break;
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
const $childUList = popsDOMUtils.createElement("ul");
|
|
1664
|
+
$childUList.className = childUListClassName;
|
|
1665
|
+
popsDOMUtils.after($li, $childUList);
|
|
1666
|
+
that.uListContainerAddItem(viewConfig, {
|
|
1667
|
+
ulElement: $childUList,
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
});
|
|
1671
|
+
},
|
|
1672
|
+
/**
|
|
1673
|
+
* 监听点击事件
|
|
1674
|
+
*/
|
|
1675
|
+
onClick() {
|
|
1676
|
+
popsDOMUtils.on(this.$el.$select, "click", void 0, (event) => {
|
|
1677
|
+
this.setSelectOptionsDisableStatus();
|
|
1678
|
+
if (typeof viewConfig.clickCallBack === "function") {
|
|
1679
|
+
const $isSelectedElement = this.$el.$select[this.$el.$select.selectedIndex] as HTMLOptionElement;
|
|
1680
|
+
const selectInfo = this.getSelectOptionInfo($isSelectedElement);
|
|
1681
|
+
viewConfig.clickCallBack(event, selectInfo);
|
|
1682
|
+
}
|
|
1683
|
+
});
|
|
1684
|
+
},
|
|
1685
|
+
};
|
|
1686
|
+
|
|
1687
|
+
PopsPanelSelectNative.init();
|
|
1688
|
+
Reflect.set($li, "data-select", PopsPanelSelectNative);
|
|
1689
|
+
handler = PopsPanelSelectNative;
|
|
1690
|
+
} else if (mode === "dialog") {
|
|
1691
|
+
const PopsPanelSelect = {
|
|
1692
|
+
[Symbol.toStringTag]: "PopsPanelSelect",
|
|
1693
|
+
$el: {
|
|
1694
|
+
$itemLeftContainer: $itemLeftContainer,
|
|
1695
|
+
/** 选择框容器 */
|
|
1696
|
+
$container: void 0 as any as HTMLElement,
|
|
1697
|
+
/** 选择框包裹的容器 */
|
|
1698
|
+
$wrapper: void 0 as any as HTMLElement,
|
|
1699
|
+
/** 内容区域 */
|
|
1700
|
+
$section: void 0 as any as HTMLElement,
|
|
1701
|
+
/** 手动输入 */
|
|
1702
|
+
$selectedInputWrapper: void 0 as any as HTMLElement,
|
|
1703
|
+
/** 灰色提示语 */
|
|
1704
|
+
$selectedPlaceHolderWrapper: void 0 as any as HTMLElement,
|
|
1705
|
+
/** 下拉箭头区域 */
|
|
1706
|
+
$suffix: void 0 as any as HTMLElement,
|
|
1707
|
+
/** 下拉箭头图标 */
|
|
1708
|
+
$suffixIcon: void 0 as any as HTMLElement,
|
|
1709
|
+
/** 下拉列表弹窗的下拉列表容器 */
|
|
1710
|
+
$selectDialogContainer: void 0 as any as HTMLElement | null,
|
|
1711
|
+
},
|
|
1712
|
+
$data: {
|
|
1713
|
+
/**
|
|
1714
|
+
* 数据
|
|
1715
|
+
*/
|
|
1716
|
+
data: [] as PopsPanelSelectDataOption<any>[],
|
|
1717
|
+
/**
|
|
1718
|
+
* 默认值
|
|
1719
|
+
*/
|
|
1720
|
+
defaultValue: viewConfig.getValue(),
|
|
1721
|
+
/**
|
|
1722
|
+
* 选择的信息
|
|
1723
|
+
*/
|
|
1724
|
+
selectedData: void 0 as PopsPanelSelectDataOption<any> | undefined,
|
|
1725
|
+
/**
|
|
1726
|
+
* 是否验证通过
|
|
1727
|
+
*/
|
|
1728
|
+
isValidSuccess: true,
|
|
1729
|
+
/**
|
|
1730
|
+
* 箭头旋转的属性
|
|
1731
|
+
*/
|
|
1732
|
+
rotateKey: "data-show-option",
|
|
1733
|
+
},
|
|
1734
|
+
/** 初始化 */
|
|
1735
|
+
init() {
|
|
1736
|
+
this.initDefault();
|
|
1737
|
+
this.initEl();
|
|
1738
|
+
this.initPlaceHolder();
|
|
1739
|
+
this.renderSelectText();
|
|
1740
|
+
this.onShowSelectDialogClick();
|
|
1741
|
+
|
|
1742
|
+
const disabled = typeof viewConfig.disabled === "function" ? viewConfig.disabled() : viewConfig.disabled;
|
|
1743
|
+
if (disabled) {
|
|
1744
|
+
this.disable();
|
|
1745
|
+
}
|
|
1746
|
+
},
|
|
1747
|
+
/** 初始化默认值 */
|
|
1748
|
+
initDefault() {
|
|
1749
|
+
this.$data.data = typeof viewConfig.data === "function" ? viewConfig.data() : viewConfig.data;
|
|
1750
|
+
this.$data.data.forEach((dataItem) => {
|
|
1751
|
+
const flag = this.$data.defaultValue.includes(dataItem.value);
|
|
1752
|
+
if (flag) {
|
|
1753
|
+
// 初始化选中的配置
|
|
1754
|
+
this.resetCurrentSelectedInfo();
|
|
1755
|
+
this.updateSelectedInfo(dataItem);
|
|
1756
|
+
}
|
|
1757
|
+
});
|
|
1758
|
+
},
|
|
1759
|
+
/** 初始化$ele变量 */
|
|
1760
|
+
initEl() {
|
|
1761
|
+
this.$el.$container = $container;
|
|
1762
|
+
this.$el.$container.setAttribute("data-mode", mode);
|
|
1763
|
+
PopsSafeUtils.setSafeHTML(
|
|
1764
|
+
this.$el.$container,
|
|
1765
|
+
/*html*/ `
|
|
1766
|
+
<div class="el-select__wrapper">
|
|
1767
|
+
<div class="el-select__selection">
|
|
1768
|
+
<!-- 这个是用于手动输入的,这里暂不适配 -->
|
|
1769
|
+
<div class="el-select__selected-item el-select__input-wrapper"></div>
|
|
1770
|
+
<!-- 这个是placeholder -->
|
|
1771
|
+
<div class="el-select__selected-item el-select__placeholder"></div>
|
|
1772
|
+
</div>
|
|
1773
|
+
<!-- 下拉箭头 -->
|
|
1774
|
+
<div class="el-select__suffix">
|
|
1775
|
+
<i class="el-icon el-select__caret el-select__icon">
|
|
1776
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
|
|
1777
|
+
<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>
|
|
1778
|
+
</svg>
|
|
1779
|
+
</i>
|
|
1780
|
+
</div>
|
|
1781
|
+
</div>`
|
|
1782
|
+
);
|
|
1783
|
+
this.$el.$wrapper = $li.querySelector<HTMLElement>(".el-select__wrapper")!;
|
|
1784
|
+
this.$el.$section = $li.querySelector<HTMLElement>(".el-select__selection")!;
|
|
1785
|
+
this.$el.$selectedInputWrapper = $li.querySelector<HTMLElement>(
|
|
1786
|
+
".el-select__selected-item.el-select__input-wrapper"
|
|
1787
|
+
)!;
|
|
1788
|
+
this.$el.$selectedPlaceHolderWrapper = $li.querySelector<HTMLElement>(
|
|
1789
|
+
".el-select__selected-item.el-select__placeholder"
|
|
1790
|
+
)!;
|
|
1791
|
+
this.$el.$suffix = $li.querySelector<HTMLElement>(".el-select__suffix")!;
|
|
1792
|
+
this.$el.$suffixIcon = $li.querySelector<HTMLElement>(".el-select__suffix .el-icon")!;
|
|
1793
|
+
|
|
1794
|
+
// 先把手动输入框隐藏
|
|
1795
|
+
this.hideInputWrapper();
|
|
1796
|
+
},
|
|
1797
|
+
/**
|
|
1798
|
+
* 初始化提示文字
|
|
1799
|
+
*/
|
|
1800
|
+
initPlaceHolder() {
|
|
1801
|
+
let placeholder = "--请选择--";
|
|
1802
|
+
if (typeof viewConfig.placeholder === "string") {
|
|
1803
|
+
placeholder = viewConfig.placeholder;
|
|
1804
|
+
} else if (typeof viewConfig.placeholder === "function") {
|
|
1805
|
+
const placeholderResult = viewConfig.placeholder();
|
|
1806
|
+
if (typeof placeholderResult === "string") {
|
|
1807
|
+
placeholder = placeholderResult;
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
/**
|
|
1811
|
+
* 默认提示文字的位置
|
|
1812
|
+
*/
|
|
1813
|
+
const defaultSelectedTextAlign: NonNullable<PopsPanelSelectConfig<any>["selectedTextAlign"]> = "left";
|
|
1814
|
+
this.$el.$section.setAttribute(
|
|
1815
|
+
"data-selected-text-align",
|
|
1816
|
+
viewConfig.selectedTextAlign || defaultSelectedTextAlign
|
|
1817
|
+
);
|
|
1818
|
+
|
|
1819
|
+
const $placeholder = popsDOMUtils.createElement("span", {
|
|
1820
|
+
innerText: placeholder,
|
|
1821
|
+
});
|
|
1822
|
+
this.$el.$selectedPlaceHolderWrapper.appendChild($placeholder);
|
|
1823
|
+
},
|
|
1824
|
+
/**
|
|
1825
|
+
* 重新渲染外面的已选择项的文本
|
|
1826
|
+
*
|
|
1827
|
+
* 如果未选择,显示提示文字
|
|
1828
|
+
*/
|
|
1829
|
+
renderSelectText() {
|
|
1830
|
+
let item = this.$data.data.find((dataItem) => {
|
|
1831
|
+
return dataItem.value === this.$data.selectedData?.value;
|
|
1832
|
+
});
|
|
1833
|
+
if (item == null) {
|
|
1834
|
+
// 未找到但是有选中信息,且是自定义输入的
|
|
1835
|
+
if (this.$data.selectedData && this.$data.selectedData.addCustomInput) {
|
|
1836
|
+
item = this.$data.selectedData;
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
if (item != null) {
|
|
1840
|
+
// 默认值在数据中
|
|
1841
|
+
// 显示该数据项的文本
|
|
1842
|
+
// 隐藏placeholder
|
|
1843
|
+
const text = typeof item.text === "function" ? item.text(item.value, item) : item.text;
|
|
1844
|
+
if (item.isHTML) {
|
|
1845
|
+
PopsSafeUtils.setSafeHTML(this.$el.$selectedInputWrapper, text);
|
|
1846
|
+
} else {
|
|
1847
|
+
PopsSafeUtils.setSafeHTML(
|
|
1848
|
+
this.$el.$selectedInputWrapper,
|
|
1849
|
+
/*html*/ `
|
|
1850
|
+
<span>${text}</span>
|
|
1851
|
+
`
|
|
1852
|
+
);
|
|
1853
|
+
}
|
|
1854
|
+
// 显示选中的内容
|
|
1855
|
+
this.showInputWrapper();
|
|
1856
|
+
// 隐藏placeholder
|
|
1857
|
+
this.hidePlaceHolderWrapper();
|
|
1858
|
+
} else {
|
|
1859
|
+
// 仅显示placeholder
|
|
1860
|
+
this.hideInputWrapper();
|
|
1861
|
+
this.showPlaceHolderWrapper();
|
|
1862
|
+
}
|
|
1863
|
+
},
|
|
1864
|
+
/**
|
|
1865
|
+
* 禁用选项容器
|
|
1866
|
+
*/
|
|
1867
|
+
disable() {
|
|
1868
|
+
popsDOMUtils.addClassName(this.$el.$container, "pops-panel-select-disable");
|
|
1869
|
+
popsDOMUtils.addClassName(this.$el.$itemLeftContainer, PopsCommonCSSClassName.textIsDisabled);
|
|
1870
|
+
},
|
|
1871
|
+
/**
|
|
1872
|
+
* 取消禁用选项容器
|
|
1873
|
+
*/
|
|
1874
|
+
cancleDisable() {
|
|
1875
|
+
popsDOMUtils.removeClassName(this.$el.$container, "pops-panel-select-disable");
|
|
1876
|
+
popsDOMUtils.removeClassName(this.$el.$itemLeftContainer, PopsCommonCSSClassName.textIsDisabled);
|
|
1877
|
+
},
|
|
1878
|
+
/**
|
|
1879
|
+
* 判断当前是否已禁用选项容器
|
|
1880
|
+
*/
|
|
1881
|
+
isDisabled() {
|
|
1882
|
+
return (
|
|
1883
|
+
popsDOMUtils.containsClassName(this.$el.$container, "pops-panel-select-disable") ||
|
|
1884
|
+
popsDOMUtils.containsClassName(this.$el.$itemLeftContainer, PopsCommonCSSClassName.textIsDisabled)
|
|
1885
|
+
);
|
|
1886
|
+
},
|
|
1887
|
+
/**
|
|
1888
|
+
* 设置选择列表的点击事件
|
|
1889
|
+
*
|
|
1890
|
+
* 点击显示选择列表的弹窗
|
|
1891
|
+
*/
|
|
1892
|
+
onShowSelectDialogClick() {
|
|
1893
|
+
const defaultCSS = PopsCSS.panelComponents_Select;
|
|
1894
|
+
popsDOMUtils.on(this.$el.$container, "click", () => {
|
|
1895
|
+
if (this.isDisabled()) {
|
|
1896
|
+
return;
|
|
1897
|
+
}
|
|
1898
|
+
/** 当前已选中的值 */
|
|
1899
|
+
const { style, ...userConfirmConfig } = viewConfig.selectConfirmDialogConfig || {};
|
|
1900
|
+
/**
|
|
1901
|
+
* 弹窗关闭的回调
|
|
1902
|
+
*/
|
|
1903
|
+
const dialogCloseCallback = () => {
|
|
1904
|
+
if (this.$data.selectedData?.addCustomInput && !this.$data.isValidSuccess) {
|
|
1905
|
+
// 当前是自定义输入的且未通过校验
|
|
1906
|
+
return false;
|
|
1907
|
+
} else {
|
|
1908
|
+
// 清除自定义输入的值
|
|
1909
|
+
this.getAllSelectItems(false).forEach((it) => {
|
|
1910
|
+
if (!it.data.addCustomInput) return;
|
|
1911
|
+
it.data.value = "";
|
|
1912
|
+
it.data.text = "";
|
|
1913
|
+
this.onValueChangeCallback(it.data);
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1916
|
+
this.renderSelectText();
|
|
1917
|
+
this.$el.$selectDialogContainer = null;
|
|
1918
|
+
this.$el.$container.removeAttribute(this.$data.rotateKey);
|
|
1919
|
+
};
|
|
1920
|
+
this.$el.$container.setAttribute(this.$data.rotateKey, String(true));
|
|
1921
|
+
const confirmConfig = popsUtils.assign(
|
|
1922
|
+
<PopsAlertConfig>{
|
|
1923
|
+
title: {
|
|
1924
|
+
text: "请勾选需要选择的选项",
|
|
1925
|
+
position: "center",
|
|
1926
|
+
},
|
|
1927
|
+
content: {
|
|
1928
|
+
text: /*html*/ `<ul class="select-container"></ul>`,
|
|
1929
|
+
html: true,
|
|
1930
|
+
},
|
|
1931
|
+
btn: {
|
|
1932
|
+
ok: {
|
|
1933
|
+
enable: false,
|
|
1934
|
+
},
|
|
1935
|
+
close: {
|
|
1936
|
+
enable: true,
|
|
1937
|
+
callback(evtConfig) {
|
|
1938
|
+
const ret = dialogCloseCallback();
|
|
1939
|
+
if (typeof ret === "boolean" && !ret) {
|
|
1940
|
+
return;
|
|
1941
|
+
}
|
|
1942
|
+
evtConfig.close();
|
|
1943
|
+
},
|
|
1944
|
+
},
|
|
1945
|
+
},
|
|
1946
|
+
mask: {
|
|
1947
|
+
enable: true,
|
|
1948
|
+
clickCallBack(originalRun) {
|
|
1949
|
+
const ret = dialogCloseCallback();
|
|
1950
|
+
if (typeof ret === "boolean" && !ret) {
|
|
1951
|
+
return;
|
|
1952
|
+
}
|
|
1953
|
+
originalRun();
|
|
1954
|
+
},
|
|
1955
|
+
clickEvent: {
|
|
1956
|
+
toClose: true,
|
|
1957
|
+
},
|
|
1958
|
+
},
|
|
1959
|
+
drag: true,
|
|
1960
|
+
dragLimit: true,
|
|
1961
|
+
width: "300px",
|
|
1962
|
+
height: "auto",
|
|
1963
|
+
style: /*css*/ `
|
|
1964
|
+
${defaultCSS}
|
|
1965
|
+
|
|
1966
|
+
${PopsCSS.panelCSS}
|
|
1967
|
+
|
|
1968
|
+
${style || ""}
|
|
1969
|
+
`,
|
|
1970
|
+
},
|
|
1971
|
+
userConfirmConfig
|
|
1972
|
+
);
|
|
1973
|
+
const $dialog = PopsAlert.init(confirmConfig);
|
|
1974
|
+
const $selectContainer = $dialog.$shadowRoot.querySelector<HTMLUListElement>(".select-container")!;
|
|
1975
|
+
// 初始化选项元素
|
|
1976
|
+
this.$data.data.forEach((item) => {
|
|
1977
|
+
if (item.addCustomInput) {
|
|
1978
|
+
// 添加自定义输入的
|
|
1979
|
+
const customInputDataOption = item;
|
|
1980
|
+
const $customInputSelecItem = this.createSelectItemElement(customInputDataOption);
|
|
1981
|
+
const context = this;
|
|
1982
|
+
const PanelInput = that.createSectionContainerItem_input({
|
|
1983
|
+
type: "input",
|
|
1984
|
+
text: "",
|
|
1985
|
+
getValue() {
|
|
1986
|
+
return customInputDataOption.value;
|
|
1987
|
+
},
|
|
1988
|
+
callback(evt, value) {
|
|
1989
|
+
customInputDataOption.text = value;
|
|
1990
|
+
customInputDataOption.value = value;
|
|
1991
|
+
if (typeof customInputDataOption.onValid === "function") {
|
|
1992
|
+
const ret = customInputDataOption.onValid(customInputDataOption);
|
|
1993
|
+
context.$data.isValidSuccess = ret.valid;
|
|
1994
|
+
if (ret.valid) {
|
|
1995
|
+
PanelInputHandler.removeValidErrorMsg();
|
|
1996
|
+
} else {
|
|
1997
|
+
PanelInputHandler.addValidErrorMsg(ret.message);
|
|
1998
|
+
return ret;
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
context.updateSelectedInfo(customInputDataOption);
|
|
2003
|
+
context.onValueChangeCallback(customInputDataOption);
|
|
2004
|
+
},
|
|
2005
|
+
});
|
|
2006
|
+
// 获取输入框处理函数
|
|
2007
|
+
const PanelInputHandler = PanelInput.handler;
|
|
2008
|
+
|
|
2009
|
+
const $inputContainer = PanelInput.$el.querySelector<HTMLElement>(".pops-panel-input")!;
|
|
2010
|
+
PopsSafeUtils.setSafeHTML($customInputSelecItem, "");
|
|
2011
|
+
|
|
2012
|
+
$customInputSelecItem.appendChild($inputContainer);
|
|
2013
|
+
// 添加到confirm中
|
|
2014
|
+
$selectContainer.appendChild($customInputSelecItem);
|
|
2015
|
+
// 设置项的点击事件
|
|
2016
|
+
this.onSelectItemClick(customInputDataOption, $customInputSelecItem);
|
|
2017
|
+
} else {
|
|
2018
|
+
const $select = this.createSelectItemElement(item);
|
|
2019
|
+
// 添加到confirm中
|
|
2020
|
+
$selectContainer.appendChild($select);
|
|
2021
|
+
// 设置项的点击事件
|
|
2022
|
+
this.onSelectItemClick(item, $select);
|
|
2023
|
+
}
|
|
2024
|
+
});
|
|
2025
|
+
this.$el.$selectDialogContainer = $selectContainer;
|
|
2026
|
+
// 初始化状态
|
|
2027
|
+
this.updateAllSelectItemStatus();
|
|
2028
|
+
});
|
|
2029
|
+
},
|
|
2030
|
+
/**
|
|
2031
|
+
* 选中的值改变的回调
|
|
2032
|
+
* @param data 当前的选中信息
|
|
2033
|
+
*/
|
|
2034
|
+
onValueChangeCallback(data?: PopsPanelSelectDataOption<any>, isUpdateSelectItem: boolean = true) {
|
|
2035
|
+
// 动态更新禁用状态、选中状态
|
|
2036
|
+
isUpdateSelectItem && this.updateAllSelectItemStatus();
|
|
2037
|
+
// 触发回调
|
|
2038
|
+
if (typeof viewConfig.callback === "function") {
|
|
2039
|
+
viewConfig.callback(data || this.$data.selectedData!);
|
|
2040
|
+
}
|
|
2041
|
+
},
|
|
2042
|
+
/**
|
|
2043
|
+
* 更新选项弹窗内的所有选项元素的状态
|
|
2044
|
+
*
|
|
2045
|
+
* + 更新禁用状态
|
|
2046
|
+
* + 更新选中状态
|
|
2047
|
+
*/
|
|
2048
|
+
updateAllSelectItemStatus() {
|
|
2049
|
+
const allSelectItems = this.getAllSelectItems(false);
|
|
2050
|
+
allSelectItems.forEach(($selectInfo) => {
|
|
2051
|
+
const { data, $select } = $selectInfo;
|
|
2052
|
+
// 更新文字
|
|
2053
|
+
this.setSelectItemText(data, $selectInfo.$select);
|
|
2054
|
+
if (typeof data.disable === "function" && data.disable(data.value, this.$data.selectedData)) {
|
|
2055
|
+
// 移除选中状态
|
|
2056
|
+
this.removeItemSelected($select);
|
|
2057
|
+
// 禁用
|
|
2058
|
+
this.setSelectItemDisabled($select);
|
|
2059
|
+
} else {
|
|
2060
|
+
// 移除禁用状态
|
|
2061
|
+
this.removeSelectItemDisabled($select);
|
|
2062
|
+
}
|
|
2063
|
+
// 根据当前已选择的信息,判断并更新选中状态
|
|
2064
|
+
if (this.$data.selectedData != null && this.$data.selectedData.value === data.value) {
|
|
2065
|
+
// 就是这个项
|
|
2066
|
+
// 设置选中
|
|
2067
|
+
this.setItemSelected($select);
|
|
2068
|
+
} else {
|
|
2069
|
+
// 不是这个项
|
|
2070
|
+
// 移除选中状态
|
|
2071
|
+
this.removeItemSelected($select);
|
|
2072
|
+
}
|
|
2073
|
+
});
|
|
2074
|
+
},
|
|
2075
|
+
/**
|
|
2076
|
+
* 重置所有已选中的项以下状态
|
|
2077
|
+
*
|
|
2078
|
+
* + 更新选项显示的文字
|
|
2079
|
+
* + 移除禁用状态
|
|
2080
|
+
* + 移除选中状态
|
|
2081
|
+
*/
|
|
2082
|
+
resetAllSelectedItemStatus() {
|
|
2083
|
+
const allSelectedItems = this.getAllSelectItems(true);
|
|
2084
|
+
if (allSelectedItems.length) {
|
|
2085
|
+
// 移除选中信息
|
|
2086
|
+
this.resetCurrentSelectedInfo();
|
|
2087
|
+
}
|
|
2088
|
+
allSelectedItems.forEach(($selectInfo) => {
|
|
2089
|
+
const { data, $select } = $selectInfo;
|
|
2090
|
+
// 更新文字
|
|
2091
|
+
this.setSelectItemText(data, $selectInfo.$select);
|
|
2092
|
+
// 移除选中状态
|
|
2093
|
+
this.removeItemSelected($select);
|
|
2094
|
+
// 取消禁用
|
|
2095
|
+
this.removeSelectItemDisabled($select);
|
|
2096
|
+
});
|
|
2097
|
+
},
|
|
2098
|
+
/**
|
|
2099
|
+
* 设置选项元素选中
|
|
2100
|
+
* @param $el 选项元素
|
|
2101
|
+
*/
|
|
2102
|
+
setItemSelected($el: HTMLElement) {
|
|
2103
|
+
if (this.isItemSelected($el)) return;
|
|
2104
|
+
$el.classList.add("select-item-is-selected");
|
|
2105
|
+
},
|
|
2106
|
+
/**
|
|
2107
|
+
* 移除选项元素选中
|
|
2108
|
+
* @param $el 选项元素
|
|
2109
|
+
*/
|
|
2110
|
+
removeItemSelected($el: HTMLElement) {
|
|
2111
|
+
$el.classList.remove("select-item-is-selected");
|
|
2112
|
+
},
|
|
2113
|
+
/**
|
|
2114
|
+
* 判断选项元素是否选中
|
|
2115
|
+
* @param $el
|
|
2116
|
+
*/
|
|
2117
|
+
isItemSelected($el: HTMLElement): boolean {
|
|
2118
|
+
return $el.classList.contains("select-item-is-selected");
|
|
2119
|
+
},
|
|
2120
|
+
/**
|
|
2121
|
+
* 获取项上存储的信息
|
|
2122
|
+
* @param $el 选项元素
|
|
2123
|
+
*/
|
|
2124
|
+
getItemDataOption($el: HTMLElement): PopsPanelSelectDataOption<any> {
|
|
2125
|
+
return Reflect.get($el, "data-info");
|
|
2126
|
+
},
|
|
2127
|
+
/**
|
|
2128
|
+
* 添加选中信息
|
|
2129
|
+
* @param data 选择项的数据
|
|
2130
|
+
* @param [triggerValueChangeCallBack=true] 主动触发值改变回调
|
|
2131
|
+
*/
|
|
2132
|
+
addSelectedItemInfo(data: PopsPanelSelectDataOption<any>) {
|
|
2133
|
+
this.resetCurrentSelectedInfo();
|
|
2134
|
+
this.updateSelectedInfo(data);
|
|
2135
|
+
this.onValueChangeCallback(data);
|
|
2136
|
+
},
|
|
2137
|
+
/**
|
|
2138
|
+
* 移除选中信息
|
|
2139
|
+
* @param data 选择项的数据
|
|
2140
|
+
*/
|
|
2141
|
+
removeSelectedItemInfo() {
|
|
2142
|
+
// 删除
|
|
2143
|
+
this.updateSelectedInfo();
|
|
2144
|
+
this.onValueChangeCallback();
|
|
2145
|
+
},
|
|
2146
|
+
/**
|
|
2147
|
+
* 更新选中信息
|
|
2148
|
+
* @param data 数据
|
|
2149
|
+
*/
|
|
2150
|
+
updateSelectedInfo(data?: PopsPanelSelectDataOption<any>) {
|
|
2151
|
+
// 先删除再赋值
|
|
2152
|
+
this.$data.selectedData = void 0;
|
|
2153
|
+
if (data) {
|
|
2154
|
+
if (data.addCustomInput && data.value.toString() === "") {
|
|
2155
|
+
// 自定义输入框,但是内容是空字符串
|
|
2156
|
+
// 不更新选中信息
|
|
2157
|
+
return;
|
|
2158
|
+
}
|
|
2159
|
+
this.$data.selectedData = data;
|
|
2160
|
+
}
|
|
2161
|
+
},
|
|
2162
|
+
/**
|
|
2163
|
+
* 从保存的已选中的信息列表中移除目标信息
|
|
2164
|
+
*/
|
|
2165
|
+
resetCurrentSelectedInfo() {
|
|
2166
|
+
this.updateSelectedInfo();
|
|
2167
|
+
},
|
|
2168
|
+
/**
|
|
2169
|
+
* 获取所有选项的信息
|
|
2170
|
+
* @param [onlySelected=true] 是否仅获取选中的项的信息
|
|
2171
|
+
* + true (默认)仅获取选中项的信息
|
|
2172
|
+
* + false 获取所有选择项的信息
|
|
2173
|
+
*/
|
|
2174
|
+
getAllSelectItems(onlySelected: boolean = true) {
|
|
2175
|
+
return Array.from(this.$el.$selectDialogContainer?.querySelectorAll<HTMLElement>(".select-item") ?? [])
|
|
2176
|
+
.map(($select) => {
|
|
2177
|
+
const data = this.getItemDataOption($select);
|
|
2178
|
+
const result = {
|
|
2179
|
+
/** 选项信息数据 */
|
|
2180
|
+
data: data,
|
|
2181
|
+
/** 选项元素 */
|
|
2182
|
+
$select: $select,
|
|
2183
|
+
};
|
|
2184
|
+
if (onlySelected) {
|
|
2185
|
+
// 仅选中
|
|
2186
|
+
const isSelected = this.isItemSelected($select);
|
|
2187
|
+
if (isSelected) {
|
|
2188
|
+
return result;
|
|
2189
|
+
}
|
|
2190
|
+
return;
|
|
2191
|
+
} else {
|
|
2192
|
+
return result;
|
|
2193
|
+
}
|
|
2194
|
+
})
|
|
2195
|
+
.filter((item) => {
|
|
2196
|
+
return item != null;
|
|
2197
|
+
});
|
|
2198
|
+
},
|
|
2199
|
+
/**
|
|
2200
|
+
* 创建一个选择项元素
|
|
2201
|
+
* @param data 选择项的数据
|
|
2202
|
+
*/
|
|
2203
|
+
createSelectItemElement(data: PopsPanelSelectDataOption<any>) {
|
|
2204
|
+
const $select = popsDOMUtils.createElement("li", {
|
|
2205
|
+
className: "select-item",
|
|
2206
|
+
innerHTML: /*html*/ `<span class="select-item-text"></span>`,
|
|
2207
|
+
});
|
|
2208
|
+
this.setSelectItemText(data, $select);
|
|
2209
|
+
Reflect.set($select, "data-info", data);
|
|
2210
|
+
return $select;
|
|
2211
|
+
},
|
|
2212
|
+
/**
|
|
2213
|
+
* 设置选择项的文字
|
|
2214
|
+
* @param data 选择项的数据
|
|
2215
|
+
* @param $select 选择项元素
|
|
2216
|
+
*/
|
|
2217
|
+
setSelectItemText(data: PopsPanelSelectDataOption<any>, $select: HTMLElement) {
|
|
2218
|
+
const text = typeof data.text === "function" ? data.text(data.value, this.$data.selectedData) : data.text;
|
|
2219
|
+
const $selectSpan = $select.querySelector<HTMLElement>(".select-item-text");
|
|
2220
|
+
if (!$selectSpan) return;
|
|
2221
|
+
if (data.isHTML) {
|
|
2222
|
+
PopsSafeUtils.setSafeHTML($selectSpan, text);
|
|
2223
|
+
} else {
|
|
2224
|
+
$selectSpan.innerText = text;
|
|
2225
|
+
}
|
|
2226
|
+
},
|
|
2227
|
+
/**
|
|
2228
|
+
* 设置选择项禁用
|
|
2229
|
+
* @param $select 选择项元素
|
|
2230
|
+
*/
|
|
2231
|
+
setSelectItemDisabled($select: HTMLElement) {
|
|
2232
|
+
$select.setAttribute("aria-disabled", "true");
|
|
2233
|
+
$select.setAttribute("disabled", "true");
|
|
2234
|
+
},
|
|
2235
|
+
/**
|
|
2236
|
+
* 移除选择项的禁用状态
|
|
2237
|
+
* @param $select 选择项元素
|
|
2238
|
+
*/
|
|
2239
|
+
removeSelectItemDisabled($select: HTMLElement) {
|
|
2240
|
+
$select.removeAttribute("aria-disabled");
|
|
2241
|
+
$select.removeAttribute("disabled");
|
|
2242
|
+
},
|
|
2243
|
+
/**
|
|
2244
|
+
* 判断选择项是否禁用
|
|
2245
|
+
* @param $select 选择项元素
|
|
2246
|
+
*/
|
|
2247
|
+
isSelectItemDisabled($select: HTMLElement) {
|
|
2248
|
+
return $select.hasAttribute("disabled") || $select.ariaDisabled;
|
|
2249
|
+
},
|
|
2250
|
+
/**
|
|
2251
|
+
* 设置选择项的点击事件
|
|
2252
|
+
* @param data 该选择项的信息
|
|
2253
|
+
* @param $select 该选择项元素
|
|
2254
|
+
*/
|
|
2255
|
+
onSelectItemClick(data: PopsPanelSelectDataOption<any> | undefined, $select: HTMLElement) {
|
|
2256
|
+
const updateCustomInputStatus = () => {
|
|
2257
|
+
this.setItemSelected($select);
|
|
2258
|
+
this.addSelectedItemInfo(data!);
|
|
2259
|
+
};
|
|
2260
|
+
popsDOMUtils.on<PointerEvent | MouseEvent>($select, "click", (event) => {
|
|
2261
|
+
popsDOMUtils.preventEvent(event);
|
|
2262
|
+
const $click = event.target as HTMLElement;
|
|
2263
|
+
if (data?.addCustomInput && $click instanceof HTMLInputElement) {
|
|
2264
|
+
// 自定义输入框 单独处理值更新,选中
|
|
2265
|
+
updateCustomInputStatus();
|
|
2266
|
+
return;
|
|
2267
|
+
}
|
|
2268
|
+
if (this.isSelectItemDisabled($select)) {
|
|
2269
|
+
// 被禁用了
|
|
2270
|
+
return;
|
|
2271
|
+
}
|
|
2272
|
+
if (typeof viewConfig.clickCallBack === "function") {
|
|
2273
|
+
const clickResult = viewConfig.clickCallBack(event, this.$data.selectedData!);
|
|
2274
|
+
if (typeof clickResult === "boolean" && !clickResult) {
|
|
2275
|
+
return;
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
if (data?.addCustomInput) {
|
|
2279
|
+
// 自定义输入框 添加选中
|
|
2280
|
+
updateCustomInputStatus();
|
|
2281
|
+
} else {
|
|
2282
|
+
// 修改选中状态
|
|
2283
|
+
if (this.isItemSelected($select)) {
|
|
2284
|
+
// 移除选中
|
|
2285
|
+
this.removeItemSelected($select);
|
|
2286
|
+
this.removeSelectedItemInfo();
|
|
2287
|
+
} else {
|
|
2288
|
+
// 添加选中
|
|
2289
|
+
this.setItemSelected($select);
|
|
2290
|
+
this.addSelectedItemInfo(data!);
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
});
|
|
2294
|
+
},
|
|
2295
|
+
/** 显示输入框 */
|
|
2296
|
+
showInputWrapper() {
|
|
2297
|
+
popsDOMUtils.cssShow(this.$el.$selectedInputWrapper);
|
|
2298
|
+
},
|
|
2299
|
+
/** 隐藏输入框 */
|
|
2300
|
+
hideInputWrapper() {
|
|
2301
|
+
popsDOMUtils.cssHide(this.$el.$selectedInputWrapper, true);
|
|
2302
|
+
},
|
|
2303
|
+
/** 显示palceholder */
|
|
2304
|
+
showPlaceHolderWrapper() {
|
|
2305
|
+
popsDOMUtils.cssShow(this.$el.$selectedPlaceHolderWrapper);
|
|
2306
|
+
},
|
|
2307
|
+
/** 隐藏palceholder */
|
|
2308
|
+
hidePlaceHolderWrapper() {
|
|
2309
|
+
popsDOMUtils.cssHide(this.$el.$selectedPlaceHolderWrapper, true);
|
|
2310
|
+
},
|
|
2311
|
+
};
|
|
2312
|
+
PopsPanelSelect.init();
|
|
2313
|
+
Reflect.set($li, "data-select", PopsPanelSelect);
|
|
2314
|
+
handler = PopsPanelSelect;
|
|
2315
|
+
} else if (mode === "horizontal") {
|
|
2316
|
+
const PopsPanelSelectHorizontal = {
|
|
2317
|
+
[Symbol.toStringTag]: "PopsPanelSelectHorizontal",
|
|
2318
|
+
$el: {
|
|
2319
|
+
$itemLeftContainer: $itemLeftContainer,
|
|
2320
|
+
/** 选择框容器 */
|
|
2321
|
+
$container: $container,
|
|
2322
|
+
/** 选择框包裹的容器 */
|
|
2323
|
+
$wrapper: void 0 as any as HTMLElement,
|
|
2324
|
+
},
|
|
2325
|
+
$data: {
|
|
2326
|
+
/**
|
|
2327
|
+
* 数据
|
|
2328
|
+
*/
|
|
2329
|
+
data: [] as PopsPanelSelectDataOption<any>[],
|
|
2330
|
+
/**
|
|
2331
|
+
* 默认值
|
|
2332
|
+
*/
|
|
2333
|
+
defaultValue: viewConfig.getValue(),
|
|
2334
|
+
/**
|
|
2335
|
+
* 选择的信息
|
|
2336
|
+
*/
|
|
2337
|
+
selectedData: void 0 as PopsPanelSelectDataOption<any> | undefined,
|
|
2338
|
+
/**
|
|
2339
|
+
* 箭头旋转的属性
|
|
2340
|
+
*/
|
|
2341
|
+
rotateKey: "data-show-option",
|
|
2342
|
+
},
|
|
2343
|
+
/** 初始化 */
|
|
2344
|
+
init() {
|
|
2345
|
+
this.initDefault();
|
|
2346
|
+
this.initEl();
|
|
2347
|
+
|
|
2348
|
+
const disabled = typeof viewConfig.disabled === "function" ? viewConfig.disabled() : viewConfig.disabled;
|
|
2349
|
+
if (disabled) {
|
|
2350
|
+
this.disable();
|
|
2351
|
+
}
|
|
2352
|
+
},
|
|
2353
|
+
/** 初始化默认值 */
|
|
2354
|
+
initDefault() {
|
|
2355
|
+
this.$data.data = typeof viewConfig.data === "function" ? viewConfig.data() : viewConfig.data;
|
|
2356
|
+
if (!this.$data.data.length) {
|
|
2357
|
+
throw new Error("PopsPanelSelect: data is empty");
|
|
2358
|
+
}
|
|
2359
|
+
},
|
|
2360
|
+
/** 初始化$ele变量 */
|
|
2361
|
+
initEl() {
|
|
2362
|
+
this.$el.$container.setAttribute("data-mode", mode);
|
|
2363
|
+
PopsSafeUtils.setSafeHTML(
|
|
2364
|
+
this.$el.$container,
|
|
2365
|
+
/*html*/ `
|
|
2366
|
+
<div class="el-select__wrapper">
|
|
2367
|
+
</div>`
|
|
2368
|
+
);
|
|
2369
|
+
this.$el.$wrapper = $li.querySelector<HTMLElement>(".el-select__wrapper")!;
|
|
1435
2370
|
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
this.
|
|
1459
|
-
}
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
*/
|
|
1498
|
-
isDisabled() {
|
|
1499
|
-
return (
|
|
1500
|
-
this.$ele.select.hasAttribute("disabled") ||
|
|
1501
|
-
popsDOMUtils.containsClassName(this.$ele.panelSelect, "pops-panel-select-disable")
|
|
1502
|
-
);
|
|
1503
|
-
},
|
|
1504
|
-
/**
|
|
1505
|
-
* 初始化选项
|
|
1506
|
-
*/
|
|
1507
|
-
initOption() {
|
|
1508
|
-
viewConfig.data.forEach((dataItem) => {
|
|
1509
|
-
// 初始化默认选中
|
|
1510
|
-
const optionElement = popsDOMUtils.createElement("option");
|
|
1511
|
-
this.setNodeValue(optionElement, this.$eleKey.value, dataItem.value);
|
|
1512
|
-
this.setNodeValue(optionElement, this.$eleKey.disable, dataItem.disable);
|
|
1513
|
-
this.setNodeValue(optionElement, this.$eleKey.viewConfig, dataItem.views);
|
|
1514
|
-
if (dataItem.value === this.$data.defaultValue) {
|
|
1515
|
-
this.setOptionSelected(optionElement);
|
|
2371
|
+
this.$data.data.forEach((dataItem) => {
|
|
2372
|
+
const $item = this.createSelectItemElement(dataItem);
|
|
2373
|
+
this.onSelectItemClick(dataItem, $item);
|
|
2374
|
+
if (this.$data.defaultValue === dataItem.value) {
|
|
2375
|
+
this.addSelectedItemInfo(dataItem);
|
|
2376
|
+
}
|
|
2377
|
+
this.$el.$wrapper.appendChild($item);
|
|
2378
|
+
});
|
|
2379
|
+
this.updateAllSelectItemStatus();
|
|
2380
|
+
},
|
|
2381
|
+
/**
|
|
2382
|
+
* 禁用选项容器
|
|
2383
|
+
*/
|
|
2384
|
+
disable() {
|
|
2385
|
+
popsDOMUtils.addClassName(this.$el.$container, "pops-panel-select-disable");
|
|
2386
|
+
popsDOMUtils.addClassName(this.$el.$itemLeftContainer, PopsCommonCSSClassName.textIsDisabled);
|
|
2387
|
+
},
|
|
2388
|
+
/**
|
|
2389
|
+
* 取消禁用选项容器
|
|
2390
|
+
*/
|
|
2391
|
+
cancleDisable() {
|
|
2392
|
+
popsDOMUtils.removeClassName(this.$el.$container, "pops-panel-select-disable");
|
|
2393
|
+
popsDOMUtils.removeClassName(this.$el.$itemLeftContainer, PopsCommonCSSClassName.textIsDisabled);
|
|
2394
|
+
},
|
|
2395
|
+
/**
|
|
2396
|
+
* 判断当前是否已禁用选项容器
|
|
2397
|
+
*/
|
|
2398
|
+
isDisabled() {
|
|
2399
|
+
return (
|
|
2400
|
+
popsDOMUtils.containsClassName(this.$el.$container, "pops-panel-select-disable") ||
|
|
2401
|
+
popsDOMUtils.containsClassName(this.$el.$itemLeftContainer, PopsCommonCSSClassName.textIsDisabled)
|
|
2402
|
+
);
|
|
2403
|
+
},
|
|
2404
|
+
/**
|
|
2405
|
+
* 创建选择项
|
|
2406
|
+
* @param data 数据
|
|
2407
|
+
*/
|
|
2408
|
+
createSelectItemElement(data: PopsPanelSelectDataOption<any>) {
|
|
2409
|
+
const $select = popsDOMUtils.createElement("div", {
|
|
2410
|
+
className: "select-item",
|
|
2411
|
+
innerHTML: /*html*/ `
|
|
2412
|
+
<span class="select-item-text"></span>
|
|
2413
|
+
`,
|
|
2414
|
+
});
|
|
2415
|
+
this.setSelectItemText(data, $select);
|
|
2416
|
+
Reflect.set($select, "data-info", data);
|
|
2417
|
+
return $select;
|
|
2418
|
+
},
|
|
2419
|
+
/**
|
|
2420
|
+
* 设置选择项的文字
|
|
2421
|
+
* @param data 选择项的数据
|
|
2422
|
+
* @param $select 选择项元素
|
|
2423
|
+
*/
|
|
2424
|
+
setSelectItemText(data: PopsPanelSelectDataOption<any>, $select: HTMLElement) {
|
|
2425
|
+
const text = typeof data.text === "function" ? data.text(data.value, this.$data.selectedData) : data.text;
|
|
2426
|
+
const $selectSpan = $select.querySelector<HTMLElement>(".select-item-text");
|
|
2427
|
+
if (!$selectSpan) return;
|
|
2428
|
+
if (data.isHTML) {
|
|
2429
|
+
PopsSafeUtils.setSafeHTML($selectSpan, text);
|
|
2430
|
+
} else {
|
|
2431
|
+
$selectSpan.innerText = text;
|
|
1516
2432
|
}
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
2433
|
+
},
|
|
2434
|
+
/**
|
|
2435
|
+
* 设置选择项点击事件
|
|
2436
|
+
*/
|
|
2437
|
+
onSelectItemClick(data: PopsPanelSelectDataOption<any> | undefined, $el: HTMLElement) {
|
|
2438
|
+
popsDOMUtils.on<PointerEvent | MouseEvent>($el, "click", (event) => {
|
|
2439
|
+
popsDOMUtils.preventEvent(event);
|
|
2440
|
+
if (this.isDisabled()) {
|
|
2441
|
+
return;
|
|
2442
|
+
}
|
|
2443
|
+
if (this.isSelectItemDisabled($el)) {
|
|
2444
|
+
// 被禁用了
|
|
2445
|
+
return;
|
|
2446
|
+
}
|
|
2447
|
+
if (typeof viewConfig.clickCallBack === "function") {
|
|
2448
|
+
const clickResult = viewConfig.clickCallBack(event, this.$data.selectedData!);
|
|
2449
|
+
if (typeof clickResult === "boolean" && !clickResult) {
|
|
2450
|
+
return;
|
|
2451
|
+
}
|
|
2452
|
+
} // 修改选中状态
|
|
2453
|
+
if (this.isItemSelected($el)) {
|
|
2454
|
+
// 移除选中
|
|
2455
|
+
this.removeItemSelected($el);
|
|
2456
|
+
this.removeSelectedItemInfo();
|
|
2457
|
+
} else {
|
|
2458
|
+
// 添加选中
|
|
2459
|
+
this.setItemSelected($el);
|
|
2460
|
+
this.addSelectedItemInfo(data!);
|
|
2461
|
+
}
|
|
1532
2462
|
});
|
|
1533
|
-
}
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
}
|
|
1543
|
-
if (disable) {
|
|
1544
|
-
optionElement.setAttribute("disabled", "true");
|
|
1545
|
-
} else {
|
|
1546
|
-
optionElement.removeAttribute("disabled");
|
|
1547
|
-
}
|
|
1548
|
-
},
|
|
1549
|
-
/** 获取option上的信息 */
|
|
1550
|
-
getSelectOptionInfo($option: HTMLOptionElement) {
|
|
1551
|
-
const optionValue = this.getNodeValue($option, this.$eleKey.value);
|
|
1552
|
-
const optionText = $option.innerText || $option.textContent!;
|
|
1553
|
-
const views = this.getNodeValue($option, this.$eleKey.viewConfig) as (typeof viewConfig.data)[0]["views"];
|
|
1554
|
-
return {
|
|
1555
|
-
value: optionValue,
|
|
1556
|
-
text: optionText,
|
|
1557
|
-
views: views,
|
|
1558
|
-
$option: $option,
|
|
1559
|
-
};
|
|
1560
|
-
},
|
|
1561
|
-
/**
|
|
1562
|
-
* 监听选择内容改变
|
|
1563
|
-
*/
|
|
1564
|
-
setChangeEvent() {
|
|
1565
|
-
popsDOMUtils.on<PointerEvent | TouchEvent>(this.$ele.select, "change", void 0, (event) => {
|
|
1566
|
-
const $isSelectedElement = this.$ele.select[this.$ele.select.selectedIndex] as HTMLOptionElement;
|
|
1567
|
-
const selectInfo = this.getSelectOptionInfo($isSelectedElement);
|
|
1568
|
-
this.setSelectOptionsDisableStatus();
|
|
2463
|
+
},
|
|
2464
|
+
/**
|
|
2465
|
+
* 选中的值改变的回调
|
|
2466
|
+
* @param data 当前的选中信息
|
|
2467
|
+
*/
|
|
2468
|
+
onValueChangeCallback(data?: PopsPanelSelectDataOption<any>, isUpdateSelectItem: boolean = true) {
|
|
2469
|
+
// 动态更新禁用状态、选中状态
|
|
2470
|
+
isUpdateSelectItem && this.updateAllSelectItemStatus();
|
|
2471
|
+
// 触发回调
|
|
1569
2472
|
if (typeof viewConfig.callback === "function") {
|
|
1570
|
-
viewConfig.callback(
|
|
2473
|
+
viewConfig.callback(data || this.$data.selectedData!);
|
|
1571
2474
|
}
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
2475
|
+
},
|
|
2476
|
+
/**
|
|
2477
|
+
* 更新选项弹窗内的所有选项元素的状态
|
|
2478
|
+
*
|
|
2479
|
+
* + 更新禁用状态
|
|
2480
|
+
* + 更新选中状态
|
|
2481
|
+
*/
|
|
2482
|
+
updateAllSelectItemStatus() {
|
|
2483
|
+
const allSelectItems = this.getAllSelectItems(false);
|
|
2484
|
+
allSelectItems.forEach(($selectInfo) => {
|
|
2485
|
+
const { data, $select } = $selectInfo;
|
|
2486
|
+
// 更新文字
|
|
2487
|
+
this.setSelectItemText(data, $selectInfo.$select);
|
|
2488
|
+
if (typeof data.disable === "function" && data.disable(data.value, this.$data.selectedData)) {
|
|
2489
|
+
// 移除选中状态
|
|
2490
|
+
this.removeItemSelected($select);
|
|
2491
|
+
// 禁用
|
|
2492
|
+
this.setSelectItemDisabled($select);
|
|
2493
|
+
} else {
|
|
2494
|
+
// 移除禁用状态
|
|
2495
|
+
this.removeSelectItemDisabled($select);
|
|
1583
2496
|
}
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
}
|
|
2497
|
+
// 根据当前已选择的信息,判断并更新选中状态
|
|
2498
|
+
if (this.$data.selectedData != null && this.$data.selectedData.value === data.value) {
|
|
2499
|
+
// 就是这个项
|
|
2500
|
+
// 设置选中
|
|
2501
|
+
this.setItemSelected($select);
|
|
2502
|
+
} else {
|
|
2503
|
+
// 不是这个项
|
|
2504
|
+
// 移除选中状态
|
|
2505
|
+
this.removeItemSelected($select);
|
|
2506
|
+
}
|
|
2507
|
+
});
|
|
2508
|
+
},
|
|
2509
|
+
/**
|
|
2510
|
+
* 重置所有已选中的项以下状态
|
|
2511
|
+
*
|
|
2512
|
+
* + 更新选项显示的文字
|
|
2513
|
+
* + 移除禁用状态
|
|
2514
|
+
* + 移除选中状态
|
|
2515
|
+
*/
|
|
2516
|
+
resetAllSelectedItemStatus() {
|
|
2517
|
+
const allSelectedItems = this.getAllSelectItems(true);
|
|
2518
|
+
if (allSelectedItems.length) {
|
|
2519
|
+
// 移除选中信息
|
|
2520
|
+
this.resetCurrentSelectedInfo();
|
|
1590
2521
|
}
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
2522
|
+
allSelectedItems.forEach(($selectInfo) => {
|
|
2523
|
+
const { data, $select } = $selectInfo;
|
|
2524
|
+
// 更新文字
|
|
2525
|
+
this.setSelectItemText(data, $selectInfo.$select);
|
|
2526
|
+
// 移除选中状态
|
|
2527
|
+
this.removeItemSelected($select);
|
|
2528
|
+
// 取消禁用
|
|
2529
|
+
this.removeSelectItemDisabled($select);
|
|
2530
|
+
});
|
|
2531
|
+
},
|
|
2532
|
+
/**
|
|
2533
|
+
* 添加选中信息
|
|
2534
|
+
* @param data 选择项的数据
|
|
2535
|
+
* @param [triggerValueChangeCallBack=true] 主动触发值改变回调
|
|
2536
|
+
*/
|
|
2537
|
+
addSelectedItemInfo(data: PopsPanelSelectDataOption<any>) {
|
|
2538
|
+
this.resetCurrentSelectedInfo();
|
|
2539
|
+
this.updateSelectedInfo(data);
|
|
2540
|
+
this.onValueChangeCallback(data);
|
|
2541
|
+
},
|
|
2542
|
+
/**
|
|
2543
|
+
* 移除选中信息
|
|
2544
|
+
* @param data 选择项的数据
|
|
2545
|
+
*/
|
|
2546
|
+
removeSelectedItemInfo() {
|
|
2547
|
+
// 删除
|
|
2548
|
+
this.updateSelectedInfo();
|
|
2549
|
+
this.onValueChangeCallback();
|
|
2550
|
+
},
|
|
2551
|
+
/**
|
|
2552
|
+
* 更新选中信息
|
|
2553
|
+
* @param data 数据
|
|
2554
|
+
*/
|
|
2555
|
+
updateSelectedInfo(data?: PopsPanelSelectDataOption<any>) {
|
|
2556
|
+
// 先删除再赋值
|
|
2557
|
+
this.$data.selectedData = void 0;
|
|
2558
|
+
if (data) {
|
|
2559
|
+
if (data.addCustomInput && data.value.toString() === "") {
|
|
2560
|
+
// 自定义输入框,但是内容是空字符串
|
|
2561
|
+
// 不更新选中信息
|
|
2562
|
+
return;
|
|
2563
|
+
}
|
|
2564
|
+
this.$data.selectedData = data;
|
|
1601
2565
|
}
|
|
1602
|
-
}
|
|
1603
|
-
|
|
2566
|
+
},
|
|
2567
|
+
/**
|
|
2568
|
+
* 从保存的已选中的信息列表中移除目标信息
|
|
2569
|
+
*/
|
|
2570
|
+
resetCurrentSelectedInfo() {
|
|
2571
|
+
this.updateSelectedInfo();
|
|
2572
|
+
},
|
|
2573
|
+
/**
|
|
2574
|
+
* 设置选择项禁用
|
|
2575
|
+
* @param $select 选择项元素
|
|
2576
|
+
*/
|
|
2577
|
+
setSelectItemDisabled($select: HTMLElement) {
|
|
2578
|
+
$select.setAttribute("aria-disabled", "true");
|
|
2579
|
+
$select.setAttribute("disabled", "true");
|
|
2580
|
+
},
|
|
2581
|
+
/**
|
|
2582
|
+
* 移除选择项的禁用状态
|
|
2583
|
+
* @param $select 选择项元素
|
|
2584
|
+
*/
|
|
2585
|
+
removeSelectItemDisabled($select: HTMLElement) {
|
|
2586
|
+
$select.removeAttribute("aria-disabled");
|
|
2587
|
+
$select.removeAttribute("disabled");
|
|
2588
|
+
},
|
|
2589
|
+
/**
|
|
2590
|
+
* 判断选择项是否禁用
|
|
2591
|
+
* @param $select 选择项元素
|
|
2592
|
+
*/
|
|
2593
|
+
isSelectItemDisabled($select: HTMLElement) {
|
|
2594
|
+
return $select.hasAttribute("disabled") || $select.ariaDisabled;
|
|
2595
|
+
},
|
|
2596
|
+
/**
|
|
2597
|
+
* 设置选择项选中
|
|
2598
|
+
* @param $select 选择项元素(.select-item)
|
|
2599
|
+
*/
|
|
2600
|
+
setItemSelected($select: HTMLElement) {
|
|
2601
|
+
if (this.isItemSelected($select)) return;
|
|
2602
|
+
$select.classList.add("select__selected-item");
|
|
2603
|
+
},
|
|
2604
|
+
/**
|
|
2605
|
+
* 移除选择项选中
|
|
2606
|
+
* @param $select 选择项元素(.select-item)
|
|
2607
|
+
*/
|
|
2608
|
+
removeItemSelected($select: HTMLElement) {
|
|
2609
|
+
$select.classList.remove("select__selected-item");
|
|
2610
|
+
},
|
|
2611
|
+
/**
|
|
2612
|
+
* 判断选择项是否选中
|
|
2613
|
+
* @param $select 选择项元素(.select-item)
|
|
2614
|
+
*/
|
|
2615
|
+
isItemSelected($select: HTMLElement) {
|
|
2616
|
+
return $select.classList.contains("select__selected-item");
|
|
2617
|
+
},
|
|
2618
|
+
/**
|
|
2619
|
+
* 获取所有选项的信息
|
|
2620
|
+
* @param [onlySelected=true] 是否仅获取选中的项的信息
|
|
2621
|
+
* + true (默认)仅获取选中项的信息
|
|
2622
|
+
* + false 获取所有选择项的信息
|
|
2623
|
+
*/
|
|
2624
|
+
getAllSelectItems(onlySelected: boolean = true) {
|
|
2625
|
+
return Array.from(this.$el.$wrapper?.querySelectorAll<HTMLElement>(".select-item") ?? [])
|
|
2626
|
+
.map(($select) => {
|
|
2627
|
+
const data = this.getItemDataOption($select);
|
|
2628
|
+
const result = {
|
|
2629
|
+
/** 选项信息数据 */
|
|
2630
|
+
data: data,
|
|
2631
|
+
/** 选项元素 */
|
|
2632
|
+
$select: $select,
|
|
2633
|
+
};
|
|
2634
|
+
if (onlySelected) {
|
|
2635
|
+
// 仅选中
|
|
2636
|
+
const isSelected = this.isItemSelected($select);
|
|
2637
|
+
if (isSelected) {
|
|
2638
|
+
return result;
|
|
2639
|
+
}
|
|
2640
|
+
return;
|
|
2641
|
+
} else {
|
|
2642
|
+
return result;
|
|
2643
|
+
}
|
|
2644
|
+
})
|
|
2645
|
+
.filter((item) => {
|
|
2646
|
+
return item != null;
|
|
2647
|
+
});
|
|
2648
|
+
},
|
|
2649
|
+
/**
|
|
2650
|
+
* 获取项上存储的信息
|
|
2651
|
+
* @param $el 选项元素
|
|
2652
|
+
*/
|
|
2653
|
+
getItemDataOption($el: HTMLElement): PopsPanelSelectDataOption<any> {
|
|
2654
|
+
return Reflect.get($el, "data-info");
|
|
2655
|
+
},
|
|
2656
|
+
};
|
|
2657
|
+
PopsPanelSelectHorizontal.init();
|
|
2658
|
+
Reflect.set($li, "data-select", PopsPanelSelectHorizontal);
|
|
2659
|
+
handler = PopsPanelSelectHorizontal;
|
|
2660
|
+
}
|
|
2661
|
+
return {
|
|
2662
|
+
$el: $li,
|
|
2663
|
+
handler: handler,
|
|
1604
2664
|
};
|
|
1605
|
-
|
|
1606
|
-
PopsPanelSelect.init();
|
|
1607
|
-
Reflect.set($li, "data-select", PopsPanelSelect);
|
|
1608
|
-
return $li;
|
|
1609
2665
|
},
|
|
1610
2666
|
/**
|
|
1611
2667
|
* type ==> select-multiple
|
|
@@ -1655,7 +2711,7 @@ export const PanelHandlerComponents = () => {
|
|
|
1655
2711
|
[Symbol.toStringTag]: "PopsPanelSelectMultiple",
|
|
1656
2712
|
$el: {
|
|
1657
2713
|
/** 左侧文本容器 */
|
|
1658
|
-
|
|
2714
|
+
$itemLeftContainer: $li.querySelector<HTMLElement>(".pops-panel-item-left-text"),
|
|
1659
2715
|
/** 选择框容器 */
|
|
1660
2716
|
$container: void 0 as any as HTMLElement,
|
|
1661
2717
|
/** 选择框包裹的容器 */
|
|
@@ -1677,9 +2733,9 @@ export const PanelHandlerComponents = () => {
|
|
|
1677
2733
|
/** 默认值 */
|
|
1678
2734
|
defaultValue: viewConfig.getValue(),
|
|
1679
2735
|
/**
|
|
1680
|
-
*
|
|
2736
|
+
* 已选择的信息
|
|
1681
2737
|
*/
|
|
1682
|
-
|
|
2738
|
+
selectedDataList: [] as PopsPanelSelectMultipleDataOption<any>[],
|
|
1683
2739
|
/**
|
|
1684
2740
|
* 箭头旋转的属性
|
|
1685
2741
|
*/
|
|
@@ -1691,7 +2747,7 @@ export const PanelHandlerComponents = () => {
|
|
|
1691
2747
|
this.inintEl();
|
|
1692
2748
|
this.initPlaceHolder();
|
|
1693
2749
|
this.initTagElement();
|
|
1694
|
-
this.
|
|
2750
|
+
this.onShowSelectDialogClick();
|
|
1695
2751
|
|
|
1696
2752
|
const disabled = typeof viewConfig.disabled === "function" ? viewConfig.disabled() : viewConfig.disabled;
|
|
1697
2753
|
if (disabled) {
|
|
@@ -1703,12 +2759,7 @@ export const PanelHandlerComponents = () => {
|
|
|
1703
2759
|
viewConfig.data.forEach((dataItem) => {
|
|
1704
2760
|
if (this.$data.defaultValue.includes(dataItem.value)) {
|
|
1705
2761
|
// 初始化选中的配置
|
|
1706
|
-
this.$data.
|
|
1707
|
-
text: dataItem.text,
|
|
1708
|
-
value: dataItem.value,
|
|
1709
|
-
isHTML: Boolean(dataItem.isHTML),
|
|
1710
|
-
disable: dataItem.disable?.bind(dataItem),
|
|
1711
|
-
});
|
|
2762
|
+
this.$data.selectedDataList.push(dataItem);
|
|
1712
2763
|
}
|
|
1713
2764
|
});
|
|
1714
2765
|
},
|
|
@@ -1729,7 +2780,9 @@ export const PanelHandlerComponents = () => {
|
|
|
1729
2780
|
// 先把手动输入框隐藏
|
|
1730
2781
|
this.hideInputWrapper();
|
|
1731
2782
|
},
|
|
1732
|
-
/**
|
|
2783
|
+
/**
|
|
2784
|
+
* 初始化提示文字
|
|
2785
|
+
*/
|
|
1733
2786
|
initPlaceHolder() {
|
|
1734
2787
|
let placeholder = "";
|
|
1735
2788
|
if (typeof viewConfig.placeholder === "string") {
|
|
@@ -1745,16 +2798,18 @@ export const PanelHandlerComponents = () => {
|
|
|
1745
2798
|
});
|
|
1746
2799
|
this.$el.$selectedPlaceHolderWrapper.appendChild($placeholder);
|
|
1747
2800
|
},
|
|
1748
|
-
/**
|
|
2801
|
+
/**
|
|
2802
|
+
* 初始化tag元素
|
|
2803
|
+
*/
|
|
1749
2804
|
initTagElement() {
|
|
1750
2805
|
// 遍历数据,寻找对应的值
|
|
1751
2806
|
viewConfig.data.forEach((dataItem) => {
|
|
1752
|
-
const findValue = this.$data.
|
|
2807
|
+
const findValue = this.$data.selectedDataList.find((item) => item.value === dataItem.value);
|
|
1753
2808
|
if (findValue) {
|
|
1754
2809
|
// 存在对应的值
|
|
1755
|
-
const selectedInfo = this.
|
|
1756
|
-
this.
|
|
1757
|
-
this.
|
|
2810
|
+
const selectedInfo = this.createTagItem(dataItem);
|
|
2811
|
+
this.addTagItem(selectedInfo.$tag);
|
|
2812
|
+
this.onSelectItemCloseIconClick({
|
|
1758
2813
|
$tag: selectedInfo.$tag,
|
|
1759
2814
|
$closeIcon: selectedInfo.$closeIcon,
|
|
1760
2815
|
value: dataItem.value,
|
|
@@ -1768,8 +2823,8 @@ export const PanelHandlerComponents = () => {
|
|
|
1768
2823
|
* 生成一个tag项
|
|
1769
2824
|
* @param data 配置
|
|
1770
2825
|
*/
|
|
1771
|
-
|
|
1772
|
-
const $
|
|
2826
|
+
createTagItem(data: PopsPanelSelectMultipleDataOption<any>) {
|
|
2827
|
+
const $tag = popsDOMUtils.createElement("div", {
|
|
1773
2828
|
className: "el-select__selected-item el-select__choose_tag",
|
|
1774
2829
|
innerHTML: /*html*/ `
|
|
1775
2830
|
<span class="el-tag is-closable el-tag--info el-tag--default el-tag--light">
|
|
@@ -1786,10 +2841,10 @@ export const PanelHandlerComponents = () => {
|
|
|
1786
2841
|
`,
|
|
1787
2842
|
});
|
|
1788
2843
|
/** 标签 */
|
|
1789
|
-
const $tagText = $
|
|
2844
|
+
const $tagText = $tag.querySelector<HTMLSpanElement>(".el-select__tags-text")!;
|
|
1790
2845
|
/** 关闭图标 */
|
|
1791
|
-
const $closeIcon = $
|
|
1792
|
-
const text = typeof data.text === "function" ? data.text(data, this.$data.
|
|
2846
|
+
const $closeIcon = $tag.querySelector<HTMLElement>(".el-icon.el-tag__close")!;
|
|
2847
|
+
const text = typeof data.text === "function" ? data.text(data, this.$data.selectedDataList) : data.text;
|
|
1793
2848
|
if (data.isHTML) {
|
|
1794
2849
|
PopsSafeUtils.setSafeHTML($tagText, text);
|
|
1795
2850
|
} else {
|
|
@@ -1797,7 +2852,7 @@ export const PanelHandlerComponents = () => {
|
|
|
1797
2852
|
}
|
|
1798
2853
|
|
|
1799
2854
|
return {
|
|
1800
|
-
$tag: $
|
|
2855
|
+
$tag: $tag,
|
|
1801
2856
|
$tagText: $tagText,
|
|
1802
2857
|
$closeIcon: $closeIcon,
|
|
1803
2858
|
};
|
|
@@ -1806,7 +2861,7 @@ export const PanelHandlerComponents = () => {
|
|
|
1806
2861
|
* 添加选中项的tag元素
|
|
1807
2862
|
* @param $tag 添加的元素
|
|
1808
2863
|
*/
|
|
1809
|
-
|
|
2864
|
+
addTagItem($tag: HTMLElement) {
|
|
1810
2865
|
// 往前添加
|
|
1811
2866
|
// 去除前面的空白
|
|
1812
2867
|
this.setSectionIsNear();
|
|
@@ -1835,8 +2890,10 @@ export const PanelHandlerComponents = () => {
|
|
|
1835
2890
|
this.hideInputWrapper();
|
|
1836
2891
|
this.hidePlaceHolderWrapper();
|
|
1837
2892
|
},
|
|
1838
|
-
/**
|
|
1839
|
-
|
|
2893
|
+
/**
|
|
2894
|
+
* 更新tag信息
|
|
2895
|
+
*/
|
|
2896
|
+
updateTagItem() {
|
|
1840
2897
|
this.$el.$section.querySelectorAll<HTMLElement>(".el-select__choose_tag").forEach(($ele) => {
|
|
1841
2898
|
$ele.remove();
|
|
1842
2899
|
});
|
|
@@ -1846,11 +2903,11 @@ export const PanelHandlerComponents = () => {
|
|
|
1846
2903
|
* 选中的值改变的回调
|
|
1847
2904
|
* @param selectedDataList 当前的选中信息
|
|
1848
2905
|
*/
|
|
1849
|
-
|
|
2906
|
+
onValueChange(selectedDataList?: PopsPanelSelectMultipleDataOption<any>[]) {
|
|
1850
2907
|
// 动态更新禁用状态
|
|
1851
|
-
this.
|
|
2908
|
+
this.updateAllSelectItems();
|
|
1852
2909
|
if (typeof viewConfig.callback === "function") {
|
|
1853
|
-
viewConfig.callback(selectedDataList || this.$data.
|
|
2910
|
+
viewConfig.callback(selectedDataList || this.$data.selectedDataList);
|
|
1854
2911
|
}
|
|
1855
2912
|
},
|
|
1856
2913
|
/**
|
|
@@ -1859,29 +2916,29 @@ export const PanelHandlerComponents = () => {
|
|
|
1859
2916
|
* + 更新禁用状态
|
|
1860
2917
|
* + 更新选中状态
|
|
1861
2918
|
*/
|
|
1862
|
-
|
|
2919
|
+
updateAllSelectItems() {
|
|
1863
2920
|
this.getAllSelectItemInfo(false).forEach(($selectInfo) => {
|
|
1864
2921
|
const { data, $select } = $selectInfo;
|
|
1865
2922
|
// 更新文字
|
|
1866
2923
|
this.setSelectItemText(data, $selectInfo.$select);
|
|
1867
2924
|
// 更新禁用状态
|
|
1868
|
-
if (typeof data.disable === "function" && data.disable(data.value, this.$data.
|
|
2925
|
+
if (typeof data.disable === "function" && data.disable(data.value, this.$data.selectedDataList)) {
|
|
1869
2926
|
// 禁用
|
|
1870
|
-
this.
|
|
2927
|
+
this.disableSelectItem($select);
|
|
1871
2928
|
// 移除选中信息
|
|
1872
2929
|
this.removeSelectedInfo(data, false);
|
|
1873
2930
|
// 移除选中状态
|
|
1874
|
-
this.
|
|
2931
|
+
this.removeItemSelected($select);
|
|
1875
2932
|
} else {
|
|
1876
2933
|
// 取消禁用
|
|
1877
|
-
this.
|
|
2934
|
+
this.cancleDisableSelectItem($select);
|
|
1878
2935
|
}
|
|
1879
2936
|
// 更新选中状态
|
|
1880
|
-
const findValue = this.$data.
|
|
2937
|
+
const findValue = this.$data.selectedDataList.find((it) => it.value === data.value);
|
|
1881
2938
|
if (findValue) {
|
|
1882
|
-
this.
|
|
2939
|
+
this.setItemSelected($select);
|
|
1883
2940
|
} else {
|
|
1884
|
-
this.
|
|
2941
|
+
this.removeItemSelected($select);
|
|
1885
2942
|
}
|
|
1886
2943
|
});
|
|
1887
2944
|
},
|
|
@@ -1889,22 +2946,22 @@ export const PanelHandlerComponents = () => {
|
|
|
1889
2946
|
* 设置选项元素选中
|
|
1890
2947
|
* @param $select 选项元素
|
|
1891
2948
|
*/
|
|
1892
|
-
|
|
1893
|
-
if (this.
|
|
2949
|
+
setItemSelected($select: HTMLElement) {
|
|
2950
|
+
if (this.isItemSelected($select)) return;
|
|
1894
2951
|
$select.classList.add("select-item-is-selected");
|
|
1895
2952
|
},
|
|
1896
2953
|
/**
|
|
1897
2954
|
* 移除选项元素选中
|
|
1898
2955
|
* @param $select 选项元素
|
|
1899
2956
|
*/
|
|
1900
|
-
|
|
2957
|
+
removeItemSelected($select: HTMLElement) {
|
|
1901
2958
|
$select.classList.remove("select-item-is-selected");
|
|
1902
2959
|
},
|
|
1903
2960
|
/**
|
|
1904
2961
|
* 判断选项元素是否选中
|
|
1905
2962
|
* @param $select
|
|
1906
2963
|
*/
|
|
1907
|
-
|
|
2964
|
+
isItemSelected($select: HTMLElement): boolean {
|
|
1908
2965
|
return $select.classList.contains("select-item-is-selected");
|
|
1909
2966
|
},
|
|
1910
2967
|
/**
|
|
@@ -1912,25 +2969,20 @@ export const PanelHandlerComponents = () => {
|
|
|
1912
2969
|
* @param dataList 选择项列表的数据
|
|
1913
2970
|
* @param $select 选项元素
|
|
1914
2971
|
*/
|
|
1915
|
-
|
|
2972
|
+
addItemSelected(dataList: PopsPanelSelectMultipleDataOption<any>[], $select: HTMLElement) {
|
|
1916
2973
|
const info = this.getSelectedItemInfo($select);
|
|
1917
2974
|
const findValue = dataList.find((item) => item.value === info.value);
|
|
1918
2975
|
if (!findValue) {
|
|
1919
|
-
dataList.push(
|
|
1920
|
-
value: info.value,
|
|
1921
|
-
text: info.text,
|
|
1922
|
-
isHTML: Boolean(info.isHTML),
|
|
1923
|
-
disable: info.disable?.bind(info),
|
|
1924
|
-
});
|
|
2976
|
+
dataList.push(info);
|
|
1925
2977
|
}
|
|
1926
|
-
this.
|
|
2978
|
+
this.onValueChange(dataList);
|
|
1927
2979
|
},
|
|
1928
2980
|
/**
|
|
1929
2981
|
* 获取选中的项的信息
|
|
1930
2982
|
* @param $select 选项元素
|
|
1931
2983
|
*/
|
|
1932
|
-
getSelectedItemInfo($select: HTMLElement) {
|
|
1933
|
-
return Reflect.get($select, "data-info")
|
|
2984
|
+
getSelectedItemInfo($select: HTMLElement): PopsPanelSelectMultipleDataOption<any> {
|
|
2985
|
+
return Reflect.get($select, "data-info");
|
|
1934
2986
|
},
|
|
1935
2987
|
/**
|
|
1936
2988
|
* 移除选中信息
|
|
@@ -1943,7 +2995,7 @@ export const PanelHandlerComponents = () => {
|
|
|
1943
2995
|
if (findIndex !== -1) {
|
|
1944
2996
|
dataList.splice(findIndex, 1);
|
|
1945
2997
|
}
|
|
1946
|
-
this.
|
|
2998
|
+
this.onValueChange(dataList);
|
|
1947
2999
|
},
|
|
1948
3000
|
/**
|
|
1949
3001
|
* 获取所有选项的信息
|
|
@@ -1963,7 +3015,7 @@ export const PanelHandlerComponents = () => {
|
|
|
1963
3015
|
};
|
|
1964
3016
|
if (onlySelected) {
|
|
1965
3017
|
// 仅选中
|
|
1966
|
-
const isSelected = this.
|
|
3018
|
+
const isSelected = this.isItemSelected($select);
|
|
1967
3019
|
if (isSelected) {
|
|
1968
3020
|
return result;
|
|
1969
3021
|
}
|
|
@@ -1997,7 +3049,7 @@ export const PanelHandlerComponents = () => {
|
|
|
1997
3049
|
* @param $select 选择项元素
|
|
1998
3050
|
*/
|
|
1999
3051
|
setSelectItemText(data: PopsPanelSelectMultipleDataOption<any>, $select: HTMLElement) {
|
|
2000
|
-
const text = typeof data.text === "function" ? data.text(data.value, this.$data.
|
|
3052
|
+
const text = typeof data.text === "function" ? data.text(data.value, this.$data.selectedDataList) : data.text;
|
|
2001
3053
|
const $selectSpan = $select.querySelector<HTMLElement>(".select-item-text")!;
|
|
2002
3054
|
if (data.isHTML) {
|
|
2003
3055
|
PopsSafeUtils.setSafeHTML($selectSpan, text);
|
|
@@ -2009,7 +3061,7 @@ export const PanelHandlerComponents = () => {
|
|
|
2009
3061
|
* 设置选择项的禁用状态
|
|
2010
3062
|
* @param $select 选择项元素
|
|
2011
3063
|
*/
|
|
2012
|
-
|
|
3064
|
+
disableSelectItem($select: HTMLElement) {
|
|
2013
3065
|
$select.setAttribute("aria-disabled", "true");
|
|
2014
3066
|
$select.setAttribute("disabled", "true");
|
|
2015
3067
|
},
|
|
@@ -2017,7 +3069,7 @@ export const PanelHandlerComponents = () => {
|
|
|
2017
3069
|
* 移除选择项的禁用状态
|
|
2018
3070
|
* @param $select 选择项元素
|
|
2019
3071
|
*/
|
|
2020
|
-
|
|
3072
|
+
cancleDisableSelectItem($select: HTMLElement) {
|
|
2021
3073
|
$select.removeAttribute("aria-disabled");
|
|
2022
3074
|
$select.removeAttribute("disabled");
|
|
2023
3075
|
},
|
|
@@ -2033,7 +3085,7 @@ export const PanelHandlerComponents = () => {
|
|
|
2033
3085
|
* @param dataList 选中的信息列表
|
|
2034
3086
|
* @param $select 选择项元素
|
|
2035
3087
|
*/
|
|
2036
|
-
|
|
3088
|
+
onSelectItemClick(dataList: PopsPanelSelectMultipleDataOption<any>[], $select: HTMLElement) {
|
|
2037
3089
|
popsDOMUtils.on<PointerEvent | MouseEvent>($select, "click", (event) => {
|
|
2038
3090
|
popsDOMUtils.preventEvent(event);
|
|
2039
3091
|
if (this.isSelectItemDisabled($select)) {
|
|
@@ -2047,12 +3099,12 @@ export const PanelHandlerComponents = () => {
|
|
|
2047
3099
|
}
|
|
2048
3100
|
}
|
|
2049
3101
|
// 修改选中状态
|
|
2050
|
-
if (this.
|
|
2051
|
-
this.
|
|
3102
|
+
if (this.isItemSelected($select)) {
|
|
3103
|
+
this.removeItemSelected($select);
|
|
2052
3104
|
this.removeSelectedItemInfo(dataList, $select);
|
|
2053
3105
|
} else {
|
|
2054
|
-
this.
|
|
2055
|
-
this.
|
|
3106
|
+
this.setItemSelected($select);
|
|
3107
|
+
this.addItemSelected(dataList, $select);
|
|
2056
3108
|
}
|
|
2057
3109
|
});
|
|
2058
3110
|
},
|
|
@@ -2061,79 +3113,18 @@ export const PanelHandlerComponents = () => {
|
|
|
2061
3113
|
*
|
|
2062
3114
|
* 点击显示下拉列表弹窗
|
|
2063
3115
|
*/
|
|
2064
|
-
|
|
2065
|
-
const defaultCSS =
|
|
2066
|
-
.select-container{
|
|
2067
|
-
--el-font-size-base: 14px;
|
|
2068
|
-
--el-text-color-regular: #606266;
|
|
2069
|
-
--el-color-primary: #409eff;
|
|
2070
|
-
--el-fill-color-light: #f5f7fa;
|
|
2071
|
-
--el-disable-color: #a8abb2;
|
|
2072
|
-
}
|
|
2073
|
-
.select-item{
|
|
2074
|
-
cursor: pointer;
|
|
2075
|
-
font-size: var(--el-font-size-base);
|
|
2076
|
-
padding: 0 32px 0 20px;
|
|
2077
|
-
position: relative;
|
|
2078
|
-
white-space: nowrap;
|
|
2079
|
-
overflow: hidden;
|
|
2080
|
-
text-overflow: ellipsis;
|
|
2081
|
-
color: var(--el-text-color-regular);
|
|
2082
|
-
height: 34px;
|
|
2083
|
-
line-height: 34px;
|
|
2084
|
-
box-sizing: border-box;
|
|
2085
|
-
}
|
|
2086
|
-
.select-item[aria-disabled],
|
|
2087
|
-
.select-item[disabled]{
|
|
2088
|
-
cursor: not-allowed;
|
|
2089
|
-
color: var(--el-disable-color);
|
|
2090
|
-
background: unset;
|
|
2091
|
-
}
|
|
2092
|
-
.select-item:hover{
|
|
2093
|
-
background-color: var(--el-fill-color-light);
|
|
2094
|
-
}
|
|
2095
|
-
.select-item.select-item-is-selected{
|
|
2096
|
-
color: var(--el-color-primary);
|
|
2097
|
-
font-weight: 700;
|
|
2098
|
-
}
|
|
2099
|
-
.select-item.select-item-is-selected::after{
|
|
2100
|
-
content: "";
|
|
2101
|
-
position: absolute;
|
|
2102
|
-
top: 50%;
|
|
2103
|
-
right: 20px;
|
|
2104
|
-
border-top: none;
|
|
2105
|
-
border-right: none;
|
|
2106
|
-
background-repeat: no-repeat;
|
|
2107
|
-
background-position: center;
|
|
2108
|
-
background-color: var(--el-color-primary);
|
|
2109
|
-
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;
|
|
2110
|
-
mask-size: 100% 100%;
|
|
2111
|
-
-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;
|
|
2112
|
-
-webkit-mask-size: 100% 100%;
|
|
2113
|
-
transform: translateY(-50%);
|
|
2114
|
-
width: 12px;
|
|
2115
|
-
height: 12px;
|
|
2116
|
-
}
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
@media (prefers-color-scheme: dark) {
|
|
2120
|
-
.select-container{
|
|
2121
|
-
--el-text-color-regular: #f2f2f2;
|
|
2122
|
-
--el-disable-color: #8D9095;
|
|
2123
|
-
--el-fill-color-light: #262727;
|
|
2124
|
-
}
|
|
2125
|
-
}
|
|
2126
|
-
`;
|
|
3116
|
+
onShowSelectDialogClick() {
|
|
3117
|
+
const defaultCSS = PopsCSS.panelComponents_Select;
|
|
2127
3118
|
popsDOMUtils.on(this.$el.$container, "click", () => {
|
|
2128
3119
|
if (this.isDisabled()) {
|
|
2129
3120
|
return;
|
|
2130
3121
|
}
|
|
2131
3122
|
/** 当前已选中的值 */
|
|
2132
|
-
const selectInfo = this.$data.
|
|
3123
|
+
const selectInfo = this.$data.selectedDataList;
|
|
2133
3124
|
const { style, ...userConfirmConfig } = viewConfig.selectConfirmDialogConfig || {};
|
|
2134
3125
|
const dialogCloseCallback = () => {
|
|
2135
|
-
this.$data.
|
|
2136
|
-
this.
|
|
3126
|
+
this.$data.selectedDataList = [...selectInfo];
|
|
3127
|
+
this.updateTagItem();
|
|
2137
3128
|
this.$el.$selectContainer = null;
|
|
2138
3129
|
this.$el.$container.removeAttribute(this.$data.rotateKey);
|
|
2139
3130
|
};
|
|
@@ -2145,9 +3136,7 @@ export const PanelHandlerComponents = () => {
|
|
|
2145
3136
|
position: "center",
|
|
2146
3137
|
},
|
|
2147
3138
|
content: {
|
|
2148
|
-
text: /*html*/
|
|
2149
|
-
<ul class="select-container"></ul>
|
|
2150
|
-
`,
|
|
3139
|
+
text: /*html*/ `<ul class="select-container"></ul>`,
|
|
2151
3140
|
html: true,
|
|
2152
3141
|
},
|
|
2153
3142
|
btn: {
|
|
@@ -2175,7 +3164,7 @@ export const PanelHandlerComponents = () => {
|
|
|
2175
3164
|
drag: true,
|
|
2176
3165
|
dragLimit: true,
|
|
2177
3166
|
width: "300px",
|
|
2178
|
-
height: "
|
|
3167
|
+
height: "auto",
|
|
2179
3168
|
style: /*css*/ `
|
|
2180
3169
|
${defaultCSS}
|
|
2181
3170
|
|
|
@@ -2192,18 +3181,18 @@ export const PanelHandlerComponents = () => {
|
|
|
2192
3181
|
// 添加到confirm中
|
|
2193
3182
|
$selectContainer.appendChild($select);
|
|
2194
3183
|
// 设置每一项的点击事件
|
|
2195
|
-
this.
|
|
3184
|
+
this.onSelectItemClick(selectInfo, $select);
|
|
2196
3185
|
});
|
|
2197
3186
|
this.$el.$selectContainer = $selectContainer;
|
|
2198
3187
|
// 动态更新禁用状态
|
|
2199
|
-
this.
|
|
3188
|
+
this.updateAllSelectItems();
|
|
2200
3189
|
});
|
|
2201
3190
|
},
|
|
2202
3191
|
/**
|
|
2203
3192
|
* 设置关闭图标的点击事件
|
|
2204
3193
|
* @param data 选中的信息
|
|
2205
3194
|
*/
|
|
2206
|
-
|
|
3195
|
+
onSelectItemCloseIconClick(data: {
|
|
2207
3196
|
/** 关闭图标的元素 */
|
|
2208
3197
|
$closeIcon: HTMLElement;
|
|
2209
3198
|
/** tag元素 */
|
|
@@ -2244,7 +3233,9 @@ export const PanelHandlerComponents = () => {
|
|
|
2244
3233
|
);
|
|
2245
3234
|
},
|
|
2246
3235
|
/**
|
|
2247
|
-
* 检测tag
|
|
3236
|
+
* 检测tag是否为空
|
|
3237
|
+
*
|
|
3238
|
+
* 如果为空则显示placeholder
|
|
2248
3239
|
*/
|
|
2249
3240
|
checkTagEmpty() {
|
|
2250
3241
|
if (!this.$el.$section.querySelectorAll(".el-select__choose_tag").length) {
|
|
@@ -2269,14 +3260,14 @@ export const PanelHandlerComponents = () => {
|
|
|
2269
3260
|
* + false 不触发值改变的回调
|
|
2270
3261
|
*/
|
|
2271
3262
|
removeSelectedInfo(data: PopsPanelSelectMultipleDataOption<any>, triggerValueChangeCallBack: boolean = true) {
|
|
2272
|
-
for (let index = 0; index < this.$data.
|
|
2273
|
-
const selectInfo = this.$data.
|
|
3263
|
+
for (let index = 0; index < this.$data.selectedDataList.length; index++) {
|
|
3264
|
+
const selectInfo = this.$data.selectedDataList[index];
|
|
2274
3265
|
if (selectInfo.value === data.value) {
|
|
2275
|
-
this.$data.
|
|
3266
|
+
this.$data.selectedDataList.splice(index, 1);
|
|
2276
3267
|
break;
|
|
2277
3268
|
}
|
|
2278
3269
|
}
|
|
2279
|
-
triggerValueChangeCallBack && this.
|
|
3270
|
+
triggerValueChangeCallBack && this.onValueChange();
|
|
2280
3271
|
},
|
|
2281
3272
|
/** 显示输入框 */
|
|
2282
3273
|
showInputWrapper() {
|
|
@@ -2306,27 +3297,30 @@ export const PanelHandlerComponents = () => {
|
|
|
2306
3297
|
* 禁用标签
|
|
2307
3298
|
*/
|
|
2308
3299
|
disable() {
|
|
2309
|
-
popsDOMUtils.addClassName(this.$el
|
|
2310
|
-
popsDOMUtils.addClassName(this.$el.$container, "pops-panel-select-
|
|
3300
|
+
popsDOMUtils.addClassName(this.$el.$itemLeftContainer, PopsCommonCSSClassName.textIsDisabled);
|
|
3301
|
+
popsDOMUtils.addClassName(this.$el.$container, "pops-panel-select-disable");
|
|
2311
3302
|
},
|
|
2312
3303
|
/**
|
|
2313
3304
|
* 判断是否被禁用
|
|
2314
3305
|
*/
|
|
2315
3306
|
isDisabled() {
|
|
2316
|
-
return popsDOMUtils.containsClassName(this.$el.$container, "pops-panel-select-
|
|
3307
|
+
return popsDOMUtils.containsClassName(this.$el.$container, "pops-panel-select-disable");
|
|
2317
3308
|
},
|
|
2318
3309
|
/**
|
|
2319
3310
|
* 取消禁用标签
|
|
2320
3311
|
*/
|
|
2321
3312
|
cancleDisable() {
|
|
2322
|
-
popsDOMUtils.removeClassName(this.$el
|
|
2323
|
-
popsDOMUtils.removeClassName(this.$el.$container, "pops-panel-select-
|
|
3313
|
+
popsDOMUtils.removeClassName(this.$el.$itemLeftContainer, PopsCommonCSSClassName.textIsDisabled);
|
|
3314
|
+
popsDOMUtils.removeClassName(this.$el.$container, "pops-panel-select-disable");
|
|
2324
3315
|
},
|
|
2325
3316
|
};
|
|
2326
3317
|
|
|
2327
3318
|
PopsPanelSelectMultiple.init();
|
|
2328
3319
|
Reflect.set($li, "data-select-multiple", PopsPanelSelectMultiple);
|
|
2329
|
-
return
|
|
3320
|
+
return {
|
|
3321
|
+
$el: $li,
|
|
3322
|
+
handler: PopsPanelSelectMultiple,
|
|
3323
|
+
};
|
|
2330
3324
|
},
|
|
2331
3325
|
/**
|
|
2332
3326
|
* type ==> button
|
|
@@ -2371,7 +3365,7 @@ export const PanelHandlerComponents = () => {
|
|
|
2371
3365
|
init() {
|
|
2372
3366
|
this.$ele.panelButton.appendChild(this.$ele.button);
|
|
2373
3367
|
this.initButton();
|
|
2374
|
-
this.
|
|
3368
|
+
this.onButtonClick();
|
|
2375
3369
|
},
|
|
2376
3370
|
initButton() {
|
|
2377
3371
|
if (typeof viewConfig.buttonIcon === "string" && viewConfig.buttonIcon.trim() !== "") {
|
|
@@ -2465,7 +3459,10 @@ export const PanelHandlerComponents = () => {
|
|
|
2465
3459
|
setButtonText(text: string) {
|
|
2466
3460
|
PopsSafeUtils.setSafeHTML(this.$ele.spanText, text);
|
|
2467
3461
|
},
|
|
2468
|
-
|
|
3462
|
+
/**
|
|
3463
|
+
* 设置按钮的点击事件
|
|
3464
|
+
*/
|
|
3465
|
+
onButtonClick() {
|
|
2469
3466
|
popsDOMUtils.on(this.$ele.button, "click", void 0, (event) => {
|
|
2470
3467
|
if (typeof viewConfig.callback === "function") {
|
|
2471
3468
|
viewConfig.callback(event);
|
|
@@ -2475,7 +3472,10 @@ export const PanelHandlerComponents = () => {
|
|
|
2475
3472
|
};
|
|
2476
3473
|
PopsPanelButton.init();
|
|
2477
3474
|
Reflect.set($li, "data-button", PopsPanelButton);
|
|
2478
|
-
return
|
|
3475
|
+
return {
|
|
3476
|
+
$el: $li,
|
|
3477
|
+
handler: PopsPanelButton,
|
|
3478
|
+
};
|
|
2479
3479
|
},
|
|
2480
3480
|
/**
|
|
2481
3481
|
* type ==> deepMenu
|
|
@@ -2525,7 +3525,7 @@ export const PanelHandlerComponents = () => {
|
|
|
2525
3525
|
},
|
|
2526
3526
|
},
|
|
2527
3527
|
init() {
|
|
2528
|
-
this.
|
|
3528
|
+
this.onLiClick();
|
|
2529
3529
|
},
|
|
2530
3530
|
/**
|
|
2531
3531
|
* 生成配置每一项的元素
|
|
@@ -2748,7 +3748,7 @@ export const PanelHandlerComponents = () => {
|
|
|
2748
3748
|
that.triggerRenderRightContainer($deepMenuSection);
|
|
2749
3749
|
},
|
|
2750
3750
|
/** 设置项的点击事件 */
|
|
2751
|
-
|
|
3751
|
+
onLiClick() {
|
|
2752
3752
|
popsDOMUtils.on($li, "click", void 0, async (event) => {
|
|
2753
3753
|
if (typeof viewConfig.clickCallBack === "function") {
|
|
2754
3754
|
const result = await viewConfig.clickCallBack(event, viewConfig);
|
|
@@ -2764,7 +3764,10 @@ export const PanelHandlerComponents = () => {
|
|
|
2764
3764
|
PopsPanelDeepMenu.init();
|
|
2765
3765
|
Reflect.set($li, "data-deepMenu", PopsPanelDeepMenu);
|
|
2766
3766
|
|
|
2767
|
-
return
|
|
3767
|
+
return {
|
|
3768
|
+
$el: $li,
|
|
3769
|
+
handler: PopsPanelDeepMenu,
|
|
3770
|
+
};
|
|
2768
3771
|
},
|
|
2769
3772
|
/**
|
|
2770
3773
|
* type ===> own
|
|
@@ -2777,8 +3780,10 @@ export const PanelHandlerComponents = () => {
|
|
|
2777
3780
|
this.setElementClassName($li, viewConfig.className);
|
|
2778
3781
|
this.setElementAttributes($li, viewConfig.attributes);
|
|
2779
3782
|
this.setElementProps($li, viewConfig.props);
|
|
2780
|
-
$li = viewConfig.
|
|
2781
|
-
return
|
|
3783
|
+
$li = viewConfig.createLIElement($li);
|
|
3784
|
+
return {
|
|
3785
|
+
$el: $li,
|
|
3786
|
+
};
|
|
2782
3787
|
},
|
|
2783
3788
|
/**
|
|
2784
3789
|
* 获取中间容器的元素<li>
|
|
@@ -2789,23 +3794,23 @@ export const PanelHandlerComponents = () => {
|
|
|
2789
3794
|
const componentType = viewConfig.type;
|
|
2790
3795
|
|
|
2791
3796
|
if (componentType === "switch") {
|
|
2792
|
-
return this.createSectionContainerItem_switch(viewConfig
|
|
3797
|
+
return this.createSectionContainerItem_switch(viewConfig);
|
|
2793
3798
|
} else if (componentType === "slider") {
|
|
2794
|
-
return this.
|
|
3799
|
+
return this.createSectionContainerItem_slider(viewConfig);
|
|
2795
3800
|
} else if (componentType === "input") {
|
|
2796
|
-
return this.createSectionContainerItem_input(viewConfig
|
|
3801
|
+
return this.createSectionContainerItem_input(viewConfig);
|
|
2797
3802
|
} else if (componentType === "textarea") {
|
|
2798
|
-
return this.createSectionContainerItem_textarea(viewConfig
|
|
3803
|
+
return this.createSectionContainerItem_textarea(viewConfig);
|
|
2799
3804
|
} else if (componentType === "select") {
|
|
2800
|
-
return this.createSectionContainerItem_select(viewConfig
|
|
3805
|
+
return this.createSectionContainerItem_select(viewConfig);
|
|
2801
3806
|
} else if (componentType === "select-multiple") {
|
|
2802
|
-
return this.createSectionContainerItem_select_multiple(viewConfig
|
|
3807
|
+
return this.createSectionContainerItem_select_multiple(viewConfig);
|
|
2803
3808
|
} else if (componentType === "button") {
|
|
2804
|
-
return this.createSectionContainerItem_button(viewConfig
|
|
3809
|
+
return this.createSectionContainerItem_button(viewConfig);
|
|
2805
3810
|
} else if (componentType === "deepMenu") {
|
|
2806
|
-
return this.createSectionContainerItem_deepMenu(viewConfig
|
|
3811
|
+
return this.createSectionContainerItem_deepMenu(viewConfig);
|
|
2807
3812
|
} else if (componentType === "own") {
|
|
2808
|
-
return this.createSectionContainerItem_own(viewConfig
|
|
3813
|
+
return this.createSectionContainerItem_own(viewConfig);
|
|
2809
3814
|
} else {
|
|
2810
3815
|
console.error("尚未实现的type类型", viewConfig);
|
|
2811
3816
|
}
|
|
@@ -2920,14 +3925,14 @@ export const PanelHandlerComponents = () => {
|
|
|
2920
3925
|
viewConfig: PopsPanelViewConfig,
|
|
2921
3926
|
containerOptions: Omit<PopsPanelRightAsideContainerConfig, "target">
|
|
2922
3927
|
) {
|
|
2923
|
-
const
|
|
2924
|
-
if (
|
|
2925
|
-
containerOptions["ulElement"].appendChild(
|
|
3928
|
+
const itemInfo = this.createSectionContainerItem(viewConfig);
|
|
3929
|
+
if (itemInfo) {
|
|
3930
|
+
containerOptions["ulElement"].appendChild(itemInfo.$el);
|
|
2926
3931
|
}
|
|
2927
3932
|
if (typeof viewConfig.afterAddToUListCallBack === "function") {
|
|
2928
3933
|
viewConfig.afterAddToUListCallBack(viewConfig as any, {
|
|
2929
3934
|
...containerOptions,
|
|
2930
|
-
target:
|
|
3935
|
+
target: itemInfo?.$el,
|
|
2931
3936
|
});
|
|
2932
3937
|
}
|
|
2933
3938
|
},
|
|
@@ -2936,7 +3941,7 @@ export const PanelHandlerComponents = () => {
|
|
|
2936
3941
|
* @param $asideItem 左侧的容器<li>元素
|
|
2937
3942
|
* @param asideConfig 配置
|
|
2938
3943
|
*/
|
|
2939
|
-
|
|
3944
|
+
onAsideItemClick($asideItem: HTMLElement, asideConfig: PopsPanelContentConfig) {
|
|
2940
3945
|
popsDOMUtils.on<MouseEvent | PointerEvent>($asideItem, "click", async (event) => {
|
|
2941
3946
|
if (typeof asideConfig.clickFirstCallback === "function") {
|
|
2942
3947
|
const clickFirstCallbackResult = await asideConfig.clickFirstCallback(
|