@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.
package/dist/index.umd.js CHANGED
@@ -5546,6 +5546,7 @@
5546
5546
  disable() {
5547
5547
  return false;
5548
5548
  },
5549
+ forms: [],
5549
5550
  },
5550
5551
  {
5551
5552
  value: "text",
@@ -5553,6 +5554,7 @@
5553
5554
  disable() {
5554
5555
  return false;
5555
5556
  },
5557
+ forms: [],
5556
5558
  },
5557
5559
  {
5558
5560
  value: "html",
@@ -5560,6 +5562,7 @@
5560
5562
  disable() {
5561
5563
  return false;
5562
5564
  },
5565
+ forms: [],
5563
5566
  },
5564
5567
  ],
5565
5568
  },
@@ -7063,6 +7066,7 @@
7063
7066
  * @param formConfig
7064
7067
  */
7065
7068
  createSectionContainerItem_select(formConfig) {
7069
+ const that = this;
7066
7070
  let liElement = document.createElement("li");
7067
7071
  liElement["__formConfig__"] = formConfig;
7068
7072
  this.setElementClassName(liElement, formConfig.className);
@@ -7091,6 +7095,7 @@
7091
7095
  $eleKey: {
7092
7096
  disable: "__disable__",
7093
7097
  value: "__value__",
7098
+ forms: "__forms__",
7094
7099
  },
7095
7100
  $data: {
7096
7101
  defaultValue: formConfig.getValue(),
@@ -7121,31 +7126,50 @@
7121
7126
  getNodeValue($ele, key) {
7122
7127
  return Reflect.get($ele, key);
7123
7128
  },
7129
+ /**
7130
+ * 禁用选项
7131
+ */
7124
7132
  disable() {
7125
7133
  this.$ele.select.setAttribute("disabled", "true");
7126
7134
  this.$ele.panelSelect.classList.add("pops-panel-select-disable");
7127
7135
  },
7136
+ /**
7137
+ * 取消禁用
7138
+ */
7128
7139
  notDisable() {
7129
7140
  this.$ele.select.removeAttribute("disabled");
7130
7141
  this.$ele.panelSelect.classList.remove("pops-panel-select-disable");
7131
7142
  },
7143
+ /**
7144
+ * 判断是否禁用
7145
+ */
7132
7146
  isDisabled() {
7133
7147
  return (this.$ele.select.hasAttribute("disabled") ||
7134
7148
  this.$ele.panelSelect.classList.contains("pops-panel-select-disable"));
7135
7149
  },
7150
+ /**
7151
+ * 初始化选项
7152
+ */
7136
7153
  initOption() {
7137
7154
  formConfig.data.forEach((dataItem) => {
7138
7155
  // 初始化默认选中
7139
7156
  let optionElement = document.createElement("option");
7140
7157
  this.setNodeValue(optionElement, this.$eleKey.value, dataItem.value);
7141
7158
  this.setNodeValue(optionElement, this.$eleKey.disable, dataItem.disable);
7159
+ this.setNodeValue(optionElement, this.$eleKey.forms, dataItem.forms);
7142
7160
  if (dataItem.value === this.$data.defaultValue) {
7143
- optionElement.setAttribute("selected", "true");
7161
+ this.setOptionSelected(optionElement);
7144
7162
  }
7145
7163
  optionElement.innerText = dataItem.text;
7146
7164
  this.$ele.select.appendChild(optionElement);
7147
7165
  });
7148
7166
  },
7167
+ /**
7168
+ * 设置选项选中
7169
+ */
7170
+ setOptionSelected($option) {
7171
+ $option.setAttribute("selected", "true");
7172
+ },
7149
7173
  /** 检测所有option并设置禁用状态 */
7150
7174
  setSelectOptionsDisableStatus() {
7151
7175
  if (this.$ele.select.options && this.$ele.select.options.length) {
@@ -7173,9 +7197,11 @@
7173
7197
  getSelectOptionInfo($option) {
7174
7198
  let optionValue = this.getNodeValue($option, this.$eleKey.value);
7175
7199
  let optionText = $option.innerText || $option.textContent;
7200
+ let optionForms = this.getNodeValue($option, this.$eleKey.forms);
7176
7201
  return {
7177
7202
  value: optionValue,
7178
7203
  text: optionText,
7204
+ forms: optionForms,
7179
7205
  $option: $option,
7180
7206
  };
7181
7207
  },
@@ -7184,12 +7210,34 @@
7184
7210
  */
7185
7211
  setChangeEvent() {
7186
7212
  popsDOMUtils.on(this.$ele.select, "change", void 0, (event) => {
7213
+ let $isSelectedElement = event.target[event.target.selectedIndex];
7214
+ let selectInfo = this.getSelectOptionInfo($isSelectedElement);
7187
7215
  this.setSelectOptionsDisableStatus();
7188
7216
  if (typeof formConfig.callback === "function") {
7189
- let $isSelectedElement = event.target[event.target.selectedIndex];
7190
- let selectInfo = this.getSelectOptionInfo($isSelectedElement);
7191
7217
  formConfig.callback(event, selectInfo.value, selectInfo.text);
7192
7218
  }
7219
+ let forms = typeof selectInfo.forms === "function"
7220
+ ? selectInfo.forms()
7221
+ : selectInfo.forms;
7222
+ if (Array.isArray(forms)) {
7223
+ /* 如果成功创建,加入到中间容器中 */
7224
+ let childUListClassName = "pops-panel-select-child-forms";
7225
+ // 移除旧的元素
7226
+ while (liElement.nextElementSibling) {
7227
+ if (liElement.nextElementSibling.classList.contains(childUListClassName)) {
7228
+ liElement.nextElementSibling.remove();
7229
+ }
7230
+ else {
7231
+ break;
7232
+ }
7233
+ }
7234
+ let $childUList = document.createElement("ul");
7235
+ $childUList.className = childUListClassName;
7236
+ popsDOMUtils.after(liElement, $childUList);
7237
+ that.uListContainerAddItem(formConfig, {
7238
+ ulElement: $childUList,
7239
+ });
7240
+ }
7193
7241
  });
7194
7242
  },
7195
7243
  /**
@@ -7528,12 +7576,28 @@
7528
7576
  Reflect.set($item, "data-info", dataInfo);
7529
7577
  return $item;
7530
7578
  }
7579
+ /**
7580
+ * 设置选择项的禁用状态
7581
+ */
7582
+ function setSelectItemDisabled($el) {
7583
+ $el.setAttribute("aria-disabled", "true");
7584
+ }
7585
+ /**
7586
+ * 移除选择项的禁用状态
7587
+ */
7588
+ function removeSelectItemDisabled($el) {
7589
+ $el.removeAttribute("aria-disabled");
7590
+ $el.removeAttribute("disabled");
7591
+ }
7531
7592
  /**
7532
7593
  * 设置选择项的点击事件
7533
7594
  */
7534
7595
  function setSelectElementClickEvent($ele) {
7535
7596
  popsDOMUtils.on($ele, "click", (event) => {
7536
7597
  popsDOMUtils.preventEvent(event);
7598
+ if ($ele.hasAttribute("disabled") || $ele.ariaDisabled) {
7599
+ return;
7600
+ }
7537
7601
  if (typeof formConfig.clickCallBack === "function") {
7538
7602
  let clickResult = formConfig.clickCallBack(event, getAllSelectedInfo());
7539
7603
  if (typeof clickResult === "boolean" && !clickResult) {
@@ -7599,7 +7663,6 @@
7599
7663
  --el-fill-color-light: #f5f7fa;
7600
7664
  }
7601
7665
  .select-item{
7602
- cursor: pointer;
7603
7666
  cursor: pointer;
7604
7667
  font-size: var(--el-font-size-base);
7605
7668
  padding: 0 32px 0 20px;
@@ -7612,6 +7675,12 @@
7612
7675
  line-height: 34px;
7613
7676
  box-sizing: border-box;
7614
7677
  }
7678
+ .select-item[aria-disabled],
7679
+ .select-item[disabled]{
7680
+ cursor: not-allowed;
7681
+ color: #a8abb2;
7682
+ background: unset;
7683
+ }
7615
7684
  .select-item:hover{
7616
7685
  background-color: var(--el-fill-color-light);
7617
7686
  }
@@ -7649,6 +7718,15 @@
7649
7718
  $selectContainer.appendChild($select);
7650
7719
  // 设置每一项的点击事件
7651
7720
  setSelectElementClickEvent($select);
7721
+ // 设置禁用状态
7722
+ if (typeof item.disable === "function" &&
7723
+ item.disable(item.value)) {
7724
+ setSelectItemDisabled($select);
7725
+ // 后续不设置元素的选中状态
7726
+ return;
7727
+ }
7728
+ // 移除禁用状态
7729
+ removeSelectItemDisabled($select);
7652
7730
  let findValue = selectedInfo.find((value) => value.value === item.value);
7653
7731
  if (findValue) {
7654
7732
  setItemSelected($select);
@@ -10059,7 +10137,7 @@
10059
10137
  /** 配置 */
10060
10138
  config = {
10061
10139
  /** 版本号 */
10062
- version: "2024.12.8",
10140
+ version: "2025.1.1",
10063
10141
  cssText: {
10064
10142
  /** 主CSS */
10065
10143
  index: indexCSS,