@sl-material/sl-import 1.0.0-beta20 → 1.0.0

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/sl-import.es.js CHANGED
@@ -2633,15 +2633,31 @@ class ImportDialogRenderer {
2633
2633
  `;
2634
2634
  }
2635
2635
  renderDownloadSection() {
2636
- return `
2637
- <div class="import-dialog-vanilla-section">
2638
- <div class="import-dialog-vanilla-section-title">${t("downloadTemplateTitle")}</div>
2639
- <a id="import-dialog-download-btn" class="import-dialog-vanilla-btn download-template-btn import-dialog-vanilla-btn-primary" href="${this.context.currentConfig.templateUrl}">
2640
- <i class="iconfont icon-xiazai"></i>
2641
- ${t("downloadTemplateText")}
2642
- </a>
2643
- </div>
2644
- `;
2636
+ const hasTemplateUrl = !!this.context.currentConfig.templateUrl;
2637
+ const hasDownloadCallback = !!this.context.modalOptions.onDownloadTemplate;
2638
+ if (hasDownloadCallback) {
2639
+ return `
2640
+ <div class="import-dialog-vanilla-section">
2641
+ <div class="import-dialog-vanilla-section-title">${t("downloadTemplateTitle")}</div>
2642
+ <button id="import-dialog-download-btn" class="import-dialog-vanilla-btn download-template-btn import-dialog-vanilla-btn-primary">
2643
+ <i class="iconfont icon-xiazai"></i>
2644
+ ${t("downloadTemplateText")}
2645
+ </button>
2646
+ </div>
2647
+ `;
2648
+ } else if (hasTemplateUrl) {
2649
+ return `
2650
+ <div class="import-dialog-vanilla-section">
2651
+ <div class="import-dialog-vanilla-section-title">${t("downloadTemplateTitle")}</div>
2652
+ <a id="import-dialog-download-btn" class="import-dialog-vanilla-btn download-template-btn import-dialog-vanilla-btn-primary" href="${this.context.currentConfig.templateUrl}">
2653
+ <i class="iconfont icon-xiazai"></i>
2654
+ ${t("downloadTemplateText")}
2655
+ </a>
2656
+ </div>
2657
+ `;
2658
+ } else {
2659
+ return "";
2660
+ }
2645
2661
  }
2646
2662
  renderSettingSection() {
2647
2663
  const config = this.context.currentConfig;
@@ -3599,6 +3615,7 @@ const _ImportDialog = class _ImportDialog {
3599
3615
  var _a, _b;
3600
3616
  return {
3601
3617
  currentConfig: this.currentConfig,
3618
+ modalOptions: this.modalOptions,
3602
3619
  dialogTitle: this.dialogTitle,
3603
3620
  width: this.dialogWidth,
3604
3621
  activeTabIndex: this.activeTabIndex,
@@ -3782,6 +3799,13 @@ const _ImportDialog = class _ImportDialog {
3782
3799
  "#import-dialog-cancel-btn"
3783
3800
  );
3784
3801
  cancelBtn == null ? void 0 : cancelBtn.addEventListener("click", () => this.handleCancel());
3802
+ const downloadBtn = this.modalElement.querySelector(
3803
+ "#import-dialog-download-btn"
3804
+ );
3805
+ downloadBtn == null ? void 0 : downloadBtn.addEventListener("click", (e) => {
3806
+ e.preventDefault();
3807
+ this.handleDownloadTemplate();
3808
+ });
3785
3809
  }
3786
3810
  bindFormEvents() {
3787
3811
  if (!this.modalElement) return;
@@ -4042,6 +4066,25 @@ const _ImportDialog = class _ImportDialog {
4042
4066
  closeModal() {
4043
4067
  this.handleCancel();
4044
4068
  }
4069
+ /**
4070
+ * 处理下载模板
4071
+ */
4072
+ handleDownloadTemplate() {
4073
+ var _a;
4074
+ if (this.modalOptions.onDownloadTemplate) {
4075
+ this.modalOptions.onDownloadTemplate({
4076
+ url: this.currentConfig.templateUrl || "",
4077
+ activeTab: (_a = this.modalOptions.tabs) == null ? void 0 : _a[this.activeTabIndex]
4078
+ });
4079
+ } else if (this.currentConfig.templateUrl) {
4080
+ const link = document.createElement("a");
4081
+ link.href = this.currentConfig.templateUrl;
4082
+ link.download = "";
4083
+ document.body.appendChild(link);
4084
+ link.click();
4085
+ document.body.removeChild(link);
4086
+ }
4087
+ }
4045
4088
  setConfirmLoading(loading) {
4046
4089
  this.confirmLoading = loading;
4047
4090
  this.updateModal();