@whitesev/pops 3.3.3 → 3.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -5354,10 +5354,13 @@
5354
5354
  </div>`);
5355
5355
  // 存储原来的值
5356
5356
  Reflect.set($fileName, "__value__", folderData);
5357
- Reflect.set($folder, "folderData", folderData);
5357
+ Reflect.set($folder, "__value__", folderData);
5358
5358
  $folder.appendChild($fileName);
5359
5359
  return {
5360
5360
  folderElement: $folder,
5361
+ /**
5362
+ * 超链接标签的容器
5363
+ */
5361
5364
  fileNameElement: $fileName,
5362
5365
  };
5363
5366
  }
@@ -5446,8 +5449,17 @@
5446
5449
  },
5447
5450
  addIndexCSS: false,
5448
5451
  });
5452
+ let childConfig;
5449
5453
  if (typeof dataConfig.clickEvent === "function") {
5450
- const childConfig = await dataConfig.clickEvent(clickEvent, dataConfig);
5454
+ const result = await dataConfig.clickEvent(clickEvent, dataConfig);
5455
+ if (Array.isArray(result)) {
5456
+ childConfig = result;
5457
+ }
5458
+ }
5459
+ else if (Array.isArray(dataConfig.clickEvent)) {
5460
+ childConfig = dataConfig.clickEvent;
5461
+ }
5462
+ if (childConfig) {
5451
5463
  // 添加顶部导航的箭头
5452
5464
  folderFileListBreadcrumbPrimaryElement.appendChild(this.createHeaderArrowIcon());
5453
5465
  // 添加顶部导航的链接文字
@@ -5461,50 +5473,65 @@
5461
5473
  }
5462
5474
  loadingMask.close();
5463
5475
  }
5476
+ /**
5477
+ * 更新文件的显示的链接信息
5478
+ *
5479
+ * 这里主要用于鼠标中键或者右键触发,左键触发方式会根据mode进行处理
5480
+ * @returns 更新的文件的下载链接
5481
+ */
5482
+ updateFileLink($row, downloadInfo) {
5483
+ const downloadUrl = typeof downloadInfo?.url === "string" ? downloadInfo.url.trim() : "";
5484
+ if (downloadUrl !== "" && downloadUrl !== "null" && downloadUrl !== "undefined") {
5485
+ const $link = $row.querySelector("a");
5486
+ $link.setAttribute("href", downloadUrl);
5487
+ return downloadUrl;
5488
+ }
5489
+ }
5464
5490
  /**
5465
5491
  * 文件的点击事件 - 下载文件
5466
- * @param $target
5492
+ * @param evt 点击事件
5493
+ * @param $row 列表项
5467
5494
  * @param dataConfig
5468
5495
  */
5469
- async downloadFile(clickEvent, $row, dataConfig) {
5470
- popsDOMUtils.preventEvent(clickEvent);
5471
- const $link = $row.querySelector("a");
5496
+ async onFileClick(evt, $row, dataConfig) {
5497
+ let downloadInfo;
5472
5498
  if (typeof dataConfig.clickEvent === "function") {
5473
- const downloadInfo = await dataConfig.clickEvent(clickEvent, dataConfig);
5474
- if (downloadInfo != null &&
5475
- typeof downloadInfo === "object" &&
5476
- !Array.isArray(downloadInfo) &&
5477
- typeof downloadInfo.url === "string" &&
5478
- downloadInfo.url.trim() !== "") {
5479
- $link.setAttribute("href", downloadInfo.url);
5480
- $link.setAttribute("target", "_blank");
5481
- if (downloadInfo.autoDownload) {
5482
- if (downloadInfo.mode == null || String(downloadInfo.mode) === "") {
5483
- // 未设置mode的话默认为aBlank
5484
- downloadInfo.mode = "aBlank";
5485
- }
5499
+ const result = await dataConfig.clickEvent(evt, dataConfig);
5500
+ if (typeof result === "object" && result != null && !Array.isArray(result)) {
5501
+ downloadInfo = result;
5502
+ }
5503
+ }
5504
+ else if (typeof dataConfig.clickEvent === "object" &&
5505
+ dataConfig.clickEvent != null &&
5506
+ !Array.isArray(dataConfig.clickEvent)) {
5507
+ downloadInfo = dataConfig.clickEvent;
5508
+ }
5509
+ if (downloadInfo) {
5510
+ const downloadUrl = this.updateFileLink($row, downloadInfo);
5511
+ if (downloadUrl) {
5512
+ if (typeof downloadInfo.mode === "string") {
5486
5513
  if (downloadInfo.mode === "a" || downloadInfo.mode === "aBlank") {
5487
5514
  // a标签下载
5488
5515
  const $anchor = popsDOMUtils.createElement("a");
5489
5516
  if (downloadInfo.mode === "aBlank") {
5490
5517
  $anchor.setAttribute("target", "_blank");
5491
5518
  }
5492
- $anchor.href = downloadInfo.url;
5519
+ $anchor.href = downloadUrl;
5493
5520
  $anchor.click();
5494
5521
  }
5495
5522
  else if (downloadInfo.mode === "open" || downloadInfo.mode === "openBlank") {
5496
5523
  // window.open下载
5497
5524
  if (downloadInfo.mode === "openBlank") {
5498
- globalThis.open(downloadInfo.url, "_blank");
5525
+ globalThis.open(downloadUrl, "_blank");
5499
5526
  }
5500
5527
  else {
5501
- globalThis.open(downloadInfo.url);
5528
+ globalThis.open(downloadUrl);
5502
5529
  }
5503
5530
  }
5504
5531
  else if (downloadInfo.mode === "iframe") {
5505
5532
  // iframe下载
5506
5533
  const $downloadIframe = popsDOMUtils.createElement("iframe");
5507
- $downloadIframe.src = downloadInfo.url;
5534
+ $downloadIframe.src = downloadUrl;
5508
5535
  $downloadIframe.onload = function () {
5509
5536
  popsUtils.setTimeout(() => {
5510
5537
  $downloadIframe.remove();
@@ -5686,8 +5713,14 @@
5686
5713
  // 文件 - 点击事件
5687
5714
  popsDOMUtils.on(fileNameElement, "click", (event) => {
5688
5715
  // 下载文件
5689
- this.downloadFile(event, fileNameElement, item);
5716
+ popsDOMUtils.preventEvent(event);
5717
+ this.onFileClick(event, fileNameElement, item);
5690
5718
  });
5719
+ // 如果clickEvent不是函数,那么现在就可以进行配置
5720
+ if (typeof item.clickEvent === "object" && item.clickEvent !== null && !Array.isArray(item.clickEvent)) {
5721
+ // {} 单文件配置
5722
+ this.updateFileLink(fileNameElement, item.clickEvent);
5723
+ }
5691
5724
  folderListBodyElement.appendChild(folderElement);
5692
5725
  }
5693
5726
  });
@@ -13372,7 +13405,7 @@
13372
13405
  },
13373
13406
  };
13374
13407
 
13375
- const version = "3.3.3";
13408
+ const version = "3.3.4";
13376
13409
 
13377
13410
  class Pops {
13378
13411
  /** 配置 */