@whitesev/pops 1.6.3 → 1.6.4

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