@whitesev/pops 1.9.6 → 1.9.7

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.
@@ -1,4 +1,6 @@
1
1
  import type { PopsPanelCommonDetails } from "./commonType";
2
+ import type { PopsPanelFormsDetails } from "./formsType";
3
+ import type { PopsPanelFormsTotalDetails } from "./indexType";
2
4
  /**
3
5
  * pops.panel的 select
4
6
  */
@@ -71,5 +73,9 @@ export interface PopsPanelSelectDetails<T = any> extends PopsPanelCommonDetails<
71
73
  * + select元素触发change事件
72
74
  */
73
75
  disable?(value: T): boolean;
76
+ /**
77
+ * 子配置,跟随切换改变
78
+ */
79
+ forms?: (PopsPanelFormsDetails | PopsPanelFormsTotalDetails)[] | (() => (PopsPanelFormsDetails | PopsPanelFormsTotalDetails)[]);
74
80
  }[];
75
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/pops",
3
- "version": "1.9.6",
3
+ "version": "1.9.7",
4
4
  "description": "弹窗库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
package/src/Pops.ts CHANGED
@@ -83,7 +83,7 @@ class Pops {
83
83
  /** 配置 */
84
84
  config = {
85
85
  /** 版本号 */
86
- version: "2024.12.19",
86
+ version: "2025.1.1",
87
87
  cssText: {
88
88
  /** 主CSS */
89
89
  index: indexCSS,
@@ -1325,6 +1325,7 @@ export const PanelHandleContentDetails = () => {
1325
1325
  * @param formConfig
1326
1326
  */
1327
1327
  createSectionContainerItem_select(formConfig: PopsPanelSelectDetails<any>) {
1328
+ const that = this;
1328
1329
  let liElement = document.createElement("li");
1329
1330
  (liElement as any)["__formConfig__"] = formConfig;
1330
1331
  this.setElementClassName(liElement, formConfig.className);
@@ -1357,6 +1358,7 @@ export const PanelHandleContentDetails = () => {
1357
1358
  $eleKey: {
1358
1359
  disable: "__disable__",
1359
1360
  value: "__value__",
1361
+ forms: "__forms__",
1360
1362
  },
1361
1363
  $data: {
1362
1364
  defaultValue: formConfig.getValue(),
@@ -1387,14 +1389,23 @@ export const PanelHandleContentDetails = () => {
1387
1389
  getNodeValue($ele: HTMLElement, key: string) {
1388
1390
  return Reflect.get($ele, key);
1389
1391
  },
1392
+ /**
1393
+ * 禁用选项
1394
+ */
1390
1395
  disable() {
1391
1396
  this.$ele.select.setAttribute("disabled", "true");
1392
1397
  this.$ele.panelSelect.classList.add("pops-panel-select-disable");
1393
1398
  },
1399
+ /**
1400
+ * 取消禁用
1401
+ */
1394
1402
  notDisable() {
1395
1403
  this.$ele.select.removeAttribute("disabled");
1396
1404
  this.$ele.panelSelect.classList.remove("pops-panel-select-disable");
1397
1405
  },
1406
+ /**
1407
+ * 判断是否禁用
1408
+ */
1398
1409
  isDisabled() {
1399
1410
  return (
1400
1411
  this.$ele.select.hasAttribute("disabled") ||
@@ -1403,6 +1414,9 @@ export const PanelHandleContentDetails = () => {
1403
1414
  )
1404
1415
  );
1405
1416
  },
1417
+ /**
1418
+ * 初始化选项
1419
+ */
1406
1420
  initOption() {
1407
1421
  formConfig.data.forEach((dataItem) => {
1408
1422
  // 初始化默认选中
@@ -1417,13 +1431,24 @@ export const PanelHandleContentDetails = () => {
1417
1431
  this.$eleKey.disable,
1418
1432
  dataItem.disable
1419
1433
  );
1434
+ this.setNodeValue(
1435
+ optionElement,
1436
+ this.$eleKey.forms,
1437
+ dataItem.forms
1438
+ );
1420
1439
  if (dataItem.value === this.$data.defaultValue) {
1421
- optionElement.setAttribute("selected", "true");
1440
+ this.setOptionSelected(optionElement);
1422
1441
  }
1423
1442
  optionElement.innerText = dataItem.text;
1424
1443
  this.$ele.select.appendChild(optionElement);
1425
1444
  });
1426
1445
  },
1446
+ /**
1447
+ * 设置选项选中
1448
+ */
1449
+ setOptionSelected($option: HTMLOptionElement) {
1450
+ $option.setAttribute("selected", "true");
1451
+ },
1427
1452
  /** 检测所有option并设置禁用状态 */
1428
1453
  setSelectOptionsDisableStatus() {
1429
1454
  if (this.$ele.select.options && this.$ele.select.options.length) {
@@ -1453,9 +1478,14 @@ export const PanelHandleContentDetails = () => {
1453
1478
  getSelectOptionInfo($option: HTMLOptionElement) {
1454
1479
  let optionValue = this.getNodeValue($option, this.$eleKey.value);
1455
1480
  let optionText = $option.innerText || $option.textContent!;
1481
+ let optionForms = this.getNodeValue(
1482
+ $option,
1483
+ this.$eleKey.forms
1484
+ ) as (typeof formConfig.data)[0]["forms"];
1456
1485
  return {
1457
1486
  value: optionValue,
1458
1487
  text: optionText,
1488
+ forms: optionForms,
1459
1489
  $option: $option,
1460
1490
  };
1461
1491
  },
@@ -1464,18 +1494,44 @@ export const PanelHandleContentDetails = () => {
1464
1494
  */
1465
1495
  setChangeEvent() {
1466
1496
  popsDOMUtils.on(this.$ele.select, "change", void 0, (event) => {
1497
+ let $isSelectedElement = (event as any).target[
1498
+ (event as any).target.selectedIndex
1499
+ ] as HTMLOptionElement;
1500
+ let selectInfo = this.getSelectOptionInfo($isSelectedElement);
1467
1501
  this.setSelectOptionsDisableStatus();
1468
1502
  if (typeof formConfig.callback === "function") {
1469
- let $isSelectedElement = (event as any).target[
1470
- (event as any).target.selectedIndex
1471
- ] as HTMLOptionElement;
1472
- let selectInfo = this.getSelectOptionInfo($isSelectedElement);
1473
1503
  formConfig.callback(
1474
1504
  event as any,
1475
1505
  selectInfo.value,
1476
1506
  selectInfo.text
1477
1507
  );
1478
1508
  }
1509
+ let forms =
1510
+ typeof selectInfo.forms === "function"
1511
+ ? selectInfo.forms()
1512
+ : selectInfo.forms;
1513
+ if (Array.isArray(forms)) {
1514
+ /* 如果成功创建,加入到中间容器中 */
1515
+ let childUListClassName = "pops-panel-select-child-forms";
1516
+ // 移除旧的元素
1517
+ while (liElement.nextElementSibling) {
1518
+ if (
1519
+ liElement.nextElementSibling.classList.contains(
1520
+ childUListClassName
1521
+ )
1522
+ ) {
1523
+ liElement.nextElementSibling.remove();
1524
+ } else {
1525
+ break;
1526
+ }
1527
+ }
1528
+ let $childUList = document.createElement("ul");
1529
+ $childUList.className = childUListClassName;
1530
+ popsDOMUtils.after(liElement, $childUList);
1531
+ that.uListContainerAddItem(formConfig as any, {
1532
+ ulElement: $childUList,
1533
+ });
1534
+ }
1479
1535
  });
1480
1536
  },
1481
1537
  /**
@@ -1852,6 +1908,19 @@ export const PanelHandleContentDetails = () => {
1852
1908
  Reflect.set($item, "data-info", dataInfo);
1853
1909
  return $item;
1854
1910
  }
1911
+ /**
1912
+ * 设置选择项的禁用状态
1913
+ */
1914
+ function setSelectItemDisabled($el: HTMLElement) {
1915
+ $el.setAttribute("aria-disabled", "true");
1916
+ }
1917
+ /**
1918
+ * 移除选择项的禁用状态
1919
+ */
1920
+ function removeSelectItemDisabled($el: HTMLElement) {
1921
+ $el.removeAttribute("aria-disabled");
1922
+ $el.removeAttribute("disabled");
1923
+ }
1855
1924
  /**
1856
1925
  * 设置选择项的点击事件
1857
1926
  */
@@ -1861,6 +1930,9 @@ export const PanelHandleContentDetails = () => {
1861
1930
  "click",
1862
1931
  (event) => {
1863
1932
  popsDOMUtils.preventEvent(event);
1933
+ if ($ele.hasAttribute("disabled") || $ele.ariaDisabled) {
1934
+ return;
1935
+ }
1864
1936
  if (typeof formConfig.clickCallBack === "function") {
1865
1937
  let clickResult = formConfig.clickCallBack(
1866
1938
  event,
@@ -1931,7 +2003,6 @@ export const PanelHandleContentDetails = () => {
1931
2003
  --el-fill-color-light: #f5f7fa;
1932
2004
  }
1933
2005
  .select-item{
1934
- cursor: pointer;
1935
2006
  cursor: pointer;
1936
2007
  font-size: var(--el-font-size-base);
1937
2008
  padding: 0 32px 0 20px;
@@ -1944,6 +2015,12 @@ export const PanelHandleContentDetails = () => {
1944
2015
  line-height: 34px;
1945
2016
  box-sizing: border-box;
1946
2017
  }
2018
+ .select-item[aria-disabled],
2019
+ .select-item[disabled]{
2020
+ cursor: not-allowed;
2021
+ color: #a8abb2;
2022
+ background: unset;
2023
+ }
1947
2024
  .select-item:hover{
1948
2025
  background-color: var(--el-fill-color-light);
1949
2026
  }
@@ -1986,6 +2063,17 @@ export const PanelHandleContentDetails = () => {
1986
2063
  $selectContainer.appendChild($select);
1987
2064
  // 设置每一项的点击事件
1988
2065
  setSelectElementClickEvent($select);
2066
+ // 设置禁用状态
2067
+ if (
2068
+ typeof item.disable === "function" &&
2069
+ item.disable(item.value)
2070
+ ) {
2071
+ setSelectItemDisabled($select);
2072
+ // 后续不设置元素的选中状态
2073
+ return;
2074
+ }
2075
+ // 移除禁用状态
2076
+ removeSelectItemDisabled($select);
1989
2077
  let findValue = selectedInfo.find(
1990
2078
  (value) => value.value === item.value
1991
2079
  );
@@ -187,6 +187,7 @@ export const PopsPanelConfig = (): DeepRequired<PopsPanelDetails> => {
187
187
  disable() {
188
188
  return false;
189
189
  },
190
+ forms: [],
190
191
  },
191
192
  {
192
193
  value: "text",
@@ -194,6 +195,7 @@ export const PopsPanelConfig = (): DeepRequired<PopsPanelDetails> => {
194
195
  disable() {
195
196
  return false;
196
197
  },
198
+ forms: [],
197
199
  },
198
200
  {
199
201
  value: "html",
@@ -201,6 +203,7 @@ export const PopsPanelConfig = (): DeepRequired<PopsPanelDetails> => {
201
203
  disable() {
202
204
  return false;
203
205
  },
206
+ forms: [],
204
207
  },
205
208
  ],
206
209
  },
@@ -1,4 +1,6 @@
1
1
  import type { PopsPanelCommonDetails } from "./commonType";
2
+ import type { PopsPanelFormsDetails } from "./formsType";
3
+ import type { PopsPanelFormsTotalDetails } from "./indexType";
2
4
 
3
5
  /**
4
6
  * pops.panel的 select
@@ -80,5 +82,11 @@ export interface PopsPanelSelectDetails<T = any>
80
82
  * + select元素触发change事件
81
83
  */
82
84
  disable?(value: T): boolean;
85
+ /**
86
+ * 子配置,跟随切换改变
87
+ */
88
+ forms?:
89
+ | (PopsPanelFormsDetails | PopsPanelFormsTotalDetails)[]
90
+ | (() => (PopsPanelFormsDetails | PopsPanelFormsTotalDetails)[]);
83
91
  }[];
84
92
  }