@whitesev/pops 1.6.3 → 1.6.4

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
@@ -7272,2310 +7272,2315 @@
7272
7272
  },
7273
7273
  };
7274
7274
 
7275
- const PanelHandleContentDetails = {
7276
- /**
7277
- * 左侧的ul容器
7278
- */
7279
- asideULElement: null,
7280
- /**
7281
- * 右侧主内容的顶部文字ul容器
7282
- */
7283
- sectionContainerHeaderULElement: null,
7284
- /**
7285
- * 右侧主内容的ul容器
7286
- */
7287
- sectionContainerULElement: null,
7288
- $el: {
7289
- $content: null,
7290
- $contentAside: null,
7291
- $contentSectionContainer: null,
7292
- },
7293
- init(details) {
7294
- // @ts-ignore
7295
- this.$el = null;
7296
- this.$el = {
7297
- ...details.$el,
7298
- };
7299
- this.asideULElement =
7300
- this.$el.$contentAside.querySelector("ul");
7301
- this.sectionContainerHeaderULElement =
7302
- this.$el.$contentSectionContainer.querySelectorAll("ul")[0];
7303
- this.sectionContainerULElement =
7304
- this.$el.$contentSectionContainer.querySelectorAll("ul")[1];
7275
+ const PanelHandleContentDetails = () => {
7276
+ return {
7305
7277
  /**
7306
- * 默认点击的左侧容器
7278
+ * 左侧的ul容器
7307
7279
  */
7308
- let asideDefaultItemElement = null;
7309
- let isScrollToDefaultView = false;
7310
- details.config.content.forEach((asideItem) => {
7311
- let asideLiElement = this.getAsideItem(asideItem);
7312
- this.setAsideItemClickEvent(asideLiElement, asideItem);
7313
- this.asideULElement.appendChild(asideLiElement);
7314
- if (asideDefaultItemElement == null) {
7315
- let flag = false;
7316
- if (typeof asideItem.isDefault === "function") {
7317
- flag = Boolean(asideItem.isDefault());
7318
- }
7319
- else {
7320
- flag = Boolean(asideItem.isDefault);
7280
+ asideULElement: null,
7281
+ /**
7282
+ * 右侧主内容的顶部文字ul容器
7283
+ */
7284
+ sectionContainerHeaderULElement: null,
7285
+ /**
7286
+ * 右侧主内容的ul容器
7287
+ */
7288
+ sectionContainerULElement: null,
7289
+ $el: {
7290
+ $content: null,
7291
+ $contentAside: null,
7292
+ $contentSectionContainer: null,
7293
+ },
7294
+ init(details) {
7295
+ // @ts-ignore
7296
+ this.$el = null;
7297
+ this.$el = {
7298
+ ...details.$el,
7299
+ };
7300
+ this.asideULElement =
7301
+ this.$el.$contentAside.querySelector("ul");
7302
+ this.sectionContainerHeaderULElement =
7303
+ this.$el.$contentSectionContainer.querySelectorAll("ul")[0];
7304
+ this.sectionContainerULElement =
7305
+ this.$el.$contentSectionContainer.querySelectorAll("ul")[1];
7306
+ /**
7307
+ * 默认点击的左侧容器
7308
+ */
7309
+ let asideDefaultItemElement = null;
7310
+ let isScrollToDefaultView = false;
7311
+ details.config.content.forEach((asideItem) => {
7312
+ let asideLiElement = this.getAsideItem(asideItem);
7313
+ this.setAsideItemClickEvent(asideLiElement, asideItem);
7314
+ this.asideULElement.appendChild(asideLiElement);
7315
+ if (asideDefaultItemElement == null) {
7316
+ let flag = false;
7317
+ if (typeof asideItem.isDefault === "function") {
7318
+ flag = Boolean(asideItem.isDefault());
7319
+ }
7320
+ else {
7321
+ flag = Boolean(asideItem.isDefault);
7322
+ }
7323
+ if (flag) {
7324
+ asideDefaultItemElement = asideLiElement;
7325
+ isScrollToDefaultView = Boolean(asideItem.scrollToDefaultView);
7326
+ }
7321
7327
  }
7322
- if (flag) {
7323
- asideDefaultItemElement = asideLiElement;
7324
- isScrollToDefaultView = Boolean(asideItem.scrollToDefaultView);
7328
+ });
7329
+ /* 点击左侧列表 */
7330
+ if (asideDefaultItemElement == null &&
7331
+ this.asideULElement.children.length) {
7332
+ /* 默认第一个 */
7333
+ asideDefaultItemElement = this.asideULElement
7334
+ .children[0];
7335
+ }
7336
+ if (asideDefaultItemElement) {
7337
+ /* 点击选择的那一项 */
7338
+ asideDefaultItemElement.click();
7339
+ if (isScrollToDefaultView) {
7340
+ asideDefaultItemElement?.scrollIntoView();
7325
7341
  }
7326
7342
  }
7327
- });
7328
- /* 点击左侧列表 */
7329
- if (asideDefaultItemElement == null &&
7330
- this.asideULElement.children.length) {
7331
- /* 默认第一个 */
7332
- asideDefaultItemElement = this.asideULElement
7333
- .children[0];
7334
- }
7335
- if (asideDefaultItemElement) {
7336
- /* 点击选择的那一项 */
7337
- asideDefaultItemElement.click();
7338
- if (isScrollToDefaultView) {
7339
- asideDefaultItemElement?.scrollIntoView();
7343
+ else {
7344
+ console.error("pops.panel:左侧容器没有项");
7340
7345
  }
7341
- }
7342
- else {
7343
- console.error("pops.panel:左侧容器没有项");
7344
- }
7345
- },
7346
- /**
7347
- * 清空container容器的元素
7348
- */
7349
- clearContainer() {
7350
- this.sectionContainerHeaderULElement.innerHTML = "";
7351
- this.sectionContainerULElement.innerHTML = "";
7352
- this.$el.$content
7353
- ?.querySelectorAll("section.pops-panel-deepMenu-container")
7354
- .forEach((ele) => ele.remove());
7355
- },
7356
- /**
7357
- * 清空左侧容器已访问记录
7358
- */
7359
- clearAsideItemIsVisited() {
7360
- this.$el.$contentAside
7361
- .querySelectorAll(".pops-is-visited")
7362
- .forEach((element) => {
7363
- popsDOMUtils.removeClassName(element, "pops-is-visited");
7364
- });
7365
- },
7366
- /**
7367
- * 设置左侧容器已访问记录
7368
- * @param element
7369
- */
7370
- setAsideItemIsVisited(element) {
7371
- popsDOMUtils.addClassName(element, "pops-is-visited");
7372
- },
7373
- /**
7374
- * 为元素添加自定义属性
7375
- * @param element
7376
- * @param attributes
7377
- */
7378
- addElementAttributes(element, attributes) {
7379
- if (attributes == null) {
7380
- return;
7381
- }
7382
- if (Array.isArray(attributes)) {
7383
- attributes.forEach((attrObject) => {
7384
- this.addElementAttributes(element, attrObject);
7346
+ },
7347
+ /**
7348
+ * 清空container容器的元素
7349
+ */
7350
+ clearContainer() {
7351
+ this.sectionContainerHeaderULElement.innerHTML = "";
7352
+ this.sectionContainerULElement.innerHTML = "";
7353
+ this.$el.$content
7354
+ ?.querySelectorAll("section.pops-panel-deepMenu-container")
7355
+ .forEach((ele) => ele.remove());
7356
+ },
7357
+ /**
7358
+ * 清空左侧容器已访问记录
7359
+ */
7360
+ clearAsideItemIsVisited() {
7361
+ this.$el.$contentAside
7362
+ .querySelectorAll(".pops-is-visited")
7363
+ .forEach((element) => {
7364
+ popsDOMUtils.removeClassName(element, "pops-is-visited");
7385
7365
  });
7386
- }
7387
- else {
7388
- Object.keys(attributes).forEach((attributeName) => {
7389
- element.setAttribute(attributeName, attributes[attributeName]);
7366
+ },
7367
+ /**
7368
+ * 设置左侧容器已访问记录
7369
+ * @param element
7370
+ */
7371
+ setAsideItemIsVisited(element) {
7372
+ popsDOMUtils.addClassName(element, "pops-is-visited");
7373
+ },
7374
+ /**
7375
+ * 为元素添加自定义属性
7376
+ * @param element
7377
+ * @param attributes
7378
+ */
7379
+ addElementAttributes(element, attributes) {
7380
+ if (attributes == null) {
7381
+ return;
7382
+ }
7383
+ if (Array.isArray(attributes)) {
7384
+ attributes.forEach((attrObject) => {
7385
+ this.addElementAttributes(element, attrObject);
7386
+ });
7387
+ }
7388
+ else {
7389
+ Object.keys(attributes).forEach((attributeName) => {
7390
+ element.setAttribute(attributeName, attributes[attributeName]);
7391
+ });
7392
+ }
7393
+ },
7394
+ /**
7395
+ * 为元素设置(自定义)属性
7396
+ * @param element
7397
+ * @param props
7398
+ */
7399
+ setElementProps(element, props) {
7400
+ if (props == null) {
7401
+ return;
7402
+ }
7403
+ Object.keys(props).forEach((propName) => {
7404
+ element[propName] = props[propName];
7390
7405
  });
7391
- }
7392
- },
7393
- /**
7394
- * 为元素设置(自定义)属性
7395
- * @param element
7396
- * @param props
7397
- */
7398
- setElementProps(element, props) {
7399
- if (props == null) {
7400
- return;
7401
- }
7402
- Object.keys(props).forEach((propName) => {
7403
- element[propName] = props[propName];
7404
- });
7405
- },
7406
- /**
7407
- * 获取左侧容器元素<li>
7408
- * @param asideConfig
7409
- */
7410
- getAsideItem(asideConfig) {
7411
- let liElement = document.createElement("li");
7412
- liElement.id = asideConfig.id;
7413
- liElement["__forms__"] = asideConfig.forms;
7414
- liElement.innerHTML = asideConfig.title;
7415
- this.addElementAttributes(liElement, asideConfig.attributes);
7416
- this.setElementProps(liElement, asideConfig.props);
7417
- return liElement;
7418
- },
7419
- /**
7420
- * 获取中间容器的元素<li>
7421
- * type ==> switch
7422
- * @param formConfig
7423
- */
7424
- getSectionContainerItem_switch(formConfig) {
7425
- let liElement = document.createElement("li");
7426
- liElement["__formConfig__"] = formConfig;
7427
- if (formConfig.className) {
7428
- liElement.className = formConfig.className;
7429
- }
7430
- this.addElementAttributes(liElement, formConfig.attributes);
7431
- this.setElementProps(liElement, formConfig.props);
7432
- /* 左边底部的描述的文字 */
7433
- let leftDescriptionText = "";
7434
- if (Boolean(formConfig.description)) {
7435
- leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
7436
- }
7437
- liElement.innerHTML = /*html*/ `
7438
- <div class="pops-panel-item-left-text">
7439
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
7440
- ${leftDescriptionText}
7441
- </div>
7442
- <div class="pops-panel-switch">
7443
- <input class="pops-panel-switch__input" type="checkbox">
7444
- <span class="pops-panel-switch__core">
7445
- <div class="pops-panel-switch__action">
7446
- </div>
7447
- </span>
7448
- </div>`;
7449
- const PopsPanelSwitch = {
7450
- [Symbol.toStringTag]: "PopsPanelSwitch",
7451
- $data: {
7452
- value: Boolean(formConfig.getValue()),
7453
- },
7454
- $ele: {
7455
- switch: liElement.querySelector(".pops-panel-switch"),
7456
- input: liElement.querySelector(".pops-panel-switch__input"),
7457
- core: liElement.querySelector(".pops-panel-switch__core"),
7458
- },
7459
- init() {
7460
- this.setStatus(this.$data.value);
7461
- if (formConfig.disabled) {
7462
- this.disable();
7463
- }
7464
- this.setClickEvent();
7465
- },
7466
- setClickEvent() {
7467
- let that = this;
7468
- popsDOMUtils.on(this.$ele.core, "click", void 0, function (event) {
7469
- if (that.$ele.input.disabled ||
7470
- that.$ele.switch.hasAttribute("data-disabled")) {
7471
- return;
7406
+ },
7407
+ /**
7408
+ * 获取左侧容器元素<li>
7409
+ * @param asideConfig
7410
+ */
7411
+ getAsideItem(asideConfig) {
7412
+ let liElement = document.createElement("li");
7413
+ liElement.id = asideConfig.id;
7414
+ liElement["__forms__"] = asideConfig.forms;
7415
+ liElement.innerHTML = asideConfig.title;
7416
+ this.addElementAttributes(liElement, asideConfig.attributes);
7417
+ this.setElementProps(liElement, asideConfig.props);
7418
+ return liElement;
7419
+ },
7420
+ /**
7421
+ * 获取中间容器的元素<li>
7422
+ * type ==> switch
7423
+ * @param formConfig
7424
+ */
7425
+ getSectionContainerItem_switch(formConfig) {
7426
+ let liElement = document.createElement("li");
7427
+ liElement["__formConfig__"] = formConfig;
7428
+ if (formConfig.className) {
7429
+ liElement.className = formConfig.className;
7430
+ }
7431
+ this.addElementAttributes(liElement, formConfig.attributes);
7432
+ this.setElementProps(liElement, formConfig.props);
7433
+ /* 左边底部的描述的文字 */
7434
+ let leftDescriptionText = "";
7435
+ if (Boolean(formConfig.description)) {
7436
+ leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
7437
+ }
7438
+ liElement.innerHTML = /*html*/ `
7439
+ <div class="pops-panel-item-left-text">
7440
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
7441
+ ${leftDescriptionText}
7442
+ </div>
7443
+ <div class="pops-panel-switch">
7444
+ <input class="pops-panel-switch__input" type="checkbox">
7445
+ <span class="pops-panel-switch__core">
7446
+ <div class="pops-panel-switch__action">
7447
+ </div>
7448
+ </span>
7449
+ </div>`;
7450
+ const PopsPanelSwitch = {
7451
+ [Symbol.toStringTag]: "PopsPanelSwitch",
7452
+ $data: {
7453
+ value: Boolean(formConfig.getValue()),
7454
+ },
7455
+ $ele: {
7456
+ switch: liElement.querySelector(".pops-panel-switch"),
7457
+ input: liElement.querySelector(".pops-panel-switch__input"),
7458
+ core: liElement.querySelector(".pops-panel-switch__core"),
7459
+ },
7460
+ init() {
7461
+ this.setStatus(this.$data.value);
7462
+ if (formConfig.disabled) {
7463
+ this.disable();
7472
7464
  }
7473
- that.$data.value = that.getStatus();
7474
- that.setStatus(that.$data.value);
7475
- if (typeof formConfig.callback === "function") {
7476
- formConfig.callback(event, that.$data.value);
7465
+ this.setClickEvent();
7466
+ },
7467
+ setClickEvent() {
7468
+ let that = this;
7469
+ popsDOMUtils.on(this.$ele.core, "click", void 0, function (event) {
7470
+ if (that.$ele.input.disabled ||
7471
+ that.$ele.switch.hasAttribute("data-disabled")) {
7472
+ return;
7473
+ }
7474
+ that.$data.value = that.getStatus();
7475
+ that.setStatus(that.$data.value);
7476
+ if (typeof formConfig.callback === "function") {
7477
+ formConfig.callback(event, that.$data.value);
7478
+ }
7479
+ });
7480
+ },
7481
+ /**
7482
+ * 设置状态
7483
+ */
7484
+ setStatus(isChecked = false) {
7485
+ isChecked = Boolean(isChecked);
7486
+ this.$ele.input.checked = isChecked;
7487
+ if (isChecked) {
7488
+ popsDOMUtils.addClassName(this.$ele.switch, "pops-panel-switch-is-checked");
7477
7489
  }
7478
- });
7479
- },
7490
+ else {
7491
+ popsDOMUtils.removeClassName(this.$ele.switch, "pops-panel-switch-is-checked");
7492
+ }
7493
+ },
7494
+ /**
7495
+ * 根据className来获取逆反值
7496
+ */
7497
+ getStatus() {
7498
+ let checkedValue = false;
7499
+ if (!popsDOMUtils.containsClassName(this.$ele.switch, "pops-panel-switch-is-checked")) {
7500
+ checkedValue = true;
7501
+ }
7502
+ return checkedValue;
7503
+ },
7504
+ /**
7505
+ * 禁用复选框
7506
+ */
7507
+ disable() {
7508
+ this.$ele.input.disabled = true;
7509
+ this.$ele.switch.setAttribute("data-disabled", "true");
7510
+ },
7511
+ /**
7512
+ * 启用复选框
7513
+ */
7514
+ notDisable() {
7515
+ this.$ele.input.disabled = false;
7516
+ this.$ele.switch.removeAttribute("data-disabled");
7517
+ },
7518
+ };
7519
+ PopsPanelSwitch.init();
7520
+ liElement["data-switch"] = PopsPanelSwitch;
7521
+ return liElement;
7522
+ },
7523
+ /**
7524
+ * 获取中间容器的元素<li>
7525
+ * type ==> slider
7526
+ * @param formConfig
7527
+ */
7528
+ getSectionContainerItem_slider(formConfig) {
7529
+ let liElement = document.createElement("li");
7530
+ liElement["__formConfig__"] = formConfig;
7531
+ if (formConfig.className) {
7532
+ liElement.className = formConfig.className;
7533
+ }
7534
+ this.addElementAttributes(liElement, formConfig.attributes);
7535
+ this.setElementProps(liElement, formConfig.props);
7536
+ /* 左边底部的描述的文字 */
7537
+ let leftDescriptionText = "";
7538
+ if (Boolean(formConfig.description)) {
7539
+ leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
7540
+ }
7541
+ liElement.innerHTML = `
7542
+ <div class="pops-panel-item-left-text">
7543
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
7544
+ ${leftDescriptionText}
7545
+ </div>
7546
+ <div class="pops-panel-slider">
7547
+ <input type="range" min="${formConfig.min}" max="${formConfig.max}">
7548
+ </div>`;
7549
+ let rangeInputElement = liElement.querySelector(".pops-panel-slider input[type=range]");
7550
+ if (formConfig.step) {
7551
+ rangeInputElement.setAttribute("step", formConfig.step.toString());
7552
+ }
7553
+ rangeInputElement.value = formConfig.getValue().toString();
7480
7554
  /**
7481
- * 设置状态
7555
+ * 获取提示的内容
7556
+ * @param value
7482
7557
  */
7483
- setStatus(isChecked = false) {
7484
- isChecked = Boolean(isChecked);
7485
- this.$ele.input.checked = isChecked;
7486
- if (isChecked) {
7487
- popsDOMUtils.addClassName(this.$ele.switch, "pops-panel-switch-is-checked");
7558
+ let getToolTipContent = function (value) {
7559
+ if (typeof formConfig.getToolTipContent === "function") {
7560
+ return formConfig.getToolTipContent(value);
7488
7561
  }
7489
7562
  else {
7490
- popsDOMUtils.removeClassName(this.$ele.switch, "pops-panel-switch-is-checked");
7563
+ return value;
7491
7564
  }
7492
- },
7493
- /**
7494
- * 根据className来获取逆反值
7495
- */
7496
- getStatus() {
7497
- let checkedValue = false;
7498
- if (!popsDOMUtils.containsClassName(this.$ele.switch, "pops-panel-switch-is-checked")) {
7499
- checkedValue = true;
7565
+ };
7566
+ let tooltip = pops.tooltip({
7567
+ target: rangeInputElement.parentElement,
7568
+ content: getToolTipContent(rangeInputElement.value),
7569
+ zIndex: 1000000,
7570
+ className: "github-tooltip",
7571
+ showBeforeCallBack() {
7572
+ tooltip.toolTipNode.querySelector("div").innerText =
7573
+ getToolTipContent(rangeInputElement.value);
7574
+ },
7575
+ alwaysShow: false,
7576
+ only: false,
7577
+ position: "top",
7578
+ arrowDistance: 10,
7579
+ });
7580
+ popsDOMUtils.on(rangeInputElement, ["input", "propertychange"], void 0, function (event) {
7581
+ tooltip.toolTipNode.querySelector("div").innerText =
7582
+ getToolTipContent(rangeInputElement.value);
7583
+ if (typeof formConfig.callback === "function") {
7584
+ formConfig.callback(event, event.target.value);
7500
7585
  }
7501
- return checkedValue;
7502
- },
7503
- /**
7504
- * 禁用复选框
7505
- */
7506
- disable() {
7507
- this.$ele.input.disabled = true;
7508
- this.$ele.switch.setAttribute("data-disabled", "true");
7509
- },
7510
- /**
7511
- * 启用复选框
7512
- */
7513
- notDisable() {
7514
- this.$ele.input.disabled = false;
7515
- this.$ele.switch.removeAttribute("data-disabled");
7516
- },
7517
- };
7518
- PopsPanelSwitch.init();
7519
- liElement["data-switch"] = PopsPanelSwitch;
7520
- return liElement;
7521
- },
7522
- /**
7523
- * 获取中间容器的元素<li>
7524
- * type ==> slider
7525
- * @param formConfig
7526
- */
7527
- getSectionContainerItem_slider(formConfig) {
7528
- let liElement = document.createElement("li");
7529
- liElement["__formConfig__"] = formConfig;
7530
- if (formConfig.className) {
7531
- liElement.className = formConfig.className;
7532
- }
7533
- this.addElementAttributes(liElement, formConfig.attributes);
7534
- this.setElementProps(liElement, formConfig.props);
7535
- /* 左边底部的描述的文字 */
7536
- let leftDescriptionText = "";
7537
- if (Boolean(formConfig.description)) {
7538
- leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
7539
- }
7540
- liElement.innerHTML = `
7541
- <div class="pops-panel-item-left-text">
7542
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
7543
- ${leftDescriptionText}
7544
- </div>
7545
- <div class="pops-panel-slider">
7546
- <input type="range" min="${formConfig.min}" max="${formConfig.max}">
7547
- </div>`;
7548
- let rangeInputElement = liElement.querySelector(".pops-panel-slider input[type=range]");
7549
- if (formConfig.step) {
7550
- rangeInputElement.setAttribute("step", formConfig.step.toString());
7551
- }
7552
- rangeInputElement.value = formConfig.getValue().toString();
7586
+ });
7587
+ return liElement;
7588
+ },
7553
7589
  /**
7554
- * 获取提示的内容
7555
- * @param value
7590
+ * 获取中间容器的元素<li>
7591
+ * type ==> slider
7592
+ * @param formConfig
7556
7593
  */
7557
- let getToolTipContent = function (value) {
7558
- if (typeof formConfig.getToolTipContent === "function") {
7559
- return formConfig.getToolTipContent(value);
7560
- }
7561
- else {
7562
- return value;
7594
+ getSectionContainerItem_slider_new(formConfig) {
7595
+ let liElement = document.createElement("li");
7596
+ liElement["__formConfig__"] = formConfig;
7597
+ if (formConfig.className) {
7598
+ liElement.className = formConfig.className;
7563
7599
  }
7564
- };
7565
- let tooltip = pops.tooltip({
7566
- target: rangeInputElement.parentElement,
7567
- content: getToolTipContent(rangeInputElement.value),
7568
- zIndex: 1000000,
7569
- className: "github-tooltip",
7570
- showBeforeCallBack() {
7571
- tooltip.toolTipNode.querySelector("div").innerText = getToolTipContent(rangeInputElement.value);
7572
- },
7573
- alwaysShow: false,
7574
- only: false,
7575
- position: "top",
7576
- arrowDistance: 10,
7577
- });
7578
- popsDOMUtils.on(rangeInputElement, ["input", "propertychange"], void 0, function (event) {
7579
- tooltip.toolTipNode.querySelector("div").innerText = getToolTipContent(rangeInputElement.value);
7580
- if (typeof formConfig.callback === "function") {
7581
- formConfig.callback(event, event.target.value);
7600
+ this.addElementAttributes(liElement, formConfig.attributes);
7601
+ this.setElementProps(liElement, formConfig.props);
7602
+ /* 左边底部的描述的文字 */
7603
+ let leftDescriptionText = "";
7604
+ if (Boolean(formConfig.description)) {
7605
+ leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
7582
7606
  }
7583
- });
7584
- return liElement;
7585
- },
7586
- /**
7587
- * 获取中间容器的元素<li>
7588
- * type ==> slider
7589
- * @param formConfig
7590
- */
7591
- getSectionContainerItem_slider_new(formConfig) {
7592
- let liElement = document.createElement("li");
7593
- liElement["__formConfig__"] = formConfig;
7594
- if (formConfig.className) {
7595
- liElement.className = formConfig.className;
7596
- }
7597
- this.addElementAttributes(liElement, formConfig.attributes);
7598
- this.setElementProps(liElement, formConfig.props);
7599
- /* 左边底部的描述的文字 */
7600
- let leftDescriptionText = "";
7601
- if (Boolean(formConfig.description)) {
7602
- leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
7603
- }
7604
- liElement.innerHTML = /*html*/ `
7605
- <div class="pops-panel-item-left-text" style="flex: 1;">
7606
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
7607
- ${leftDescriptionText}
7608
- </div>
7609
- <div class="pops-slider pops-slider-width">
7610
- <div class="pops-slider__runway">
7611
- <div class="pops-slider__bar" style="width: 0%; left: 0%"></div>
7612
- <div class="pops-slider__button-wrapper" style="left: 0%">
7613
- <div class="pops-slider__button"></div>
7614
- </div>
7615
- </div>
7616
- </div>`;
7617
- const PopsPanelSlider = {
7618
- [Symbol.toStringTag]: "PopsPanelSlider",
7619
- /**
7620
- * 值
7621
- */
7622
- value: formConfig.getValue(),
7623
- /**
7624
- * 最小值
7625
- */
7626
- min: formConfig.min,
7627
- /**
7628
- * 最大值
7629
- */
7630
- max: formConfig.max,
7631
- /**
7632
- * 间隔
7633
- */
7634
- step: formConfig.step || 1,
7635
- $data: {
7607
+ liElement.innerHTML = /*html*/ `
7608
+ <div class="pops-panel-item-left-text" style="flex: 1;">
7609
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
7610
+ ${leftDescriptionText}
7611
+ </div>
7612
+ <div class="pops-slider pops-slider-width">
7613
+ <div class="pops-slider__runway">
7614
+ <div class="pops-slider__bar" style="width: 0%; left: 0%"></div>
7615
+ <div class="pops-slider__button-wrapper" style="left: 0%">
7616
+ <div class="pops-slider__button"></div>
7617
+ </div>
7618
+ </div>
7619
+ </div>`;
7620
+ const PopsPanelSlider = {
7621
+ [Symbol.toStringTag]: "PopsPanelSlider",
7636
7622
  /**
7637
- * 是否正在移动
7623
+ *
7638
7624
  */
7639
- isMove: false,
7625
+ value: formConfig.getValue(),
7640
7626
  /**
7641
- * 是否已初始化已拖拽的距离
7627
+ * 最小值
7642
7628
  */
7643
- isInitDragPosition: false,
7629
+ min: formConfig.min,
7644
7630
  /**
7645
- * 是否正在检测是否停止拖拽
7631
+ * 最大值
7646
7632
  */
7647
- isCheckingStopDragMove: false,
7633
+ max: formConfig.max,
7648
7634
  /**
7649
- * 总宽度(px)
7635
+ * 间隔
7650
7636
  */
7651
- totalWidth: 0,
7637
+ step: formConfig.step || 1,
7638
+ $data: {
7639
+ /**
7640
+ * 是否正在移动
7641
+ */
7642
+ isMove: false,
7643
+ /**
7644
+ * 是否已初始化已拖拽的距离
7645
+ */
7646
+ isInitDragPosition: false,
7647
+ /**
7648
+ * 是否正在检测是否停止拖拽
7649
+ */
7650
+ isCheckingStopDragMove: false,
7651
+ /**
7652
+ * 总宽度(px)
7653
+ */
7654
+ totalWidth: 0,
7655
+ /**
7656
+ * 每一块的间隔(px)
7657
+ */
7658
+ stepPx: 0,
7659
+ /**
7660
+ * 已拖拽的距离(px)
7661
+ */
7662
+ dragWidth: 0,
7663
+ /**
7664
+ * 已拖拽的百分比
7665
+ */
7666
+ dragPercent: 0,
7667
+ /**
7668
+ * 每一次块的信息
7669
+ * 例如:当最小值是2,最大值是10,step为2
7670
+ * 那么生成[2,4,6,8,10] 共计5个
7671
+ * 又获取到当前滑块总长度是200px
7672
+ * 那么生成映射
7673
+ * 2 => 0px~40px
7674
+ * 4 => 40px~80px
7675
+ * 6 => 80px~120px
7676
+ * 8 => 120px~160px
7677
+ * 10 => 160px~200px
7678
+ */
7679
+ stepBlockMap: new Map(),
7680
+ },
7681
+ $ele: {
7682
+ slider: liElement.querySelector(".pops-slider"),
7683
+ runAway: liElement.querySelector(".pops-slider__runway"),
7684
+ bar: liElement.querySelector(".pops-slider__bar"),
7685
+ buttonWrapper: liElement.querySelector(".pops-slider__button-wrapper"),
7686
+ button: liElement.querySelector(".pops-slider__button"),
7687
+ tooltip: null,
7688
+ },
7689
+ $interval: {
7690
+ isCheck: false,
7691
+ },
7692
+ $tooltip: null,
7693
+ init() {
7694
+ this.initEleData();
7695
+ this.setToolTipEvent();
7696
+ this.setPanEvent();
7697
+ this.setRunAwayClickEvent();
7698
+ this.intervalInit();
7699
+ if (formConfig.disabled) {
7700
+ this.disableDrag();
7701
+ }
7702
+ },
7652
7703
  /**
7653
- * 每一块的间隔(px)
7704
+ * 10s内循环获取slider的宽度等信息
7705
+ * 获取到了就可以初始化left的值
7706
+ * @param {number} [checkStepTime=200] 每次检测的间隔时间
7707
+ * @param {number} [maxTime=10000] 最大的检测时间
7654
7708
  */
7655
- stepPx: 0,
7709
+ intervalInit(checkStepTime = 200, maxTime = 10000) {
7710
+ if (this.$interval.isCheck) {
7711
+ return;
7712
+ }
7713
+ this.$interval.isCheck = true;
7714
+ let isSuccess = false;
7715
+ let oldTotalWidth = this.$data.totalWidth;
7716
+ let timer = void 0;
7717
+ let interval = setInterval(() => {
7718
+ if (isSuccess) {
7719
+ this.$interval.isCheck = false;
7720
+ clearTimeout(timer);
7721
+ clearInterval(interval);
7722
+ }
7723
+ else {
7724
+ this.initTotalWidth();
7725
+ if (this.$data.totalWidth !== 0) {
7726
+ isSuccess = true;
7727
+ if (this.$data.totalWidth !== oldTotalWidth) {
7728
+ /* slider的总宽度改变了 */
7729
+ if (PopsMathFloatUtils.isFloat(this.step)) {
7730
+ this.initFloatStepMap();
7731
+ }
7732
+ else {
7733
+ this.initStepMap();
7734
+ }
7735
+ this.initSliderPosition();
7736
+ }
7737
+ }
7738
+ }
7739
+ }, checkStepTime);
7740
+ /* 最长检测时间是10s */
7741
+ timer = setTimeout(() => {
7742
+ clearInterval(interval);
7743
+ }, maxTime);
7744
+ },
7656
7745
  /**
7657
- * 已拖拽的距离(px)
7746
+ * 把数据添加到元素上
7658
7747
  */
7659
- dragWidth: 0,
7748
+ initEleData() {
7749
+ this.$ele.slider.setAttribute("data-min", this.min.toString());
7750
+ this.$ele.slider.setAttribute("data-max", this.max.toString());
7751
+ this.$ele.slider.setAttribute("data-value", this.value.toString());
7752
+ this.$ele.slider.setAttribute("data-step", this.step.toString());
7753
+ this.$ele.slider["data-min"] = this.min;
7754
+ this.$ele.slider["data-max"] = this.max;
7755
+ this.$ele.slider["data-value"] = this.value;
7756
+ this.$ele.slider["data-step"] = this.step;
7757
+ },
7660
7758
  /**
7661
- * 已拖拽的百分比
7759
+ * 初始化滑块的总长度的数据(px)
7662
7760
  */
7663
- dragPercent: 0,
7761
+ initTotalWidth() {
7762
+ this.$data.totalWidth = popsDOMUtils.width(this.$ele.runAway);
7763
+ },
7664
7764
  /**
7665
- * 每一次块的信息
7666
- * 例如:当最小值是2,最大值是10,step为2
7667
- * 那么生成[2,4,6,8,10] 共计5个
7668
- * 又获取到当前滑块总长度是200px
7669
- * 那么生成映射
7670
- * 2 => 0px~40px
7671
- * 4 => 40px~80px
7672
- * 6 => 80px~120px
7673
- * 8 => 120px~160px
7674
- * 10 => 160px~200px
7765
+ * 初始化每一个块的具体数据信息
7675
7766
  */
7676
- stepBlockMap: new Map(),
7677
- },
7678
- $ele: {
7679
- slider: liElement.querySelector(".pops-slider"),
7680
- runAway: liElement.querySelector(".pops-slider__runway"),
7681
- bar: liElement.querySelector(".pops-slider__bar"),
7682
- buttonWrapper: liElement.querySelector(".pops-slider__button-wrapper"),
7683
- button: liElement.querySelector(".pops-slider__button"),
7684
- tooltip: null,
7685
- },
7686
- $interval: {
7687
- isCheck: false,
7688
- },
7689
- $tooltip: null,
7690
- init() {
7691
- this.initEleData();
7692
- this.setToolTipEvent();
7693
- this.setPanEvent();
7694
- this.setRunAwayClickEvent();
7695
- this.intervalInit();
7696
- if (formConfig.disabled) {
7697
- this.disableDrag();
7698
- }
7699
- },
7700
- /**
7701
- * 10s内循环获取slider的宽度等信息
7702
- * 获取到了就可以初始化left的值
7703
- * @param {number} [checkStepTime=200] 每次检测的间隔时间
7704
- * @param {number} [maxTime=10000] 最大的检测时间
7705
- */
7706
- intervalInit(checkStepTime = 200, maxTime = 10000) {
7707
- if (this.$interval.isCheck) {
7708
- return;
7709
- }
7710
- this.$interval.isCheck = true;
7711
- let isSuccess = false;
7712
- let oldTotalWidth = this.$data.totalWidth;
7713
- let timer = void 0;
7714
- let interval = setInterval(() => {
7715
- if (isSuccess) {
7716
- this.$interval.isCheck = false;
7717
- clearTimeout(timer);
7718
- clearInterval(interval);
7767
+ initStepMap() {
7768
+ let index = 0;
7769
+ // 计算出份数
7770
+ let blockNums = (this.max - this.min) / this.step;
7771
+ // 计算出每一份占据的px
7772
+ this.$data.stepPx = this.$data.totalWidth / blockNums;
7773
+ let widthPx = 0;
7774
+ for (let stepValue = this.min; stepValue <= this.max; stepValue += this.step) {
7775
+ let value = this.formatValue(stepValue);
7776
+ let info = {};
7777
+ if (value === this.min) {
7778
+ /* 起始 */
7779
+ info = {
7780
+ value: value,
7781
+ px: 0,
7782
+ pxLeft: 0,
7783
+ pxRight: this.$data.stepPx / 2,
7784
+ percent: 0,
7785
+ };
7786
+ }
7787
+ else {
7788
+ info = {
7789
+ value: value,
7790
+ px: widthPx,
7791
+ pxLeft: widthPx - this.$data.stepPx / 2,
7792
+ pxRight: widthPx + this.$data.stepPx / 2,
7793
+ percent: widthPx / this.$data.totalWidth,
7794
+ };
7795
+ //if (value === this.max) {
7796
+ // info["pxLeft"] = this.$data.stepBlockMap.get(
7797
+ // index - 1
7798
+ // ).pxRight;
7799
+ // info["pxRight"] = this.$data.totalWidth;
7800
+ //}
7801
+ }
7802
+ this.$data.stepBlockMap.set(index, info);
7803
+ index++;
7804
+ widthPx += this.$data.stepPx;
7719
7805
  }
7720
- else {
7721
- this.initTotalWidth();
7722
- if (this.$data.totalWidth !== 0) {
7723
- isSuccess = true;
7724
- if (this.$data.totalWidth !== oldTotalWidth) {
7725
- /* slider的总宽度改变了 */
7726
- if (PopsMathFloatUtils.isFloat(this.step)) {
7727
- this.initFloatStepMap();
7728
- }
7729
- else {
7730
- this.initStepMap();
7731
- }
7732
- this.initSliderPosition();
7733
- }
7806
+ },
7807
+ /**
7808
+ * 初始化每一个块的具体数据信息(浮点)
7809
+ */
7810
+ initFloatStepMap() {
7811
+ let index = 0;
7812
+ // 计算出份数
7813
+ let blockNums = (this.max - this.min) / this.step;
7814
+ // 计算出每一份占据的px
7815
+ this.$data.stepPx = this.$data.totalWidth / blockNums;
7816
+ let widthPx = 0;
7817
+ for (let stepValue = this.min; stepValue <= this.max; stepValue = PopsMathFloatUtils.add(stepValue, this.step)) {
7818
+ let value = this.formatValue(stepValue);
7819
+ let info = {};
7820
+ if (value === this.min) {
7821
+ /* 起始 */
7822
+ info = {
7823
+ value: value,
7824
+ px: 0,
7825
+ pxLeft: 0,
7826
+ pxRight: this.$data.stepPx / 2,
7827
+ percent: 0,
7828
+ };
7829
+ }
7830
+ else {
7831
+ info = {
7832
+ value: value,
7833
+ px: widthPx,
7834
+ pxLeft: widthPx - this.$data.stepPx / 2,
7835
+ pxRight: widthPx + this.$data.stepPx / 2,
7836
+ percent: widthPx / this.$data.totalWidth,
7837
+ };
7838
+ //if (value === this.max) {
7839
+ // info["pxLeft"] = this.$data.stepBlockMap.get(
7840
+ // index - 1
7841
+ // ).pxRight;
7842
+ // info["pxRight"] = this.$data.totalWidth;
7843
+ //}
7734
7844
  }
7845
+ this.$data.stepBlockMap.set(index, info);
7846
+ index++;
7847
+ widthPx += this.$data.stepPx;
7735
7848
  }
7736
- }, checkStepTime);
7737
- /* 最长检测时间是10s */
7738
- timer = setTimeout(() => {
7739
- clearInterval(interval);
7740
- }, maxTime);
7741
- },
7742
- /**
7743
- * 把数据添加到元素上
7744
- */
7745
- initEleData() {
7746
- this.$ele.slider.setAttribute("data-min", this.min.toString());
7747
- this.$ele.slider.setAttribute("data-max", this.max.toString());
7748
- this.$ele.slider.setAttribute("data-value", this.value.toString());
7749
- this.$ele.slider.setAttribute("data-step", this.step.toString());
7750
- this.$ele.slider["data-min"] = this.min;
7751
- this.$ele.slider["data-max"] = this.max;
7752
- this.$ele.slider["data-value"] = this.value;
7753
- this.$ele.slider["data-step"] = this.step;
7754
- },
7755
- /**
7756
- * 初始化滑块的总长度的数据(px)
7757
- */
7758
- initTotalWidth() {
7759
- this.$data.totalWidth = popsDOMUtils.width(this.$ele.runAway);
7760
- },
7761
- /**
7762
- * 初始化每一个块的具体数据信息
7763
- */
7764
- initStepMap() {
7765
- let index = 0;
7766
- // 计算出份数
7767
- let blockNums = (this.max - this.min) / this.step;
7768
- // 计算出每一份占据的px
7769
- this.$data.stepPx = this.$data.totalWidth / blockNums;
7770
- let widthPx = 0;
7771
- for (let stepValue = this.min; stepValue <= this.max; stepValue += this.step) {
7772
- let value = this.formatValue(stepValue);
7773
- let info = {};
7774
- if (value === this.min) {
7775
- /* 起始 */
7776
- info = {
7777
- value: value,
7778
- px: 0,
7779
- pxLeft: 0,
7780
- pxRight: this.$data.stepPx / 2,
7781
- percent: 0,
7782
- };
7849
+ },
7850
+ /**
7851
+ * 初始化slider的默认起始left的百分比值
7852
+ */
7853
+ initSliderPosition() {
7854
+ /* 设置起始默认style的left值 */
7855
+ let percent = 0;
7856
+ for (const [, stepBlockInfo] of this.$data.stepBlockMap.entries()) {
7857
+ /* 判断值是否和区域内的值相等 */
7858
+ if (stepBlockInfo.value == this.value) {
7859
+ percent = stepBlockInfo.percent;
7860
+ this.$data.dragWidth = stepBlockInfo.px;
7861
+ break;
7862
+ }
7783
7863
  }
7784
- else {
7785
- info = {
7786
- value: value,
7787
- px: widthPx,
7788
- pxLeft: widthPx - this.$data.stepPx / 2,
7789
- pxRight: widthPx + this.$data.stepPx / 2,
7790
- percent: widthPx / this.$data.totalWidth,
7791
- };
7792
- //if (value === this.max) {
7793
- // info["pxLeft"] = this.$data.stepBlockMap.get(
7794
- // index - 1
7795
- // ).pxRight;
7796
- // info["pxRight"] = this.$data.totalWidth;
7797
- //}
7864
+ percent = this.formatValue(percent * 100);
7865
+ this.setSliderPosition(percent);
7866
+ },
7867
+ /**
7868
+ * 判断数字是否是浮点数
7869
+ * @param num
7870
+ * @returns
7871
+ */
7872
+ isFloat(num) {
7873
+ return Number(num) === num && num % 1 !== 0;
7874
+ },
7875
+ /**
7876
+ * 值改变的回调
7877
+ * @param event
7878
+ * @param value
7879
+ */
7880
+ valueChangeCallBack(event, value) {
7881
+ if (typeof formConfig.callback === "function") {
7882
+ formConfig.callback(event, value);
7798
7883
  }
7799
- this.$data.stepBlockMap.set(index, info);
7800
- index++;
7801
- widthPx += this.$data.stepPx;
7802
- }
7803
- },
7804
- /**
7805
- * 初始化每一个块的具体数据信息(浮点)
7806
- */
7807
- initFloatStepMap() {
7808
- let index = 0;
7809
- // 计算出份数
7810
- let blockNums = (this.max - this.min) / this.step;
7811
- // 计算出每一份占据的px
7812
- this.$data.stepPx = this.$data.totalWidth / blockNums;
7813
- let widthPx = 0;
7814
- for (let stepValue = this.min; stepValue <= this.max; stepValue = PopsMathFloatUtils.add(stepValue, this.step)) {
7815
- let value = this.formatValue(stepValue);
7816
- let info = {};
7817
- if (value === this.min) {
7818
- /* 起始 */
7819
- info = {
7820
- value: value,
7821
- px: 0,
7822
- pxLeft: 0,
7823
- pxRight: this.$data.stepPx / 2,
7824
- percent: 0,
7825
- };
7884
+ },
7885
+ /**
7886
+ * 根据拖拽距离获取滑块应该在的区间和值
7887
+ */
7888
+ getDragInfo(dragX) {
7889
+ let result = this.$data.stepBlockMap.get(0);
7890
+ for (const [, stepBlockInfo] of this.$data.stepBlockMap.entries()) {
7891
+ if (stepBlockInfo.pxLeft <= dragX &&
7892
+ dragX < stepBlockInfo.pxRight) {
7893
+ result = stepBlockInfo;
7894
+ break;
7895
+ }
7826
7896
  }
7827
- else {
7828
- info = {
7829
- value: value,
7830
- px: widthPx,
7831
- pxLeft: widthPx - this.$data.stepPx / 2,
7832
- pxRight: widthPx + this.$data.stepPx / 2,
7833
- percent: widthPx / this.$data.totalWidth,
7834
- };
7835
- //if (value === this.max) {
7836
- // info["pxLeft"] = this.$data.stepBlockMap.get(
7837
- // index - 1
7838
- // ).pxRight;
7839
- // info["pxRight"] = this.$data.totalWidth;
7840
- //}
7897
+ return result;
7898
+ },
7899
+ /**
7900
+ * 获取滑块的当前脱拖拽占据的百分比
7901
+ * @param {number} dragWidth
7902
+ */
7903
+ getSliderPositonPercent(dragWidth) {
7904
+ return dragWidth / this.$data.totalWidth;
7905
+ },
7906
+ /**
7907
+ * 根据step格式化value
7908
+ * @param num
7909
+ */
7910
+ formatValue(num) {
7911
+ if (PopsMathFloatUtils.isFloat(this.step)) {
7912
+ num = parseFloat(num.toFixed(2));
7841
7913
  }
7842
- this.$data.stepBlockMap.set(index, info);
7843
- index++;
7844
- widthPx += this.$data.stepPx;
7845
- }
7846
- },
7847
- /**
7848
- * 初始化slider的默认起始left的百分比值
7849
- */
7850
- initSliderPosition() {
7851
- /* 设置起始默认style的left值 */
7852
- let percent = 0;
7853
- for (const [, stepBlockInfo] of this.$data.stepBlockMap.entries()) {
7854
- /* 判断值是否和区域内的值相等 */
7855
- if (stepBlockInfo.value == this.value) {
7856
- percent = stepBlockInfo.percent;
7857
- this.$data.dragWidth = stepBlockInfo.px;
7858
- break;
7914
+ else {
7915
+ num = parseInt(num.toString());
7859
7916
  }
7860
- }
7861
- percent = this.formatValue(percent * 100);
7862
- this.setSliderPosition(percent);
7863
- },
7864
- /**
7865
- * 判断数字是否是浮点数
7866
- * @param num
7867
- * @returns
7868
- */
7869
- isFloat(num) {
7870
- return Number(num) === num && num % 1 !== 0;
7871
- },
7872
- /**
7873
- * 值改变的回调
7874
- * @param event
7875
- * @param value
7876
- */
7877
- valueChangeCallBack(event, value) {
7878
- if (typeof formConfig.callback === "function") {
7879
- formConfig.callback(event, value);
7880
- }
7881
- },
7882
- /**
7883
- * 根据拖拽距离获取滑块应该在的区间和值
7884
- */
7885
- getDragInfo(dragX) {
7886
- let result = this.$data.stepBlockMap.get(0);
7887
- for (const [, stepBlockInfo] of this.$data.stepBlockMap.entries()) {
7888
- if (stepBlockInfo.pxLeft <= dragX && dragX < stepBlockInfo.pxRight) {
7889
- result = stepBlockInfo;
7890
- break;
7917
+ return num;
7918
+ },
7919
+ /**
7920
+ * 设置滑块的位置偏移(left)
7921
+ * @param percent 百分比
7922
+ */
7923
+ setSliderPosition(percent) {
7924
+ if (parseInt(percent.toString()) === 1) {
7925
+ percent = 1;
7891
7926
  }
7892
- }
7893
- return result;
7894
- },
7895
- /**
7896
- * 获取滑块的当前脱拖拽占据的百分比
7897
- * @param {number} dragWidth
7898
- */
7899
- getSliderPositonPercent(dragWidth) {
7900
- return dragWidth / this.$data.totalWidth;
7901
- },
7902
- /**
7903
- * 根据step格式化value
7904
- * @param num
7905
- */
7906
- formatValue(num) {
7907
- if (PopsMathFloatUtils.isFloat(this.step)) {
7908
- num = parseFloat(num.toFixed(2));
7909
- }
7910
- else {
7911
- num = parseInt(num.toString());
7912
- }
7913
- return num;
7914
- },
7915
- /**
7916
- * 设置滑块的位置偏移(left)
7917
- * @param percent 百分比
7918
- */
7919
- setSliderPosition(percent) {
7920
- if (parseInt(percent.toString()) === 1) {
7921
- percent = 1;
7922
- }
7923
- if (percent > 1) {
7924
- percent = percent / 100;
7925
- }
7926
- /* 滑块按钮的偏移 */
7927
- this.$ele.buttonWrapper.style.left = `${percent * 100}%`;
7928
- /* 滑块进度的宽度 */
7929
- this.$ele.bar.style.width = `${percent * 100}%`;
7930
- },
7931
- /**
7932
- * 禁止拖拽
7933
- */
7934
- disableDrag() {
7935
- this.$ele.runAway.classList.add("pops-slider-is-disabled");
7936
- },
7937
- /**
7938
- * 允许拖拽
7939
- */
7940
- allowDrag() {
7941
- this.$ele.runAway.classList.remove("pops-slider-is-disabled");
7942
- },
7943
- /**
7944
- * 判断当前滑块是否被禁用
7945
- */
7946
- isDisabledDrag() {
7947
- return this.$ele.runAway.classList.contains("pops-slider-is-disabled");
7948
- },
7949
- /**
7950
- * 设置进度条点击定位的事件
7951
- */
7952
- setRunAwayClickEvent() {
7953
- popsDOMUtils.on(this.$ele.runAway, "click", void 0, (event) => {
7954
- if (event.target !== this.$ele.runAway &&
7955
- event.target !== this.$ele.bar) {
7956
- return;
7927
+ if (percent > 1) {
7928
+ percent = percent / 100;
7957
7929
  }
7958
- let clickX = parseFloat(event.offsetX);
7959
- this.dragStartCallBack();
7960
- this.dragMoveCallBack(event, clickX, this.value);
7961
- this.dragEndCallBack(clickX);
7962
- }, {
7963
- capture: false,
7964
- });
7965
- },
7966
- /**
7967
- * 拖拽开始的回调,如果返回false,禁止拖拽
7968
- */
7969
- dragStartCallBack() {
7970
- if (!this.$data.isMove) {
7971
- if (this.isDisabledDrag()) {
7972
- return false;
7930
+ /* 滑块按钮的偏移 */
7931
+ this.$ele.buttonWrapper.style.left = `${percent * 100}%`;
7932
+ /* 滑块进度的宽度 */
7933
+ this.$ele.bar.style.width = `${percent * 100}%`;
7934
+ },
7935
+ /**
7936
+ * 禁止拖拽
7937
+ */
7938
+ disableDrag() {
7939
+ this.$ele.runAway.classList.add("pops-slider-is-disabled");
7940
+ },
7941
+ /**
7942
+ * 允许拖拽
7943
+ */
7944
+ allowDrag() {
7945
+ this.$ele.runAway.classList.remove("pops-slider-is-disabled");
7946
+ },
7947
+ /**
7948
+ * 判断当前滑块是否被禁用
7949
+ */
7950
+ isDisabledDrag() {
7951
+ return this.$ele.runAway.classList.contains("pops-slider-is-disabled");
7952
+ },
7953
+ /**
7954
+ * 设置进度条点击定位的事件
7955
+ */
7956
+ setRunAwayClickEvent() {
7957
+ popsDOMUtils.on(this.$ele.runAway, "click", void 0, (event) => {
7958
+ if (event.target !== this.$ele.runAway &&
7959
+ event.target !== this.$ele.bar) {
7960
+ return;
7961
+ }
7962
+ let clickX = parseFloat(event.offsetX);
7963
+ this.dragStartCallBack();
7964
+ this.dragMoveCallBack(event, clickX, this.value);
7965
+ this.dragEndCallBack(clickX);
7966
+ }, {
7967
+ capture: false,
7968
+ });
7969
+ },
7970
+ /**
7971
+ * 拖拽开始的回调,如果返回false,禁止拖拽
7972
+ */
7973
+ dragStartCallBack() {
7974
+ if (!this.$data.isMove) {
7975
+ if (this.isDisabledDrag()) {
7976
+ return false;
7977
+ }
7978
+ this.$data.isMove = true;
7973
7979
  }
7974
- this.$data.isMove = true;
7975
- }
7976
- return true;
7977
- },
7978
- /**
7979
- * 拖拽中的回调
7980
- * @param event 事件
7981
- * @param dragX 当前拖拽的距离
7982
- * @param oldValue 旧的值
7983
- */
7984
- dragMoveCallBack(event, dragX, oldValue) {
7985
- let dragPercent = 0;
7986
- if (dragX <= 0) {
7987
- dragPercent = 0;
7988
- this.value = this.min;
7989
- }
7990
- else if (dragX >= this.$data.totalWidth) {
7991
- dragPercent = 1;
7992
- this.value = this.max;
7993
- }
7994
- else {
7995
- const dragInfo = this.getDragInfo(dragX);
7996
- dragPercent = dragInfo.percent;
7997
- this.value = this.formatValue(dragInfo.value);
7998
- }
7999
- this.$data.dragPercent = dragPercent;
8000
- this.setSliderPosition(this.$data.dragPercent);
8001
- this.showToolTip();
8002
- if (oldValue !== this.value) {
8003
- this.valueChangeCallBack(event, this.value);
8004
- }
8005
- },
8006
- /**
8007
- * 拖拽结束的回调
8008
- */
8009
- dragEndCallBack(dragX) {
8010
- this.$data.isMove = false;
8011
- if (dragX <= 0) {
8012
- this.$data.dragWidth = 0;
8013
- }
8014
- else if (dragX >= this.$data.totalWidth) {
8015
- this.$data.dragWidth = this.$data.totalWidth;
8016
- }
8017
- else {
8018
- this.$data.dragWidth = dragX;
8019
- }
8020
- this.closeToolTip();
8021
- },
8022
- /**
8023
- * 设置点击拖拽事件
8024
- */
8025
- setPanEvent() {
8026
- const AnyTouch = popsUtils.AnyTouch();
8027
- this.$tooltip = new AnyTouch(this.$ele.button, {
8028
- preventEvent() {
8029
- return false;
8030
- },
8031
- });
7980
+ return true;
7981
+ },
8032
7982
  /**
8033
- * 当前的拖拽的距离px
7983
+ * 拖拽中的回调
7984
+ * @param event 事件
7985
+ * @param dragX 当前拖拽的距离
7986
+ * @param oldValue 旧的值
8034
7987
  */
8035
- let currentDragX = 0;
8036
- /* 监听拖拽 */
8037
- this.$tooltip.on("at:move", (event) => {
8038
- if (!this.dragStartCallBack()) {
8039
- return;
7988
+ dragMoveCallBack(event, dragX, oldValue) {
7989
+ let dragPercent = 0;
7990
+ if (dragX <= 0) {
7991
+ dragPercent = 0;
7992
+ this.value = this.min;
8040
7993
  }
8041
- let oldValue = this.value;
8042
- const runAwayRect = this.$ele.runAway.getBoundingClientRect();
8043
- let displacementX = event.x - (runAwayRect.left + globalThis.screenX);
8044
- if (displacementX <= 0) {
8045
- displacementX = 0;
7994
+ else if (dragX >= this.$data.totalWidth) {
7995
+ dragPercent = 1;
7996
+ this.value = this.max;
8046
7997
  }
8047
- else if (displacementX >= runAwayRect.width) {
8048
- displacementX = runAwayRect.width;
7998
+ else {
7999
+ const dragInfo = this.getDragInfo(dragX);
8000
+ dragPercent = dragInfo.percent;
8001
+ this.value = this.formatValue(dragInfo.value);
8049
8002
  }
8050
- currentDragX = displacementX;
8051
- /* 拖拽移动 */
8052
- this.dragMoveCallBack(event, currentDragX, oldValue);
8053
- });
8054
- /* 监听触点离开,处理某些情况下,拖拽松开,但是未触发pan事件,可以通过设置这个来关闭tooltip */
8055
- this.$tooltip.on("at:end", (event) => {
8056
- this.dragEndCallBack(currentDragX);
8057
- });
8058
- },
8059
- /**
8060
- * 显示悬浮的
8061
- */
8062
- showToolTip() {
8063
- this.$ele.tooltip.show();
8064
- },
8065
- /**
8066
- * 关闭悬浮的
8067
- */
8068
- closeToolTip() {
8069
- this.$ele.tooltip.close();
8070
- },
8071
- /**
8072
- * 检测在1000ms内,是否停止了拖拽
8073
- */
8074
- checkStopDragMove() {
8075
- if (this.$data.isCheckingStopDragMove) {
8076
- return;
8077
- }
8078
- this.$data.isCheckingStopDragMove = true;
8079
- let interval = setInterval(() => {
8080
- if (!this.$data.isMove) {
8081
- this.$data.isCheckingStopDragMove = false;
8082
- this.closeToolTip();
8083
- clearInterval(interval);
8003
+ this.$data.dragPercent = dragPercent;
8004
+ this.setSliderPosition(this.$data.dragPercent);
8005
+ this.showToolTip();
8006
+ if (oldValue !== this.value) {
8007
+ this.valueChangeCallBack(event, this.value);
8084
8008
  }
8085
- }, 200);
8086
- setTimeout(() => {
8087
- this.$data.isCheckingStopDragMove = false;
8088
- clearInterval(interval);
8089
- }, 2000);
8090
- },
8091
- /**
8092
- * 设置拖拽按钮的悬浮事件
8093
- */
8094
- setToolTipEvent() {
8009
+ },
8095
8010
  /**
8096
- * 获取提示的内容
8011
+ * 拖拽结束的回调
8097
8012
  */
8098
- function getToolTipContent() {
8099
- if (typeof formConfig.getToolTipContent === "function") {
8100
- return formConfig.getToolTipContent(PopsPanelSlider.value);
8013
+ dragEndCallBack(dragX) {
8014
+ this.$data.isMove = false;
8015
+ if (dragX <= 0) {
8016
+ this.$data.dragWidth = 0;
8017
+ }
8018
+ else if (dragX >= this.$data.totalWidth) {
8019
+ this.$data.dragWidth = this.$data.totalWidth;
8101
8020
  }
8102
8021
  else {
8103
- return PopsPanelSlider.value;
8022
+ this.$data.dragWidth = dragX;
8104
8023
  }
8105
- }
8106
- let tooltipContent = null;
8107
- this.$ele.tooltip = pops.tooltip({
8108
- target: this.$ele.button,
8109
- content: getToolTipContent,
8110
- zIndex: 1000000,
8111
- className: "github-tooltip",
8112
- only: false,
8113
- eventOption: {
8114
- capture: true,
8115
- passive: true,
8116
- },
8117
- showBeforeCallBack: () => {
8118
- this.intervalInit();
8119
- },
8120
- showAfterCallBack: (toolTipNode) => {
8121
- tooltipContent.innerText = getToolTipContent();
8122
- },
8123
- closeBeforeCallBack: () => {
8124
- if (this.$data.isMove) {
8125
- this.checkStopDragMove();
8024
+ this.closeToolTip();
8025
+ },
8026
+ /**
8027
+ * 设置点击拖拽事件
8028
+ */
8029
+ setPanEvent() {
8030
+ const AnyTouch = popsUtils.AnyTouch();
8031
+ this.$tooltip = new AnyTouch(this.$ele.button, {
8032
+ preventEvent() {
8126
8033
  return false;
8034
+ },
8035
+ });
8036
+ /**
8037
+ * 当前的拖拽的距离px
8038
+ */
8039
+ let currentDragX = 0;
8040
+ /* 监听拖拽 */
8041
+ this.$tooltip.on("at:move", (event) => {
8042
+ if (!this.dragStartCallBack()) {
8043
+ return;
8127
8044
  }
8128
- },
8129
- alwaysShow: false,
8130
- // only: false,
8131
- position: "top",
8132
- arrowDistance: 10,
8133
- });
8134
- tooltipContent =
8135
- this.$ele.tooltip.toolTipNode.querySelector("div");
8136
- },
8137
- };
8138
- PopsPanelSlider.init();
8139
- liElement["data-slider"] = PopsPanelSlider;
8140
- return liElement;
8141
- },
8142
- /**
8143
- * 获取中间容器的元素<li>
8144
- * type ==> input
8145
- * @param formConfig
8146
- */
8147
- getSectionContainerItem_input(formConfig) {
8148
- let liElement = document.createElement("li");
8149
- liElement["__formConfig__"] = formConfig;
8150
- if (formConfig.className) {
8151
- liElement.className = formConfig.className;
8152
- }
8153
- this.addElementAttributes(liElement, formConfig.attributes);
8154
- this.setElementProps(liElement, formConfig.props);
8155
- let inputType = "text";
8156
- if (formConfig.isPassword) {
8157
- inputType = "password";
8158
- }
8159
- else if (formConfig.isNumber) {
8160
- inputType = "number";
8161
- }
8162
- /* 左边底部的描述的文字 */
8163
- let leftDescriptionText = "";
8164
- if (Boolean(formConfig.description)) {
8165
- leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
8166
- }
8167
- liElement.innerHTML = `
8168
- <div class="pops-panel-item-left-text">
8169
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
8170
- ${leftDescriptionText}
8171
- </div>
8172
- <div class="pops-panel-input">
8173
- <input type="${inputType}" placeholder="${formConfig.placeholder}">
8174
- </div>
8175
- `;
8176
- const PopsPanelInput = {
8177
- [Symbol.toStringTag]: "PopsPanelInput",
8178
- $ele: {
8179
- panelInput: liElement.querySelector(".pops-panel-input"),
8180
- input: liElement.querySelector("input"),
8181
- inputSpanIcon: document.createElement("span"),
8182
- inputSpanIconInner: null,
8183
- icon: null,
8184
- },
8185
- $data: {
8186
- value: formConfig.getValue(),
8187
- isView: false,
8188
- },
8189
- init() {
8190
- this.initEle();
8191
- this.setInputValue(this.$data.value);
8192
- /* 如果是密码框,放进图标 */
8193
- if (formConfig.isPassword) {
8194
- this.setCircleIcon(pops.config.iconSVG.view);
8195
- this.setCircleIconClickEvent();
8196
- }
8197
- else {
8198
- /* 先判断预设值是否为空,不为空添加清空图标按钮 */
8199
- if (this.$ele.input.value != "") {
8200
- this.setCircleIcon(pops.config.iconSVG.circleClose);
8201
- this.setCircleIconClickEvent();
8202
- }
8203
- }
8204
- this.setInputChangeEvent();
8205
- if (formConfig.disabled) {
8206
- this.disable();
8207
- }
8208
- if (typeof formConfig.handlerCallBack === "function") {
8209
- formConfig.handlerCallBack(liElement, this.$ele.input);
8210
- }
8211
- },
8212
- /**
8213
- * 初始化$ele的配置
8214
- */
8215
- initEle() {
8216
- this.$ele.input.parentElement.insertBefore(this.$ele.inputSpanIcon, this.$ele.input.nextSibling);
8217
- this.$ele.inputSpanIcon.className = "pops-panel-input__suffix";
8218
- this.$ele.inputSpanIcon.innerHTML = `
8219
- <span class="pops-panel-input__suffix-inner">
8220
- <i class="pops-panel-icon"></i>
8221
- </span>
8222
- `;
8223
- this.$ele.inputSpanIconInner =
8224
- this.$ele.inputSpanIcon.querySelector(".pops-panel-input__suffix-inner");
8225
- this.$ele.icon =
8226
- this.$ele.inputSpanIcon.querySelector(".pops-panel-icon");
8227
- },
8228
- /**
8229
- * 禁用
8230
- */
8231
- disable() {
8232
- this.$ele.input.disabled = true;
8233
- this.$ele.panelInput.classList.add("pops-input-disabled");
8234
- },
8235
- /**
8236
- * 取消禁用
8237
- */
8238
- notDisable() {
8239
- this.$ele.input.disabled = false;
8240
- this.$ele.panelInput.classList.remove("pops-input-disabled");
8241
- },
8242
- /**
8243
- * 判断是否已被禁用
8244
- */
8245
- isDisabled() {
8246
- return this.$ele.input.disabled;
8247
- },
8248
- /**
8249
- * 设置输入框内容
8250
- * @param {string} [value=""] 值
8251
- */
8252
- setInputValue(value = "") {
8253
- this.$ele.input.value = value;
8254
- },
8255
- /**
8256
- * 设置input元素的type
8257
- * @param {string} [typeValue="text"] type值
8258
- */
8259
- setInputType(typeValue = "text") {
8260
- this.$ele.input.setAttribute("type", typeValue);
8261
- },
8262
- /**
8263
- * 删除图标按钮
8264
- */
8265
- removeCircleIcon() {
8266
- this.$ele.icon.innerHTML = "";
8267
- },
8268
- /**
8269
- * 添加清空图标按钮
8270
- * @param {string} [svgHTML=pops.config.iconSVG.circleClose] svg图标,默认为清空的图标
8271
- */
8272
- setCircleIcon(svgHTML = pops.config.iconSVG.circleClose) {
8273
- this.$ele.icon.innerHTML = svgHTML;
8274
- },
8275
- /**
8276
- * 添加图标按钮的点击事件
8277
- */
8278
- setCircleIconClickEvent() {
8279
- popsDOMUtils.on(this.$ele.icon, "click", void 0, () => {
8280
- if (this.isDisabled()) {
8281
- return;
8282
- }
8283
- /* 删除图标 */
8284
- this.removeCircleIcon();
8285
- if (formConfig.isPassword) {
8286
- /* 密码输入框 */
8287
- if (this.$data.isView) {
8288
- /* 当前可见 => 点击改变为隐藏 */
8289
- this.$data.isView = false;
8290
- /* 显示输入框内容,且更换图标为隐藏图标 */
8291
- this.setInputType("text");
8292
- this.setCircleIcon(pops.config.iconSVG.hide);
8045
+ let oldValue = this.value;
8046
+ const runAwayRect = this.$ele.runAway.getBoundingClientRect();
8047
+ let displacementX = event.x - (runAwayRect.left + globalThis.screenX);
8048
+ if (displacementX <= 0) {
8049
+ displacementX = 0;
8293
8050
  }
8294
- else {
8295
- /* 当前不可见 => 点击改变为显示 */
8296
- this.$data.isView = true;
8297
- /* 隐藏输入框内容,且更换图标为显示图标 */
8298
- this.setInputType("password");
8299
- this.setCircleIcon(pops.config.iconSVG.view);
8051
+ else if (displacementX >= runAwayRect.width) {
8052
+ displacementX = runAwayRect.width;
8300
8053
  }
8054
+ currentDragX = displacementX;
8055
+ /* 拖拽移动 */
8056
+ this.dragMoveCallBack(event, currentDragX, oldValue);
8057
+ });
8058
+ /* 监听触点离开,处理某些情况下,拖拽松开,但是未触发pan事件,可以通过设置这个来关闭tooltip */
8059
+ this.$tooltip.on("at:end", (event) => {
8060
+ this.dragEndCallBack(currentDragX);
8061
+ });
8062
+ },
8063
+ /**
8064
+ * 显示悬浮的
8065
+ */
8066
+ showToolTip() {
8067
+ this.$ele.tooltip.show();
8068
+ },
8069
+ /**
8070
+ * 关闭悬浮的
8071
+ */
8072
+ closeToolTip() {
8073
+ this.$ele.tooltip.close();
8074
+ },
8075
+ /**
8076
+ * 检测在1000ms内,是否停止了拖拽
8077
+ */
8078
+ checkStopDragMove() {
8079
+ if (this.$data.isCheckingStopDragMove) {
8080
+ return;
8301
8081
  }
8302
- else {
8303
- /* 普通输入框 */
8304
- /* 清空内容 */
8305
- this.setInputValue("");
8306
- /* 获取焦点 */
8307
- this.$ele.input.focus();
8308
- /* 触发内容改变事件 */
8309
- this.$ele.input.dispatchEvent(new Event("input"));
8310
- }
8311
- });
8312
- },
8313
- /**
8314
- * 监听输入框内容改变
8315
- */
8316
- setInputChangeEvent() {
8317
- popsDOMUtils.on(this.$ele.input, ["input", "propertychange"], void 0, (event) => {
8318
- this.$data.value = this.$ele.input.value;
8319
- if (!formConfig.isPassword) {
8320
- /* 不是密码框 */
8321
- if (this.$ele.input.value !== "" &&
8322
- this.$ele.icon.innerHTML === "") {
8323
- /* 不为空,显示清空图标 */
8324
- this.setCircleIcon(pops.config.iconSVG.circleClose);
8325
- this.setCircleIconClickEvent();
8082
+ this.$data.isCheckingStopDragMove = true;
8083
+ let interval = setInterval(() => {
8084
+ if (!this.$data.isMove) {
8085
+ this.$data.isCheckingStopDragMove = false;
8086
+ this.closeToolTip();
8087
+ clearInterval(interval);
8326
8088
  }
8327
- else if (this.$ele.input.value === "") {
8328
- this.removeCircleIcon();
8329
- }
8330
- }
8331
- if (typeof formConfig.callback === "function") {
8332
- if (formConfig.isNumber) {
8333
- formConfig.callback(event, this.$ele.input.value, this.$ele.input.valueAsNumber);
8089
+ }, 200);
8090
+ setTimeout(() => {
8091
+ this.$data.isCheckingStopDragMove = false;
8092
+ clearInterval(interval);
8093
+ }, 2000);
8094
+ },
8095
+ /**
8096
+ * 设置拖拽按钮的悬浮事件
8097
+ */
8098
+ setToolTipEvent() {
8099
+ /**
8100
+ * 获取提示的内容
8101
+ */
8102
+ function getToolTipContent() {
8103
+ if (typeof formConfig.getToolTipContent === "function") {
8104
+ return formConfig.getToolTipContent(PopsPanelSlider.value);
8334
8105
  }
8335
8106
  else {
8336
- formConfig.callback(event, this.$ele.input.value);
8107
+ return PopsPanelSlider.value;
8337
8108
  }
8338
8109
  }
8339
- });
8340
- },
8341
- };
8342
- PopsPanelInput.init();
8343
- liElement["data-input"] = PopsPanelInput;
8344
- return liElement;
8345
- },
8346
- /**
8347
- * 获取中间容器的元素<li>
8348
- * type ==> textarea
8349
- * @param formConfig
8350
- */
8351
- getSectionContainerItem_textarea(formConfig) {
8352
- let liElement = document.createElement("li");
8353
- liElement["__formConfig__"] = formConfig;
8354
- if (formConfig.className) {
8355
- liElement.className = formConfig.className;
8356
- }
8357
- this.addElementAttributes(liElement, formConfig.attributes);
8358
- this.setElementProps(liElement, formConfig.props);
8359
- /* 左边底部的描述的文字 */
8360
- let leftDescriptionText = "";
8361
- if (Boolean(formConfig.description)) {
8362
- leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
8363
- }
8364
- liElement.innerHTML = `
8365
- <div class="pops-panel-item-left-text">
8366
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
8367
- ${leftDescriptionText}
8368
- </div>
8369
- <div class="pops-panel-textarea">
8370
- <textarea placeholder="${formConfig.placeholder ?? ""}">
8371
- </textarea>
8372
- </div>
8373
- `;
8374
- const PopsPanelTextArea = {
8375
- [Symbol.toStringTag]: "PopsPanelTextArea",
8376
- $ele: {
8377
- panelTextarea: liElement.querySelector(".pops-panel-textarea"),
8378
- textarea: liElement.querySelector(".pops-panel-textarea textarea"),
8379
- },
8380
- $data: {
8381
- value: formConfig.getValue(),
8382
- },
8383
- init() {
8384
- this.setValue(this.$data.value);
8385
- this.setChangeEvent();
8386
- if (formConfig.disabled) {
8387
- this.disable();
8388
- }
8389
- },
8390
- disable() {
8391
- this.$ele.textarea.setAttribute("disabled", "true");
8392
- this.$ele.panelTextarea.classList.add("pops-panel-textarea-disable");
8393
- },
8394
- notDisable() {
8395
- this.$ele.textarea.removeAttribute("disabled");
8396
- this.$ele.panelTextarea.classList.remove("pops-panel-textarea-disable");
8397
- },
8398
- isDisabled() {
8399
- return (this.$ele.textarea.hasAttribute("disabled") ||
8400
- this.$ele.panelTextarea.classList.contains("pops-panel-textarea-disable"));
8401
- },
8402
- setValue(value) {
8403
- this.$ele.textarea.value = value;
8404
- },
8405
- /**
8406
- * 监听选择内容改变
8407
- */
8408
- setChangeEvent() {
8409
- popsDOMUtils.on(this.$ele.textarea, ["input", "propertychange"], void 0, (event) => {
8410
- this.$data.value = event.target.value;
8411
- if (typeof formConfig.callback === "function") {
8412
- formConfig.callback(event, event.target.value);
8110
+ let tooltipContent = null;
8111
+ this.$ele.tooltip = pops.tooltip({
8112
+ target: this.$ele.button,
8113
+ content: getToolTipContent,
8114
+ zIndex: 1000000,
8115
+ className: "github-tooltip",
8116
+ only: false,
8117
+ eventOption: {
8118
+ capture: true,
8119
+ passive: true,
8120
+ },
8121
+ showBeforeCallBack: () => {
8122
+ this.intervalInit();
8123
+ },
8124
+ showAfterCallBack: (toolTipNode) => {
8125
+ tooltipContent.innerText = getToolTipContent();
8126
+ },
8127
+ closeBeforeCallBack: () => {
8128
+ if (this.$data.isMove) {
8129
+ this.checkStopDragMove();
8130
+ return false;
8131
+ }
8132
+ },
8133
+ alwaysShow: false,
8134
+ // only: false,
8135
+ position: "top",
8136
+ arrowDistance: 10,
8137
+ });
8138
+ tooltipContent =
8139
+ this.$ele.tooltip.toolTipNode.querySelector("div");
8140
+ },
8141
+ };
8142
+ PopsPanelSlider.init();
8143
+ liElement["data-slider"] = PopsPanelSlider;
8144
+ return liElement;
8145
+ },
8146
+ /**
8147
+ * 获取中间容器的元素<li>
8148
+ * type ==> input
8149
+ * @param formConfig
8150
+ */
8151
+ getSectionContainerItem_input(formConfig) {
8152
+ let liElement = document.createElement("li");
8153
+ liElement["__formConfig__"] = formConfig;
8154
+ if (formConfig.className) {
8155
+ liElement.className = formConfig.className;
8156
+ }
8157
+ this.addElementAttributes(liElement, formConfig.attributes);
8158
+ this.setElementProps(liElement, formConfig.props);
8159
+ let inputType = "text";
8160
+ if (formConfig.isPassword) {
8161
+ inputType = "password";
8162
+ }
8163
+ else if (formConfig.isNumber) {
8164
+ inputType = "number";
8165
+ }
8166
+ /* 左边底部的描述的文字 */
8167
+ let leftDescriptionText = "";
8168
+ if (Boolean(formConfig.description)) {
8169
+ leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
8170
+ }
8171
+ liElement.innerHTML = `
8172
+ <div class="pops-panel-item-left-text">
8173
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
8174
+ ${leftDescriptionText}
8175
+ </div>
8176
+ <div class="pops-panel-input">
8177
+ <input type="${inputType}" placeholder="${formConfig.placeholder}">
8178
+ </div>
8179
+ `;
8180
+ const PopsPanelInput = {
8181
+ [Symbol.toStringTag]: "PopsPanelInput",
8182
+ $ele: {
8183
+ panelInput: liElement.querySelector(".pops-panel-input"),
8184
+ input: liElement.querySelector("input"),
8185
+ inputSpanIcon: document.createElement("span"),
8186
+ inputSpanIconInner: null,
8187
+ icon: null,
8188
+ },
8189
+ $data: {
8190
+ value: formConfig.getValue(),
8191
+ isView: false,
8192
+ },
8193
+ init() {
8194
+ this.initEle();
8195
+ this.setInputValue(this.$data.value);
8196
+ /* 如果是密码框,放进图标 */
8197
+ if (formConfig.isPassword) {
8198
+ this.setCircleIcon(pops.config.iconSVG.view);
8199
+ this.setCircleIconClickEvent();
8413
8200
  }
8414
- });
8415
- },
8416
- };
8417
- PopsPanelTextArea.init();
8418
- liElement["data-textarea"] = PopsPanelTextArea;
8419
- return liElement;
8420
- },
8421
- /**
8422
- * 获取中间容器的元素<li>
8423
- * type ==> select
8424
- * @param formConfig
8425
- */
8426
- getSectionContainerItem_select(formConfig) {
8427
- let liElement = document.createElement("li");
8428
- liElement["__formConfig__"] = formConfig;
8429
- if (formConfig.className) {
8430
- liElement.className = formConfig.className;
8431
- }
8432
- this.addElementAttributes(liElement, formConfig.attributes);
8433
- this.setElementProps(liElement, formConfig.props);
8434
- /* 左边底部的描述的文字 */
8435
- let leftDescriptionText = "";
8436
- if (Boolean(formConfig.description)) {
8437
- leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
8438
- }
8439
- liElement.innerHTML = /*html*/ `
8440
- <div class="pops-panel-item-left-text">
8441
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
8442
- ${leftDescriptionText}
8443
- </div>
8444
- <div class="pops-panel-select">
8445
- <select></select>
8446
- </div>
8447
- `;
8448
- const PopsPanelSelect = {
8449
- [Symbol.toStringTag]: "PopsPanelSelect",
8450
- $ele: {
8451
- panelSelect: liElement.querySelector(".pops-panel-select"),
8452
- select: liElement.querySelector(".pops-panel-select select"),
8453
- },
8454
- $eleKey: {
8455
- disable: "__disable__",
8456
- value: "__value__",
8457
- },
8458
- $data: {
8459
- defaultValue: formConfig.getValue(),
8460
- },
8461
- init() {
8462
- this.initOption();
8463
- this.setChangeEvent();
8464
- this.setClickEvent();
8465
- if (formConfig.disabled) {
8466
- this.disable();
8467
- }
8468
- },
8469
- /**
8470
- * 给option元素设置属性
8471
- * @param $ele
8472
- * @param key
8473
- * @param value
8474
- */
8475
- setNodeValue($ele, key, value) {
8476
- Reflect.set($ele, key, value);
8477
- },
8478
- /**
8479
- * 获取option元素上设置的属性
8480
- * @param $ele
8481
- * @param value
8482
- * @param key
8483
- */
8484
- getNodeValue($ele, key) {
8485
- return Reflect.get($ele, key);
8486
- },
8487
- disable() {
8488
- this.$ele.select.setAttribute("disabled", "true");
8489
- this.$ele.panelSelect.classList.add("pops-panel-select-disable");
8490
- },
8491
- notDisable() {
8492
- this.$ele.select.removeAttribute("disabled");
8493
- this.$ele.panelSelect.classList.remove("pops-panel-select-disable");
8494
- },
8495
- isDisabled() {
8496
- return (this.$ele.select.hasAttribute("disabled") ||
8497
- this.$ele.panelSelect.classList.contains("pops-panel-select-disable"));
8498
- },
8499
- initOption() {
8500
- formConfig.data.forEach((dataItem) => {
8501
- // 初始化默认选中
8502
- let optionElement = document.createElement("option");
8503
- this.setNodeValue(optionElement, this.$eleKey.value, dataItem.value);
8504
- this.setNodeValue(optionElement, this.$eleKey.disable, dataItem.disable);
8505
- if (dataItem.value === this.$data.defaultValue) {
8506
- optionElement.setAttribute("selected", "true");
8201
+ else {
8202
+ /* 先判断预设值是否为空,不为空添加清空图标按钮 */
8203
+ if (this.$ele.input.value != "") {
8204
+ this.setCircleIcon(pops.config.iconSVG.circleClose);
8205
+ this.setCircleIconClickEvent();
8206
+ }
8507
8207
  }
8508
- optionElement.innerText = dataItem.text;
8509
- this.$ele.select.appendChild(optionElement);
8510
- });
8511
- },
8512
- /** 检测所有option并设置禁用状态 */
8513
- setSelectOptionsDisableStatus() {
8514
- if (this.$ele.select.options && this.$ele.select.options.length) {
8515
- Array.from(this.$ele.select.options).forEach((optionItem) => {
8516
- this.setOptionDisableStatus(optionItem);
8517
- });
8518
- }
8519
- },
8520
- /** 设置禁用状态 */
8521
- setOptionDisableStatus(optionElement) {
8522
- let disable = false;
8523
- let optionDisableAttr = this.getNodeValue(optionElement, this.$eleKey.disable);
8524
- if (optionDisableAttr === "function") {
8525
- let value = this.getNodeValue(optionElement, this.$eleKey.value);
8526
- disable = Boolean(optionDisableAttr(value));
8527
- }
8528
- if (disable) {
8529
- optionElement.setAttribute("disabled", "true");
8530
- }
8531
- else {
8532
- optionElement.removeAttribute("disabled");
8533
- }
8534
- },
8535
- /** 获取option上的信息 */
8536
- getSelectOptionInfo($option) {
8537
- let optionValue = this.getNodeValue($option, this.$eleKey.value);
8538
- let optionText = $option.innerText || $option.textContent;
8539
- return {
8540
- value: optionValue,
8541
- text: optionText,
8542
- $option: $option,
8543
- };
8544
- },
8545
- /**
8546
- * 监听选择内容改变
8547
- */
8548
- setChangeEvent() {
8549
- popsDOMUtils.on(this.$ele.select, "change", void 0, (event) => {
8550
- this.setSelectOptionsDisableStatus();
8551
- if (typeof formConfig.callback === "function") {
8552
- let $isSelectedElement = event.target[event.target.selectedIndex];
8553
- let selectInfo = this.getSelectOptionInfo($isSelectedElement);
8554
- formConfig.callback(event, selectInfo.value, selectInfo.text);
8208
+ this.setInputChangeEvent();
8209
+ if (formConfig.disabled) {
8210
+ this.disable();
8555
8211
  }
8556
- });
8557
- },
8558
- /**
8559
- * 监听点击事件
8560
- */
8561
- setClickEvent() {
8562
- popsDOMUtils.on(this.$ele.select, "click", void 0, (event) => {
8563
- this.setSelectOptionsDisableStatus();
8564
- if (typeof formConfig.clickCallBack === "function") {
8565
- formConfig.clickCallBack(event, this.$ele.select);
8212
+ if (typeof formConfig.handlerCallBack === "function") {
8213
+ formConfig.handlerCallBack(liElement, this.$ele.input);
8566
8214
  }
8567
- });
8568
- },
8569
- };
8570
- PopsPanelSelect.init();
8571
- Reflect.set(liElement, "data-select", PopsPanelSelect);
8572
- return liElement;
8573
- },
8574
- /**
8575
- * 获取中间容器的元素<li>
8576
- * type ==> select-multiple
8577
- * @param formConfig
8578
- */
8579
- getSectionContainerItem_select_multiple_new(formConfig) {
8580
- let liElement = document.createElement("li");
8581
- Reflect.set(liElement, "__formConfig__", formConfig);
8582
- if (formConfig.className) {
8583
- liElement.className = formConfig.className;
8584
- }
8585
- this.addElementAttributes(liElement, formConfig.attributes);
8586
- this.setElementProps(liElement, formConfig.props);
8587
- /* 左边底部的描述的文字 */
8588
- let leftDescriptionText = "";
8589
- if (Boolean(formConfig.description)) {
8590
- leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
8591
- }
8592
- liElement.innerHTML = /*html*/ `
8593
- <div class="pops-panel-item-left-text">
8594
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
8595
- ${leftDescriptionText}
8596
- </div>
8597
- <div class="pops-panel-select-multiple">
8598
- <div class="el-select__wrapper">
8599
- <div class="el-select__selection">
8600
- <!-- 这个是用于手动输入的,这里暂不适配 -->
8601
- <div class="el-select__selected-item el-select__input-wrapper">
8602
-
8603
- </div>
8604
- <!-- 这个是placeholder -->
8605
- <div class="el-select__selected-item el-select__placeholder">
8606
- </div>
8607
- </div>
8608
- <!-- 下拉箭头 -->
8609
- <div class="el-select__suffix">
8610
- <i class="el-icon el-select__caret el-select__icon">
8611
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
8612
- <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>
8613
- </svg>
8614
- </i>
8615
- </div>
8616
- </div>
8617
- </div>
8618
- `;
8619
- const PopsPanelSelectMultiple = {
8620
- [Symbol.toStringTag]: "PopsPanelSelectMultiple",
8621
- $el: {
8622
- /** 容器 */
8623
- $container: void 0,
8624
- /** 包括的容器 */
8625
- $wrapper: void 0,
8626
- /** 内容区域 */
8627
- $section: void 0,
8628
- /** 手动输入 */
8629
- $selectedInputWrapper: void 0,
8630
- /** 灰色提示语 */
8631
- $selectedPlaceHolderWrapper: void 0,
8632
- /** 下拉箭头区域 */
8633
- $suffix: void 0,
8634
- /** 下拉箭头图标 */
8635
- $suffixIcon: void 0,
8636
- },
8637
- $data: {
8638
- /** 默认值 */
8639
- defaultValue: formConfig.getValue(),
8640
- selectInfo: [],
8641
- },
8642
- /** 初始化 */
8643
- init() {
8644
- this.initDefault();
8645
- this.inintEl();
8646
- this.initPlaceHolder();
8647
- this.updateTagElement();
8648
- this.setSelectContainerClickEvent();
8649
- },
8650
- /** 初始化默认值 */
8651
- initDefault() {
8652
- formConfig.data.forEach((dataItem) => {
8653
- if (this.$data.defaultValue.includes(dataItem.value)) {
8654
- // 初始化选中的配置
8655
- this.$data.selectInfo.push({
8656
- text: dataItem.text,
8657
- value: dataItem.value,
8658
- isHTML: Boolean(dataItem.isHTML),
8659
- disable: dataItem.disable,
8660
- });
8215
+ },
8216
+ /**
8217
+ * 初始化$ele的配置
8218
+ */
8219
+ initEle() {
8220
+ this.$ele.input.parentElement.insertBefore(this.$ele.inputSpanIcon, this.$ele.input.nextSibling);
8221
+ this.$ele.inputSpanIcon.className = "pops-panel-input__suffix";
8222
+ this.$ele.inputSpanIcon.innerHTML = `
8223
+ <span class="pops-panel-input__suffix-inner">
8224
+ <i class="pops-panel-icon"></i>
8225
+ </span>
8226
+ `;
8227
+ this.$ele.inputSpanIconInner =
8228
+ this.$ele.inputSpanIcon.querySelector(".pops-panel-input__suffix-inner");
8229
+ this.$ele.icon =
8230
+ this.$ele.inputSpanIcon.querySelector(".pops-panel-icon");
8231
+ },
8232
+ /**
8233
+ * 禁用
8234
+ */
8235
+ disable() {
8236
+ this.$ele.input.disabled = true;
8237
+ this.$ele.panelInput.classList.add("pops-input-disabled");
8238
+ },
8239
+ /**
8240
+ * 取消禁用
8241
+ */
8242
+ notDisable() {
8243
+ this.$ele.input.disabled = false;
8244
+ this.$ele.panelInput.classList.remove("pops-input-disabled");
8245
+ },
8246
+ /**
8247
+ * 判断是否已被禁用
8248
+ */
8249
+ isDisabled() {
8250
+ return this.$ele.input.disabled;
8251
+ },
8252
+ /**
8253
+ * 设置输入框内容
8254
+ * @param {string} [value=""] 值
8255
+ */
8256
+ setInputValue(value = "") {
8257
+ this.$ele.input.value = value;
8258
+ },
8259
+ /**
8260
+ * 设置input元素的type
8261
+ * @param {string} [typeValue="text"] type值
8262
+ */
8263
+ setInputType(typeValue = "text") {
8264
+ this.$ele.input.setAttribute("type", typeValue);
8265
+ },
8266
+ /**
8267
+ * 删除图标按钮
8268
+ */
8269
+ removeCircleIcon() {
8270
+ this.$ele.icon.innerHTML = "";
8271
+ },
8272
+ /**
8273
+ * 添加清空图标按钮
8274
+ * @param {string} [svgHTML=pops.config.iconSVG.circleClose] svg图标,默认为清空的图标
8275
+ */
8276
+ setCircleIcon(svgHTML = pops.config.iconSVG.circleClose) {
8277
+ this.$ele.icon.innerHTML = svgHTML;
8278
+ },
8279
+ /**
8280
+ * 添加图标按钮的点击事件
8281
+ */
8282
+ setCircleIconClickEvent() {
8283
+ popsDOMUtils.on(this.$ele.icon, "click", void 0, () => {
8284
+ if (this.isDisabled()) {
8285
+ return;
8286
+ }
8287
+ /* 删除图标 */
8288
+ this.removeCircleIcon();
8289
+ if (formConfig.isPassword) {
8290
+ /* 密码输入框 */
8291
+ if (this.$data.isView) {
8292
+ /* 当前可见 => 点击改变为隐藏 */
8293
+ this.$data.isView = false;
8294
+ /* 显示输入框内容,且更换图标为隐藏图标 */
8295
+ this.setInputType("text");
8296
+ this.setCircleIcon(pops.config.iconSVG.hide);
8297
+ }
8298
+ else {
8299
+ /* 当前不可见 => 点击改变为显示 */
8300
+ this.$data.isView = true;
8301
+ /* 隐藏输入框内容,且更换图标为显示图标 */
8302
+ this.setInputType("password");
8303
+ this.setCircleIcon(pops.config.iconSVG.view);
8304
+ }
8305
+ }
8306
+ else {
8307
+ /* 普通输入框 */
8308
+ /* 清空内容 */
8309
+ this.setInputValue("");
8310
+ /* 获取焦点 */
8311
+ this.$ele.input.focus();
8312
+ /* 触发内容改变事件 */
8313
+ this.$ele.input.dispatchEvent(new Event("input"));
8314
+ }
8315
+ });
8316
+ },
8317
+ /**
8318
+ * 监听输入框内容改变
8319
+ */
8320
+ setInputChangeEvent() {
8321
+ popsDOMUtils.on(this.$ele.input, ["input", "propertychange"], void 0, (event) => {
8322
+ this.$data.value = this.$ele.input.value;
8323
+ if (!formConfig.isPassword) {
8324
+ /* 不是密码框 */
8325
+ if (this.$ele.input.value !== "" &&
8326
+ this.$ele.icon.innerHTML === "") {
8327
+ /* 不为空,显示清空图标 */
8328
+ this.setCircleIcon(pops.config.iconSVG.circleClose);
8329
+ this.setCircleIconClickEvent();
8330
+ }
8331
+ else if (this.$ele.input.value === "") {
8332
+ this.removeCircleIcon();
8333
+ }
8334
+ }
8335
+ if (typeof formConfig.callback === "function") {
8336
+ if (formConfig.isNumber) {
8337
+ formConfig.callback(event, this.$ele.input.value, this.$ele.input.valueAsNumber);
8338
+ }
8339
+ else {
8340
+ formConfig.callback(event, this.$ele.input.value);
8341
+ }
8342
+ }
8343
+ });
8344
+ },
8345
+ };
8346
+ PopsPanelInput.init();
8347
+ liElement["data-input"] = PopsPanelInput;
8348
+ return liElement;
8349
+ },
8350
+ /**
8351
+ * 获取中间容器的元素<li>
8352
+ * type ==> textarea
8353
+ * @param formConfig
8354
+ */
8355
+ getSectionContainerItem_textarea(formConfig) {
8356
+ let liElement = document.createElement("li");
8357
+ liElement["__formConfig__"] = formConfig;
8358
+ if (formConfig.className) {
8359
+ liElement.className = formConfig.className;
8360
+ }
8361
+ this.addElementAttributes(liElement, formConfig.attributes);
8362
+ this.setElementProps(liElement, formConfig.props);
8363
+ /* 左边底部的描述的文字 */
8364
+ let leftDescriptionText = "";
8365
+ if (Boolean(formConfig.description)) {
8366
+ leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
8367
+ }
8368
+ liElement.innerHTML = `
8369
+ <div class="pops-panel-item-left-text">
8370
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
8371
+ ${leftDescriptionText}
8372
+ </div>
8373
+ <div class="pops-panel-textarea">
8374
+ <textarea placeholder="${formConfig.placeholder ?? ""}">
8375
+ </textarea>
8376
+ </div>
8377
+ `;
8378
+ const PopsPanelTextArea = {
8379
+ [Symbol.toStringTag]: "PopsPanelTextArea",
8380
+ $ele: {
8381
+ panelTextarea: liElement.querySelector(".pops-panel-textarea"),
8382
+ textarea: liElement.querySelector(".pops-panel-textarea textarea"),
8383
+ },
8384
+ $data: {
8385
+ value: formConfig.getValue(),
8386
+ },
8387
+ init() {
8388
+ this.setValue(this.$data.value);
8389
+ this.setChangeEvent();
8390
+ if (formConfig.disabled) {
8391
+ this.disable();
8661
8392
  }
8662
- });
8663
- },
8664
- /** 初始化$el变量 */
8665
- inintEl() {
8666
- this.$el.$container = liElement.querySelector(".pops-panel-select-multiple");
8667
- this.$el.$wrapper = liElement.querySelector(".el-select__wrapper");
8668
- this.$el.$section = liElement.querySelector(".el-select__selection");
8669
- this.$el.$selectedInputWrapper = liElement.querySelector(".el-select__selected-item.el-select__input-wrapper");
8670
- this.$el.$selectedPlaceHolderWrapper =
8671
- liElement.querySelector(".el-select__selected-item.el-select__placeholder");
8672
- this.$el.$suffix =
8673
- liElement.querySelector(".el-select__suffix");
8674
- this.$el.$suffixIcon = liElement.querySelector(".el-select__suffix .el-icon");
8675
- // 先把手动输入框隐藏
8676
- this.hideInputWrapper();
8677
- },
8678
- /** 初始化提示文字 */
8679
- initPlaceHolder() {
8680
- let placeholder = "";
8681
- if (typeof formConfig.placeholder === "string") {
8682
- placeholder = formConfig.placeholder;
8683
- }
8684
- else if (typeof formConfig.placeholder === "function") {
8685
- let placeholderResult = formConfig.placeholder();
8686
- if (typeof placeholderResult === "string") {
8687
- placeholder = placeholderResult;
8393
+ },
8394
+ disable() {
8395
+ this.$ele.textarea.setAttribute("disabled", "true");
8396
+ this.$ele.panelTextarea.classList.add("pops-panel-textarea-disable");
8397
+ },
8398
+ notDisable() {
8399
+ this.$ele.textarea.removeAttribute("disabled");
8400
+ this.$ele.panelTextarea.classList.remove("pops-panel-textarea-disable");
8401
+ },
8402
+ isDisabled() {
8403
+ return (this.$ele.textarea.hasAttribute("disabled") ||
8404
+ this.$ele.panelTextarea.classList.contains("pops-panel-textarea-disable"));
8405
+ },
8406
+ setValue(value) {
8407
+ this.$ele.textarea.value = value;
8408
+ },
8409
+ /**
8410
+ * 监听选择内容改变
8411
+ */
8412
+ setChangeEvent() {
8413
+ popsDOMUtils.on(this.$ele.textarea, ["input", "propertychange"], void 0, (event) => {
8414
+ this.$data.value = event.target.value;
8415
+ if (typeof formConfig.callback === "function") {
8416
+ formConfig.callback(event, event.target.value);
8417
+ }
8418
+ });
8419
+ },
8420
+ };
8421
+ PopsPanelTextArea.init();
8422
+ liElement["data-textarea"] = PopsPanelTextArea;
8423
+ return liElement;
8424
+ },
8425
+ /**
8426
+ * 获取中间容器的元素<li>
8427
+ * type ==> select
8428
+ * @param formConfig
8429
+ */
8430
+ getSectionContainerItem_select(formConfig) {
8431
+ let liElement = document.createElement("li");
8432
+ liElement["__formConfig__"] = formConfig;
8433
+ if (formConfig.className) {
8434
+ liElement.className = formConfig.className;
8435
+ }
8436
+ this.addElementAttributes(liElement, formConfig.attributes);
8437
+ this.setElementProps(liElement, formConfig.props);
8438
+ /* 左边底部的描述的文字 */
8439
+ let leftDescriptionText = "";
8440
+ if (Boolean(formConfig.description)) {
8441
+ leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
8442
+ }
8443
+ liElement.innerHTML = /*html*/ `
8444
+ <div class="pops-panel-item-left-text">
8445
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
8446
+ ${leftDescriptionText}
8447
+ </div>
8448
+ <div class="pops-panel-select">
8449
+ <select></select>
8450
+ </div>
8451
+ `;
8452
+ const PopsPanelSelect = {
8453
+ [Symbol.toStringTag]: "PopsPanelSelect",
8454
+ $ele: {
8455
+ panelSelect: liElement.querySelector(".pops-panel-select"),
8456
+ select: liElement.querySelector(".pops-panel-select select"),
8457
+ },
8458
+ $eleKey: {
8459
+ disable: "__disable__",
8460
+ value: "__value__",
8461
+ },
8462
+ $data: {
8463
+ defaultValue: formConfig.getValue(),
8464
+ },
8465
+ init() {
8466
+ this.initOption();
8467
+ this.setChangeEvent();
8468
+ this.setClickEvent();
8469
+ if (formConfig.disabled) {
8470
+ this.disable();
8688
8471
  }
8689
- }
8690
- let $placeholder = popsDOMUtils.createElement("span", {
8691
- innerText: placeholder,
8692
- });
8693
- this.$el.$selectedPlaceHolderWrapper.appendChild($placeholder);
8694
- },
8695
- /** 初始化tag */
8696
- updateTagElement() {
8697
- // 遍历数据,寻找对应的值
8698
- formConfig.data.forEach((dataItem) => {
8699
- let findValue = this.$data.selectInfo.find((item) => item.value === dataItem.value);
8700
- if (findValue) {
8701
- // 选中的值和获取的所有的值相同
8702
- let selectedInfo = this.createSelectedItem({
8703
- text: dataItem.text,
8704
- isHTML: dataItem.isHTML,
8705
- });
8706
- this.addSelectedItem(selectedInfo.$tag);
8707
- this.setSelectedItemCloseIconClickEvent({
8708
- $tag: selectedInfo.$tag,
8709
- $closeIcon: selectedInfo.$closeIcon,
8710
- value: dataItem.value,
8711
- text: dataItem.text,
8472
+ },
8473
+ /**
8474
+ * 给option元素设置属性
8475
+ * @param $ele
8476
+ * @param key
8477
+ * @param value
8478
+ */
8479
+ setNodeValue($ele, key, value) {
8480
+ Reflect.set($ele, key, value);
8481
+ },
8482
+ /**
8483
+ * 获取option元素上设置的属性
8484
+ * @param $ele
8485
+ * @param value
8486
+ * @param key
8487
+ */
8488
+ getNodeValue($ele, key) {
8489
+ return Reflect.get($ele, key);
8490
+ },
8491
+ disable() {
8492
+ this.$ele.select.setAttribute("disabled", "true");
8493
+ this.$ele.panelSelect.classList.add("pops-panel-select-disable");
8494
+ },
8495
+ notDisable() {
8496
+ this.$ele.select.removeAttribute("disabled");
8497
+ this.$ele.panelSelect.classList.remove("pops-panel-select-disable");
8498
+ },
8499
+ isDisabled() {
8500
+ return (this.$ele.select.hasAttribute("disabled") ||
8501
+ this.$ele.panelSelect.classList.contains("pops-panel-select-disable"));
8502
+ },
8503
+ initOption() {
8504
+ formConfig.data.forEach((dataItem) => {
8505
+ // 初始化默认选中
8506
+ let optionElement = document.createElement("option");
8507
+ this.setNodeValue(optionElement, this.$eleKey.value, dataItem.value);
8508
+ this.setNodeValue(optionElement, this.$eleKey.disable, dataItem.disable);
8509
+ if (dataItem.value === this.$data.defaultValue) {
8510
+ optionElement.setAttribute("selected", "true");
8511
+ }
8512
+ optionElement.innerText = dataItem.text;
8513
+ this.$ele.select.appendChild(optionElement);
8514
+ });
8515
+ },
8516
+ /** 检测所有option并设置禁用状态 */
8517
+ setSelectOptionsDisableStatus() {
8518
+ if (this.$ele.select.options && this.$ele.select.options.length) {
8519
+ Array.from(this.$ele.select.options).forEach((optionItem) => {
8520
+ this.setOptionDisableStatus(optionItem);
8712
8521
  });
8713
8522
  }
8714
- });
8715
- this.checkTagEmpty();
8716
- },
8717
- /**
8718
- * 生成一个tag项
8719
- * @param data 配置
8720
- */
8721
- createSelectedItem(data) {
8722
- const $selectedItem = popsDOMUtils.createElement("div", {
8723
- className: "el-select__selected-item el-select__choose_tag",
8724
- innerHTML: /*html*/ `
8725
- <span class="el-tag is-closable el-tag--info el-tag--default el-tag--light">
8726
- <span class="el-tag__content">
8727
- <span class="el-select__tags-text"></span>
8728
- </span>
8729
- <!-- 关闭tag的图标 -->
8730
- <i class="el-icon el-tag__close">
8731
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
8732
- <path fill="currentColor" d="M764.288 214.592 512 466.88 259.712 214.592a31.936 31.936 0 0 0-45.12 45.12L466.752 512 214.528 764.224a31.936 31.936 0 1 0 45.12 45.184L512 557.184l252.288 252.288a31.936 31.936 0 0 0 45.12-45.12L557.12 512.064l252.288-252.352a31.936 31.936 0 1 0-45.12-45.184z"></path>
8733
- </svg>
8734
- </i>
8735
- </span>
8736
- `,
8737
- });
8738
- /** 标签 */
8739
- const $tagText = $selectedItem.querySelector(".el-select__tags-text");
8740
- /** 关闭图标 */
8741
- const $closeIcon = $selectedItem.querySelector(".el-icon.el-tag__close");
8742
- if (data.isHTML) {
8743
- $tagText.innerHTML = data.text;
8744
- }
8745
- else {
8746
- $tagText.innerText = data.text;
8747
- }
8748
- return {
8749
- $tag: $selectedItem,
8750
- $tagText: $tagText,
8751
- $closeIcon: $closeIcon,
8752
- };
8753
- },
8754
- /**
8755
- * 添加选中项元素
8756
- */
8757
- addSelectedItem($ele) {
8758
- // 往前添加
8759
- // 去除前面的空白
8760
- this.setSectionIsNear();
8761
- if (this.$el.$section.contains(this.$el.$selectedInputWrapper)) {
8762
- let $prev = this.$el.$selectedInputWrapper.previousElementSibling;
8763
- if ($prev) {
8764
- // 存在前一个元素,添加到前面的元素的后面
8765
- popsDOMUtils.after($prev, $ele);
8766
- }
8767
- else {
8768
- // 不存在前一个元素,添加到最前面
8769
- popsDOMUtils.before(this.$el.$selectedInputWrapper, $ele);
8523
+ },
8524
+ /** 设置禁用状态 */
8525
+ setOptionDisableStatus(optionElement) {
8526
+ let disable = false;
8527
+ let optionDisableAttr = this.getNodeValue(optionElement, this.$eleKey.disable);
8528
+ if (optionDisableAttr === "function") {
8529
+ let value = this.getNodeValue(optionElement, this.$eleKey.value);
8530
+ disable = Boolean(optionDisableAttr(value));
8770
8531
  }
8771
- }
8772
- else if (this.$el.$section.contains(this.$el.$selectedPlaceHolderWrapper)) {
8773
- let $prev = this.$el.$selectedPlaceHolderWrapper.previousElementSibling;
8774
- if ($prev) {
8775
- // 存在前一个元素,添加到前面的元素的后面
8776
- popsDOMUtils.after($prev, $ele);
8532
+ if (disable) {
8533
+ optionElement.setAttribute("disabled", "true");
8777
8534
  }
8778
8535
  else {
8779
- // 不存在前一个元素,添加到最前面
8780
- popsDOMUtils.before(this.$el.$selectedPlaceHolderWrapper, $ele);
8536
+ optionElement.removeAttribute("disabled");
8781
8537
  }
8782
- }
8783
- else {
8784
- this.$el.$section.appendChild($ele);
8785
- }
8786
- // 隐藏元素
8787
- this.hideInputWrapper();
8788
- this.hidePlaceHolderWrapper();
8789
- },
8790
- /** 更新tag信息 */
8791
- updateSelectTagItem() {
8792
- this.$el.$section
8793
- .querySelectorAll(".el-select__choose_tag")
8794
- .forEach(($ele) => {
8795
- $ele.remove();
8796
- });
8797
- this.updateTagElement();
8798
- },
8799
- /**
8800
- * 选中的值改变的回调
8801
- * @param currentSelectInfo 当前的选中信息
8802
- */
8803
- selectValueChangeCallBack(currentSelectInfo) {
8804
- if (typeof formConfig.callback === "function") {
8805
- formConfig.callback(currentSelectInfo || this.$data.selectInfo);
8806
- }
8807
- },
8808
- /** 设置下拉列表的点击事件 */
8809
- setSelectContainerClickEvent() {
8810
- const that = this;
8811
- popsDOMUtils.on(this.$el.$container, "click", (event) => {
8812
- /** 弹窗的选中的值 */
8813
- let selectedInfo = [];
8814
- selectedInfo = selectedInfo.concat(that.$data.selectInfo);
8815
- /**
8816
- * 设置项选中
8817
- * @param $ele
8818
- */
8819
- function setItemSelected($ele) {
8820
- $ele.classList.add("select-item-is-selected");
8538
+ },
8539
+ /** 获取option上的信息 */
8540
+ getSelectOptionInfo($option) {
8541
+ let optionValue = this.getNodeValue($option, this.$eleKey.value);
8542
+ let optionText = $option.innerText || $option.textContent;
8543
+ return {
8544
+ value: optionValue,
8545
+ text: optionText,
8546
+ $option: $option,
8547
+ };
8548
+ },
8549
+ /**
8550
+ * 监听选择内容改变
8551
+ */
8552
+ setChangeEvent() {
8553
+ popsDOMUtils.on(this.$ele.select, "change", void 0, (event) => {
8554
+ this.setSelectOptionsDisableStatus();
8555
+ if (typeof formConfig.callback === "function") {
8556
+ let $isSelectedElement = event.target[event.target.selectedIndex];
8557
+ let selectInfo = this.getSelectOptionInfo($isSelectedElement);
8558
+ formConfig.callback(event, selectInfo.value, selectInfo.text);
8559
+ }
8560
+ });
8561
+ },
8562
+ /**
8563
+ * 监听点击事件
8564
+ */
8565
+ setClickEvent() {
8566
+ popsDOMUtils.on(this.$ele.select, "click", void 0, (event) => {
8567
+ this.setSelectOptionsDisableStatus();
8568
+ if (typeof formConfig.clickCallBack === "function") {
8569
+ formConfig.clickCallBack(event, this.$ele.select);
8570
+ }
8571
+ });
8572
+ },
8573
+ };
8574
+ PopsPanelSelect.init();
8575
+ Reflect.set(liElement, "data-select", PopsPanelSelect);
8576
+ return liElement;
8577
+ },
8578
+ /**
8579
+ * 获取中间容器的元素<li>
8580
+ * type ==> select-multiple
8581
+ * @param formConfig
8582
+ */
8583
+ getSectionContainerItem_select_multiple_new(formConfig) {
8584
+ let liElement = document.createElement("li");
8585
+ Reflect.set(liElement, "__formConfig__", formConfig);
8586
+ if (formConfig.className) {
8587
+ liElement.className = formConfig.className;
8588
+ }
8589
+ this.addElementAttributes(liElement, formConfig.attributes);
8590
+ this.setElementProps(liElement, formConfig.props);
8591
+ /* 左边底部的描述的文字 */
8592
+ let leftDescriptionText = "";
8593
+ if (Boolean(formConfig.description)) {
8594
+ leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
8595
+ }
8596
+ liElement.innerHTML = /*html*/ `
8597
+ <div class="pops-panel-item-left-text">
8598
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
8599
+ ${leftDescriptionText}
8600
+ </div>
8601
+ <div class="pops-panel-select-multiple">
8602
+ <div class="el-select__wrapper">
8603
+ <div class="el-select__selection">
8604
+ <!-- 这个是用于手动输入的,这里暂不适配 -->
8605
+ <div class="el-select__selected-item el-select__input-wrapper">
8606
+
8607
+ </div>
8608
+ <!-- 这个是placeholder -->
8609
+ <div class="el-select__selected-item el-select__placeholder">
8610
+ </div>
8611
+ </div>
8612
+ <!-- 下拉箭头 -->
8613
+ <div class="el-select__suffix">
8614
+ <i class="el-icon el-select__caret el-select__icon">
8615
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
8616
+ <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>
8617
+ </svg>
8618
+ </i>
8619
+ </div>
8620
+ </div>
8621
+ </div>
8622
+ `;
8623
+ const PopsPanelSelectMultiple = {
8624
+ [Symbol.toStringTag]: "PopsPanelSelectMultiple",
8625
+ $el: {
8626
+ /** 容器 */
8627
+ $container: void 0,
8628
+ /** 包括的容器 */
8629
+ $wrapper: void 0,
8630
+ /** 内容区域 */
8631
+ $section: void 0,
8632
+ /** 手动输入 */
8633
+ $selectedInputWrapper: void 0,
8634
+ /** 灰色提示语 */
8635
+ $selectedPlaceHolderWrapper: void 0,
8636
+ /** 下拉箭头区域 */
8637
+ $suffix: void 0,
8638
+ /** 下拉箭头图标 */
8639
+ $suffixIcon: void 0,
8640
+ },
8641
+ $data: {
8642
+ /** 默认值 */
8643
+ defaultValue: formConfig.getValue(),
8644
+ selectInfo: [],
8645
+ },
8646
+ /** 初始化 */
8647
+ init() {
8648
+ this.initDefault();
8649
+ this.inintEl();
8650
+ this.initPlaceHolder();
8651
+ this.updateTagElement();
8652
+ this.setSelectContainerClickEvent();
8653
+ },
8654
+ /** 初始化默认值 */
8655
+ initDefault() {
8656
+ formConfig.data.forEach((dataItem) => {
8657
+ if (this.$data.defaultValue.includes(dataItem.value)) {
8658
+ // 初始化选中的配置
8659
+ this.$data.selectInfo.push({
8660
+ text: dataItem.text,
8661
+ value: dataItem.value,
8662
+ isHTML: Boolean(dataItem.isHTML),
8663
+ disable: dataItem.disable,
8664
+ });
8665
+ }
8666
+ });
8667
+ },
8668
+ /** 初始化$el变量 */
8669
+ inintEl() {
8670
+ this.$el.$container = liElement.querySelector(".pops-panel-select-multiple");
8671
+ this.$el.$wrapper = liElement.querySelector(".el-select__wrapper");
8672
+ this.$el.$section = liElement.querySelector(".el-select__selection");
8673
+ this.$el.$selectedInputWrapper = liElement.querySelector(".el-select__selected-item.el-select__input-wrapper");
8674
+ this.$el.$selectedPlaceHolderWrapper =
8675
+ liElement.querySelector(".el-select__selected-item.el-select__placeholder");
8676
+ this.$el.$suffix =
8677
+ liElement.querySelector(".el-select__suffix");
8678
+ this.$el.$suffixIcon = liElement.querySelector(".el-select__suffix .el-icon");
8679
+ // 先把手动输入框隐藏
8680
+ this.hideInputWrapper();
8681
+ },
8682
+ /** 初始化提示文字 */
8683
+ initPlaceHolder() {
8684
+ let placeholder = "";
8685
+ if (typeof formConfig.placeholder === "string") {
8686
+ placeholder = formConfig.placeholder;
8821
8687
  }
8822
- /**
8823
- * 设置项取消选中
8824
- * @param $ele
8825
- */
8826
- function removeItemSelected($ele) {
8827
- $ele.classList.remove("select-item-is-selected");
8688
+ else if (typeof formConfig.placeholder === "function") {
8689
+ let placeholderResult = formConfig.placeholder();
8690
+ if (typeof placeholderResult === "string") {
8691
+ placeholder = placeholderResult;
8692
+ }
8828
8693
  }
8829
- /**
8830
- * 添加选中信息
8831
- */
8832
- function addSelectedInfo($ele) {
8833
- let info = getSelectedInfo($ele);
8834
- let findValue = selectedInfo.find((item) => item.value === info.value);
8835
- if (!findValue) {
8836
- selectedInfo.push({
8837
- value: info.value,
8838
- text: info.text,
8839
- isHTML: Boolean(info.isHTML),
8840
- disable: info.disable,
8694
+ let $placeholder = popsDOMUtils.createElement("span", {
8695
+ innerText: placeholder,
8696
+ });
8697
+ this.$el.$selectedPlaceHolderWrapper.appendChild($placeholder);
8698
+ },
8699
+ /** 初始化tag */
8700
+ updateTagElement() {
8701
+ // 遍历数据,寻找对应的值
8702
+ formConfig.data.forEach((dataItem) => {
8703
+ let findValue = this.$data.selectInfo.find((item) => item.value === dataItem.value);
8704
+ if (findValue) {
8705
+ // 选中的值和获取的所有的值相同
8706
+ let selectedInfo = this.createSelectedItem({
8707
+ text: dataItem.text,
8708
+ isHTML: dataItem.isHTML,
8709
+ });
8710
+ this.addSelectedItem(selectedInfo.$tag);
8711
+ this.setSelectedItemCloseIconClickEvent({
8712
+ $tag: selectedInfo.$tag,
8713
+ $closeIcon: selectedInfo.$closeIcon,
8714
+ value: dataItem.value,
8715
+ text: dataItem.text,
8841
8716
  });
8842
8717
  }
8843
- that.selectValueChangeCallBack(selectedInfo);
8718
+ });
8719
+ this.checkTagEmpty();
8720
+ },
8721
+ /**
8722
+ * 生成一个tag项
8723
+ * @param data 配置
8724
+ */
8725
+ createSelectedItem(data) {
8726
+ const $selectedItem = popsDOMUtils.createElement("div", {
8727
+ className: "el-select__selected-item el-select__choose_tag",
8728
+ innerHTML: /*html*/ `
8729
+ <span class="el-tag is-closable el-tag--info el-tag--default el-tag--light">
8730
+ <span class="el-tag__content">
8731
+ <span class="el-select__tags-text"></span>
8732
+ </span>
8733
+ <!-- 关闭tag的图标 -->
8734
+ <i class="el-icon el-tag__close">
8735
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
8736
+ <path fill="currentColor" d="M764.288 214.592 512 466.88 259.712 214.592a31.936 31.936 0 0 0-45.12 45.12L466.752 512 214.528 764.224a31.936 31.936 0 1 0 45.12 45.184L512 557.184l252.288 252.288a31.936 31.936 0 0 0 45.12-45.12L557.12 512.064l252.288-252.352a31.936 31.936 0 1 0-45.12-45.184z"></path>
8737
+ </svg>
8738
+ </i>
8739
+ </span>
8740
+ `,
8741
+ });
8742
+ /** 标签 */
8743
+ const $tagText = $selectedItem.querySelector(".el-select__tags-text");
8744
+ /** 关闭图标 */
8745
+ const $closeIcon = $selectedItem.querySelector(".el-icon.el-tag__close");
8746
+ if (data.isHTML) {
8747
+ $tagText.innerHTML = data.text;
8844
8748
  }
8845
- /**
8846
- * 移除选中信息
8847
- */
8848
- function removeSelectedInfo($ele) {
8849
- let info = getSelectedInfo($ele);
8850
- let findIndex = selectedInfo.findIndex((item) => item.value === info.value);
8851
- if (findIndex !== -1) {
8852
- selectedInfo.splice(findIndex, 1);
8853
- }
8854
- that.selectValueChangeCallBack(selectedInfo);
8749
+ else {
8750
+ $tagText.innerText = data.text;
8855
8751
  }
8856
- /**
8857
- * 判断该项是否选中
8858
- * @param $ele
8859
- */
8860
- function isSelected($ele) {
8861
- return $ele.classList.contains("select-item-is-selected");
8752
+ return {
8753
+ $tag: $selectedItem,
8754
+ $tagText: $tagText,
8755
+ $closeIcon: $closeIcon,
8756
+ };
8757
+ },
8758
+ /**
8759
+ * 添加选中项元素
8760
+ */
8761
+ addSelectedItem($ele) {
8762
+ // 往前添加
8763
+ // 去除前面的空白
8764
+ this.setSectionIsNear();
8765
+ if (this.$el.$section.contains(this.$el.$selectedInputWrapper)) {
8766
+ let $prev = this.$el.$selectedInputWrapper.previousElementSibling;
8767
+ if ($prev) {
8768
+ // 存在前一个元素,添加到前面的元素的后面
8769
+ popsDOMUtils.after($prev, $ele);
8770
+ }
8771
+ else {
8772
+ // 不存在前一个元素,添加到最前面
8773
+ popsDOMUtils.before(this.$el.$selectedInputWrapper, $ele);
8774
+ }
8862
8775
  }
8863
- /**
8864
- * 获取选中的项的信息
8865
- */
8866
- function getSelectedInfo($ele) {
8867
- return Reflect.get($ele, "data-info");
8776
+ else if (this.$el.$section.contains(this.$el.$selectedPlaceHolderWrapper)) {
8777
+ let $prev = this.$el.$selectedPlaceHolderWrapper.previousElementSibling;
8778
+ if ($prev) {
8779
+ // 存在前一个元素,添加到前面的元素的后面
8780
+ popsDOMUtils.after($prev, $ele);
8781
+ }
8782
+ else {
8783
+ // 不存在前一个元素,添加到最前面
8784
+ popsDOMUtils.before(this.$el.$selectedPlaceHolderWrapper, $ele);
8785
+ }
8868
8786
  }
8869
- /**
8870
- * 获取所有选中的项的信息
8871
- */
8872
- function getAllSelectedInfo() {
8873
- return Array.from($selectContainer.querySelectorAll(".select-item"))
8874
- .map(($ele) => {
8875
- if (isSelected($ele)) {
8876
- return getSelectedInfo($ele);
8877
- }
8878
- })
8879
- .filter((item) => {
8880
- return item != null;
8881
- });
8787
+ else {
8788
+ this.$el.$section.appendChild($ele);
8882
8789
  }
8883
- /**
8884
- * 创建一个选择项元素
8885
- */
8886
- function createSelectItemElement(dataInfo) {
8887
- let $item = popsDOMUtils.createElement("li", {
8888
- className: "select-item",
8889
- innerHTML: /*html*/ `
8890
- <span>${dataInfo.text}</span>
8891
- `,
8892
- });
8893
- Reflect.set($item, "data-info", dataInfo);
8894
- return $item;
8790
+ // 隐藏元素
8791
+ this.hideInputWrapper();
8792
+ this.hidePlaceHolderWrapper();
8793
+ },
8794
+ /** 更新tag信息 */
8795
+ updateSelectTagItem() {
8796
+ this.$el.$section
8797
+ .querySelectorAll(".el-select__choose_tag")
8798
+ .forEach(($ele) => {
8799
+ $ele.remove();
8800
+ });
8801
+ this.updateTagElement();
8802
+ },
8803
+ /**
8804
+ * 选中的值改变的回调
8805
+ * @param currentSelectInfo 当前的选中信息
8806
+ */
8807
+ selectValueChangeCallBack(currentSelectInfo) {
8808
+ if (typeof formConfig.callback === "function") {
8809
+ formConfig.callback(currentSelectInfo || this.$data.selectInfo);
8895
8810
  }
8896
- /**
8897
- * 设置选择项的点击事件
8898
- */
8899
- function setSelectElementClickEvent($ele) {
8900
- popsDOMUtils.on($ele, "click", (event) => {
8901
- popsDOMUtils.preventEvent(event);
8902
- if (typeof formConfig.clickCallBack === "function") {
8903
- let clickResult = formConfig.clickCallBack(event, getAllSelectedInfo());
8904
- if (typeof clickResult === "boolean" && !clickResult) {
8905
- return;
8906
- }
8907
- }
8908
- // 修改选中状态
8909
- if (isSelected($ele)) {
8910
- removeItemSelected($ele);
8911
- removeSelectedInfo($ele);
8811
+ },
8812
+ /** 设置下拉列表的点击事件 */
8813
+ setSelectContainerClickEvent() {
8814
+ const that = this;
8815
+ popsDOMUtils.on(this.$el.$container, "click", (event) => {
8816
+ /** 弹窗的选中的值 */
8817
+ let selectedInfo = [];
8818
+ selectedInfo = selectedInfo.concat(that.$data.selectInfo);
8819
+ /**
8820
+ * 设置项选中
8821
+ * @param $ele
8822
+ */
8823
+ function setItemSelected($ele) {
8824
+ $ele.classList.add("select-item-is-selected");
8825
+ }
8826
+ /**
8827
+ * 设置项取消选中
8828
+ * @param $ele
8829
+ */
8830
+ function removeItemSelected($ele) {
8831
+ $ele.classList.remove("select-item-is-selected");
8832
+ }
8833
+ /**
8834
+ * 添加选中信息
8835
+ */
8836
+ function addSelectedInfo($ele) {
8837
+ let info = getSelectedInfo($ele);
8838
+ let findValue = selectedInfo.find((item) => item.value === info.value);
8839
+ if (!findValue) {
8840
+ selectedInfo.push({
8841
+ value: info.value,
8842
+ text: info.text,
8843
+ isHTML: Boolean(info.isHTML),
8844
+ disable: info.disable,
8845
+ });
8912
8846
  }
8913
- else {
8914
- setItemSelected($ele);
8915
- addSelectedInfo($ele);
8847
+ that.selectValueChangeCallBack(selectedInfo);
8848
+ }
8849
+ /**
8850
+ * 移除选中信息
8851
+ */
8852
+ function removeSelectedInfo($ele) {
8853
+ let info = getSelectedInfo($ele);
8854
+ let findIndex = selectedInfo.findIndex((item) => item.value === info.value);
8855
+ if (findIndex !== -1) {
8856
+ selectedInfo.splice(findIndex, 1);
8916
8857
  }
8917
- });
8918
- }
8919
- let { style, ...userConfirmDetails } = formConfig.selectConfirmDialogDetails || {};
8920
- let confirmDetails = popsUtils.assign({
8921
- title: {
8922
- text: "请勾选需要选择的选项",
8923
- position: "center",
8924
- },
8925
- content: {
8926
- text: /*html*/ `
8927
- <ul class="select-container"></ul>
8858
+ that.selectValueChangeCallBack(selectedInfo);
8859
+ }
8860
+ /**
8861
+ * 判断该项是否选中
8862
+ * @param $ele
8863
+ */
8864
+ function isSelected($ele) {
8865
+ return $ele.classList.contains("select-item-is-selected");
8866
+ }
8867
+ /**
8868
+ * 获取选中的项的信息
8869
+ */
8870
+ function getSelectedInfo($ele) {
8871
+ return Reflect.get($ele, "data-info");
8872
+ }
8873
+ /**
8874
+ * 获取所有选中的项的信息
8875
+ */
8876
+ function getAllSelectedInfo() {
8877
+ return Array.from($selectContainer.querySelectorAll(".select-item"))
8878
+ .map(($ele) => {
8879
+ if (isSelected($ele)) {
8880
+ return getSelectedInfo($ele);
8881
+ }
8882
+ })
8883
+ .filter((item) => {
8884
+ return item != null;
8885
+ });
8886
+ }
8887
+ /**
8888
+ * 创建一个选择项元素
8889
+ */
8890
+ function createSelectItemElement(dataInfo) {
8891
+ let $item = popsDOMUtils.createElement("li", {
8892
+ className: "select-item",
8893
+ innerHTML: /*html*/ `
8894
+ <span>${dataInfo.text}</span>
8928
8895
  `,
8929
- html: true,
8930
- },
8931
- btn: {
8932
- ok: {
8933
- enable: false,
8896
+ });
8897
+ Reflect.set($item, "data-info", dataInfo);
8898
+ return $item;
8899
+ }
8900
+ /**
8901
+ * 设置选择项的点击事件
8902
+ */
8903
+ function setSelectElementClickEvent($ele) {
8904
+ popsDOMUtils.on($ele, "click", (event) => {
8905
+ popsDOMUtils.preventEvent(event);
8906
+ if (typeof formConfig.clickCallBack === "function") {
8907
+ let clickResult = formConfig.clickCallBack(event, getAllSelectedInfo());
8908
+ if (typeof clickResult === "boolean" && !clickResult) {
8909
+ return;
8910
+ }
8911
+ }
8912
+ // 修改选中状态
8913
+ if (isSelected($ele)) {
8914
+ removeItemSelected($ele);
8915
+ removeSelectedInfo($ele);
8916
+ }
8917
+ else {
8918
+ setItemSelected($ele);
8919
+ addSelectedInfo($ele);
8920
+ }
8921
+ });
8922
+ }
8923
+ let { style, ...userConfirmDetails } = formConfig.selectConfirmDialogDetails || {};
8924
+ let confirmDetails = popsUtils.assign({
8925
+ title: {
8926
+ text: "请勾选需要选择的选项",
8927
+ position: "center",
8928
+ },
8929
+ content: {
8930
+ text: /*html*/ `
8931
+ <ul class="select-container"></ul>
8932
+ `,
8933
+ html: true,
8934
+ },
8935
+ btn: {
8936
+ ok: {
8937
+ enable: false,
8938
+ },
8939
+ close: {
8940
+ enable: true,
8941
+ callback(details, event) {
8942
+ that.$data.selectInfo = [...selectedInfo];
8943
+ that.updateSelectTagItem();
8944
+ details.close();
8945
+ },
8946
+ },
8934
8947
  },
8935
- close: {
8948
+ mask: {
8936
8949
  enable: true,
8937
- callback(details, event) {
8950
+ clickCallBack(originalRun, config) {
8951
+ originalRun();
8938
8952
  that.$data.selectInfo = [...selectedInfo];
8939
8953
  that.updateSelectTagItem();
8940
- details.close();
8954
+ },
8955
+ clickEvent: {
8956
+ toClose: true,
8941
8957
  },
8942
8958
  },
8943
- },
8944
- mask: {
8945
- enable: true,
8946
- clickCallBack(originalRun, config) {
8947
- originalRun();
8948
- that.$data.selectInfo = [...selectedInfo];
8949
- that.updateSelectTagItem();
8950
- },
8951
- clickEvent: {
8952
- toClose: true,
8953
- },
8954
- },
8955
- drag: true,
8956
- dragLimit: true,
8957
- width: "300px",
8958
- height: "300px",
8959
- style: /*css*/ `
8960
- .select-container{
8961
- --el-font-size-base: 14px;
8962
- --el-text-color-regular: #606266;
8963
- --el-color-primary: #409eff;
8964
- --el-fill-color-light: #f5f7fa;
8965
- }
8966
- .select-item{
8967
- cursor: pointer;
8968
- cursor: pointer;
8969
- font-size: var(--el-font-size-base);
8970
- padding: 0 32px 0 20px;
8971
- position: relative;
8972
- white-space: nowrap;
8973
- overflow: hidden;
8974
- text-overflow: ellipsis;
8975
- color: var(--el-text-color-regular);
8976
- height: 34px;
8977
- line-height: 34px;
8978
- box-sizing: border-box;
8979
- }
8980
- .select-item:hover{
8981
- background-color: var(--el-fill-color-light);
8982
- }
8983
- .select-item.select-item-is-selected{
8984
- color: var(--el-color-primary);
8985
- font-weight: 700;
8986
- }
8987
- .select-item.select-item-is-selected::after{
8988
- content: "";
8989
- position: absolute;
8990
- top: 50%;
8991
- right: 20px;
8992
- border-top: none;
8993
- border-right: none;
8994
- background-repeat: no-repeat;
8995
- background-position: center;
8996
- background-color: var(--el-color-primary);
8997
- 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;
8998
- mask-size: 100% 100%;
8999
- -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;
9000
- -webkit-mask-size: 100% 100%;
9001
- transform: translateY(-50%);
9002
- width: 12px;
9003
- height: 12px;
9004
- }
9005
- ${style || ""}
9006
- `,
9007
- }, userConfirmDetails);
9008
- let $dialog = pops.alert(confirmDetails);
9009
- let $selectContainer = $dialog.$shadowRoot.querySelector(".select-container");
9010
- // 配置选项元素
9011
- formConfig.data.forEach((item) => {
9012
- let $select = createSelectItemElement(item);
9013
- // 添加到confirm中
9014
- $selectContainer.appendChild($select);
9015
- // 设置每一项的点击事件
9016
- setSelectElementClickEvent($select);
9017
- let findValue = selectedInfo.find((value) => value.value === item.value);
9018
- if (findValue) {
9019
- setItemSelected($select);
8959
+ drag: true,
8960
+ dragLimit: true,
8961
+ width: "300px",
8962
+ height: "300px",
8963
+ style: /*css*/ `
8964
+ .select-container{
8965
+ --el-font-size-base: 14px;
8966
+ --el-text-color-regular: #606266;
8967
+ --el-color-primary: #409eff;
8968
+ --el-fill-color-light: #f5f7fa;
8969
+ }
8970
+ .select-item{
8971
+ cursor: pointer;
8972
+ cursor: pointer;
8973
+ font-size: var(--el-font-size-base);
8974
+ padding: 0 32px 0 20px;
8975
+ position: relative;
8976
+ white-space: nowrap;
8977
+ overflow: hidden;
8978
+ text-overflow: ellipsis;
8979
+ color: var(--el-text-color-regular);
8980
+ height: 34px;
8981
+ line-height: 34px;
8982
+ box-sizing: border-box;
8983
+ }
8984
+ .select-item:hover{
8985
+ background-color: var(--el-fill-color-light);
8986
+ }
8987
+ .select-item.select-item-is-selected{
8988
+ color: var(--el-color-primary);
8989
+ font-weight: 700;
8990
+ }
8991
+ .select-item.select-item-is-selected::after{
8992
+ content: "";
8993
+ position: absolute;
8994
+ top: 50%;
8995
+ right: 20px;
8996
+ border-top: none;
8997
+ border-right: none;
8998
+ background-repeat: no-repeat;
8999
+ background-position: center;
9000
+ background-color: var(--el-color-primary);
9001
+ 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;
9002
+ mask-size: 100% 100%;
9003
+ -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;
9004
+ -webkit-mask-size: 100% 100%;
9005
+ transform: translateY(-50%);
9006
+ width: 12px;
9007
+ height: 12px;
9008
+ }
9009
+ ${style || ""}
9010
+ `,
9011
+ }, userConfirmDetails);
9012
+ let $dialog = pops.alert(confirmDetails);
9013
+ let $selectContainer = $dialog.$shadowRoot.querySelector(".select-container");
9014
+ // 配置选项元素
9015
+ formConfig.data.forEach((item) => {
9016
+ let $select = createSelectItemElement(item);
9017
+ // 添加到confirm中
9018
+ $selectContainer.appendChild($select);
9019
+ // 设置每一项的点击事件
9020
+ setSelectElementClickEvent($select);
9021
+ let findValue = selectedInfo.find((value) => value.value === item.value);
9022
+ if (findValue) {
9023
+ setItemSelected($select);
9024
+ }
9025
+ });
9026
+ });
9027
+ },
9028
+ /** 设置关闭图标的点击事件 */
9029
+ setSelectedItemCloseIconClickEvent(data) {
9030
+ popsDOMUtils.on(data.$closeIcon, "click", (event) => {
9031
+ popsDOMUtils.preventEvent(event);
9032
+ if (typeof formConfig.closeIconClickCallBack === "function") {
9033
+ let result = formConfig.closeIconClickCallBack(event, {
9034
+ $tag: data.$tag,
9035
+ $closeIcon: data.$closeIcon,
9036
+ value: data.value,
9037
+ text: data.text,
9038
+ });
9039
+ if (typeof result === "boolean" && !result) {
9040
+ return;
9041
+ }
9042
+ }
9043
+ this.removeSelectedItem(data.$tag);
9044
+ this.removeSelectedInfo({
9045
+ value: data.value,
9046
+ text: data.text,
9047
+ });
9048
+ }, {
9049
+ capture: true,
9050
+ });
9051
+ },
9052
+ /**
9053
+ * 检测tag是否为空,为空显示placeholder
9054
+ */
9055
+ checkTagEmpty() {
9056
+ if (!this.$el.$section.querySelectorAll(".el-select__choose_tag").length) {
9057
+ // 没有tag了
9058
+ // this.showInputWrapper();
9059
+ this.showPlaceHolderWrapper();
9060
+ this.removeSectionIsNear();
9061
+ }
9062
+ },
9063
+ /** 移除选中项元素 */
9064
+ removeSelectedItem($ele) {
9065
+ $ele.remove();
9066
+ this.checkTagEmpty();
9067
+ },
9068
+ /** 移除选中的信息 */
9069
+ removeSelectedInfo(data) {
9070
+ for (let index = 0; index < this.$data.selectInfo.length; index++) {
9071
+ const selectInfo = this.$data.selectInfo[index];
9072
+ if (selectInfo.value === data.value) {
9073
+ this.$data.selectInfo.splice(index, 1);
9074
+ break;
9075
+ }
9076
+ }
9077
+ this.selectValueChangeCallBack();
9078
+ },
9079
+ /** 显示输入框 */
9080
+ showInputWrapper() {
9081
+ popsDOMUtils.cssShow(this.$el.$selectedInputWrapper);
9082
+ },
9083
+ /** 隐藏输入框 */
9084
+ hideInputWrapper() {
9085
+ popsDOMUtils.cssHide(this.$el.$selectedInputWrapper, true);
9086
+ },
9087
+ /** 显示palceholder */
9088
+ showPlaceHolderWrapper() {
9089
+ popsDOMUtils.cssShow(this.$el.$selectedPlaceHolderWrapper);
9090
+ },
9091
+ /** 隐藏palceholder */
9092
+ hidePlaceHolderWrapper() {
9093
+ popsDOMUtils.cssHide(this.$el.$selectedPlaceHolderWrapper, true);
9094
+ },
9095
+ /** 设置隐藏section的前面的空白 */
9096
+ setSectionIsNear() {
9097
+ this.$el.$section.classList.add("is-near");
9098
+ },
9099
+ /** 取消设置隐藏section的前面的空白 */
9100
+ removeSectionIsNear() {
9101
+ this.$el.$section.classList.remove("is-near");
9102
+ },
9103
+ };
9104
+ PopsPanelSelectMultiple.init();
9105
+ Reflect.set(liElement, "data-select-multiple", PopsPanelSelectMultiple);
9106
+ return liElement;
9107
+ },
9108
+ /**
9109
+ * 获取中间容器的元素<li>
9110
+ * type ==> button
9111
+ * @param formConfig
9112
+ */
9113
+ getSectionContainerItem_button(formConfig) {
9114
+ let liElement = document.createElement("li");
9115
+ liElement["__formConfig__"] = formConfig;
9116
+ if (formConfig.className) {
9117
+ liElement.className = formConfig.className;
9118
+ }
9119
+ this.addElementAttributes(liElement, formConfig.attributes);
9120
+ this.setElementProps(liElement, formConfig.props);
9121
+ /* 左边底部的描述的文字 */
9122
+ let leftDescriptionText = "";
9123
+ if (Boolean(formConfig.description)) {
9124
+ leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
9125
+ }
9126
+ liElement.innerHTML = /*html*/ `
9127
+ <div class="pops-panel-item-left-text">
9128
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
9129
+ ${leftDescriptionText}
9130
+ </div>
9131
+ <div class="pops-panel-button">
9132
+ <button class="pops-panel-button_inner">
9133
+ <i class="pops-bottom-icon"></i>
9134
+ <span class="pops-panel-button-text"></span>
9135
+ </button>
9136
+ </div>
9137
+ `;
9138
+ const PopsPanelButton = {
9139
+ [Symbol.toStringTag]: "PopsPanelButton",
9140
+ $ele: {
9141
+ panelButton: liElement.querySelector(".pops-panel-button"),
9142
+ button: liElement.querySelector(".pops-panel-button .pops-panel-button_inner"),
9143
+ icon: liElement.querySelector(".pops-panel-button .pops-bottom-icon"),
9144
+ spanText: liElement.querySelector(".pops-panel-button .pops-panel-button-text"),
9145
+ },
9146
+ $data: {},
9147
+ init() {
9148
+ this.$ele.panelButton.appendChild(this.$ele.button);
9149
+ this.initButton();
9150
+ this.setClickEvent();
9151
+ },
9152
+ initButton() {
9153
+ if (typeof formConfig.buttonIcon === "string" &&
9154
+ formConfig.buttonIcon.trim() !== "") {
9155
+ /* 存在icon图标且不为空 */
9156
+ if (formConfig.buttonIcon in pops.config.iconSVG) {
9157
+ this.setIconSVG(pops.config.iconSVG[formConfig.buttonIcon]);
9020
9158
  }
9021
- });
9022
- });
9023
- },
9024
- /** 设置关闭图标的点击事件 */
9025
- setSelectedItemCloseIconClickEvent(data) {
9026
- popsDOMUtils.on(data.$closeIcon, "click", (event) => {
9027
- popsDOMUtils.preventEvent(event);
9028
- if (typeof formConfig.closeIconClickCallBack === "function") {
9029
- let result = formConfig.closeIconClickCallBack(event, {
9030
- $tag: data.$tag,
9031
- $closeIcon: data.$closeIcon,
9032
- value: data.value,
9033
- text: data.text,
9034
- });
9035
- if (typeof result === "boolean" && !result) {
9036
- return;
9159
+ else {
9160
+ this.setIconSVG(formConfig.buttonIcon);
9037
9161
  }
9162
+ this.showIcon();
9038
9163
  }
9039
- this.removeSelectedItem(data.$tag);
9040
- this.removeSelectedInfo({
9041
- value: data.value,
9042
- text: data.text,
9043
- });
9044
- }, {
9045
- capture: true,
9046
- });
9047
- },
9048
- /**
9049
- * 检测tag是否为空,为空显示placeholder
9050
- */
9051
- checkTagEmpty() {
9052
- if (!this.$el.$section.querySelectorAll(".el-select__choose_tag").length) {
9053
- // 没有tag了
9054
- // this.showInputWrapper();
9055
- this.showPlaceHolderWrapper();
9056
- this.removeSectionIsNear();
9057
- }
9058
- },
9059
- /** 移除选中项元素 */
9060
- removeSelectedItem($ele) {
9061
- $ele.remove();
9062
- this.checkTagEmpty();
9063
- },
9064
- /** 移除选中的信息 */
9065
- removeSelectedInfo(data) {
9066
- for (let index = 0; index < this.$data.selectInfo.length; index++) {
9067
- const selectInfo = this.$data.selectInfo[index];
9068
- if (selectInfo.value === data.value) {
9069
- this.$data.selectInfo.splice(index, 1);
9070
- break;
9164
+ else {
9165
+ this.hideIcon();
9071
9166
  }
9072
- }
9073
- this.selectValueChangeCallBack();
9074
- },
9075
- /** 显示输入框 */
9076
- showInputWrapper() {
9077
- popsDOMUtils.cssShow(this.$el.$selectedInputWrapper);
9078
- },
9079
- /** 隐藏输入框 */
9080
- hideInputWrapper() {
9081
- popsDOMUtils.cssHide(this.$el.$selectedInputWrapper, true);
9082
- },
9083
- /** 显示palceholder */
9084
- showPlaceHolderWrapper() {
9085
- popsDOMUtils.cssShow(this.$el.$selectedPlaceHolderWrapper);
9086
- },
9087
- /** 隐藏palceholder */
9088
- hidePlaceHolderWrapper() {
9089
- popsDOMUtils.cssHide(this.$el.$selectedPlaceHolderWrapper, true);
9090
- },
9091
- /** 设置隐藏section的前面的空白 */
9092
- setSectionIsNear() {
9093
- this.$el.$section.classList.add("is-near");
9094
- },
9095
- /** 取消设置隐藏section的前面的空白 */
9096
- removeSectionIsNear() {
9097
- this.$el.$section.classList.remove("is-near");
9098
- },
9099
- };
9100
- PopsPanelSelectMultiple.init();
9101
- Reflect.set(liElement, "data-select-multiple", PopsPanelSelectMultiple);
9102
- return liElement;
9103
- },
9104
- /**
9105
- * 获取中间容器的元素<li>
9106
- * type ==> button
9107
- * @param formConfig
9108
- */
9109
- getSectionContainerItem_button(formConfig) {
9110
- let liElement = document.createElement("li");
9111
- liElement["__formConfig__"] = formConfig;
9112
- if (formConfig.className) {
9113
- liElement.className = formConfig.className;
9114
- }
9115
- this.addElementAttributes(liElement, formConfig.attributes);
9116
- this.setElementProps(liElement, formConfig.props);
9117
- /* 左边底部的描述的文字 */
9118
- let leftDescriptionText = "";
9119
- if (Boolean(formConfig.description)) {
9120
- leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
9121
- }
9122
- liElement.innerHTML = /*html*/ `
9123
- <div class="pops-panel-item-left-text">
9124
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
9125
- ${leftDescriptionText}
9126
- </div>
9127
- <div class="pops-panel-button">
9128
- <button class="pops-panel-button_inner">
9129
- <i class="pops-bottom-icon"></i>
9130
- <span class="pops-panel-button-text"></span>
9131
- </button>
9132
- </div>
9133
- `;
9134
- const PopsPanelButton = {
9135
- [Symbol.toStringTag]: "PopsPanelButton",
9136
- $ele: {
9137
- panelButton: liElement.querySelector(".pops-panel-button"),
9138
- button: liElement.querySelector(".pops-panel-button .pops-panel-button_inner"),
9139
- icon: liElement.querySelector(".pops-panel-button .pops-bottom-icon"),
9140
- spanText: liElement.querySelector(".pops-panel-button .pops-panel-button-text"),
9141
- },
9142
- $data: {},
9143
- init() {
9144
- this.$ele.panelButton.appendChild(this.$ele.button);
9145
- this.initButton();
9146
- this.setClickEvent();
9147
- },
9148
- initButton() {
9149
- if (typeof formConfig.buttonIcon === "string" &&
9150
- formConfig.buttonIcon.trim() !== "") {
9151
- /* 存在icon图标且不为空 */
9152
- if (formConfig.buttonIcon in pops.config.iconSVG) {
9153
- this.setIconSVG(pops.config.iconSVG[formConfig.buttonIcon]);
9167
+ /* 按钮文字 */
9168
+ let buttonText = formConfig.buttonText;
9169
+ if (typeof formConfig.buttonText === "function") {
9170
+ buttonText = formConfig.buttonText();
9171
+ }
9172
+ this.setButtonType(formConfig.buttonType);
9173
+ if (formConfig.buttonIsRightIcon) {
9174
+ this.setIconRight();
9154
9175
  }
9155
9176
  else {
9156
- this.setIconSVG(formConfig.buttonIcon);
9177
+ this.setIconLeft();
9157
9178
  }
9158
- this.showIcon();
9159
- }
9160
- else {
9161
- this.hideIcon();
9162
- }
9163
- /* 按钮文字 */
9164
- let buttonText = formConfig.buttonText;
9165
- if (typeof formConfig.buttonText === "function") {
9166
- buttonText = formConfig.buttonText();
9167
- }
9168
- this.setButtonType(formConfig.buttonType);
9169
- if (formConfig.buttonIsRightIcon) {
9170
- this.setIconRight();
9171
- }
9172
- else {
9173
- this.setIconLeft();
9174
- }
9175
- if (formConfig.disable) {
9176
- this.disable();
9177
- }
9178
- this.setButtonText(buttonText);
9179
- this.setIconLoadingStatus(formConfig.buttonIconIsLoading);
9180
- },
9181
- disable() {
9182
- this.$ele.button.setAttribute("disabled", "true");
9183
- },
9184
- notDisable() {
9185
- this.$ele.button.removeAttribute("disabled");
9186
- },
9187
- /**
9188
- * 隐藏icon图标
9189
- */
9190
- hideIcon() {
9191
- this.$ele.panelButton.classList.add("pops-panel-button-no-icon");
9192
- },
9193
- /**
9194
- * 显示icon图标
9195
- */
9196
- showIcon() {
9197
- this.$ele.panelButton.classList.remove("pops-panel-button-no-icon");
9198
- },
9199
- /**
9200
- * 设置icon图标的svg
9201
- */
9202
- setIconSVG(svgHTML) {
9203
- this.$ele.icon.innerHTML = svgHTML;
9204
- },
9205
- /**
9206
- * 设置icon图标是否旋转
9207
- * @param status
9208
- */
9209
- setIconLoadingStatus(status) {
9210
- this.$ele.icon.setAttribute("is-loading", Boolean(status).toString());
9211
- },
9212
- /**
9213
- * 设置属性上是否存在icon图标
9214
- */
9215
- setHasIcon(value) {
9216
- this.$ele.button.setAttribute("data-icon", Boolean(value).toString());
9217
- },
9218
- /**
9219
- * 设置按钮类型
9220
- * @param typeValue
9221
- */
9222
- setButtonType(typeValue) {
9223
- this.$ele.button.setAttribute("type", typeValue);
9224
- },
9225
- /**
9226
- * 添加按钮的图标在右边
9227
- */
9228
- setIconRight() {
9229
- this.$ele.button.classList.add("pops-panel-button-right-icon");
9230
- },
9231
- /**
9232
- * (默认)添加按钮的图标在左边
9233
- */
9234
- setIconLeft() {
9235
- this.$ele.button.classList.remove("pops-panel-button-right-icon");
9236
- },
9237
- /**
9238
- * 设置按钮文本
9239
- * @param text
9240
- */
9241
- setButtonText(text) {
9242
- this.$ele.spanText.innerHTML = text;
9243
- },
9244
- setClickEvent() {
9245
- popsDOMUtils.on(this.$ele.button, "click", void 0, (event) => {
9246
- if (typeof formConfig.callback === "function") {
9247
- formConfig.callback(event);
9179
+ if (formConfig.disable) {
9180
+ this.disable();
9248
9181
  }
9249
- });
9250
- },
9251
- };
9252
- PopsPanelButton.init();
9253
- liElement["data-button"] = PopsPanelButton;
9254
- return liElement;
9255
- },
9256
- /**
9257
- * 获取深层容器的元素<li>
9258
- * @param formConfig
9259
- */
9260
- getSectionContainerItem_deepMenu(formConfig) {
9261
- let that = this;
9262
- let liElement = document.createElement("li");
9263
- liElement.classList.add("pops-panel-deepMenu-nav-item");
9264
- liElement["__formConfig__"] = formConfig;
9265
- if (formConfig.className) {
9266
- liElement.classList.add(formConfig.className);
9267
- }
9268
- // 设置属性
9269
- this.addElementAttributes(liElement, formConfig.attributes);
9270
- // 设置元素上的属性
9271
- this.setElementProps(liElement, formConfig.props);
9272
- /* 左边底部的描述的文字 */
9273
- let leftDescriptionText = "";
9274
- if (Boolean(formConfig.description)) {
9275
- // 设置描述
9276
- leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
9277
- }
9278
- // 箭头图标
9279
- let arrowRightIcon = typeof formConfig.arrowRightIcon === "boolean"
9280
- ? formConfig.arrowRightIcon
9281
- : true;
9282
- let arrowRightIconHTML = "";
9283
- if (arrowRightIcon) {
9284
- arrowRightIconHTML = `<i class="pops-panel-deepMenu-arrowRight-icon">${pops.config.iconSVG.arrowRight}</i>`;
9285
- }
9286
- let rightText = "";
9287
- if (formConfig.rightText) {
9288
- rightText = /*html*/ `<p class="pops-panel-item-right-text">${formConfig.rightText}</p>`;
9289
- }
9290
- liElement.innerHTML = /*html*/ `
9291
- <div class="pops-panel-item-left-text">
9292
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
9293
- ${leftDescriptionText}
9294
- </div>
9295
- <div class="pops-panel-deepMenu">
9296
- ${rightText}
9297
- ${arrowRightIconHTML}
9298
- </div>
9299
- `;
9300
- const PopsPanelDeepMenu = {
9301
- [Symbol.toStringTag]: "PopsPanelDeepMenu",
9302
- $ele: {
9303
- get parentSection() {
9304
- return that.$el.$contentSectionContainer;
9182
+ this.setButtonText(buttonText);
9183
+ this.setIconLoadingStatus(formConfig.buttonIconIsLoading);
9305
9184
  },
9306
- },
9307
- init() {
9308
- this.setLiClickEvent();
9309
- },
9310
- /**
9311
- * 生成配置每一项的元素
9312
- * @param $container
9313
- * @param formItemConfig
9314
- */
9315
- initFormItem($container, formItemConfig) {
9316
- if (formItemConfig["type"] === "forms") {
9317
- let childForms = formItemConfig["forms"];
9318
- /* 每一项<li>元素 */
9319
- let formContainerListElement = document.createElement("li");
9320
- /* 每一项<li>内的子<ul>元素 */
9321
- let formContainerULElement = document.createElement("ul");
9322
- formContainerListElement.className =
9323
- "pops-panel-forms-container-item";
9324
- /* 区域头部的文字 */
9325
- let formHeaderDivElement = popsDOMUtils.createElement("div", {
9326
- className: "pops-panel-forms-container-item-header-text",
9185
+ disable() {
9186
+ this.$ele.button.setAttribute("disabled", "true");
9187
+ },
9188
+ notDisable() {
9189
+ this.$ele.button.removeAttribute("disabled");
9190
+ },
9191
+ /**
9192
+ * 隐藏icon图标
9193
+ */
9194
+ hideIcon() {
9195
+ this.$ele.panelButton.classList.add("pops-panel-button-no-icon");
9196
+ },
9197
+ /**
9198
+ * 显示icon图标
9199
+ */
9200
+ showIcon() {
9201
+ this.$ele.panelButton.classList.remove("pops-panel-button-no-icon");
9202
+ },
9203
+ /**
9204
+ * 设置icon图标的svg
9205
+ */
9206
+ setIconSVG(svgHTML) {
9207
+ this.$ele.icon.innerHTML = svgHTML;
9208
+ },
9209
+ /**
9210
+ * 设置icon图标是否旋转
9211
+ * @param status
9212
+ */
9213
+ setIconLoadingStatus(status) {
9214
+ this.$ele.icon.setAttribute("is-loading", Boolean(status).toString());
9215
+ },
9216
+ /**
9217
+ * 设置属性上是否存在icon图标
9218
+ */
9219
+ setHasIcon(value) {
9220
+ this.$ele.button.setAttribute("data-icon", Boolean(value).toString());
9221
+ },
9222
+ /**
9223
+ * 设置按钮类型
9224
+ * @param typeValue
9225
+ */
9226
+ setButtonType(typeValue) {
9227
+ this.$ele.button.setAttribute("type", typeValue);
9228
+ },
9229
+ /**
9230
+ * 添加按钮的图标在右边
9231
+ */
9232
+ setIconRight() {
9233
+ this.$ele.button.classList.add("pops-panel-button-right-icon");
9234
+ },
9235
+ /**
9236
+ * (默认)添加按钮的图标在左边
9237
+ */
9238
+ setIconLeft() {
9239
+ this.$ele.button.classList.remove("pops-panel-button-right-icon");
9240
+ },
9241
+ /**
9242
+ * 设置按钮文本
9243
+ * @param text
9244
+ */
9245
+ setButtonText(text) {
9246
+ this.$ele.spanText.innerHTML = text;
9247
+ },
9248
+ setClickEvent() {
9249
+ popsDOMUtils.on(this.$ele.button, "click", void 0, (event) => {
9250
+ if (typeof formConfig.callback === "function") {
9251
+ formConfig.callback(event);
9252
+ }
9327
9253
  });
9328
- formHeaderDivElement.innerHTML = formItemConfig["text"];
9329
- /* 加进容器内 */
9330
- formContainerListElement.appendChild(formHeaderDivElement);
9331
- if (formItemConfig.className) {
9332
- popsDOMUtils.addClassName(formContainerListElement, formItemConfig.className);
9254
+ },
9255
+ };
9256
+ PopsPanelButton.init();
9257
+ liElement["data-button"] = PopsPanelButton;
9258
+ return liElement;
9259
+ },
9260
+ /**
9261
+ * 获取深层容器的元素<li>
9262
+ * @param formConfig
9263
+ */
9264
+ getSectionContainerItem_deepMenu(formConfig) {
9265
+ let that = this;
9266
+ let liElement = document.createElement("li");
9267
+ liElement.classList.add("pops-panel-deepMenu-nav-item");
9268
+ liElement["__formConfig__"] = formConfig;
9269
+ if (formConfig.className) {
9270
+ liElement.classList.add(formConfig.className);
9271
+ }
9272
+ // 设置属性
9273
+ this.addElementAttributes(liElement, formConfig.attributes);
9274
+ // 设置元素上的属性
9275
+ this.setElementProps(liElement, formConfig.props);
9276
+ /* 左边底部的描述的文字 */
9277
+ let leftDescriptionText = "";
9278
+ if (Boolean(formConfig.description)) {
9279
+ // 设置描述
9280
+ leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
9281
+ }
9282
+ // 箭头图标
9283
+ let arrowRightIcon = typeof formConfig.arrowRightIcon === "boolean"
9284
+ ? formConfig.arrowRightIcon
9285
+ : true;
9286
+ let arrowRightIconHTML = "";
9287
+ if (arrowRightIcon) {
9288
+ arrowRightIconHTML = `<i class="pops-panel-deepMenu-arrowRight-icon">${pops.config.iconSVG.arrowRight}</i>`;
9289
+ }
9290
+ let rightText = "";
9291
+ if (formConfig.rightText) {
9292
+ rightText = /*html*/ `<p class="pops-panel-item-right-text">${formConfig.rightText}</p>`;
9293
+ }
9294
+ liElement.innerHTML = /*html*/ `
9295
+ <div class="pops-panel-item-left-text">
9296
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
9297
+ ${leftDescriptionText}
9298
+ </div>
9299
+ <div class="pops-panel-deepMenu">
9300
+ ${rightText}
9301
+ ${arrowRightIconHTML}
9302
+ </div>
9303
+ `;
9304
+ const PopsPanelDeepMenu = {
9305
+ [Symbol.toStringTag]: "PopsPanelDeepMenu",
9306
+ $ele: {
9307
+ get parentSection() {
9308
+ return that.$el.$contentSectionContainer;
9309
+ },
9310
+ },
9311
+ init() {
9312
+ this.setLiClickEvent();
9313
+ },
9314
+ /**
9315
+ * 生成配置每一项的元素
9316
+ * @param $container
9317
+ * @param formItemConfig
9318
+ */
9319
+ initFormItem($container, formItemConfig) {
9320
+ if (formItemConfig["type"] === "forms") {
9321
+ let childForms = formItemConfig["forms"];
9322
+ /* 每一项<li>元素 */
9323
+ let formContainerListElement = document.createElement("li");
9324
+ /* 每一项<li>内的子<ul>元素 */
9325
+ let formContainerULElement = document.createElement("ul");
9326
+ formContainerListElement.className =
9327
+ "pops-panel-forms-container-item";
9328
+ /* 区域头部的文字 */
9329
+ let formHeaderDivElement = popsDOMUtils.createElement("div", {
9330
+ className: "pops-panel-forms-container-item-header-text",
9331
+ });
9332
+ formHeaderDivElement.innerHTML = formItemConfig["text"];
9333
+ /* 加进容器内 */
9334
+ formContainerListElement.appendChild(formHeaderDivElement);
9335
+ if (formItemConfig.className) {
9336
+ popsDOMUtils.addClassName(formContainerListElement, formItemConfig.className);
9337
+ }
9338
+ that.addElementAttributes(formContainerListElement, formItemConfig.attributes);
9339
+ that.setElementProps(formContainerListElement, formItemConfig.props);
9340
+ childForms.forEach((childFormConfig) => {
9341
+ that.uListContainerAddItem(childFormConfig, {
9342
+ ulElement: formContainerULElement,
9343
+ sectionContainerULElement: that.sectionContainerULElement,
9344
+ formContainerListElement: formContainerListElement,
9345
+ formHeaderDivElement: formHeaderDivElement,
9346
+ });
9347
+ });
9348
+ formContainerListElement.appendChild(formContainerULElement);
9349
+ $container.appendChild(formContainerListElement);
9333
9350
  }
9334
- that.addElementAttributes(formContainerListElement, formItemConfig.attributes);
9335
- that.setElementProps(formContainerListElement, formItemConfig.props);
9336
- childForms.forEach((childFormConfig) => {
9337
- that.uListContainerAddItem(childFormConfig, {
9338
- ulElement: formContainerULElement,
9339
- sectionContainerULElement: that.sectionContainerULElement,
9340
- formContainerListElement: formContainerListElement,
9341
- formHeaderDivElement: formHeaderDivElement,
9351
+ else {
9352
+ /* 如果成功创建,加入到中间容器中 */
9353
+ that.uListContainerAddItem(formConfig, {
9354
+ ulElement: that.sectionContainerULElement,
9342
9355
  });
9356
+ }
9357
+ },
9358
+ /**
9359
+ * 前往子菜单
9360
+ * @param event 点击事件
9361
+ * @param liElement 当前的<li>元素
9362
+ */
9363
+ gotoDeepMenu(event, liElement) {
9364
+ /** 当前所在的容器 */
9365
+ let currentSection = liElement.closest("section.pops-panel-container");
9366
+ if (currentSection) {
9367
+ popsDOMUtils.cssHide(currentSection);
9368
+ }
9369
+ // 子菜单的容器
9370
+ let $deepMenuContainer = popsDOMUtils.createElement("section", {
9371
+ className: "pops-panel-container pops-panel-deepMenu-container",
9343
9372
  });
9344
- formContainerListElement.appendChild(formContainerULElement);
9345
- $container.appendChild(formContainerListElement);
9346
- }
9347
- else {
9348
- /* 如果成功创建,加入到中间容器中 */
9349
- that.uListContainerAddItem(formConfig, {
9350
- ulElement: that.sectionContainerULElement,
9373
+ let $deepMenuHeaderUL = popsDOMUtils.createElement("ul", {
9374
+ className: "pops-panel-deepMenu-container-header-ul",
9351
9375
  });
9352
- }
9353
- },
9354
- /**
9355
- * 前往子菜单
9356
- * @param event 点击事件
9357
- * @param liElement 当前的<li>元素
9358
- */
9359
- gotoDeepMenu(event, liElement) {
9360
- /** 当前所在的容器 */
9361
- let currentSection = liElement.closest("section.pops-panel-container");
9362
- if (currentSection) {
9363
- popsDOMUtils.cssHide(currentSection);
9364
- }
9365
- // 子菜单的容器
9366
- let $deepMenuContainer = popsDOMUtils.createElement("section", {
9367
- className: "pops-panel-container pops-panel-deepMenu-container",
9368
- });
9369
- let $deepMenuHeaderUL = popsDOMUtils.createElement("ul", {
9370
- className: "pops-panel-deepMenu-container-header-ul",
9376
+ let $deepMenuChildMenuUL = popsDOMUtils.createElement("ul");
9377
+ // 标题文字
9378
+ let headerTitleText = formConfig.headerTitle ?? formConfig.text;
9379
+ let $header = popsDOMUtils.createElement("div", {
9380
+ className: "pops-panel-deepMenu-container-header",
9381
+ innerHTML: `<p>${headerTitleText}</p>`,
9382
+ });
9383
+ let $headerLeftArrow = popsDOMUtils.createElement("i", {
9384
+ className: "pops-panel-deepMenu-container-left-arrow-icon",
9385
+ innerHTML: pops.config.iconSVG.arrowLeft,
9386
+ });
9387
+ popsDOMUtils.on($headerLeftArrow, "click", void 0, (event) => {
9388
+ event?.preventDefault();
9389
+ event?.stopPropagation();
9390
+ // 返回上一层菜单
9391
+ let $prev = $deepMenuContainer.previousElementSibling;
9392
+ popsDOMUtils.cssShow($prev);
9393
+ $deepMenuContainer.remove();
9394
+ }, {
9395
+ once: true,
9396
+ });
9397
+ $header.firstElementChild?.insertAdjacentElement("beforebegin", $headerLeftArrow);
9398
+ $deepMenuHeaderUL.appendChild($header);
9399
+ $deepMenuContainer.appendChild($deepMenuHeaderUL);
9400
+ $deepMenuContainer.appendChild($deepMenuChildMenuUL);
9401
+ if (formConfig.forms && Array.isArray(formConfig.forms)) {
9402
+ for (let index = 0; index < formConfig.forms.length; index++) {
9403
+ let formItemConfig = formConfig.forms[index];
9404
+ this.initFormItem($deepMenuChildMenuUL, formItemConfig);
9405
+ }
9406
+ }
9407
+ that.$el.$content?.appendChild($deepMenuContainer);
9408
+ /* 根据标题的高度来自适应内容高度,默认开启 */
9409
+ /* 中间容器的偏移量,看设置的section.pops-panel-container的padding,默认0 */
9410
+ let contentContainerOffset = 0;
9411
+ /* 获取标题的<ul>元素的高度 */
9412
+ let sectionContainerHeaderULElementHeight = popsDOMUtils.height($deepMenuHeaderUL);
9413
+ $deepMenuChildMenuUL.style.setProperty("height", `calc( 100% - ${sectionContainerHeaderULElementHeight + contentContainerOffset}px )`);
9414
+ },
9415
+ /** 设置项的点击事件 */
9416
+ setLiClickEvent() {
9417
+ popsDOMUtils.on(liElement, "click", void 0, async (event) => {
9418
+ if (typeof formConfig.clickCallBack === "function") {
9419
+ let result = await formConfig.clickCallBack(event, formConfig);
9420
+ if (result) {
9421
+ return;
9422
+ }
9423
+ }
9424
+ this.gotoDeepMenu(event, liElement);
9425
+ });
9426
+ },
9427
+ };
9428
+ PopsPanelDeepMenu.init();
9429
+ liElement["data-deepMenu"] = PopsPanelDeepMenu;
9430
+ return liElement;
9431
+ },
9432
+ /**
9433
+ * 获取中间容器的元素<li>
9434
+ * type ===> own
9435
+ * @param formConfig
9436
+ */
9437
+ getSectionContainerItem_own(formConfig) {
9438
+ let liElement = document.createElement("li");
9439
+ liElement["__formConfig__"] = formConfig;
9440
+ if (formConfig.className) {
9441
+ liElement.className = formConfig.className;
9442
+ }
9443
+ liElement = formConfig.getLiElementCallBack(liElement);
9444
+ return liElement;
9445
+ },
9446
+ /**
9447
+ * 获取中间容器的元素<li>
9448
+ * @param formConfig
9449
+ */
9450
+ getSectionContainerItem(formConfig) {
9451
+ /** 配置项的类型 */
9452
+ let formType = formConfig["type"];
9453
+ if (formType === "switch") {
9454
+ return this.getSectionContainerItem_switch(formConfig);
9455
+ }
9456
+ else if (formType === "slider") {
9457
+ return this.getSectionContainerItem_slider_new(formConfig);
9458
+ }
9459
+ else if (formType === "input") {
9460
+ return this.getSectionContainerItem_input(formConfig);
9461
+ }
9462
+ else if (formType === "textarea") {
9463
+ return this.getSectionContainerItem_textarea(formConfig);
9464
+ }
9465
+ else if (formType === "select") {
9466
+ return this.getSectionContainerItem_select(formConfig);
9467
+ }
9468
+ else if (formType === "select-multiple") {
9469
+ return this.getSectionContainerItem_select_multiple_new(formConfig);
9470
+ }
9471
+ else if (formType === "button") {
9472
+ return this.getSectionContainerItem_button(formConfig);
9473
+ }
9474
+ else if (formType === "deepMenu") {
9475
+ return this.getSectionContainerItem_deepMenu(formConfig);
9476
+ }
9477
+ else if (formType === "own") {
9478
+ return this.getSectionContainerItem_own(formConfig);
9479
+ }
9480
+ else {
9481
+ console.error("尚未实现的type类型", formConfig);
9482
+ }
9483
+ },
9484
+ /**
9485
+ * 生成配置每一项的元素
9486
+ * @param formConfig
9487
+ */
9488
+ initFormItem(formConfig) {
9489
+ let that = this;
9490
+ if (formConfig["type"] === "forms") {
9491
+ let __formConfig_forms = formConfig;
9492
+ let childForms = formConfig["forms"];
9493
+ /* 每一项<li>元素 */
9494
+ let formContainerListElement = document.createElement("li");
9495
+ /* 每一项<li>内的子<ul>元素 */
9496
+ let formContainerULElement = document.createElement("ul");
9497
+ formContainerListElement.className = "pops-panel-forms-container-item";
9498
+ /* 区域头部的文字 */
9499
+ let formHeaderDivElement = popsDOMUtils.createElement("div", {
9500
+ className: "pops-panel-forms-container-item-header-text",
9371
9501
  });
9372
- let $deepMenuChildMenuUL = popsDOMUtils.createElement("ul");
9373
- // 标题文字
9374
- let headerTitleText = formConfig.headerTitle ?? formConfig.text;
9375
- let $header = popsDOMUtils.createElement("div", {
9376
- className: "pops-panel-deepMenu-container-header",
9377
- innerHTML: `<p>${headerTitleText}</p>`,
9502
+ formHeaderDivElement.innerHTML = __formConfig_forms["text"];
9503
+ /* 加进容器内 */
9504
+ formContainerListElement.appendChild(formHeaderDivElement);
9505
+ if (__formConfig_forms.className) {
9506
+ popsDOMUtils.addClassName(formContainerListElement, __formConfig_forms.className);
9507
+ }
9508
+ that.addElementAttributes(formContainerListElement, formConfig.attributes);
9509
+ that.setElementProps(formContainerListElement, formConfig.props);
9510
+ childForms.forEach((childFormConfig) => {
9511
+ that.uListContainerAddItem(childFormConfig, {
9512
+ ulElement: formContainerULElement,
9513
+ sectionContainerULElement: that.sectionContainerULElement,
9514
+ formContainerListElement: formContainerListElement,
9515
+ formHeaderDivElement: formHeaderDivElement,
9516
+ });
9378
9517
  });
9379
- let $headerLeftArrow = popsDOMUtils.createElement("i", {
9380
- className: "pops-panel-deepMenu-container-left-arrow-icon",
9381
- innerHTML: pops.config.iconSVG.arrowLeft,
9518
+ formContainerListElement.appendChild(formContainerULElement);
9519
+ that.sectionContainerULElement.appendChild(formContainerListElement);
9520
+ }
9521
+ else {
9522
+ /* 如果成功创建,加入到中间容器中 */
9523
+ that.uListContainerAddItem(formConfig, {
9524
+ ulElement: that.sectionContainerULElement,
9382
9525
  });
9383
- popsDOMUtils.on($headerLeftArrow, "click", void 0, (event) => {
9384
- event?.preventDefault();
9385
- event?.stopPropagation();
9386
- // 返回上一层菜单
9387
- let $prev = $deepMenuContainer.previousElementSibling;
9388
- popsDOMUtils.cssShow($prev);
9389
- $deepMenuContainer.remove();
9390
- }, {
9391
- once: true,
9526
+ }
9527
+ },
9528
+ /**
9529
+ *
9530
+ * @param formConfig
9531
+ * @param containerOptions
9532
+ */
9533
+ uListContainerAddItem(formConfig, containerOptions) {
9534
+ let itemLiElement = this.getSectionContainerItem(formConfig);
9535
+ if (itemLiElement) {
9536
+ containerOptions["ulElement"].appendChild(itemLiElement);
9537
+ }
9538
+ if (typeof formConfig.afterAddToUListCallBack === "function") {
9539
+ formConfig.afterAddToUListCallBack(formConfig, containerOptions);
9540
+ }
9541
+ },
9542
+ /**
9543
+ * 为左侧容器元素添加点击事件
9544
+ * @param asideLiElement 左侧的容器<li>元素
9545
+ * @param asideConfig 配置
9546
+ */
9547
+ setAsideItemClickEvent(asideLiElement, asideConfig) {
9548
+ const that = this;
9549
+ popsDOMUtils.on(asideLiElement, "click", void 0, (event) => {
9550
+ this.clearContainer();
9551
+ popsDOMUtils.cssShow(that.$el.$contentSectionContainer);
9552
+ this.clearAsideItemIsVisited();
9553
+ this.setAsideItemIsVisited(asideLiElement);
9554
+ /* 顶部标题栏,存在就设置 */
9555
+ let headerTitleText = asideConfig.headerTitle ?? asideConfig.title;
9556
+ if (typeof headerTitleText === "string" &&
9557
+ headerTitleText.trim() !== "") {
9558
+ let containerHeaderTitleLIElement = document.createElement("li");
9559
+ containerHeaderTitleLIElement["__asideConfig__"] =
9560
+ asideConfig;
9561
+ containerHeaderTitleLIElement.innerHTML = headerTitleText;
9562
+ this.sectionContainerHeaderULElement.appendChild(containerHeaderTitleLIElement);
9563
+ }
9564
+ let __forms__ = asideLiElement["__forms__"];
9565
+ __forms__.forEach((formConfig) => {
9566
+ this.initFormItem(formConfig);
9392
9567
  });
9393
- $header.firstElementChild?.insertAdjacentElement("beforebegin", $headerLeftArrow);
9394
- $deepMenuHeaderUL.appendChild($header);
9395
- $deepMenuContainer.appendChild($deepMenuHeaderUL);
9396
- $deepMenuContainer.appendChild($deepMenuChildMenuUL);
9397
- if (formConfig.forms && Array.isArray(formConfig.forms)) {
9398
- for (let index = 0; index < formConfig.forms.length; index++) {
9399
- let formItemConfig = formConfig.forms[index];
9400
- this.initFormItem($deepMenuChildMenuUL, formItemConfig);
9401
- }
9568
+ let autoAdaptionContentHeight = asideConfig.autoAdaptionContentHeight ?? true;
9569
+ if (autoAdaptionContentHeight) {
9570
+ /* 根据标题的高度来自适应内容高度,默认开启 */
9571
+ /* 中间容器的偏移量,看设置的section.pops-panel-container的padding,默认0 */
9572
+ let contentContainerOffset = asideConfig.contentContainerOffset ?? 0;
9573
+ /* 获取标题的<ul>元素的高度 */
9574
+ let sectionContainerHeaderULElementHeight = popsDOMUtils.height(this.sectionContainerHeaderULElement);
9575
+ this.sectionContainerULElement.style.setProperty("height", `calc( 100% - ${sectionContainerHeaderULElementHeight + contentContainerOffset}px )`);
9576
+ }
9577
+ if (typeof asideConfig.callback === "function") {
9578
+ /* 执行回调 */
9579
+ asideConfig.callback(event, this.sectionContainerHeaderULElement, this.sectionContainerULElement);
9402
9580
  }
9403
- that.$el.$content?.appendChild($deepMenuContainer);
9404
- /* 根据标题的高度来自适应内容高度,默认开启 */
9405
- /* 中间容器的偏移量,看设置的section.pops-panel-container的padding,默认0 */
9406
- let contentContainerOffset = 0;
9407
- /* 获取标题的<ul>元素的高度 */
9408
- let sectionContainerHeaderULElementHeight = popsDOMUtils.height($deepMenuHeaderUL);
9409
- $deepMenuChildMenuUL.style.setProperty("height", `calc( 100% - ${sectionContainerHeaderULElementHeight + contentContainerOffset}px )`);
9410
- },
9411
- /** 设置项的点击事件 */
9412
- setLiClickEvent() {
9413
- popsDOMUtils.on(liElement, "click", void 0, async (event) => {
9414
- if (typeof formConfig.clickCallBack === "function") {
9415
- let result = await formConfig.clickCallBack(event, formConfig);
9416
- if (result) {
9417
- return;
9418
- }
9419
- }
9420
- this.gotoDeepMenu(event, liElement);
9421
- });
9422
- },
9423
- };
9424
- PopsPanelDeepMenu.init();
9425
- liElement["data-deepMenu"] = PopsPanelDeepMenu;
9426
- return liElement;
9427
- },
9428
- /**
9429
- * 获取中间容器的元素<li>
9430
- * type ===> own
9431
- * @param formConfig
9432
- */
9433
- getSectionContainerItem_own(formConfig) {
9434
- let liElement = document.createElement("li");
9435
- liElement["__formConfig__"] = formConfig;
9436
- if (formConfig.className) {
9437
- liElement.className = formConfig.className;
9438
- }
9439
- liElement = formConfig.getLiElementCallBack(liElement);
9440
- return liElement;
9441
- },
9442
- /**
9443
- * 获取中间容器的元素<li>
9444
- * @param formConfig
9445
- */
9446
- getSectionContainerItem(formConfig) {
9447
- /** 配置项的类型 */
9448
- let formType = formConfig["type"];
9449
- if (formType === "switch") {
9450
- return this.getSectionContainerItem_switch(formConfig);
9451
- }
9452
- else if (formType === "slider") {
9453
- return this.getSectionContainerItem_slider_new(formConfig);
9454
- }
9455
- else if (formType === "input") {
9456
- return this.getSectionContainerItem_input(formConfig);
9457
- }
9458
- else if (formType === "textarea") {
9459
- return this.getSectionContainerItem_textarea(formConfig);
9460
- }
9461
- else if (formType === "select") {
9462
- return this.getSectionContainerItem_select(formConfig);
9463
- }
9464
- else if (formType === "select-multiple") {
9465
- return this.getSectionContainerItem_select_multiple_new(formConfig);
9466
- }
9467
- else if (formType === "button") {
9468
- return this.getSectionContainerItem_button(formConfig);
9469
- }
9470
- else if (formType === "deepMenu") {
9471
- return this.getSectionContainerItem_deepMenu(formConfig);
9472
- }
9473
- else if (formType === "own") {
9474
- return this.getSectionContainerItem_own(formConfig);
9475
- }
9476
- else {
9477
- console.error("尚未实现的type类型", formConfig);
9478
- }
9479
- },
9480
- /**
9481
- * 生成配置每一项的元素
9482
- * @param formConfig
9483
- */
9484
- initFormItem(formConfig) {
9485
- let that = this;
9486
- if (formConfig["type"] === "forms") {
9487
- let __formConfig_forms = formConfig;
9488
- let childForms = formConfig["forms"];
9489
- /* 每一项<li>元素 */
9490
- let formContainerListElement = document.createElement("li");
9491
- /* 每一项<li>内的子<ul>元素 */
9492
- let formContainerULElement = document.createElement("ul");
9493
- formContainerListElement.className = "pops-panel-forms-container-item";
9494
- /* 区域头部的文字 */
9495
- let formHeaderDivElement = popsDOMUtils.createElement("div", {
9496
- className: "pops-panel-forms-container-item-header-text",
9497
- });
9498
- formHeaderDivElement.innerHTML = __formConfig_forms["text"];
9499
- /* 加进容器内 */
9500
- formContainerListElement.appendChild(formHeaderDivElement);
9501
- if (__formConfig_forms.className) {
9502
- popsDOMUtils.addClassName(formContainerListElement, __formConfig_forms.className);
9503
- }
9504
- that.addElementAttributes(formContainerListElement, formConfig.attributes);
9505
- that.setElementProps(formContainerListElement, formConfig.props);
9506
- childForms.forEach((childFormConfig) => {
9507
- that.uListContainerAddItem(childFormConfig, {
9508
- ulElement: formContainerULElement,
9509
- sectionContainerULElement: that.sectionContainerULElement,
9510
- formContainerListElement: formContainerListElement,
9511
- formHeaderDivElement: formHeaderDivElement,
9512
- });
9513
- });
9514
- formContainerListElement.appendChild(formContainerULElement);
9515
- that.sectionContainerULElement.appendChild(formContainerListElement);
9516
- }
9517
- else {
9518
- /* 如果成功创建,加入到中间容器中 */
9519
- that.uListContainerAddItem(formConfig, {
9520
- ulElement: that.sectionContainerULElement,
9521
- });
9522
- }
9523
- },
9524
- /**
9525
- *
9526
- * @param formConfig
9527
- * @param containerOptions
9528
- */
9529
- uListContainerAddItem(formConfig, containerOptions) {
9530
- let itemLiElement = this.getSectionContainerItem(formConfig);
9531
- if (itemLiElement) {
9532
- containerOptions["ulElement"].appendChild(itemLiElement);
9533
- }
9534
- if (typeof formConfig.afterAddToUListCallBack === "function") {
9535
- formConfig.afterAddToUListCallBack(formConfig, containerOptions);
9536
- }
9537
- },
9538
- /**
9539
- * 为左侧容器元素添加点击事件
9540
- * @param asideLiElement 左侧的容器<li>元素
9541
- * @param asideConfig 配置
9542
- */
9543
- setAsideItemClickEvent(asideLiElement, asideConfig) {
9544
- const that = this;
9545
- popsDOMUtils.on(asideLiElement, "click", void 0, (event) => {
9546
- this.clearContainer();
9547
- popsDOMUtils.cssShow(that.$el.$contentSectionContainer);
9548
- this.clearAsideItemIsVisited();
9549
- this.setAsideItemIsVisited(asideLiElement);
9550
- /* 顶部标题栏,存在就设置 */
9551
- let headerTitleText = asideConfig.headerTitle ?? asideConfig.title;
9552
- if (typeof headerTitleText === "string" &&
9553
- headerTitleText.trim() !== "") {
9554
- let containerHeaderTitleLIElement = document.createElement("li");
9555
- containerHeaderTitleLIElement["__asideConfig__"] =
9556
- asideConfig;
9557
- containerHeaderTitleLIElement.innerHTML = headerTitleText;
9558
- this.sectionContainerHeaderULElement.appendChild(containerHeaderTitleLIElement);
9559
- }
9560
- let __forms__ = asideLiElement["__forms__"];
9561
- __forms__.forEach((formConfig) => {
9562
- this.initFormItem(formConfig);
9563
9581
  });
9564
- let autoAdaptionContentHeight = asideConfig.autoAdaptionContentHeight ?? true;
9565
- if (autoAdaptionContentHeight) {
9566
- /* 根据标题的高度来自适应内容高度,默认开启 */
9567
- /* 中间容器的偏移量,看设置的section.pops-panel-container的padding,默认0 */
9568
- let contentContainerOffset = asideConfig.contentContainerOffset ?? 0;
9569
- /* 获取标题的<ul>元素的高度 */
9570
- let sectionContainerHeaderULElementHeight = popsDOMUtils.height(this.sectionContainerHeaderULElement);
9571
- this.sectionContainerULElement.style.setProperty("height", `calc( 100% - ${sectionContainerHeaderULElementHeight + contentContainerOffset}px )`);
9572
- }
9573
- if (typeof asideConfig.callback === "function") {
9574
- /* 执行回调 */
9575
- asideConfig.callback(event, this.sectionContainerHeaderULElement, this.sectionContainerULElement);
9576
- }
9577
- });
9578
- },
9582
+ },
9583
+ };
9579
9584
  };
9580
9585
 
9581
9586
  class PopsPanel {
@@ -9666,10 +9671,11 @@
9666
9671
  if ($mask != null) {
9667
9672
  $anim.after($mask);
9668
9673
  }
9674
+ let panelHandleContentDetails = PanelHandleContentDetails();
9669
9675
  /**
9670
9676
  * 处理内部配置
9671
9677
  */
9672
- PanelHandleContentDetails.init({
9678
+ panelHandleContentDetails.init({
9673
9679
  config: config,
9674
9680
  $el: {
9675
9681
  $content: $content,