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