@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.esm.js CHANGED
@@ -5348,10 +5348,13 @@ const PopsFolder = {
5348
5348
  </div>`);
5349
5349
  // 存储原来的值
5350
5350
  Reflect.set($fileName, "__value__", folderData);
5351
- Reflect.set($folder, "folderData", folderData);
5351
+ Reflect.set($folder, "__value__", folderData);
5352
5352
  $folder.appendChild($fileName);
5353
5353
  return {
5354
5354
  folderElement: $folder,
5355
+ /**
5356
+ * 超链接标签的容器
5357
+ */
5355
5358
  fileNameElement: $fileName,
5356
5359
  };
5357
5360
  }
@@ -5440,8 +5443,17 @@ const PopsFolder = {
5440
5443
  },
5441
5444
  addIndexCSS: false,
5442
5445
  });
5446
+ let childConfig;
5443
5447
  if (typeof dataConfig.clickEvent === "function") {
5444
- const childConfig = await dataConfig.clickEvent(clickEvent, dataConfig);
5448
+ const result = await dataConfig.clickEvent(clickEvent, dataConfig);
5449
+ if (Array.isArray(result)) {
5450
+ childConfig = result;
5451
+ }
5452
+ }
5453
+ else if (Array.isArray(dataConfig.clickEvent)) {
5454
+ childConfig = dataConfig.clickEvent;
5455
+ }
5456
+ if (childConfig) {
5445
5457
  // 添加顶部导航的箭头
5446
5458
  folderFileListBreadcrumbPrimaryElement.appendChild(this.createHeaderArrowIcon());
5447
5459
  // 添加顶部导航的链接文字
@@ -5455,50 +5467,65 @@ const PopsFolder = {
5455
5467
  }
5456
5468
  loadingMask.close();
5457
5469
  }
5470
+ /**
5471
+ * 更新文件的显示的链接信息
5472
+ *
5473
+ * 这里主要用于鼠标中键或者右键触发,左键触发方式会根据mode进行处理
5474
+ * @returns 更新的文件的下载链接
5475
+ */
5476
+ updateFileLink($row, downloadInfo) {
5477
+ const downloadUrl = typeof downloadInfo?.url === "string" ? downloadInfo.url.trim() : "";
5478
+ if (downloadUrl !== "" && downloadUrl !== "null" && downloadUrl !== "undefined") {
5479
+ const $link = $row.querySelector("a");
5480
+ $link.setAttribute("href", downloadUrl);
5481
+ return downloadUrl;
5482
+ }
5483
+ }
5458
5484
  /**
5459
5485
  * 文件的点击事件 - 下载文件
5460
- * @param $target
5486
+ * @param evt 点击事件
5487
+ * @param $row 列表项
5461
5488
  * @param dataConfig
5462
5489
  */
5463
- async downloadFile(clickEvent, $row, dataConfig) {
5464
- popsDOMUtils.preventEvent(clickEvent);
5465
- const $link = $row.querySelector("a");
5490
+ async onFileClick(evt, $row, dataConfig) {
5491
+ let downloadInfo;
5466
5492
  if (typeof dataConfig.clickEvent === "function") {
5467
- const downloadInfo = await dataConfig.clickEvent(clickEvent, dataConfig);
5468
- if (downloadInfo != null &&
5469
- typeof downloadInfo === "object" &&
5470
- !Array.isArray(downloadInfo) &&
5471
- typeof downloadInfo.url === "string" &&
5472
- downloadInfo.url.trim() !== "") {
5473
- $link.setAttribute("href", downloadInfo.url);
5474
- $link.setAttribute("target", "_blank");
5475
- if (downloadInfo.autoDownload) {
5476
- if (downloadInfo.mode == null || String(downloadInfo.mode) === "") {
5477
- // 未设置mode的话默认为aBlank
5478
- downloadInfo.mode = "aBlank";
5479
- }
5493
+ const result = await dataConfig.clickEvent(evt, dataConfig);
5494
+ if (typeof result === "object" && result != null && !Array.isArray(result)) {
5495
+ downloadInfo = result;
5496
+ }
5497
+ }
5498
+ else if (typeof dataConfig.clickEvent === "object" &&
5499
+ dataConfig.clickEvent != null &&
5500
+ !Array.isArray(dataConfig.clickEvent)) {
5501
+ downloadInfo = dataConfig.clickEvent;
5502
+ }
5503
+ if (downloadInfo) {
5504
+ const downloadUrl = this.updateFileLink($row, downloadInfo);
5505
+ if (downloadUrl) {
5506
+ if (typeof downloadInfo.mode === "string") {
5480
5507
  if (downloadInfo.mode === "a" || downloadInfo.mode === "aBlank") {
5481
5508
  // a标签下载
5482
5509
  const $anchor = popsDOMUtils.createElement("a");
5483
5510
  if (downloadInfo.mode === "aBlank") {
5484
5511
  $anchor.setAttribute("target", "_blank");
5485
5512
  }
5486
- $anchor.href = downloadInfo.url;
5513
+ $anchor.href = downloadUrl;
5487
5514
  $anchor.click();
5488
5515
  }
5489
5516
  else if (downloadInfo.mode === "open" || downloadInfo.mode === "openBlank") {
5490
5517
  // window.open下载
5491
5518
  if (downloadInfo.mode === "openBlank") {
5492
- globalThis.open(downloadInfo.url, "_blank");
5519
+ globalThis.open(downloadUrl, "_blank");
5493
5520
  }
5494
5521
  else {
5495
- globalThis.open(downloadInfo.url);
5522
+ globalThis.open(downloadUrl);
5496
5523
  }
5497
5524
  }
5498
5525
  else if (downloadInfo.mode === "iframe") {
5499
5526
  // iframe下载
5500
5527
  const $downloadIframe = popsDOMUtils.createElement("iframe");
5501
- $downloadIframe.src = downloadInfo.url;
5528
+ $downloadIframe.src = downloadUrl;
5502
5529
  $downloadIframe.onload = function () {
5503
5530
  popsUtils.setTimeout(() => {
5504
5531
  $downloadIframe.remove();
@@ -5680,8 +5707,14 @@ const PopsFolder = {
5680
5707
  // 文件 - 点击事件
5681
5708
  popsDOMUtils.on(fileNameElement, "click", (event) => {
5682
5709
  // 下载文件
5683
- this.downloadFile(event, fileNameElement, item);
5710
+ popsDOMUtils.preventEvent(event);
5711
+ this.onFileClick(event, fileNameElement, item);
5684
5712
  });
5713
+ // 如果clickEvent不是函数,那么现在就可以进行配置
5714
+ if (typeof item.clickEvent === "object" && item.clickEvent !== null && !Array.isArray(item.clickEvent)) {
5715
+ // {} 单文件配置
5716
+ this.updateFileLink(fileNameElement, item.clickEvent);
5717
+ }
5685
5718
  folderListBodyElement.appendChild(folderElement);
5686
5719
  }
5687
5720
  });
@@ -13366,7 +13399,7 @@ const PopsSearchSuggestion = {
13366
13399
  },
13367
13400
  };
13368
13401
 
13369
- const version = "3.3.3";
13402
+ const version = "3.3.4";
13370
13403
 
13371
13404
  class Pops {
13372
13405
  /** 配置 */