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