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