@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.esm.js CHANGED
@@ -5540,6 +5540,7 @@ const PopsPanelConfig = () => {
5540
5540
  disable() {
5541
5541
  return false;
5542
5542
  },
5543
+ forms: [],
5543
5544
  },
5544
5545
  {
5545
5546
  value: "text",
@@ -5547,6 +5548,7 @@ const PopsPanelConfig = () => {
5547
5548
  disable() {
5548
5549
  return false;
5549
5550
  },
5551
+ forms: [],
5550
5552
  },
5551
5553
  {
5552
5554
  value: "html",
@@ -5554,6 +5556,7 @@ const PopsPanelConfig = () => {
5554
5556
  disable() {
5555
5557
  return false;
5556
5558
  },
5559
+ forms: [],
5557
5560
  },
5558
5561
  ],
5559
5562
  },
@@ -7057,6 +7060,7 @@ const PanelHandleContentDetails = () => {
7057
7060
  * @param formConfig
7058
7061
  */
7059
7062
  createSectionContainerItem_select(formConfig) {
7063
+ const that = this;
7060
7064
  let liElement = document.createElement("li");
7061
7065
  liElement["__formConfig__"] = formConfig;
7062
7066
  this.setElementClassName(liElement, formConfig.className);
@@ -7085,6 +7089,7 @@ const PanelHandleContentDetails = () => {
7085
7089
  $eleKey: {
7086
7090
  disable: "__disable__",
7087
7091
  value: "__value__",
7092
+ forms: "__forms__",
7088
7093
  },
7089
7094
  $data: {
7090
7095
  defaultValue: formConfig.getValue(),
@@ -7115,31 +7120,50 @@ const PanelHandleContentDetails = () => {
7115
7120
  getNodeValue($ele, key) {
7116
7121
  return Reflect.get($ele, key);
7117
7122
  },
7123
+ /**
7124
+ * 禁用选项
7125
+ */
7118
7126
  disable() {
7119
7127
  this.$ele.select.setAttribute("disabled", "true");
7120
7128
  this.$ele.panelSelect.classList.add("pops-panel-select-disable");
7121
7129
  },
7130
+ /**
7131
+ * 取消禁用
7132
+ */
7122
7133
  notDisable() {
7123
7134
  this.$ele.select.removeAttribute("disabled");
7124
7135
  this.$ele.panelSelect.classList.remove("pops-panel-select-disable");
7125
7136
  },
7137
+ /**
7138
+ * 判断是否禁用
7139
+ */
7126
7140
  isDisabled() {
7127
7141
  return (this.$ele.select.hasAttribute("disabled") ||
7128
7142
  this.$ele.panelSelect.classList.contains("pops-panel-select-disable"));
7129
7143
  },
7144
+ /**
7145
+ * 初始化选项
7146
+ */
7130
7147
  initOption() {
7131
7148
  formConfig.data.forEach((dataItem) => {
7132
7149
  // 初始化默认选中
7133
7150
  let optionElement = document.createElement("option");
7134
7151
  this.setNodeValue(optionElement, this.$eleKey.value, dataItem.value);
7135
7152
  this.setNodeValue(optionElement, this.$eleKey.disable, dataItem.disable);
7153
+ this.setNodeValue(optionElement, this.$eleKey.forms, dataItem.forms);
7136
7154
  if (dataItem.value === this.$data.defaultValue) {
7137
- optionElement.setAttribute("selected", "true");
7155
+ this.setOptionSelected(optionElement);
7138
7156
  }
7139
7157
  optionElement.innerText = dataItem.text;
7140
7158
  this.$ele.select.appendChild(optionElement);
7141
7159
  });
7142
7160
  },
7161
+ /**
7162
+ * 设置选项选中
7163
+ */
7164
+ setOptionSelected($option) {
7165
+ $option.setAttribute("selected", "true");
7166
+ },
7143
7167
  /** 检测所有option并设置禁用状态 */
7144
7168
  setSelectOptionsDisableStatus() {
7145
7169
  if (this.$ele.select.options && this.$ele.select.options.length) {
@@ -7167,9 +7191,11 @@ const PanelHandleContentDetails = () => {
7167
7191
  getSelectOptionInfo($option) {
7168
7192
  let optionValue = this.getNodeValue($option, this.$eleKey.value);
7169
7193
  let optionText = $option.innerText || $option.textContent;
7194
+ let optionForms = this.getNodeValue($option, this.$eleKey.forms);
7170
7195
  return {
7171
7196
  value: optionValue,
7172
7197
  text: optionText,
7198
+ forms: optionForms,
7173
7199
  $option: $option,
7174
7200
  };
7175
7201
  },
@@ -7178,12 +7204,34 @@ const PanelHandleContentDetails = () => {
7178
7204
  */
7179
7205
  setChangeEvent() {
7180
7206
  popsDOMUtils.on(this.$ele.select, "change", void 0, (event) => {
7207
+ let $isSelectedElement = event.target[event.target.selectedIndex];
7208
+ let selectInfo = this.getSelectOptionInfo($isSelectedElement);
7181
7209
  this.setSelectOptionsDisableStatus();
7182
7210
  if (typeof formConfig.callback === "function") {
7183
- let $isSelectedElement = event.target[event.target.selectedIndex];
7184
- let selectInfo = this.getSelectOptionInfo($isSelectedElement);
7185
7211
  formConfig.callback(event, selectInfo.value, selectInfo.text);
7186
7212
  }
7213
+ let forms = typeof selectInfo.forms === "function"
7214
+ ? selectInfo.forms()
7215
+ : selectInfo.forms;
7216
+ if (Array.isArray(forms)) {
7217
+ /* 如果成功创建,加入到中间容器中 */
7218
+ let childUListClassName = "pops-panel-select-child-forms";
7219
+ // 移除旧的元素
7220
+ while (liElement.nextElementSibling) {
7221
+ if (liElement.nextElementSibling.classList.contains(childUListClassName)) {
7222
+ liElement.nextElementSibling.remove();
7223
+ }
7224
+ else {
7225
+ break;
7226
+ }
7227
+ }
7228
+ let $childUList = document.createElement("ul");
7229
+ $childUList.className = childUListClassName;
7230
+ popsDOMUtils.after(liElement, $childUList);
7231
+ that.uListContainerAddItem(formConfig, {
7232
+ ulElement: $childUList,
7233
+ });
7234
+ }
7187
7235
  });
7188
7236
  },
7189
7237
  /**
@@ -7522,12 +7570,28 @@ const PanelHandleContentDetails = () => {
7522
7570
  Reflect.set($item, "data-info", dataInfo);
7523
7571
  return $item;
7524
7572
  }
7573
+ /**
7574
+ * 设置选择项的禁用状态
7575
+ */
7576
+ function setSelectItemDisabled($el) {
7577
+ $el.setAttribute("aria-disabled", "true");
7578
+ }
7579
+ /**
7580
+ * 移除选择项的禁用状态
7581
+ */
7582
+ function removeSelectItemDisabled($el) {
7583
+ $el.removeAttribute("aria-disabled");
7584
+ $el.removeAttribute("disabled");
7585
+ }
7525
7586
  /**
7526
7587
  * 设置选择项的点击事件
7527
7588
  */
7528
7589
  function setSelectElementClickEvent($ele) {
7529
7590
  popsDOMUtils.on($ele, "click", (event) => {
7530
7591
  popsDOMUtils.preventEvent(event);
7592
+ if ($ele.hasAttribute("disabled") || $ele.ariaDisabled) {
7593
+ return;
7594
+ }
7531
7595
  if (typeof formConfig.clickCallBack === "function") {
7532
7596
  let clickResult = formConfig.clickCallBack(event, getAllSelectedInfo());
7533
7597
  if (typeof clickResult === "boolean" && !clickResult) {
@@ -7593,7 +7657,6 @@ const PanelHandleContentDetails = () => {
7593
7657
  --el-fill-color-light: #f5f7fa;
7594
7658
  }
7595
7659
  .select-item{
7596
- cursor: pointer;
7597
7660
  cursor: pointer;
7598
7661
  font-size: var(--el-font-size-base);
7599
7662
  padding: 0 32px 0 20px;
@@ -7606,6 +7669,12 @@ const PanelHandleContentDetails = () => {
7606
7669
  line-height: 34px;
7607
7670
  box-sizing: border-box;
7608
7671
  }
7672
+ .select-item[aria-disabled],
7673
+ .select-item[disabled]{
7674
+ cursor: not-allowed;
7675
+ color: #a8abb2;
7676
+ background: unset;
7677
+ }
7609
7678
  .select-item:hover{
7610
7679
  background-color: var(--el-fill-color-light);
7611
7680
  }
@@ -7643,6 +7712,15 @@ const PanelHandleContentDetails = () => {
7643
7712
  $selectContainer.appendChild($select);
7644
7713
  // 设置每一项的点击事件
7645
7714
  setSelectElementClickEvent($select);
7715
+ // 设置禁用状态
7716
+ if (typeof item.disable === "function" &&
7717
+ item.disable(item.value)) {
7718
+ setSelectItemDisabled($select);
7719
+ // 后续不设置元素的选中状态
7720
+ return;
7721
+ }
7722
+ // 移除禁用状态
7723
+ removeSelectItemDisabled($select);
7646
7724
  let findValue = selectedInfo.find((value) => value.value === item.value);
7647
7725
  if (findValue) {
7648
7726
  setItemSelected($select);
@@ -10053,7 +10131,7 @@ class Pops {
10053
10131
  /** 配置 */
10054
10132
  config = {
10055
10133
  /** 版本号 */
10056
- version: "2024.12.8",
10134
+ version: "2025.1.1",
10057
10135
  cssText: {
10058
10136
  /** 主CSS */
10059
10137
  index: indexCSS,