@whitesev/pops 2.3.6 → 2.3.7

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
@@ -1158,6 +1158,7 @@
1158
1158
  * })
1159
1159
  */
1160
1160
  ready(callback) {
1161
+ const that = this;
1161
1162
  if (typeof callback !== "function") {
1162
1163
  return;
1163
1164
  }
@@ -1203,7 +1204,7 @@
1203
1204
  function addDomReadyListener() {
1204
1205
  for (let index = 0; index < targetList.length; index++) {
1205
1206
  let item = targetList[index];
1206
- item.target.addEventListener(item.eventType, item.callback);
1207
+ that.on(item.target, item.eventType, item.callback);
1207
1208
  }
1208
1209
  }
1209
1210
  /**
@@ -1212,7 +1213,7 @@
1212
1213
  function removeDomReadyListener() {
1213
1214
  for (let index = 0; index < targetList.length; index++) {
1214
1215
  let item = targetList[index];
1215
- item.target.removeEventListener(item.eventType, item.callback);
1216
+ that.off(item.target, item.eventType, item.callback);
1216
1217
  }
1217
1218
  }
1218
1219
  if (checkDOMReadyState()) {
@@ -1494,9 +1495,7 @@
1494
1495
  eventNameList = [eventNameList];
1495
1496
  }
1496
1497
  eventNameList.forEach((eventName) => {
1497
- element.addEventListener(eventName, stopEvent, {
1498
- capture: Boolean(capture),
1499
- });
1498
+ this.on(element, eventName, stopEvent, { capture: Boolean(capture) });
1500
1499
  });
1501
1500
  }
1502
1501
  }
@@ -5145,57 +5144,101 @@
5145
5144
  if ($mask != null) {
5146
5145
  $anim.after($mask);
5147
5146
  }
5148
- /* 添加文件信息 */
5149
- config.folder.sort();
5150
- /**
5151
- * 创建文件夹元素
5152
- * @param fileName
5153
- * @param latestTime
5154
- * @param [fileSize="-"]
5155
- * @param isFolder
5156
- */
5157
- function createFolderRowElement(fileName, latestTime = "-", fileSize = "-", isFolder = false) {
5158
- let origin_fileName = fileName;
5159
- let origin_latestTime = latestTime;
5160
- let origin_fileSize = fileSize;
5161
- let folderELement = popsDOMUtils.createElement("tr");
5162
- let fileNameElement = popsDOMUtils.createElement("td");
5163
- let fileTimeElement = popsDOMUtils.createElement("td");
5164
- let fileFormatSize = popsDOMUtils.createElement("td");
5165
- let fileType = "";
5166
- let fileIcon = Folder_ICON.folder;
5167
- if (isFolder) {
5168
- /* 文件夹 */
5169
- latestTime = "";
5170
- fileSize = "";
5171
- }
5172
- else {
5173
- /* 文件 */
5174
- fileIcon = "";
5175
- if (typeof latestTime === "number") {
5176
- latestTime = popsUtils.formatTime(latestTime);
5177
- }
5178
- if (typeof fileSize === "number") {
5179
- fileSize = popsUtils.formatByteToSize(fileSize);
5180
- }
5181
- for (let keyName in Folder_ICON) {
5182
- if (fileName.toLowerCase().endsWith("." + keyName)) {
5183
- fileType = keyName;
5184
- fileIcon = Folder_ICON[keyName];
5185
- break;
5186
- }
5147
+ class PopsFolder {
5148
+ init() {
5149
+ config.folder.sort();
5150
+ this.initFolderView(config.folder);
5151
+ /* 将数据存到全部文件的属性_config_中 */
5152
+ let allFilesElement = folderFileListBreadcrumbPrimaryElement.querySelector(".pops-folder-list .pops-folder-file-list-breadcrumb-allFiles:first-child");
5153
+ Reflect.set(allFilesElement, "_config_", config.folder);
5154
+ /* 设置点击顶部的全部文件事件 */
5155
+ popsDOMUtils.on(allFilesElement, "click", (event) => {
5156
+ this.setBreadcrumbClickEvent(event, true, config.folder);
5157
+ });
5158
+ // 文件名的点击排序
5159
+ popsDOMUtils.on(folderListSortFileNameElement.closest("th"), "click", (event) => {
5160
+ this.arrowToSortFolderInfoView(folderListSortFileNameElement, event, "fileName");
5161
+ }, {
5162
+ capture: true,
5163
+ });
5164
+ // 修改事件的点击排序
5165
+ popsDOMUtils.on(folderListSortLatestTimeElement.closest("th"), "click", (event) => {
5166
+ this.arrowToSortFolderInfoView(folderListSortLatestTimeElement, event, "latestTime");
5167
+ }, {
5168
+ capture: true,
5169
+ });
5170
+ // 文件大小的点击排序
5171
+ popsDOMUtils.on(folderListSortFileSizeElement.closest("th"), "click", (event) => {
5172
+ this.arrowToSortFolderInfoView(folderListSortFileSizeElement, event, "fileSize");
5173
+ }, {
5174
+ capture: true,
5175
+ });
5176
+ /* 设置默认触发的arrow */
5177
+ if (config.sort.name === "fileName") {
5178
+ popsDOMUtils.trigger(folderListSortFileNameElement, "click", {
5179
+ notChangeSortRule: true,
5180
+ });
5187
5181
  }
5188
- if (!Boolean(fileIcon)) {
5189
- fileType = "Null";
5190
- fileIcon = Folder_ICON.Null;
5182
+ else if (config.sort.name === "latestTime") {
5183
+ popsDOMUtils.trigger(folderListSortLatestTimeElement, "click", {
5184
+ notChangeSortRule: true,
5185
+ });
5186
+ }
5187
+ else if (config.sort.name === "fileSize") {
5188
+ popsDOMUtils.trigger(folderListSortFileSizeElement, "click", {
5189
+ notChangeSortRule: true,
5190
+ });
5191
5191
  }
5192
5192
  }
5193
- folderELement.className = "pops-folder-list-table__body-row";
5194
- fileNameElement.className = "pops-folder-list-table__body-td";
5195
- fileTimeElement.className = "pops-folder-list-table__body-td";
5196
- fileFormatSize.className = "pops-folder-list-table__body-td";
5197
- PopsSafeUtils.setSafeHTML(fileNameElement,
5198
- /*html*/ `
5193
+ /**
5194
+ * 创建文件夹元素
5195
+ * @param fileName 文件名
5196
+ * @param latestTime 修改时间
5197
+ * @param [fileSize="-"] 文件大小
5198
+ * @param isFolder 是否是文件夹
5199
+ */
5200
+ createFolderRowElement(fileName, latestTime = "-", fileSize = "-", isFolder = false) {
5201
+ let origin_fileName = fileName;
5202
+ let origin_latestTime = latestTime;
5203
+ let origin_fileSize = fileSize;
5204
+ let folderElement = popsDOMUtils.createElement("tr");
5205
+ let fileNameElement = popsDOMUtils.createElement("td");
5206
+ let fileTimeElement = popsDOMUtils.createElement("td");
5207
+ let fileFormatSize = popsDOMUtils.createElement("td");
5208
+ let fileType = "";
5209
+ let fileIcon = Folder_ICON.folder;
5210
+ if (isFolder) {
5211
+ /* 文件夹 */
5212
+ latestTime = "";
5213
+ fileSize = "";
5214
+ }
5215
+ else {
5216
+ /* 文件 */
5217
+ fileIcon = "";
5218
+ if (typeof latestTime === "number") {
5219
+ latestTime = popsUtils.formatTime(latestTime);
5220
+ }
5221
+ if (typeof fileSize === "number") {
5222
+ fileSize = popsUtils.formatByteToSize(fileSize);
5223
+ }
5224
+ for (let keyName in Folder_ICON) {
5225
+ if (fileName.toLowerCase().endsWith("." + keyName)) {
5226
+ fileType = keyName;
5227
+ fileIcon = Folder_ICON[keyName];
5228
+ break;
5229
+ }
5230
+ }
5231
+ if (!Boolean(fileIcon)) {
5232
+ fileType = "Null";
5233
+ fileIcon = Folder_ICON.Null;
5234
+ }
5235
+ }
5236
+ folderElement.className = "pops-folder-list-table__body-row";
5237
+ fileNameElement.className = "pops-folder-list-table__body-td";
5238
+ fileTimeElement.className = "pops-folder-list-table__body-td";
5239
+ fileFormatSize.className = "pops-folder-list-table__body-td";
5240
+ PopsSafeUtils.setSafeHTML(fileNameElement,
5241
+ /*html*/ `
5199
5242
  <div class="pops-folder-list-file-name cursor-p">
5200
5243
  <div>
5201
5244
  <img src="${fileIcon}" alt="${fileType}" class="pops-folder-list-file-icon u-file-icon u-file-icon--list">
@@ -5205,80 +5248,84 @@
5205
5248
  </div>
5206
5249
  </div>
5207
5250
  `);
5208
- PopsSafeUtils.setSafeHTML(fileTimeElement,
5209
- /*html*/ `
5251
+ PopsSafeUtils.setSafeHTML(fileTimeElement,
5252
+ /*html*/ `
5210
5253
  <div class="pops-folder-list__time">
5211
5254
  <span>${latestTime}</span>
5212
5255
  </div>
5213
5256
  `);
5214
- PopsSafeUtils.setSafeHTML(fileFormatSize,
5215
- /*html*/ `
5257
+ PopsSafeUtils.setSafeHTML(fileFormatSize,
5258
+ /*html*/ `
5216
5259
  <div class="pops-folder-list-format-size">
5217
5260
  <span>${fileSize}</span>
5218
5261
  </div>
5219
5262
  `);
5220
- /* 存储原来的值 */
5221
- let __value__ = {
5222
- fileName: origin_fileName,
5223
- latestTime: origin_latestTime,
5224
- fileSize: origin_fileSize,
5225
- isFolder: isFolder,
5226
- };
5227
- Reflect.set(fileNameElement, "__value__", __value__);
5228
- Reflect.set(fileTimeElement, "__value__", __value__);
5229
- Reflect.set(fileFormatSize, "__value__", __value__);
5230
- Reflect.set(folderELement, "__value__", __value__);
5231
- folderELement.appendChild(fileNameElement);
5232
- folderELement.appendChild(fileTimeElement);
5233
- folderELement.appendChild(fileFormatSize);
5234
- return {
5235
- folderELement,
5236
- fileNameElement,
5237
- fileTimeElement,
5238
- fileFormatSize,
5239
- };
5240
- }
5241
- /**
5242
- * 创建移动端文件夹元素
5243
- */
5244
- function createMobileFolderRowElement(fileName, latestTime = "-", fileSize = "-", isFolder = false) {
5245
- let origin_fileName = fileName;
5246
- let origin_latestTime = latestTime;
5247
- let origin_fileSize = fileSize;
5248
- let folderELement = popsDOMUtils.createElement("tr");
5249
- let fileNameElement = popsDOMUtils.createElement("td");
5250
- let fileType = "";
5251
- let fileIcon = Folder_ICON.folder;
5252
- if (isFolder) {
5253
- /* 文件夹 */
5254
- latestTime = "";
5255
- fileSize = "";
5263
+ /* 存储原来的值 */
5264
+ let __value__ = {
5265
+ fileName: origin_fileName,
5266
+ latestTime: origin_latestTime,
5267
+ fileSize: origin_fileSize,
5268
+ isFolder: isFolder,
5269
+ };
5270
+ Reflect.set(fileNameElement, "__value__", __value__);
5271
+ Reflect.set(fileTimeElement, "__value__", __value__);
5272
+ Reflect.set(fileFormatSize, "__value__", __value__);
5273
+ Reflect.set(folderElement, "__value__", __value__);
5274
+ folderElement.appendChild(fileNameElement);
5275
+ folderElement.appendChild(fileTimeElement);
5276
+ folderElement.appendChild(fileFormatSize);
5277
+ return {
5278
+ folderElement,
5279
+ fileNameElement,
5280
+ fileTimeElement,
5281
+ fileFormatSize,
5282
+ };
5256
5283
  }
5257
- else {
5258
- /* 文件 */
5259
- fileIcon = "";
5260
- if (typeof latestTime === "number") {
5261
- latestTime = popsUtils.formatTime(latestTime);
5262
- }
5263
- if (typeof fileSize === "number") {
5264
- fileSize = popsUtils.formatByteToSize(fileSize);
5265
- }
5266
- for (let keyName in Folder_ICON) {
5267
- if (fileName.toLowerCase().endsWith("." + keyName)) {
5268
- fileType = keyName;
5269
- fileIcon = Folder_ICON[keyName];
5270
- break;
5271
- }
5284
+ /**
5285
+ * 创建移动端文件夹元素
5286
+ * @param fileName 文件名
5287
+ * @param latestTime 创建时间
5288
+ * @param [fileSize="-"] 文件大小
5289
+ * @param isFolder 是否是文件夹
5290
+ */
5291
+ createFolderRowElementByMobile(fileName, latestTime = "-", fileSize = "-", isFolder = false) {
5292
+ let origin_fileName = fileName;
5293
+ let origin_latestTime = latestTime;
5294
+ let origin_fileSize = fileSize;
5295
+ let folderElement = popsDOMUtils.createElement("tr");
5296
+ let fileNameElement = popsDOMUtils.createElement("td");
5297
+ let fileType = "";
5298
+ let fileIcon = Folder_ICON.folder;
5299
+ if (isFolder) {
5300
+ /* 文件夹 */
5301
+ latestTime = "";
5302
+ fileSize = "";
5272
5303
  }
5273
- if (!Boolean(fileIcon)) {
5274
- fileType = "Null";
5275
- fileIcon = Folder_ICON.Null;
5304
+ else {
5305
+ /* 文件 */
5306
+ fileIcon = "";
5307
+ if (typeof latestTime === "number") {
5308
+ latestTime = popsUtils.formatTime(latestTime);
5309
+ }
5310
+ if (typeof fileSize === "number") {
5311
+ fileSize = popsUtils.formatByteToSize(fileSize);
5312
+ }
5313
+ for (let keyName in Folder_ICON) {
5314
+ if (fileName.toLowerCase().endsWith("." + keyName)) {
5315
+ fileType = keyName;
5316
+ fileIcon = Folder_ICON[keyName];
5317
+ break;
5318
+ }
5319
+ }
5320
+ if (!Boolean(fileIcon)) {
5321
+ fileType = "Null";
5322
+ fileIcon = Folder_ICON.Null;
5323
+ }
5276
5324
  }
5277
- }
5278
- folderELement.className = "pops-folder-list-table__body-row";
5279
- fileNameElement.className = "pops-folder-list-table__body-td";
5280
- PopsSafeUtils.setSafeHTML(fileNameElement,
5281
- /*html*/ `
5325
+ folderElement.className = "pops-folder-list-table__body-row";
5326
+ fileNameElement.className = "pops-folder-list-table__body-td";
5327
+ PopsSafeUtils.setSafeHTML(fileNameElement,
5328
+ /*html*/ `
5282
5329
  <div class="pops-folder-list-file-name pops-mobile-folder-list-file-name cursor-p">
5283
5330
  <img src="${fileIcon}" alt="${fileType}" class="pops-folder-list-file-icon u-file-icon u-file-icon--list">
5284
5331
  <div>
@@ -5287,139 +5334,138 @@
5287
5334
  </div>
5288
5335
  </div>
5289
5336
  `);
5290
- /* 存储原来的值 */
5291
- let __value__ = {
5292
- fileName: origin_fileName,
5293
- latestTime: origin_latestTime,
5294
- fileSize: origin_fileSize,
5295
- isFolder: isFolder,
5296
- };
5297
- Reflect.set(fileNameElement, "__value__", __value__);
5298
- Reflect.set(folderELement, "__value__", __value__);
5299
- folderELement.appendChild(fileNameElement);
5300
- return {
5301
- folderELement,
5302
- fileNameElement,
5303
- };
5304
- }
5305
- /**
5306
- * 清空每行的元素
5307
- */
5308
- function clearFolderRow() {
5309
- PopsSafeUtils.setSafeHTML(folderListBodyElement, "");
5310
- }
5311
- /**
5312
- * 创建顶部导航的箭头图标
5313
- */
5314
- function createHeaderArrowIcon() {
5315
- let iconArrowElement = popsDOMUtils.createElement("div", {
5316
- className: "iconArrow",
5317
- });
5318
- return iconArrowElement;
5319
- }
5320
- /**
5321
- * 添加顶部导航
5322
- * @param folderName 文件夹名
5323
- * @param folderDataConfig 文件夹配置
5324
- */
5325
- function createHeaderFileLinkNavgiation(folderName, folderDataConfig) {
5326
- let spanElement = popsDOMUtils.createElement("span", {
5327
- className: "pops-folder-file-list-breadcrumb-allFiles cursor-p",
5328
- innerHTML: `<a>${folderName}</a>`,
5329
- _config_: folderDataConfig,
5330
- }, {
5331
- title: folderName,
5332
- });
5333
- return spanElement;
5334
- }
5335
- /**
5336
- * 顶部导航的点击事件
5337
- * @param event
5338
- * @param isTop 是否是全部文件按钮
5339
- * @param folderDataConfigList 配置
5340
- */
5341
- function breadcrumbAllFilesElementClickEvent(event, isTop, folderDataConfigList) {
5342
- clearFolderRow();
5343
- /* 获取当前的导航元素 */
5344
- let $click = event.target;
5345
- let currentBreadcrumb = $click.closest("span.pops-folder-file-list-breadcrumb-allFiles");
5346
- if (currentBreadcrumb) {
5347
- while (currentBreadcrumb.nextElementSibling) {
5348
- currentBreadcrumb.nextElementSibling.remove();
5337
+ /* 存储原来的值 */
5338
+ let __value__ = {
5339
+ fileName: origin_fileName,
5340
+ latestTime: origin_latestTime,
5341
+ fileSize: origin_fileSize,
5342
+ isFolder: isFolder,
5343
+ };
5344
+ Reflect.set(fileNameElement, "__value__", __value__);
5345
+ Reflect.set(folderElement, "__value__", __value__);
5346
+ folderElement.appendChild(fileNameElement);
5347
+ return {
5348
+ folderElement,
5349
+ fileNameElement,
5350
+ };
5351
+ }
5352
+ /**
5353
+ * 清空文件夹信息页面
5354
+ */
5355
+ clearFolderInfoView() {
5356
+ PopsSafeUtils.setSafeHTML(folderListBodyElement, "");
5357
+ }
5358
+ /**
5359
+ * 创建顶部导航的箭头图标
5360
+ */
5361
+ createHeaderArrowIcon() {
5362
+ let $arrowIcon = popsDOMUtils.createElement("div", {
5363
+ className: "iconArrow",
5364
+ });
5365
+ return $arrowIcon;
5366
+ }
5367
+ /**
5368
+ * 添加顶部导航元素
5369
+ * @param folderName 文件夹名
5370
+ * @param folderDataConfig 文件夹配置
5371
+ */
5372
+ createBreadcrumb(folderName, folderDataConfig) {
5373
+ let $breadcrumb = popsDOMUtils.createElement("span", {
5374
+ className: "pops-folder-file-list-breadcrumb-allFiles cursor-p",
5375
+ innerHTML: `<a>${folderName}</a>`,
5376
+ _config_: folderDataConfig,
5377
+ }, {
5378
+ title: folderName,
5379
+ });
5380
+ return $breadcrumb;
5381
+ }
5382
+ /**
5383
+ * 顶部导航的点击事件
5384
+ * @param clickEvent
5385
+ * @param isTop 是否是全部文件按钮
5386
+ * @param dataConfigList 配置
5387
+ */
5388
+ setBreadcrumbClickEvent(clickEvent, isTop, dataConfigList) {
5389
+ this.clearFolderInfoView();
5390
+ /* 获取当前的导航元素 */
5391
+ let $click = clickEvent.target;
5392
+ let currentBreadcrumb = $click.closest("span.pops-folder-file-list-breadcrumb-allFiles");
5393
+ if (currentBreadcrumb) {
5394
+ while (currentBreadcrumb.nextElementSibling) {
5395
+ currentBreadcrumb.nextElementSibling.remove();
5396
+ }
5397
+ }
5398
+ else {
5399
+ console.error("获取导航按钮失败");
5349
5400
  }
5401
+ let loadingMask = PopsLoading.init({
5402
+ parent: $content,
5403
+ content: {
5404
+ text: "获取文件列表中...",
5405
+ },
5406
+ mask: {
5407
+ enable: true,
5408
+ clickEvent: {
5409
+ toClose: false,
5410
+ toHide: false,
5411
+ },
5412
+ },
5413
+ addIndexCSS: false,
5414
+ });
5415
+ this.initFolderView(dataConfigList);
5416
+ loadingMask.close();
5350
5417
  }
5351
- else {
5352
- console.error("获取导航按钮失败");
5353
- }
5354
- let loadingMask = PopsLoading.init({
5355
- parent: $content,
5356
- content: {
5357
- text: "获取文件列表中...",
5358
- },
5359
- mask: {
5360
- enable: true,
5361
- clickEvent: {
5362
- toClose: false,
5363
- toHide: false,
5418
+ /**
5419
+ * 文件夹的点击事件 - 进入文件夹
5420
+ *
5421
+ * 先情况页面元素
5422
+ * @param clickEvent
5423
+ * @param dataConfig
5424
+ */
5425
+ async enterFolder(clickEvent, dataConfig) {
5426
+ this.clearFolderInfoView();
5427
+ let loadingMask = PopsLoading.init({
5428
+ parent: $content,
5429
+ content: {
5430
+ text: "获取文件列表中...",
5364
5431
  },
5365
- },
5366
- addIndexCSS: false,
5367
- });
5368
- addFolderElement(folderDataConfigList);
5369
- loadingMask.close();
5370
- }
5371
- /**
5372
- * 刷新文件列表界面信息
5373
- * @param event
5374
- * @param folderDataConfig
5375
- */
5376
- async function refreshFolderInfoClickEvent(event, folderDataConfig) {
5377
- clearFolderRow();
5378
- let loadingMask = PopsLoading.init({
5379
- parent: $content,
5380
- content: {
5381
- text: "获取文件列表中...",
5382
- },
5383
- mask: {
5384
- enable: true,
5385
- },
5386
- addIndexCSS: false,
5387
- });
5388
- if (typeof folderDataConfig.clickEvent === "function") {
5389
- let childConfig = await folderDataConfig.clickEvent(event, folderDataConfig);
5390
- /* 添加顶部导航的箭头 */
5391
- folderFileListBreadcrumbPrimaryElement.appendChild(createHeaderArrowIcon());
5392
- /* 添加顶部导航的链接文字 */
5393
- let breadcrumbAllFilesElement = createHeaderFileLinkNavgiation(folderDataConfig.fileName, childConfig);
5394
- folderFileListBreadcrumbPrimaryElement.appendChild(breadcrumbAllFilesElement);
5395
- /* 设置顶部导航点击事件 */
5396
- popsDOMUtils.on(breadcrumbAllFilesElement, "click", function (event) {
5397
- breadcrumbAllFilesElementClickEvent(event, false, childConfig);
5432
+ mask: {
5433
+ enable: true,
5434
+ },
5435
+ addIndexCSS: false,
5398
5436
  });
5399
- addFolderElement(childConfig);
5437
+ if (typeof dataConfig.clickEvent === "function") {
5438
+ let childConfig = await dataConfig.clickEvent(clickEvent, dataConfig);
5439
+ /* 添加顶部导航的箭头 */
5440
+ folderFileListBreadcrumbPrimaryElement.appendChild(this.createHeaderArrowIcon());
5441
+ /* 添加顶部导航的链接文字 */
5442
+ let breadcrumbAllFilesElement = this.createBreadcrumb(dataConfig.fileName, childConfig);
5443
+ folderFileListBreadcrumbPrimaryElement.appendChild(breadcrumbAllFilesElement);
5444
+ /* 设置顶部导航点击事件 */
5445
+ popsDOMUtils.on(breadcrumbAllFilesElement, "click", (event) => {
5446
+ this.setBreadcrumbClickEvent(event, false, childConfig);
5447
+ });
5448
+ this.initFolderView(childConfig);
5449
+ }
5450
+ loadingMask.close();
5400
5451
  }
5401
- loadingMask.close();
5402
- }
5403
- /**
5404
- * 设置文件点击事件
5405
- * @param targetElement
5406
- * @param _config_
5407
- */
5408
- function setFileClickEvent(targetElement, _config_) {
5409
- popsDOMUtils.on(targetElement, "click", async function (event) {
5410
- event?.preventDefault();
5411
- event?.stopPropagation();
5412
- event?.stopImmediatePropagation();
5413
- let linkElement = targetElement.querySelector("a");
5414
- if (typeof _config_.clickEvent === "function") {
5415
- let downloadInfo = await _config_.clickEvent(event, _config_);
5452
+ /**
5453
+ * 文件的点击事件 - 下载文件
5454
+ * @param $target
5455
+ * @param dataConfig
5456
+ */
5457
+ async downloadFile(clickEvent, $row, dataConfig) {
5458
+ popsDOMUtils.preventEvent(clickEvent);
5459
+ let $link = $row.querySelector("a");
5460
+ if (typeof dataConfig.clickEvent === "function") {
5461
+ let downloadInfo = await dataConfig.clickEvent(clickEvent, dataConfig);
5416
5462
  if (downloadInfo != null &&
5417
5463
  typeof downloadInfo === "object" &&
5418
5464
  !Array.isArray(downloadInfo) &&
5419
5465
  typeof downloadInfo.url === "string" &&
5420
5466
  downloadInfo.url.trim() !== "") {
5421
- linkElement.setAttribute("href", downloadInfo.url);
5422
- linkElement.setAttribute("target", "_blank");
5467
+ $link.setAttribute("href", downloadInfo.url);
5468
+ $link.setAttribute("target", "_blank");
5423
5469
  if (downloadInfo.autoDownload) {
5424
5470
  if (downloadInfo.mode == null || downloadInfo.mode === "") {
5425
5471
  /* 未设置mode的话默认为aBlank */
@@ -5463,215 +5509,190 @@
5463
5509
  }
5464
5510
  }
5465
5511
  }
5466
- });
5467
- }
5468
- /**
5469
- * 对配置进行排序
5470
- * @param folderDataConfigList
5471
- * @param sortName 比较的属性,默认fileName
5472
- * @param isDesc 是否降序,默认false(升序)
5473
- */
5474
- function sortFolderConfig(folderDataConfigList, sortName = "fileName", isDesc = false) {
5475
- if (sortName === "fileName") {
5476
- // 如果是以文件名排序,文件夹优先放前面
5477
- let onlyFolderDataConfigList = folderDataConfigList.filter((value) => {
5478
- return value.isFolder;
5479
- });
5480
- let onlyFileDataConfigList = folderDataConfigList.filter((value) => {
5481
- return !value.isFolder;
5482
- });
5483
- // 文件夹排序
5484
- onlyFolderDataConfigList.sort((leftConfig, rightConfig) => {
5485
- let beforeVal = leftConfig[sortName].toString();
5486
- let afterVal = rightConfig[sortName].toString();
5487
- let compareVal = beforeVal.localeCompare(afterVal);
5488
- if (isDesc) {
5489
- /* 降序 */
5490
- if (compareVal > 0) {
5491
- compareVal = -1;
5512
+ }
5513
+ /**
5514
+ * 对配置进行排序
5515
+ * @param folderDataConfigList
5516
+ * @param sortName 比较的属性,默认fileName
5517
+ * @param isDesc 是否降序,默认false(升序)
5518
+ */
5519
+ sortFolderConfig(folderDataConfigList, sortName = "fileName", isDesc = false) {
5520
+ if (sortName === "fileName") {
5521
+ // 如果是以文件名排序,文件夹优先放前面
5522
+ let onlyFolderDataConfigList = folderDataConfigList.filter((value) => {
5523
+ return value.isFolder;
5524
+ });
5525
+ let onlyFileDataConfigList = folderDataConfigList.filter((value) => {
5526
+ return !value.isFolder;
5527
+ });
5528
+ // 文件夹排序
5529
+ onlyFolderDataConfigList.sort((leftConfig, rightConfig) => {
5530
+ let beforeVal = leftConfig[sortName].toString();
5531
+ let afterVal = rightConfig[sortName].toString();
5532
+ let compareVal = beforeVal.localeCompare(afterVal);
5533
+ if (isDesc) {
5534
+ /* 降序 */
5535
+ if (compareVal > 0) {
5536
+ compareVal = -1;
5537
+ }
5538
+ else if (compareVal < 0) {
5539
+ compareVal = 1;
5540
+ }
5492
5541
  }
5493
- else if (compareVal < 0) {
5494
- compareVal = 1;
5542
+ return compareVal;
5543
+ });
5544
+ // 文件名排序
5545
+ onlyFileDataConfigList.sort((leftConfig, rightConfig) => {
5546
+ let beforeVal = leftConfig[sortName].toString();
5547
+ let afterVal = rightConfig[sortName].toString();
5548
+ let compareVal = beforeVal.localeCompare(afterVal);
5549
+ if (isDesc) {
5550
+ /* 降序 */
5551
+ if (compareVal > 0) {
5552
+ compareVal = -1;
5553
+ }
5554
+ else if (compareVal < 0) {
5555
+ compareVal = 1;
5556
+ }
5495
5557
  }
5496
- }
5497
- return compareVal;
5498
- });
5499
- // 文件名排序
5500
- onlyFileDataConfigList.sort((leftConfig, rightConfig) => {
5501
- let beforeVal = leftConfig[sortName].toString();
5502
- let afterVal = rightConfig[sortName].toString();
5503
- let compareVal = beforeVal.localeCompare(afterVal);
5558
+ return compareVal;
5559
+ });
5504
5560
  if (isDesc) {
5505
- /* 降序 */
5506
- if (compareVal > 0) {
5507
- compareVal = -1;
5508
- }
5509
- else if (compareVal < 0) {
5510
- compareVal = 1;
5511
- }
5561
+ // 降序,文件夹在下面
5562
+ return [...onlyFileDataConfigList, ...onlyFolderDataConfigList];
5563
+ }
5564
+ else {
5565
+ // 升序,文件夹在上面
5566
+ return [...onlyFolderDataConfigList, ...onlyFileDataConfigList];
5512
5567
  }
5513
- return compareVal;
5514
- });
5515
- if (isDesc) {
5516
- // 降序,文件夹在下面
5517
- return [...onlyFileDataConfigList, ...onlyFolderDataConfigList];
5518
5568
  }
5519
5569
  else {
5520
- // 升序,文件夹在上面
5521
- return [...onlyFolderDataConfigList, ...onlyFileDataConfigList];
5522
- }
5523
- }
5524
- else {
5525
- folderDataConfigList.sort((beforeConfig, afterConfig) => {
5526
- let beforeVal = beforeConfig[sortName];
5527
- let afterVal = afterConfig[sortName];
5528
- if (sortName === "fileSize") {
5529
- /* 文件大小,进行Float转换 */
5530
- beforeVal = parseFloat(beforeVal.toString());
5531
- afterVal = parseFloat(afterVal.toString());
5532
- }
5533
- else if (sortName === "latestTime") {
5534
- /* 文件时间 */
5535
- beforeVal = new Date(beforeVal).getTime();
5536
- afterVal = new Date(afterVal).getTime();
5537
- }
5538
- if (beforeVal > afterVal) {
5539
- if (isDesc) {
5540
- /* 降序 */
5541
- return -1;
5570
+ folderDataConfigList.sort((beforeConfig, afterConfig) => {
5571
+ let beforeVal = beforeConfig[sortName];
5572
+ let afterVal = afterConfig[sortName];
5573
+ if (sortName === "fileSize") {
5574
+ /* 文件大小,进行Float转换 */
5575
+ beforeVal = parseFloat(beforeVal.toString());
5576
+ afterVal = parseFloat(afterVal.toString());
5542
5577
  }
5543
- else {
5544
- return 1;
5578
+ else if (sortName === "latestTime") {
5579
+ /* 文件时间 */
5580
+ beforeVal = new Date(beforeVal).getTime();
5581
+ afterVal = new Date(afterVal).getTime();
5545
5582
  }
5546
- }
5547
- else if (beforeVal < afterVal) {
5548
- if (isDesc) {
5549
- /* 降序 */
5550
- return 1;
5583
+ if (beforeVal > afterVal) {
5584
+ if (isDesc) {
5585
+ /* 降序 */
5586
+ return -1;
5587
+ }
5588
+ else {
5589
+ return 1;
5590
+ }
5591
+ }
5592
+ else if (beforeVal < afterVal) {
5593
+ if (isDesc) {
5594
+ /* 降序 */
5595
+ return 1;
5596
+ }
5597
+ else {
5598
+ return -1;
5599
+ }
5551
5600
  }
5552
5601
  else {
5553
- return -1;
5602
+ return 0;
5554
5603
  }
5604
+ });
5605
+ return folderDataConfigList;
5606
+ }
5607
+ }
5608
+ /**
5609
+ * 添加文件夹/文件行元素
5610
+ * @param dataConfig 配置
5611
+ */
5612
+ initFolderView(dataConfig) {
5613
+ // 先对文件夹、文件进行排序
5614
+ this.sortFolderConfig(dataConfig, config.sort.name, config.sort.isDesc);
5615
+ dataConfig.forEach((item) => {
5616
+ if (item.isFolder) {
5617
+ let { folderElement, fileNameElement } = popsUtils.isPhone()
5618
+ ? this.createFolderRowElementByMobile(item.fileName, "", "", true)
5619
+ : this.createFolderRowElement(item.fileName, "", "", true);
5620
+ // 文件夹 - 点击事件
5621
+ popsDOMUtils.on(fileNameElement, "click", (event) => {
5622
+ // 进入文件夹
5623
+ this.enterFolder(event, item);
5624
+ });
5625
+ folderListBodyElement.appendChild(folderElement);
5555
5626
  }
5556
5627
  else {
5557
- return 0;
5628
+ let { folderElement, fileNameElement } = popsUtils.isPhone()
5629
+ ? this.createFolderRowElementByMobile(item.fileName, item.latestTime, item.fileSize, false)
5630
+ : this.createFolderRowElement(item.fileName, item.latestTime, item.fileSize, false);
5631
+ // 文件 - 点击事件
5632
+ popsDOMUtils.on(fileNameElement, "click", (event) => {
5633
+ // 下载文件
5634
+ this.downloadFile(event, fileNameElement, item);
5635
+ });
5636
+ folderListBodyElement.appendChild(folderElement);
5558
5637
  }
5559
5638
  });
5560
- return folderDataConfigList;
5561
5639
  }
5562
- }
5563
- /**
5564
- * 添加元素
5565
- * @param _config_
5566
- */
5567
- function addFolderElement(_config_) {
5568
- sortFolderConfig(_config_, config.sort.name, config.sort.isDesc);
5569
- _config_.forEach((item) => {
5570
- if (item["isFolder"]) {
5571
- let { folderELement, fileNameElement } = popsUtils.isPhone()
5572
- ? createMobileFolderRowElement(item["fileName"], "", "", true)
5573
- : createFolderRowElement(item["fileName"], "", "", true);
5574
- popsDOMUtils.on(fileNameElement, "click", (event) => {
5575
- refreshFolderInfoClickEvent(event, item);
5576
- });
5577
- folderListBodyElement.appendChild(folderELement);
5640
+ /**
5641
+ * 移除所有箭头的被访问状态
5642
+ */
5643
+ removeArrowActiveStatus() {
5644
+ [
5645
+ ...Array.from(folderListSortFileNameElement.querySelectorAll(".pops-folder-icon-active")),
5646
+ ...Array.from(folderListSortLatestTimeElement.querySelectorAll(".pops-folder-icon-active")),
5647
+ ...Array.from(folderListSortFileSizeElement.querySelectorAll(".pops-folder-icon-active")),
5648
+ ].forEach((ele) => ele.classList.remove("pops-folder-icon-active"));
5649
+ }
5650
+ /**
5651
+ * 修改导航箭头的状态
5652
+ */
5653
+ changeArrowActive(arrowUp, arrowDown, isDesc) {
5654
+ this.removeArrowActiveStatus();
5655
+ if (isDesc) {
5656
+ arrowDown.classList.add("pops-folder-icon-active");
5578
5657
  }
5579
5658
  else {
5580
- let { folderELement, fileNameElement } = popsUtils.isPhone()
5581
- ? createMobileFolderRowElement(item["fileName"], item.latestTime, item.fileSize, false)
5582
- : createFolderRowElement(item["fileName"], item.latestTime, item.fileSize, false);
5583
- setFileClickEvent(fileNameElement, item);
5584
- folderListBodyElement.appendChild(folderELement);
5659
+ arrowUp.classList.add("pops-folder-icon-active");
5585
5660
  }
5586
- });
5587
- }
5588
- addFolderElement(config.folder);
5589
- /* 将数据存到全部文件的属性_config_中 */
5590
- let allFilesElement = folderFileListBreadcrumbPrimaryElement.querySelector(".pops-folder-list .pops-folder-file-list-breadcrumb-allFiles:first-child");
5591
- allFilesElement._config_ = config.folder;
5592
- /* 设置点击顶部的全部文件事件 */
5593
- popsDOMUtils.on(allFilesElement, "click", (event) => {
5594
- breadcrumbAllFilesElementClickEvent(event, true, config.folder);
5595
- });
5596
- /* 移除所有的当前排序的arrow */
5597
- function removeAllArrowActive() {
5598
- [
5599
- ...Array.from(folderListSortFileNameElement.querySelectorAll(".pops-folder-icon-active")),
5600
- ...Array.from(folderListSortLatestTimeElement.querySelectorAll(".pops-folder-icon-active")),
5601
- ...Array.from(folderListSortFileSizeElement.querySelectorAll(".pops-folder-icon-active")),
5602
- ].forEach((ele) => ele.classList.remove("pops-folder-icon-active"));
5603
- }
5604
- /* 设置当前的排序的arrow */
5605
- function changeArrowActive(arrowUp, arrowDown, isDesc) {
5606
- removeAllArrowActive();
5607
- if (isDesc) {
5608
- arrowDown.classList.add("pops-folder-icon-active");
5609
- }
5610
- else {
5611
- arrowUp.classList.add("pops-folder-icon-active");
5612
5661
  }
5613
- }
5614
- /**
5615
- * 排序按钮的点击事件
5616
- * @param {PointerEvent} target
5617
- * @param {HTMLElement} event
5618
- * @param {string} sortName
5619
- */
5620
- function arrowSortClickEvent(target, event, sortName) {
5621
- if (!event["notChangeSortRule"]) {
5622
- config.sort.name = sortName;
5623
- config.sort.isDesc = !config.sort.isDesc;
5624
- }
5625
- let arrowUp = target.querySelector(".pops-folder-icon-arrow-up");
5626
- let arrowDown = target.querySelector(".pops-folder-icon-arrow-down");
5627
- changeArrowActive(arrowUp, arrowDown, config.sort.isDesc);
5628
- if (typeof config.sort.callback === "function" &&
5629
- config.sort.callback(target, event, config.sort.name, config.sort.isDesc)) {
5630
- return;
5662
+ /**
5663
+ * 排序按钮的点击事件
5664
+ * @param target
5665
+ * @param event
5666
+ * @param sortName
5667
+ */
5668
+ arrowToSortFolderInfoView(target, event, sortName) {
5669
+ const notChangeSortRule = Reflect.get(event, "notChangeSortRule");
5670
+ if (!notChangeSortRule) {
5671
+ config.sort.name = sortName;
5672
+ config.sort.isDesc = !config.sort.isDesc;
5673
+ }
5674
+ let arrowUp = target.querySelector(".pops-folder-icon-arrow-up");
5675
+ let arrowDown = target.querySelector(".pops-folder-icon-arrow-down");
5676
+ this.changeArrowActive(arrowUp, arrowDown, config.sort.isDesc);
5677
+ if (typeof config.sort.callback === "function" &&
5678
+ config.sort.callback(target, event, config.sort.name, config.sort.isDesc)) {
5679
+ return;
5680
+ }
5681
+ let childrenList = [];
5682
+ Array.from(folderListBodyElement.children).forEach((trElement) => {
5683
+ let __value__ = Reflect.get(trElement, "__value__");
5684
+ Reflect.set(__value__, "target", trElement);
5685
+ childrenList.push(__value__);
5686
+ });
5687
+ let sortedConfigList = this.sortFolderConfig(childrenList, config.sort.name, config.sort.isDesc);
5688
+ sortedConfigList.forEach((item) => {
5689
+ folderListBodyElement.appendChild(item.target);
5690
+ });
5631
5691
  }
5632
- let childrenList = [];
5633
- Array.from(folderListBodyElement.children).forEach((trElement) => {
5634
- let __value__ = trElement["__value__"];
5635
- __value__["target"] = trElement;
5636
- childrenList.push(__value__);
5637
- });
5638
- let sortedConfigList = sortFolderConfig(childrenList, config.sort.name, config.sort.isDesc);
5639
- sortedConfigList.forEach((item) => {
5640
- folderListBodyElement.appendChild(item.target);
5641
- });
5642
- }
5643
- /* 设置当前排序的图标按钮 */
5644
- popsDOMUtils.on(folderListSortFileNameElement.closest("th"), "click", function (event) {
5645
- arrowSortClickEvent(folderListSortFileNameElement, event, "fileName");
5646
- }, {
5647
- capture: true,
5648
- });
5649
- popsDOMUtils.on(folderListSortLatestTimeElement.closest("th"), "click", void 0, function (event) {
5650
- arrowSortClickEvent(folderListSortLatestTimeElement, event, "latestTime");
5651
- }, {
5652
- capture: true,
5653
- });
5654
- popsDOMUtils.on(folderListSortFileSizeElement.closest("th"), "click", void 0, function (event) {
5655
- arrowSortClickEvent(folderListSortFileSizeElement, event, "fileSize");
5656
- }, {
5657
- capture: true,
5658
- });
5659
- /* 设置默认触发的arrow */
5660
- if (config.sort.name === "fileName") {
5661
- popsDOMUtils.trigger(folderListSortFileNameElement, "click", {
5662
- notChangeSortRule: true,
5663
- });
5664
- }
5665
- else if (config.sort.name === "latestTime") {
5666
- popsDOMUtils.trigger(folderListSortLatestTimeElement, "click", {
5667
- notChangeSortRule: true,
5668
- });
5669
- }
5670
- else if (config.sort.name === "fileSize") {
5671
- popsDOMUtils.trigger(folderListSortFileSizeElement, "click", {
5672
- notChangeSortRule: true,
5673
- });
5674
5692
  }
5693
+ const popsFolder = new PopsFolder();
5694
+ popsFolder.init();
5695
+ Reflect.set($pops, "data-pops-folder", popsFolder);
5675
5696
  /* 拖拽 */
5676
5697
  if (config.drag) {
5677
5698
  PopsInstanceUtils.drag($pops, {
@@ -11628,7 +11649,7 @@
11628
11649
  /** 配置 */
11629
11650
  config = {
11630
11651
  /** 版本号 */
11631
- version: "2025.8.17",
11652
+ version: "2025.8.30",
11632
11653
  cssText: PopsCSS,
11633
11654
  /** icon图标的svg代码 */
11634
11655
  iconSVG: PopsIcon.$data,