@whitesev/pops 3.2.1 → 3.2.2

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.
Files changed (126) hide show
  1. package/README.md +249 -249
  2. package/dist/index.amd.js +702 -667
  3. package/dist/index.amd.js.map +1 -1
  4. package/dist/index.amd.min.js +1 -1
  5. package/dist/index.amd.min.js.map +1 -1
  6. package/dist/index.cjs.js +702 -667
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.cjs.min.js +1 -1
  9. package/dist/index.cjs.min.js.map +1 -1
  10. package/dist/index.esm.js +702 -667
  11. package/dist/index.esm.js.map +1 -1
  12. package/dist/index.esm.min.js +1 -1
  13. package/dist/index.esm.min.js.map +1 -1
  14. package/dist/index.iife.js +702 -667
  15. package/dist/index.iife.js.map +1 -1
  16. package/dist/index.iife.min.js +1 -1
  17. package/dist/index.iife.min.js.map +1 -1
  18. package/dist/index.system.js +702 -667
  19. package/dist/index.system.js.map +1 -1
  20. package/dist/index.system.min.js +1 -1
  21. package/dist/index.system.min.js.map +1 -1
  22. package/dist/index.umd.js +702 -667
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/index.umd.min.js +1 -1
  25. package/dist/index.umd.min.js.map +1 -1
  26. package/dist/types/src/components/folder/types/index.d.ts +43 -13
  27. package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +313 -313
  28. package/dist/types/src/types/animation.d.ts +19 -19
  29. package/dist/types/src/types/button.d.ts +94 -94
  30. package/dist/types/src/types/components.d.ts +211 -211
  31. package/dist/types/src/types/event.d.ts +43 -43
  32. package/dist/types/src/types/global.d.ts +31 -31
  33. package/dist/types/src/types/icon.d.ts +32 -32
  34. package/dist/types/src/types/inst.d.ts +28 -28
  35. package/dist/types/src/types/main.d.ts +66 -66
  36. package/dist/types/src/types/mask.d.ts +52 -52
  37. package/dist/types/src/types/position.d.ts +60 -60
  38. package/package.json +27 -25
  39. package/src/Pops.ts +206 -206
  40. package/src/PopsAnimation.ts +32 -32
  41. package/src/PopsCSS.ts +54 -54
  42. package/src/PopsCore.ts +37 -37
  43. package/src/PopsIcon.ts +95 -95
  44. package/src/PopsInst.ts +21 -21
  45. package/src/components/alert/defaultConfig.ts +62 -62
  46. package/src/components/alert/index.ts +163 -163
  47. package/src/components/alert/types/index.ts +23 -23
  48. package/src/components/confirm/defaultConfig.ts +90 -90
  49. package/src/components/confirm/index.ts +165 -165
  50. package/src/components/confirm/types/index.ts +13 -17
  51. package/src/components/drawer/defaultConfig.ts +89 -89
  52. package/src/components/drawer/index.css +37 -37
  53. package/src/components/drawer/index.ts +245 -245
  54. package/src/components/drawer/types/index.ts +62 -61
  55. package/src/components/folder/defaultConfig.ts +151 -151
  56. package/src/components/folder/folderIcon.ts +28 -28
  57. package/src/components/folder/index.css +303 -303
  58. package/src/components/folder/index.ts +953 -932
  59. package/src/components/folder/types/index.ts +143 -110
  60. package/src/components/iframe/defaultConfig.ts +60 -60
  61. package/src/components/iframe/index.css +76 -76
  62. package/src/components/iframe/index.ts +331 -331
  63. package/src/components/iframe/types/index.ts +96 -96
  64. package/src/components/loading/defaultConfig.ts +29 -29
  65. package/src/components/loading/index.css +66 -66
  66. package/src/components/loading/index.ts +101 -101
  67. package/src/components/loading/types/index.ts +36 -34
  68. package/src/components/panel/css/components-select.css +84 -84
  69. package/src/components/panel/defaultConfig.ts +868 -868
  70. package/src/components/panel/handlerComponents.ts +3993 -3993
  71. package/src/components/panel/index.css +1403 -1403
  72. package/src/components/panel/index.ts +221 -221
  73. package/src/components/panel/types/components-button.ts +56 -56
  74. package/src/components/panel/types/components-common.ts +73 -73
  75. package/src/components/panel/types/components-container.ts +25 -25
  76. package/src/components/panel/types/components-deepMenu.ts +64 -64
  77. package/src/components/panel/types/components-input.ts +90 -90
  78. package/src/components/panel/types/components-own.ts +16 -16
  79. package/src/components/panel/types/components-select.ts +169 -169
  80. package/src/components/panel/types/components-selectMultiple.ts +105 -104
  81. package/src/components/panel/types/components-slider.ts +55 -55
  82. package/src/components/panel/types/components-switch.ts +33 -33
  83. package/src/components/panel/types/components-textarea.ts +45 -45
  84. package/src/components/panel/types/index.ts +244 -244
  85. package/src/components/prompt/defaultConfig.ts +94 -94
  86. package/src/components/prompt/index.css +34 -34
  87. package/src/components/prompt/index.ts +187 -215
  88. package/src/components/prompt/types/index.ts +57 -56
  89. package/src/components/rightClickMenu/defaultConfig.ts +103 -103
  90. package/src/components/rightClickMenu/index.css +115 -115
  91. package/src/components/rightClickMenu/index.ts +662 -662
  92. package/src/components/rightClickMenu/types/index.ts +145 -143
  93. package/src/components/searchSuggestion/defaultConfig.ts +63 -63
  94. package/src/components/searchSuggestion/index.ts +813 -813
  95. package/src/components/searchSuggestion/types/index.ts +244 -242
  96. package/src/components/tooltip/defaultConfig.ts +33 -33
  97. package/src/components/tooltip/index.css +199 -199
  98. package/src/components/tooltip/index.ts +617 -617
  99. package/src/components/tooltip/types/index.ts +123 -121
  100. package/src/config/CommonCSSClassName.ts +17 -17
  101. package/src/config/GlobalConfig.ts +63 -63
  102. package/src/css/animation.css +987 -987
  103. package/src/css/button.css +551 -551
  104. package/src/css/common.css +54 -54
  105. package/src/css/index.css +253 -253
  106. package/src/css/ninePalaceGridPosition.css +50 -50
  107. package/src/css/scrollbar.css +22 -22
  108. package/src/handler/PopsElementHandler.ts +303 -303
  109. package/src/handler/PopsHandler.ts +611 -611
  110. package/src/types/PopsDOMUtilsEventType.d.ts +313 -313
  111. package/src/types/animation.d.ts +19 -19
  112. package/src/types/button.d.ts +94 -94
  113. package/src/types/components.d.ts +211 -211
  114. package/src/types/event.d.ts +43 -43
  115. package/src/types/global.d.ts +31 -31
  116. package/src/types/icon.d.ts +32 -32
  117. package/src/types/inst.d.ts +28 -28
  118. package/src/types/main.d.ts +66 -66
  119. package/src/types/mask.d.ts +52 -52
  120. package/src/types/position.d.ts +60 -60
  121. package/src/utils/PopsDOMUtils.ts +2483 -2483
  122. package/src/utils/PopsDOMUtilsEventsConfig.ts +4 -4
  123. package/src/utils/PopsInstanceUtils.ts +714 -714
  124. package/src/utils/PopsMathUtils.ts +71 -71
  125. package/src/utils/PopsSafeUtils.ts +22 -22
  126. package/src/utils/PopsUtils.ts +421 -421
@@ -1,932 +1,953 @@
1
- import { GlobalConfig } from "../../config/GlobalConfig";
2
- import { PopsElementHandler } from "../../handler/PopsElementHandler";
3
- import { PopsHandler } from "../../handler/PopsHandler";
4
- import { PopsCSS } from "../../PopsCSS";
5
- import type { PopsType } from "../../types/main";
6
- import { popsDOMUtils } from "../../utils/PopsDOMUtils";
7
- import { PopsInstanceUtils } from "../../utils/PopsInstanceUtils";
8
- import { PopsSafeUtils } from "../../utils/PopsSafeUtils";
9
- import { popsUtils } from "../../utils/PopsUtils";
10
- import { PopsLoading } from "../loading";
11
- import { PopsFolderDefaultConfig } from "./defaultConfig";
12
- import { Folder_ICON } from "./folderIcon";
13
- import type { PopsFolderDataConfig, PopsFolderConfig, PopsFolderDownloadOption } from "./types";
14
-
15
- export const PopsFolder = {
16
- init(__config__: PopsFolderConfig) {
17
- const guid = popsUtils.getRandomGUID();
18
- // 设置当前类型
19
- const popsType: PopsType = "folder";
20
-
21
- let config = PopsFolderDefaultConfig();
22
- config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
23
- config = popsUtils.assign(config, __config__);
24
- config = PopsHandler.handleOnly(popsType, config);
25
-
26
- const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
27
- PopsHandler.handleInit($shadowRoot, [
28
- {
29
- name: "index",
30
- css: PopsCSS.index,
31
- },
32
- {
33
- name: "ninePalaceGridPosition",
34
- css: PopsCSS.ninePalaceGridPosition,
35
- },
36
- {
37
- name: "scrollbar",
38
- css: PopsCSS.scrollbar,
39
- },
40
- {
41
- name: "button",
42
- css: PopsCSS.button,
43
- },
44
- {
45
- name: "anim",
46
- css: PopsCSS.anim,
47
- },
48
- {
49
- name: "common",
50
- css: PopsCSS.common,
51
- },
52
- {
53
- name: "folderCSS",
54
- css: PopsCSS.folderCSS,
55
- },
56
- ]);
57
-
58
- // 办公几件套
59
- Reflect.set(Folder_ICON, "docx", Folder_ICON.doc);
60
- Reflect.set(Folder_ICON, "rtf", Folder_ICON.doc);
61
- Reflect.set(Folder_ICON, "xlsx", Folder_ICON.xls);
62
- Reflect.set(Folder_ICON, "pptx", Folder_ICON.ppt);
63
- Reflect.set(Folder_ICON, "dmg", Folder_ICON.ipa);
64
- Reflect.set(Folder_ICON, "json", Folder_ICON.js);
65
-
66
- // 压缩包
67
- const zipIconList = [
68
- "rar",
69
- "7z",
70
- "arj",
71
- "bz2",
72
- "cab",
73
- "iso",
74
- "jar",
75
- "lz",
76
- "lzh",
77
- "tar",
78
- "uue",
79
- "xz",
80
- "z",
81
- "zipx",
82
- "zst",
83
- "001",
84
- ];
85
-
86
- // 图片
87
- const imageIconList = ["jpg", "jpeg", "ico", "webp"];
88
-
89
- // 代码语言
90
- const codeLanguageIconList = ["htm", "py", "vue", "bat", "sh", "vbs", "java", "kt"];
91
-
92
- // Android安装包
93
- const androidIconList = ["apk", "apkm", "xapk"];
94
-
95
- zipIconList.forEach((keyName) => {
96
- Folder_ICON[keyName as keyof typeof Folder_ICON] = Folder_ICON.zip;
97
- });
98
- imageIconList.forEach((keyName) => {
99
- Folder_ICON[keyName as keyof typeof Folder_ICON] = Folder_ICON.png;
100
- });
101
- codeLanguageIconList.forEach((keyName) => {
102
- Folder_ICON[keyName as keyof typeof Folder_ICON] = Folder_ICON.html;
103
- });
104
- androidIconList.forEach((keyName) => {
105
- Folder_ICON[keyName as keyof typeof Folder_ICON] = Folder_ICON.apk;
106
- });
107
-
108
- if (config?.folder) {
109
- Reflect.set(config, "folder", config.folder);
110
- }
111
-
112
- // 先把z-index提取出来
113
- const zIndex = PopsHandler.handleZIndex(config.zIndex);
114
- const maskHTML = PopsElementHandler.createMask(guid, zIndex);
115
-
116
- const headerBtnHTML = PopsElementHandler.createHeader(popsType, config);
117
- const bottomBtnHTML = PopsElementHandler.createBottom(popsType, config);
118
- const { headerStyle, headerPStyle } = PopsElementHandler.createHeaderStyle(popsType, config);
119
- const animHTML = PopsElementHandler.createAnim(
120
- guid,
121
- popsType,
122
- config,
123
- /*html*/ `
124
- <div class="pops-title pops-${popsType}-title" style="text-align: ${
125
- config.title.position
126
- };${headerStyle}">${
127
- config.title.html
128
- ? config.title.text
129
- : `<p pops class="pops-${popsType}-title-text" style="${headerPStyle}">${config.title.text}</p>`
130
- }${headerBtnHTML}</div>
131
- <div class="pops-content pops-${popsType}-content ${popsUtils.isPhone() ? "pops-mobile-folder-content" : ""}">
132
- <div class="pops-folder-list">
133
- <div class="pops-folder-file-list-breadcrumb">
134
- <div class="pops-folder-file-list-breadcrumb-primary">
135
- <span class="pops-folder-file-list-breadcrumb-allFiles cursor-p" title="全部文件">
136
- <a>全部文件</a>
137
- </span>
138
- </div>
139
- </div>
140
- <div class="pops-folder-list-table__header-div">
141
- <table class="pops-folder-list-table__header">
142
- <colgroup>
143
- <col width="52%">
144
- <col width="24%">
145
- <col width="16%">
146
- </colgroup>
147
- <thead>
148
- <tr class="pops-folder-list-table__header-row">
149
- <th class="pops-folder-list-table__header-th cursor-p">
150
- <div class="text-ellip content flex-a-i-center">
151
- <span>文件名</span>
152
- <div class="pops-folder-list-table__sort" data-sort="fileName">
153
- <div class="pops-folder-icon-arrow" data-sort="按文件名排序">
154
- <svg
155
- viewBox="0 0 1024 1024"
156
- xmlns="http://www.w3.org/2000/svg">
157
- <path
158
- d="M509.624392 5.882457 57.127707 458.379143 962.121078 458.379143Z"
159
- class="pops-folder-icon-arrow-up"></path>
160
- <path
161
- d="M509.624392 1024 962.121078 571.503314 57.127707 571.503314Z"
162
- class="pops-folder-icon-arrow-down"></path>
163
- </svg>
164
- </div>
165
- </div>
166
- </div>
167
- </th>
168
- <th class="pops-folder-list-table__header-th cursor-p">
169
- <div class="text-ellip content flex-a-i-center">
170
- <span>修改时间</span>
171
- <div class="pops-folder-list-table__sort" data-sort="latestTime">
172
- <div class="pops-folder-icon-arrow" title="按修改时间排序">
173
- <svg
174
- viewBox="0 0 1024 1024"
175
- xmlns="http://www.w3.org/2000/svg">
176
- <path
177
- d="M509.624392 5.882457 57.127707 458.379143 962.121078 458.379143Z"
178
- class="pops-folder-icon-arrow-up"></path>
179
- <path
180
- d="M509.624392 1024 962.121078 571.503314 57.127707 571.503314Z"
181
- class="pops-folder-icon-arrow-down"></path>
182
- </svg>
183
- </div>
184
- </div>
185
- </div>
186
- </th>
187
- <th class="pops-folder-list-table__header-th cursor-p">
188
- <div class="text-ellip content flex-a-i-center">
189
- <span>大小</span>
190
- <div class="pops-folder-list-table__sort" data-sort="fileSize">
191
- <div class="pops-folder-icon-arrow" title="按大小排序">
192
- <svg
193
- viewBox="0 0 1024 1024"
194
- xmlns="http://www.w3.org/2000/svg">
195
- <path
196
- d="M509.624392 5.882457 57.127707 458.379143 962.121078 458.379143Z"
197
- class="pops-folder-icon-arrow-up"></path>
198
- <path
199
- d="M509.624392 1024 962.121078 571.503314 57.127707 571.503314Z"
200
- class="pops-folder-icon-arrow-down"></path>
201
- </svg>
202
- </div>
203
- </div>
204
- </div>
205
- </th>
206
- </tr>
207
- </thead>
208
- </table>
209
- </div>
210
- <div class="pops-folder-list-table__body-div">
211
- <table class="pops-folder-list-table__body">
212
- <colgroup>
213
- ${
214
- popsUtils.isPhone()
215
- ? `<col width="100%">`
216
- : `
217
- <col width="52%">
218
- <col width="24%">
219
- <col width="16%">`
220
- }
221
- </colgroup>
222
- <tbody></tbody>
223
- </table>
224
- </div>
225
- </div>
226
- </div>${bottomBtnHTML}`,
227
- bottomBtnHTML,
228
- zIndex
229
- );
230
- /**
231
- * 弹窗的主元素,包括动画层
232
- */
233
- const $anim = PopsElementHandler.parseElement<HTMLDivElement>(animHTML);
234
- const {
235
- $pops: $pops,
236
- $title: $title,
237
- $content: $content,
238
- // folderListElement,
239
- // folderListHeaderElement,
240
- // folderListHeaderRowElement,
241
- $folderTbody: folderListBodyElement,
242
- $folderHeaderBreadcrumbPrimary: folderFileListBreadcrumbPrimaryElement,
243
- $headerBtnClose: $btnCloseBtn,
244
- $btnOk: btnOkElement,
245
- $btnCancel: btnCancelElement,
246
- $btnOther: btnOtherElement,
247
- $folderSortFileName: folderListSortFileNameElement,
248
- $folderSortLatestTime: folderListSortLatestTimeElement,
249
- $folderSortFileSize: folderListSortFileSizeElement,
250
- } = PopsHandler.handleQueryElement($anim, popsType);
251
-
252
- /**
253
- * 遮罩层元素
254
- */
255
- let $mask: HTMLDivElement | undefined = void 0;
256
- /**
257
- * 已创建的元素列表
258
- */
259
- const $elList: HTMLElement[] = [$anim];
260
-
261
- if (config.mask.enable) {
262
- const handleMask = PopsHandler.handleMask({
263
- type: popsType,
264
- guid: guid,
265
- config: config,
266
- animElement: $anim,
267
- maskHTML: maskHTML,
268
- });
269
- $mask = handleMask.maskElement;
270
- $elList.push($mask);
271
- }
272
- // 事件
273
- const evtConfig = PopsHandler.handleEventConfig(
274
- config,
275
- guid,
276
- $shadowContainer,
277
- $shadowRoot,
278
- popsType,
279
- $anim,
280
- $pops,
281
- $mask
282
- );
283
- const result = PopsHandler.handleResultConfig(evtConfig);
284
- PopsHandler.handleClickEvent("close", $btnCloseBtn, evtConfig, config.btn.close.callback);
285
- PopsHandler.handleClickEvent("ok", btnOkElement, evtConfig, config.btn.ok.callback);
286
- PopsHandler.handleClickEvent("cancel", btnCancelElement, evtConfig, config.btn.cancel.callback);
287
- PopsHandler.handleClickEvent("other", btnOtherElement, evtConfig, config.btn.other.callback);
288
- // 创建到页面中
289
-
290
- popsDOMUtils.append($shadowRoot, $elList);
291
- if (typeof config.beforeAppendToPageCallBack === "function") {
292
- config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
293
- }
294
-
295
- popsDOMUtils.appendBody($shadowContainer);
296
- if ($mask != null) {
297
- $anim.after($mask);
298
- }
299
- class PopsFolder {
300
- init() {
301
- config.folder.sort();
302
- this.initFolderView(config.folder);
303
- // 将数据存到全部文件的属性_config_中
304
-
305
- const $allFiles = folderFileListBreadcrumbPrimaryElement.querySelector<HTMLDivElement>(
306
- ".pops-folder-list .pops-folder-file-list-breadcrumb-allFiles:first-child"
307
- )!;
308
-
309
- Reflect.set($allFiles, "data-config", config.folder);
310
- // 设置点击顶部的全部文件事件
311
- popsDOMUtils.on<MouseEvent | PointerEvent>($allFiles, "click", (event) => {
312
- this.setBreadcrumbClickEvent(event, true, config.folder);
313
- });
314
- // 文件名的点击排序
315
- popsDOMUtils.on<MouseEvent | PointerEvent>(
316
- folderListSortFileNameElement.closest("th"),
317
- "click",
318
- (event) => {
319
- this.arrowToSortFolderInfoView(folderListSortFileNameElement, event, "fileName");
320
- },
321
- {
322
- capture: true,
323
- }
324
- );
325
- // 修改事件的点击排序
326
- popsDOMUtils.on(
327
- folderListSortLatestTimeElement.closest("th"),
328
- "click",
329
- (event) => {
330
- this.arrowToSortFolderInfoView(folderListSortLatestTimeElement, event, "latestTime");
331
- },
332
- {
333
- capture: true,
334
- }
335
- );
336
- // 文件大小的点击排序
337
- popsDOMUtils.on(
338
- folderListSortFileSizeElement.closest("th"),
339
- "click",
340
- (event) => {
341
- this.arrowToSortFolderInfoView(folderListSortFileSizeElement, event, "fileSize");
342
- },
343
- {
344
- capture: true,
345
- }
346
- );
347
- // 设置默认触发的arrow
348
- if (config.sort.name === "fileName") {
349
- popsDOMUtils.emit(folderListSortFileNameElement, "click", {
350
- notChangeSortRule: true,
351
- });
352
- } else if (config.sort.name === "latestTime") {
353
- popsDOMUtils.emit(folderListSortLatestTimeElement, "click", {
354
- notChangeSortRule: true,
355
- });
356
- } else if (config.sort.name === "fileSize") {
357
- popsDOMUtils.emit(folderListSortFileSizeElement, "click", {
358
- notChangeSortRule: true,
359
- });
360
- }
361
- }
362
- /**
363
- * 创建文件夹元素
364
- * @param fileName 文件名
365
- * @param latestTime 修改时间
366
- * @param [fileSize="-"] 文件大小
367
- * @param isFolder 是否是文件夹
368
- */
369
- createFolderRowElement(
370
- fileName: string,
371
- latestTime: string | number = "-",
372
- fileSize: string | number = "-",
373
- isFolder: boolean = false
374
- ) {
375
- const origin_fileName = fileName;
376
- const origin_latestTime = latestTime;
377
- const origin_fileSize = fileSize;
378
-
379
- const folderElement = popsDOMUtils.createElement("tr");
380
-
381
- const fileNameElement = popsDOMUtils.createElement("td");
382
-
383
- const fileTimeElement = popsDOMUtils.createElement("td");
384
-
385
- const fileFormatSize = popsDOMUtils.createElement("td");
386
- let fileType = "";
387
- let fileIcon = Folder_ICON.folder;
388
- if (isFolder) {
389
- // 文件夹
390
- latestTime = "";
391
- fileSize = "";
392
- } else {
393
- // 文件
394
- fileIcon = "";
395
- if (typeof latestTime === "number") {
396
- latestTime = popsUtils.formatTime(latestTime);
397
- }
398
- if (typeof fileSize === "number") {
399
- fileSize = popsUtils.formatByteToSize(fileSize) as string;
400
- }
401
- for (const keyName in Folder_ICON) {
402
- if (fileName.toLowerCase().endsWith("." + keyName)) {
403
- fileType = keyName;
404
- fileIcon = Reflect.get(Folder_ICON, keyName);
405
- break;
406
- }
407
- }
408
- if (!fileIcon) {
409
- fileType = "Null";
410
- fileIcon = Folder_ICON.Null;
411
- }
412
- }
413
- folderElement.className = "pops-folder-list-table__body-row";
414
- fileNameElement.className = "pops-folder-list-table__body-td";
415
- fileTimeElement.className = "pops-folder-list-table__body-td";
416
- fileFormatSize.className = "pops-folder-list-table__body-td";
417
- PopsSafeUtils.setSafeHTML(
418
- fileNameElement,
419
- /*html*/ `
420
- <div class="pops-folder-list-file-name cursor-p">
421
- <div>
422
- <img src="${fileIcon}" alt="${fileType}" class="pops-folder-list-file-icon u-file-icon u-file-icon--list">
423
- <a title="${fileName}" class="pops-folder-list-file-name-title-text inline-block-v-middle text-ellip list-name-text">
424
- ${fileName}
425
- </a>
426
- </div>
427
- </div>
428
- `
429
- );
430
- PopsSafeUtils.setSafeHTML(
431
- fileTimeElement,
432
- /*html*/ `
433
- <div class="pops-folder-list__time">
434
- <span>${latestTime}</span>
435
- </div>
436
- `
437
- );
438
- PopsSafeUtils.setSafeHTML(
439
- fileFormatSize,
440
- /*html*/ `
441
- <div class="pops-folder-list-format-size">
442
- <span>${fileSize}</span>
443
- </div>
444
- `
445
- );
446
-
447
- // 存储原来的值
448
- const __value__ = {
449
- fileName: origin_fileName,
450
- latestTime: origin_latestTime,
451
- fileSize: origin_fileSize,
452
- isFolder: isFolder,
453
- };
454
-
455
- Reflect.set(fileNameElement, "__value__", __value__);
456
- Reflect.set(fileTimeElement, "__value__", __value__);
457
- Reflect.set(fileFormatSize, "__value__", __value__);
458
- Reflect.set(folderElement, "__value__", __value__);
459
-
460
- folderElement.appendChild(fileNameElement);
461
- folderElement.appendChild(fileTimeElement);
462
- folderElement.appendChild(fileFormatSize);
463
- return {
464
- folderElement,
465
- fileNameElement,
466
- fileTimeElement,
467
- fileFormatSize,
468
- };
469
- }
470
- /**
471
- * 创建移动端文件夹元素
472
- * @param fileName 文件名
473
- * @param latestTime 创建时间
474
- * @param [fileSize="-"] 文件大小
475
- * @param isFolder 是否是文件夹
476
- */
477
- createFolderRowElementByMobile(
478
- fileName: string,
479
- latestTime: number | string = "-",
480
- fileSize: number | string = "-",
481
- isFolder: boolean = false
482
- ) {
483
- const origin_fileName = fileName;
484
- const origin_latestTime = latestTime;
485
- const origin_fileSize = fileSize;
486
-
487
- const folderElement = popsDOMUtils.createElement("tr");
488
-
489
- const fileNameElement = popsDOMUtils.createElement("td");
490
- let fileType = "";
491
- let fileIcon = Folder_ICON.folder;
492
- if (isFolder) {
493
- // 文件夹
494
- latestTime = "";
495
- fileSize = "";
496
- } else {
497
- // 文件
498
- fileIcon = "";
499
- if (typeof latestTime === "number") {
500
- latestTime = popsUtils.formatTime(latestTime);
501
- }
502
- if (typeof fileSize === "number") {
503
- fileSize = popsUtils.formatByteToSize(fileSize) as string;
504
- }
505
- for (const keyName in Folder_ICON) {
506
- if (fileName.toLowerCase().endsWith("." + keyName)) {
507
- fileType = keyName;
508
- fileIcon = Reflect.get(Folder_ICON, keyName);
509
- break;
510
- }
511
- }
512
- if (!fileIcon) {
513
- fileType = "Null";
514
- fileIcon = Folder_ICON.Null;
515
- }
516
- }
517
- folderElement.className = "pops-folder-list-table__body-row";
518
- fileNameElement.className = "pops-folder-list-table__body-td";
519
- PopsSafeUtils.setSafeHTML(
520
- fileNameElement,
521
- /*html*/ `
522
- <div class="pops-folder-list-file-name pops-mobile-folder-list-file-name cursor-p">
523
- <img src="${fileIcon}" alt="${fileType}" class="pops-folder-list-file-icon u-file-icon u-file-icon--list">
524
- <div>
525
- <a title="${fileName}" class="pops-folder-list-file-name-title-text inline-block-v-middle text-ellip list-name-text">${fileName}</a>
526
- <span>${latestTime} ${fileSize}</span>
527
- </div>
528
- </div>
529
- `
530
- );
531
- // 存储原来的值
532
- const __value__ = {
533
- fileName: origin_fileName,
534
- latestTime: origin_latestTime,
535
- fileSize: origin_fileSize,
536
- isFolder: isFolder,
537
- };
538
- Reflect.set(fileNameElement, "__value__", __value__);
539
- Reflect.set(folderElement, "__value__", __value__);
540
- folderElement.appendChild(fileNameElement);
541
- return {
542
- folderElement,
543
- fileNameElement,
544
- };
545
- }
546
- /**
547
- * 清空文件夹信息页面
548
- */
549
- clearFolderInfoView() {
550
- PopsSafeUtils.setSafeHTML(folderListBodyElement, "");
551
- }
552
- /**
553
- * 创建顶部导航的箭头图标
554
- */
555
- createHeaderArrowIcon() {
556
- const $arrowIcon = popsDOMUtils.createElement("div", {
557
- className: "iconArrow",
558
- });
559
- return $arrowIcon;
560
- }
561
- /**
562
- * 添加顶部导航元素
563
- * @param folderName 文件夹名
564
- * @param folderDataConfig 文件夹配置
565
- */
566
- createBreadcrumb(
567
- folderName: string,
568
- folderDataConfig: PopsFolderDownloadOption | PopsFolderDataConfig[] | null | undefined | void
569
- ) {
570
- const $breadcrumb = popsDOMUtils.createElement(
571
- "span",
572
- {
573
- className: "pops-folder-file-list-breadcrumb-allFiles cursor-p",
574
- innerHTML: `<a>${folderName}</a>`,
575
- "data-config": folderDataConfig,
576
- },
577
- {
578
- title: folderName,
579
- }
580
- );
581
- return $breadcrumb;
582
- }
583
- /**
584
- * 顶部导航的点击事件
585
- * @param clickEvent
586
- * @param isTop 是否是全部文件按钮
587
- * @param dataConfigList 配置
588
- */
589
- setBreadcrumbClickEvent(
590
- clickEvent: MouseEvent | PointerEvent,
591
- isTop: boolean,
592
- dataConfigList: PopsFolderDataConfig[]
593
- ) {
594
- this.clearFolderInfoView();
595
- // 获取当前的导航元素
596
- const $click = clickEvent.target as HTMLElement;
597
- const currentBreadcrumb = $click.closest<HTMLSpanElement>("span.pops-folder-file-list-breadcrumb-allFiles");
598
- if (currentBreadcrumb) {
599
- while (currentBreadcrumb.nextElementSibling) {
600
- currentBreadcrumb.nextElementSibling.remove();
601
- }
602
- } else {
603
- console.error("获取导航按钮失败");
604
- }
605
- const loadingMask = PopsLoading.init({
606
- $parent: $content,
607
- content: {
608
- text: "获取文件列表中...",
609
- },
610
- mask: {
611
- enable: true,
612
- clickEvent: {
613
- toClose: false,
614
- toHide: false,
615
- },
616
- },
617
- addIndexCSS: false,
618
- });
619
- this.initFolderView(dataConfigList);
620
- loadingMask.close();
621
- }
622
- /**
623
- * 文件夹的点击事件 - 进入文件夹
624
- *
625
- * 先情况页面元素
626
- * @param clickEvent
627
- * @param dataConfig
628
- */
629
- async enterFolder(clickEvent: MouseEvent | PointerEvent, dataConfig: PopsFolderDataConfig) {
630
- this.clearFolderInfoView();
631
- const loadingMask = PopsLoading.init({
632
- $parent: $content,
633
- content: {
634
- text: "获取文件列表中...",
635
- },
636
- mask: {
637
- enable: true,
638
- },
639
- addIndexCSS: false,
640
- });
641
- if (typeof dataConfig.clickEvent === "function") {
642
- const childConfig = await dataConfig.clickEvent(clickEvent, dataConfig);
643
- // 添加顶部导航的箭头
644
- folderFileListBreadcrumbPrimaryElement.appendChild(this.createHeaderArrowIcon());
645
- // 添加顶部导航的链接文字
646
- const $breadcrumbAllFiles = this.createBreadcrumb(dataConfig.fileName, childConfig);
647
-
648
- folderFileListBreadcrumbPrimaryElement.appendChild($breadcrumbAllFiles);
649
- // 设置顶部导航点击事件
650
-
651
- popsDOMUtils.on<MouseEvent | PointerEvent>($breadcrumbAllFiles, "click", (event) => {
652
- this.setBreadcrumbClickEvent(event, false, childConfig as PopsFolderDataConfig[]);
653
- });
654
-
655
- this.initFolderView(childConfig as PopsFolderDataConfig[]);
656
- }
657
- loadingMask.close();
658
- }
659
- /**
660
- * 文件的点击事件 - 下载文件
661
- * @param $target
662
- * @param dataConfig
663
- */
664
- async downloadFile(clickEvent: MouseEvent | PointerEvent, $row: HTMLElement, dataConfig: PopsFolderDataConfig) {
665
- popsDOMUtils.preventEvent(clickEvent);
666
-
667
- const $link = $row.querySelector("a")!;
668
- if (typeof dataConfig.clickEvent === "function") {
669
- const downloadInfo = await dataConfig.clickEvent(clickEvent, dataConfig)!;
670
- if (
671
- downloadInfo != null &&
672
- typeof downloadInfo === "object" &&
673
- !Array.isArray(downloadInfo) &&
674
- typeof downloadInfo.url === "string" &&
675
- downloadInfo.url.trim() !== ""
676
- ) {
677
- $link.setAttribute("href", downloadInfo.url);
678
- $link.setAttribute("target", "_blank");
679
- if (downloadInfo.autoDownload) {
680
- if (downloadInfo.mode == null || String(downloadInfo.mode) === "") {
681
- // 未设置mode的话默认为aBlank
682
- downloadInfo.mode = "aBlank";
683
- }
684
- if (downloadInfo.mode === "a" || downloadInfo.mode === "aBlank") {
685
- // a标签下载
686
- const $anchor = popsDOMUtils.createElement("a");
687
-
688
- if (downloadInfo.mode === "aBlank") {
689
- $anchor.setAttribute("target", "_blank");
690
- }
691
-
692
- $anchor.href = downloadInfo.url;
693
- $anchor.click();
694
- } else if (downloadInfo.mode === "open" || downloadInfo.mode === "openBlank") {
695
- // window.open下载
696
-
697
- if (downloadInfo.mode === "openBlank") {
698
- globalThis.open(downloadInfo.url, "_blank");
699
- } else {
700
- globalThis.open(downloadInfo.url);
701
- }
702
- } else if (downloadInfo.mode === "iframe") {
703
- // iframe下载
704
- const $downloadIframe = popsDOMUtils.createElement("iframe");
705
-
706
- $downloadIframe.src = downloadInfo.url;
707
- $downloadIframe.onload = function () {
708
- popsUtils.setTimeout(() => {
709
- $downloadIframe.remove();
710
- }, 1000);
711
- };
712
- $shadowRoot.appendChild($downloadIframe);
713
- popsUtils.setTimeout(
714
- () => {
715
- $downloadIframe.remove();
716
- },
717
- 3 * 60 * 1000
718
- );
719
- } else {
720
- console.error("未知的下载模式", downloadInfo);
721
- }
722
- }
723
- }
724
- }
725
- }
726
- /**
727
- * 对配置进行排序
728
- * @param folderDataConfigList
729
- * @param sortName 比较的属性,默认fileName
730
- * @param isDesc 是否降序,默认false(升序)
731
- */
732
- sortFolderConfig(
733
- folderDataConfigList: PopsFolderDataConfig[],
734
- sortName: "fileName" | "fileSize" | "latestTime" = "fileName",
735
- isDesc = false
736
- ) {
737
- if (sortName === "fileName") {
738
- // 如果是以文件名排序,文件夹优先放前面
739
- const onlyFolderDataConfigList = folderDataConfigList.filter((value) => {
740
- return value.isFolder;
741
- });
742
- const onlyFileDataConfigList = folderDataConfigList.filter((value) => {
743
- return !value.isFolder;
744
- });
745
- // 文件夹排序
746
- onlyFolderDataConfigList.sort((leftConfig, rightConfig) => {
747
- const beforeVal = leftConfig[sortName].toString();
748
- const afterVal = rightConfig[sortName].toString();
749
- let compareVal = beforeVal.localeCompare(afterVal);
750
- if (isDesc) {
751
- // 降序
752
- if (compareVal > 0) {
753
- compareVal = -1;
754
- } else if (compareVal < 0) {
755
- compareVal = 1;
756
- }
757
- }
758
- return compareVal;
759
- });
760
- // 文件名排序
761
- onlyFileDataConfigList.sort((leftConfig, rightConfig) => {
762
- const beforeVal = leftConfig[sortName].toString();
763
- const afterVal = rightConfig[sortName].toString();
764
- let compareVal = beforeVal.localeCompare(afterVal);
765
- if (isDesc) {
766
- // 降序
767
- if (compareVal > 0) {
768
- compareVal = -1;
769
- } else if (compareVal < 0) {
770
- compareVal = 1;
771
- }
772
- }
773
- return compareVal;
774
- });
775
- if (isDesc) {
776
- // 降序,文件夹在下面
777
- return [...onlyFileDataConfigList, ...onlyFolderDataConfigList];
778
- } else {
779
- // 升序,文件夹在上面
780
- return [...onlyFolderDataConfigList, ...onlyFileDataConfigList];
781
- }
782
- } else {
783
- folderDataConfigList.sort((beforeConfig, afterConfig) => {
784
- let beforeVal = beforeConfig[sortName];
785
- let afterVal = afterConfig[sortName];
786
- if (sortName === "fileSize") {
787
- // 文件大小,进行Float转换
788
- beforeVal = parseFloat(beforeVal.toString());
789
- afterVal = parseFloat(afterVal.toString());
790
- } else if (sortName === "latestTime") {
791
- // 文件时间
792
- beforeVal = new Date(beforeVal).getTime();
793
- afterVal = new Date(afterVal).getTime();
794
- }
795
- if (beforeVal > afterVal) {
796
- if (isDesc) {
797
- // 降序
798
- return -1;
799
- } else {
800
- return 1;
801
- }
802
- } else if (beforeVal < afterVal) {
803
- if (isDesc) {
804
- // 降序
805
- return 1;
806
- } else {
807
- return -1;
808
- }
809
- } else {
810
- return 0;
811
- }
812
- });
813
- return folderDataConfigList;
814
- }
815
- }
816
- /**
817
- * 添加文件夹/文件行元素
818
- * @param dataConfig 配置
819
- */
820
- initFolderView(dataConfig: PopsFolderDataConfig[]) {
821
- // 先对文件夹、文件进行排序
822
- this.sortFolderConfig(dataConfig, config.sort.name, config.sort.isDesc);
823
- dataConfig.forEach((item) => {
824
- if (item.isFolder) {
825
- const { folderElement, fileNameElement } = popsUtils.isPhone()
826
- ? this.createFolderRowElementByMobile(item.fileName, "", "", true)
827
- : this.createFolderRowElement(item.fileName, "", "", true);
828
- // 文件夹 - 点击事件
829
- popsDOMUtils.on<MouseEvent | PointerEvent>(fileNameElement, "click", (event) => {
830
- // 进入文件夹
831
- this.enterFolder(event, item);
832
- });
833
-
834
- folderListBodyElement.appendChild(folderElement);
835
- } else {
836
- const { folderElement, fileNameElement } = popsUtils.isPhone()
837
- ? this.createFolderRowElementByMobile(item.fileName, item.latestTime, item.fileSize, false)
838
- : this.createFolderRowElement(item.fileName, item.latestTime, item.fileSize, false);
839
- // 文件 - 点击事件
840
- popsDOMUtils.on<MouseEvent | PointerEvent>(fileNameElement, "click", (event) => {
841
- // 下载文件
842
- this.downloadFile(event, fileNameElement, item);
843
- });
844
-
845
- folderListBodyElement.appendChild(folderElement);
846
- }
847
- });
848
- }
849
- /**
850
- * 移除所有箭头的被访问状态
851
- */
852
- removeArrowActiveStatus() {
853
- [
854
- ...Array.from(folderListSortFileNameElement.querySelectorAll<HTMLElement>(".pops-folder-icon-active")),
855
- ...Array.from(folderListSortLatestTimeElement.querySelectorAll<HTMLElement>(".pops-folder-icon-active")),
856
- ...Array.from(folderListSortFileSizeElement.querySelectorAll<HTMLElement>(".pops-folder-icon-active")),
857
- ].forEach((ele) => ele.classList.remove("pops-folder-icon-active"));
858
- }
859
- /**
860
- * 修改导航箭头的状态
861
- */
862
- changeArrowActive(arrowUp: HTMLElement, arrowDown: HTMLElement, isDesc: boolean) {
863
- this.removeArrowActiveStatus();
864
- if (isDesc) {
865
- arrowDown.classList.add("pops-folder-icon-active");
866
- } else {
867
- arrowUp.classList.add("pops-folder-icon-active");
868
- }
869
- }
870
- /**
871
- * 排序按钮的点击事件
872
- * @param target
873
- * @param event
874
- * @param sortName
875
- */
876
- arrowToSortFolderInfoView(target: HTMLDivElement, event: MouseEvent | PointerEvent, sortName: string) {
877
- const notChangeSortRule = Reflect.get(event, "notChangeSortRule");
878
- if (!notChangeSortRule) {
879
- config.sort.name = sortName as PopsFolderConfig["sort"]["name"];
880
- config.sort.isDesc = !config.sort.isDesc;
881
- }
882
-
883
- const $arrowUp = target.querySelector<HTMLDivElement>(".pops-folder-icon-arrow-up")!;
884
- const $arrowDown = target.querySelector<HTMLDivElement>(".pops-folder-icon-arrow-down")!;
885
- this.changeArrowActive($arrowUp, $arrowDown, config.sort.isDesc);
886
- if (
887
- typeof config.sort.callback === "function" &&
888
- config.sort.callback(target, event, config.sort.name, config.sort.isDesc)
889
- ) {
890
- return;
891
- }
892
-
893
- const childrenList: PopsFolderDataConfig[] = [];
894
-
895
- Array.from(folderListBodyElement.children).forEach((trElement) => {
896
- const __value__ = Reflect.get(trElement, "__value__");
897
- Reflect.set(__value__, "target", trElement);
898
- childrenList.push(__value__);
899
- });
900
- const sortedConfigList = this.sortFolderConfig(childrenList, config.sort.name, config.sort.isDesc);
901
- sortedConfigList.forEach((item) => {
902
- folderListBodyElement.appendChild((item as any).target);
903
- });
904
- }
905
- }
906
-
907
- const popsFolder = new PopsFolder();
908
- popsFolder.init();
909
- Reflect.set($pops, "data-pops-folder", popsFolder);
910
- // 拖拽
911
- if (config.drag) {
912
- PopsInstanceUtils.drag($pops, {
913
- dragElement: $title,
914
- limit: config.dragLimit,
915
- extraDistance: config.dragExtraDistance,
916
- moveCallBack: config.dragMoveCallBack,
917
- endCallBack: config.dragEndCallBack,
918
- });
919
- }
920
- PopsHandler.handlePush(popsType, {
921
- guid: guid,
922
- $anim: $anim,
923
- $pops: $pops,
924
- $mask: $mask!,
925
- $shadowContainer: $shadowContainer,
926
- $shadowRoot: $shadowRoot,
927
- config: config,
928
- destory: result.close,
929
- });
930
- return result;
931
- },
932
- };
1
+ import { GlobalConfig } from "../../config/GlobalConfig";
2
+ import { PopsElementHandler } from "../../handler/PopsElementHandler";
3
+ import { PopsHandler } from "../../handler/PopsHandler";
4
+ import { PopsCSS } from "../../PopsCSS";
5
+ import type { PopsType } from "../../types/main";
6
+ import { popsDOMUtils } from "../../utils/PopsDOMUtils";
7
+ import { PopsInstanceUtils } from "../../utils/PopsInstanceUtils";
8
+ import { PopsSafeUtils } from "../../utils/PopsSafeUtils";
9
+ import { popsUtils } from "../../utils/PopsUtils";
10
+ import { PopsLoading } from "../loading";
11
+ import { PopsFolderDefaultConfig } from "./defaultConfig";
12
+ import { Folder_ICON } from "./folderIcon";
13
+ import type { PopsFolderDataConfig, PopsFolderConfig, PopsFolderDownloadOption } from "./types";
14
+
15
+ export const PopsFolder = {
16
+ init(__config__: PopsFolderConfig) {
17
+ const guid = popsUtils.getRandomGUID();
18
+ // 设置当前类型
19
+ const popsType: PopsType = "folder";
20
+
21
+ let config = PopsFolderDefaultConfig();
22
+ config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
23
+ config = popsUtils.assign(config, __config__);
24
+ config = PopsHandler.handleOnly(popsType, config);
25
+
26
+ const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
27
+ PopsHandler.handleInit($shadowRoot, [
28
+ {
29
+ name: "index",
30
+ css: PopsCSS.index,
31
+ },
32
+ {
33
+ name: "ninePalaceGridPosition",
34
+ css: PopsCSS.ninePalaceGridPosition,
35
+ },
36
+ {
37
+ name: "scrollbar",
38
+ css: PopsCSS.scrollbar,
39
+ },
40
+ {
41
+ name: "button",
42
+ css: PopsCSS.button,
43
+ },
44
+ {
45
+ name: "anim",
46
+ css: PopsCSS.anim,
47
+ },
48
+ {
49
+ name: "common",
50
+ css: PopsCSS.common,
51
+ },
52
+ {
53
+ name: "folderCSS",
54
+ css: PopsCSS.folderCSS,
55
+ },
56
+ ]);
57
+
58
+ // 办公几件套
59
+ Reflect.set(Folder_ICON, "docx", Folder_ICON.doc);
60
+ Reflect.set(Folder_ICON, "rtf", Folder_ICON.doc);
61
+ Reflect.set(Folder_ICON, "xlsx", Folder_ICON.xls);
62
+ Reflect.set(Folder_ICON, "pptx", Folder_ICON.ppt);
63
+ Reflect.set(Folder_ICON, "dmg", Folder_ICON.ipa);
64
+ Reflect.set(Folder_ICON, "json", Folder_ICON.js);
65
+
66
+ // 压缩包
67
+ const zipIconList = [
68
+ "rar",
69
+ "7z",
70
+ "arj",
71
+ "bz2",
72
+ "cab",
73
+ "iso",
74
+ "jar",
75
+ "lz",
76
+ "lzh",
77
+ "tar",
78
+ "uue",
79
+ "xz",
80
+ "z",
81
+ "zipx",
82
+ "zst",
83
+ "001",
84
+ ];
85
+
86
+ // 图片
87
+ const imageIconList = ["jpg", "jpeg", "ico", "webp"];
88
+
89
+ // 代码语言
90
+ const codeLanguageIconList = ["htm", "py", "vue", "bat", "sh", "vbs", "java", "kt"];
91
+
92
+ // Android安装包
93
+ const androidIconList = ["apk", "apkm", "xapk"];
94
+
95
+ zipIconList.forEach((keyName) => {
96
+ Folder_ICON[keyName as keyof typeof Folder_ICON] = Folder_ICON.zip;
97
+ });
98
+ imageIconList.forEach((keyName) => {
99
+ Folder_ICON[keyName as keyof typeof Folder_ICON] = Folder_ICON.png;
100
+ });
101
+ codeLanguageIconList.forEach((keyName) => {
102
+ Folder_ICON[keyName as keyof typeof Folder_ICON] = Folder_ICON.html;
103
+ });
104
+ androidIconList.forEach((keyName) => {
105
+ Folder_ICON[keyName as keyof typeof Folder_ICON] = Folder_ICON.apk;
106
+ });
107
+
108
+ if (config?.folder) {
109
+ Reflect.set(config, "folder", config.folder);
110
+ }
111
+
112
+ // 先把z-index提取出来
113
+ const zIndex = PopsHandler.handleZIndex(config.zIndex);
114
+ const maskHTML = PopsElementHandler.createMask(guid, zIndex);
115
+
116
+ const headerBtnHTML = PopsElementHandler.createHeader(popsType, config);
117
+ const bottomBtnHTML = PopsElementHandler.createBottom(popsType, config);
118
+ const { headerStyle, headerPStyle } = PopsElementHandler.createHeaderStyle(popsType, config);
119
+ const animHTML = PopsElementHandler.createAnim(
120
+ guid,
121
+ popsType,
122
+ config,
123
+ /*html*/ `
124
+ <div class="pops-title pops-${popsType}-title" style="text-align: ${
125
+ config.title.position
126
+ };${headerStyle}">${
127
+ config.title.html
128
+ ? config.title.text
129
+ : `<p pops class="pops-${popsType}-title-text" style="${headerPStyle}">${config.title.text}</p>`
130
+ }${headerBtnHTML}</div>
131
+ <div class="pops-content pops-${popsType}-content ${popsUtils.isPhone() ? "pops-mobile-folder-content" : ""}">
132
+ <div class="pops-folder-list">
133
+ <div class="pops-folder-file-list-breadcrumb">
134
+ <div class="pops-folder-file-list-breadcrumb-primary">
135
+ <span class="pops-folder-file-list-breadcrumb-allFiles cursor-p" title="全部文件">
136
+ <a>全部文件</a>
137
+ </span>
138
+ </div>
139
+ </div>
140
+ <div class="pops-folder-list-table__header-div">
141
+ <table class="pops-folder-list-table__header">
142
+ <colgroup>
143
+ <col width="52%">
144
+ <col width="24%">
145
+ <col width="16%">
146
+ </colgroup>
147
+ <thead>
148
+ <tr class="pops-folder-list-table__header-row">
149
+ <th class="pops-folder-list-table__header-th cursor-p">
150
+ <div class="text-ellip content flex-a-i-center">
151
+ <span>文件名</span>
152
+ <div class="pops-folder-list-table__sort" data-sort="fileName">
153
+ <div class="pops-folder-icon-arrow" data-sort="按文件名排序">
154
+ <svg
155
+ viewBox="0 0 1024 1024"
156
+ xmlns="http://www.w3.org/2000/svg">
157
+ <path
158
+ d="M509.624392 5.882457 57.127707 458.379143 962.121078 458.379143Z"
159
+ class="pops-folder-icon-arrow-up"></path>
160
+ <path
161
+ d="M509.624392 1024 962.121078 571.503314 57.127707 571.503314Z"
162
+ class="pops-folder-icon-arrow-down"></path>
163
+ </svg>
164
+ </div>
165
+ </div>
166
+ </div>
167
+ </th>
168
+ <th class="pops-folder-list-table__header-th cursor-p">
169
+ <div class="text-ellip content flex-a-i-center">
170
+ <span>修改时间</span>
171
+ <div class="pops-folder-list-table__sort" data-sort="latestTime">
172
+ <div class="pops-folder-icon-arrow" title="按修改时间排序">
173
+ <svg
174
+ viewBox="0 0 1024 1024"
175
+ xmlns="http://www.w3.org/2000/svg">
176
+ <path
177
+ d="M509.624392 5.882457 57.127707 458.379143 962.121078 458.379143Z"
178
+ class="pops-folder-icon-arrow-up"></path>
179
+ <path
180
+ d="M509.624392 1024 962.121078 571.503314 57.127707 571.503314Z"
181
+ class="pops-folder-icon-arrow-down"></path>
182
+ </svg>
183
+ </div>
184
+ </div>
185
+ </div>
186
+ </th>
187
+ <th class="pops-folder-list-table__header-th cursor-p">
188
+ <div class="text-ellip content flex-a-i-center">
189
+ <span>大小</span>
190
+ <div class="pops-folder-list-table__sort" data-sort="fileSize">
191
+ <div class="pops-folder-icon-arrow" title="按大小排序">
192
+ <svg
193
+ viewBox="0 0 1024 1024"
194
+ xmlns="http://www.w3.org/2000/svg">
195
+ <path
196
+ d="M509.624392 5.882457 57.127707 458.379143 962.121078 458.379143Z"
197
+ class="pops-folder-icon-arrow-up"></path>
198
+ <path
199
+ d="M509.624392 1024 962.121078 571.503314 57.127707 571.503314Z"
200
+ class="pops-folder-icon-arrow-down"></path>
201
+ </svg>
202
+ </div>
203
+ </div>
204
+ </div>
205
+ </th>
206
+ </tr>
207
+ </thead>
208
+ </table>
209
+ </div>
210
+ <div class="pops-folder-list-table__body-div">
211
+ <table class="pops-folder-list-table__body">
212
+ <colgroup>
213
+ ${
214
+ popsUtils.isPhone()
215
+ ? `<col width="100%">`
216
+ : `
217
+ <col width="52%">
218
+ <col width="24%">
219
+ <col width="16%">`
220
+ }
221
+ </colgroup>
222
+ <tbody></tbody>
223
+ </table>
224
+ </div>
225
+ </div>
226
+ </div>${bottomBtnHTML}`,
227
+ bottomBtnHTML,
228
+ zIndex
229
+ );
230
+ /**
231
+ * 弹窗的主元素,包括动画层
232
+ */
233
+ const $anim = PopsElementHandler.parseElement<HTMLDivElement>(animHTML);
234
+ const {
235
+ $pops: $pops,
236
+ $title: $title,
237
+ $content: $content,
238
+ // folderListElement,
239
+ // folderListHeaderElement,
240
+ // folderListHeaderRowElement,
241
+ $folderTbody: folderListBodyElement,
242
+ $folderHeaderBreadcrumbPrimary: folderFileListBreadcrumbPrimaryElement,
243
+ $headerBtnClose: $btnCloseBtn,
244
+ $btnOk: btnOkElement,
245
+ $btnCancel: btnCancelElement,
246
+ $btnOther: btnOtherElement,
247
+ $folderSortFileName: folderListSortFileNameElement,
248
+ $folderSortLatestTime: folderListSortLatestTimeElement,
249
+ $folderSortFileSize: folderListSortFileSizeElement,
250
+ } = PopsHandler.handleQueryElement($anim, popsType);
251
+
252
+ /**
253
+ * 遮罩层元素
254
+ */
255
+ let $mask: HTMLDivElement | undefined = void 0;
256
+ /**
257
+ * 已创建的元素列表
258
+ */
259
+ const $elList: HTMLElement[] = [$anim];
260
+
261
+ if (config.mask.enable) {
262
+ const handleMask = PopsHandler.handleMask({
263
+ type: popsType,
264
+ guid: guid,
265
+ config: config,
266
+ animElement: $anim,
267
+ maskHTML: maskHTML,
268
+ });
269
+ $mask = handleMask.maskElement;
270
+ $elList.push($mask);
271
+ }
272
+ // 事件
273
+ const evtConfig = PopsHandler.handleEventConfig(
274
+ config,
275
+ guid,
276
+ $shadowContainer,
277
+ $shadowRoot,
278
+ popsType,
279
+ $anim,
280
+ $pops,
281
+ $mask
282
+ );
283
+ const result = PopsHandler.handleResultConfig(evtConfig);
284
+ PopsHandler.handleClickEvent("close", $btnCloseBtn, evtConfig, config.btn.close.callback);
285
+ PopsHandler.handleClickEvent("ok", btnOkElement, evtConfig, config.btn.ok.callback);
286
+ PopsHandler.handleClickEvent("cancel", btnCancelElement, evtConfig, config.btn.cancel.callback);
287
+ PopsHandler.handleClickEvent("other", btnOtherElement, evtConfig, config.btn.other.callback);
288
+ // 创建到页面中
289
+
290
+ popsDOMUtils.append($shadowRoot, $elList);
291
+ if (typeof config.beforeAppendToPageCallBack === "function") {
292
+ config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
293
+ }
294
+
295
+ popsDOMUtils.appendBody($shadowContainer);
296
+ if ($mask != null) {
297
+ $anim.after($mask);
298
+ }
299
+ class PopsFolder {
300
+ init() {
301
+ config.folder.sort();
302
+ this.initFolderView(config.folder);
303
+ // 将数据存到全部文件的属性_config_中
304
+
305
+ const $allFiles = folderFileListBreadcrumbPrimaryElement.querySelector<HTMLDivElement>(
306
+ ".pops-folder-list .pops-folder-file-list-breadcrumb-allFiles:first-child"
307
+ )!;
308
+
309
+ Reflect.set($allFiles, "data-config", config.folder);
310
+ // 设置点击顶部的全部文件事件
311
+ popsDOMUtils.on<MouseEvent | PointerEvent>($allFiles, "click", (event) => {
312
+ this.setBreadcrumbClickEvent(event, true, config.folder);
313
+ });
314
+ // 文件名的点击排序
315
+ popsDOMUtils.on<MouseEvent | PointerEvent>(
316
+ folderListSortFileNameElement.closest("th"),
317
+ "click",
318
+ (event) => {
319
+ this.arrowToSortFolderInfoView(folderListSortFileNameElement, event, "fileName");
320
+ },
321
+ {
322
+ capture: true,
323
+ }
324
+ );
325
+ // 修改事件的点击排序
326
+ popsDOMUtils.on(
327
+ folderListSortLatestTimeElement.closest("th"),
328
+ "click",
329
+ (event) => {
330
+ this.arrowToSortFolderInfoView(folderListSortLatestTimeElement, event, "latestTime");
331
+ },
332
+ {
333
+ capture: true,
334
+ }
335
+ );
336
+ // 文件大小的点击排序
337
+ popsDOMUtils.on(
338
+ folderListSortFileSizeElement.closest("th"),
339
+ "click",
340
+ (event) => {
341
+ this.arrowToSortFolderInfoView(folderListSortFileSizeElement, event, "fileSize");
342
+ },
343
+ {
344
+ capture: true,
345
+ }
346
+ );
347
+ // 设置默认触发的arrow
348
+ if (config.sort.name === "fileName") {
349
+ popsDOMUtils.emit(folderListSortFileNameElement, "click", {
350
+ notChangeSortRule: true,
351
+ });
352
+ } else if (config.sort.name === "latestTime") {
353
+ popsDOMUtils.emit(folderListSortLatestTimeElement, "click", {
354
+ notChangeSortRule: true,
355
+ });
356
+ } else if (config.sort.name === "fileSize") {
357
+ popsDOMUtils.emit(folderListSortFileSizeElement, "click", {
358
+ notChangeSortRule: true,
359
+ });
360
+ }
361
+ }
362
+ /**
363
+ * 在创建文件|文件夹创建元素前处理东西
364
+ */
365
+ handlerWithBeforeCreateFileOrFolderInfoNode(folderData: PopsFolderDataConfig) {
366
+ let { fileSize } = folderData;
367
+ const { fileName, latestTime, isFolder = false } = folderData;
368
+ folderData.latestTime = folderData.latestTime ?? "-";
369
+ folderData.fileSize = folderData.fileSize ?? "-";
370
+ const $folder = popsDOMUtils.createElement("tr");
371
+
372
+ const $fileName = popsDOMUtils.createElement("td");
373
+ const $fileTime = popsDOMUtils.createElement("td");
374
+ const $fileFormatSize = popsDOMUtils.createElement("td");
375
+
376
+ let show_latestTime = "";
377
+ let show_fileSize = "";
378
+ let fileType = "";
379
+ let fileIcon = "";
380
+ if (isFolder) {
381
+ // 文件夹
382
+ fileType = "";
383
+ fileIcon = Folder_ICON.folder;
384
+ show_latestTime = "";
385
+ fileSize = "";
386
+ show_fileSize = "";
387
+ } else {
388
+ // 文件
389
+ if (typeof latestTime === "function") {
390
+ const timeRet = latestTime();
391
+ show_latestTime = timeRet.showText;
392
+ } else if (typeof latestTime === "number") {
393
+ show_latestTime = popsUtils.formatTime(latestTime);
394
+ } else if (typeof latestTime === "string") {
395
+ show_latestTime = latestTime;
396
+ }
397
+ if (typeof fileSize === "number") {
398
+ show_fileSize = popsUtils.formatByteToSize(fileSize, true);
399
+ } else if (typeof fileSize === "string") {
400
+ show_fileSize = fileSize;
401
+ }
402
+ // 找到对应的图标
403
+ const findIconKeyName = Object.keys(Folder_ICON).find((keyName) => {
404
+ if (fileName.toLowerCase().endsWith("." + keyName)) {
405
+ fileType = keyName;
406
+ fileIcon = Reflect.get(Folder_ICON, keyName);
407
+ return true;
408
+ }
409
+ });
410
+ if (findIconKeyName) {
411
+ fileIcon = Reflect.get(Folder_ICON, findIconKeyName);
412
+ fileType = findIconKeyName;
413
+ } else {
414
+ fileType = "Null";
415
+ fileIcon = Folder_ICON.Null;
416
+ }
417
+ }
418
+
419
+ if (typeof folderData.fileIcon === "string") {
420
+ // 强制使用自定义
421
+ fileIcon = folderData.fileIcon;
422
+ }
423
+ $folder.className = "pops-folder-list-table__body-row";
424
+ $fileName.className = "pops-folder-list-table__body-td";
425
+ $fileTime.className = "pops-folder-list-table__body-td";
426
+ $fileFormatSize.className = "pops-folder-list-table__body-td";
427
+
428
+ return {
429
+ $folder,
430
+ $fileName,
431
+ $fileTime,
432
+ $fileFormatSize,
433
+ /** 经过处理后的数据 */
434
+ data: {
435
+ fileType,
436
+ fileIcon,
437
+ show_latestTime,
438
+ show_fileSize,
439
+ },
440
+ };
441
+ }
442
+ /**
443
+ * 创建文件夹元素
444
+ * @param fileName 文件名
445
+ * @param latestTime 修改时间
446
+ * @param [fileSize="-"] 文件大小
447
+ * @param isFolder 是否是文件夹
448
+ */
449
+ createFolderRowElement(folderData: PopsFolderDataConfig) {
450
+ const { $folder, $fileName, $fileTime, $fileFormatSize, data } =
451
+ this.handlerWithBeforeCreateFileOrFolderInfoNode(folderData);
452
+
453
+ const { fileName } = folderData;
454
+
455
+ PopsSafeUtils.setSafeHTML(
456
+ $fileName,
457
+ /*html*/ `
458
+ <div class="pops-folder-list-file-name cursor-p">
459
+ <div>
460
+ <img src="${data.fileIcon}" alt="${data.fileType}" class="pops-folder-list-file-icon u-file-icon u-file-icon--list">
461
+ <a href="javascript:;" title="${fileName}" class="pops-folder-list-file-name-title-text inline-block-v-middle text-ellip list-name-text">${fileName}</a>
462
+ </div>
463
+ </div>`
464
+ );
465
+ PopsSafeUtils.setSafeHTML(
466
+ $fileTime,
467
+ /*html*/ `
468
+ <div class="pops-folder-list__time">
469
+ <span>${data.show_latestTime}</span>
470
+ </div>`
471
+ );
472
+ PopsSafeUtils.setSafeHTML(
473
+ $fileFormatSize,
474
+ /*html*/ `
475
+ <div class="pops-folder-list-format-size">
476
+ <span>${data.show_fileSize}</span>
477
+ </div>`
478
+ );
479
+
480
+ Reflect.set($fileName, "__value__", folderData);
481
+ Reflect.set($fileTime, "__value__", folderData);
482
+ Reflect.set($fileFormatSize, "__value__", folderData);
483
+ Reflect.set($folder, "__value__", folderData);
484
+
485
+ $folder.appendChild($fileName);
486
+ $folder.appendChild($fileTime);
487
+ $folder.appendChild($fileFormatSize);
488
+ return {
489
+ folderElement: $folder,
490
+ fileNameElement: $fileName,
491
+ fileTimeElement: $fileTime,
492
+ fileFormatSize: $fileFormatSize,
493
+ };
494
+ }
495
+ /**
496
+ * 创建移动端文件夹元素
497
+ * @param fileName 文件名
498
+ * @param latestTime 创建时间
499
+ * @param [fileSize="-"] 文件大小
500
+ * @param isFolder 是否是文件夹
501
+ */
502
+ createFolderRowElementByMobile(folderData: PopsFolderDataConfig) {
503
+ const { $folder, $fileName, data } = this.handlerWithBeforeCreateFileOrFolderInfoNode(folderData);
504
+
505
+ const { fileName } = folderData;
506
+
507
+ PopsSafeUtils.setSafeHTML(
508
+ $fileName,
509
+ /*html*/ `
510
+ <div class="pops-folder-list-file-name pops-mobile-folder-list-file-name cursor-p">
511
+ <img src="${data.fileIcon}" alt="${data.fileType}" class="pops-folder-list-file-icon u-file-icon u-file-icon--list">
512
+ <div>
513
+ <a title="${fileName}" class="pops-folder-list-file-name-title-text inline-block-v-middle text-ellip list-name-text">${fileName}</a>
514
+ <span>${data.show_latestTime} ${data.show_fileSize}</span>
515
+ </div>
516
+ </div>`
517
+ );
518
+ // 存储原来的值
519
+ Reflect.set($fileName, "__value__", folderData);
520
+ Reflect.set($folder, "folderData", folderData);
521
+ $folder.appendChild($fileName);
522
+ return {
523
+ folderElement: $folder,
524
+ fileNameElement: $fileName,
525
+ };
526
+ }
527
+ /**
528
+ * 清空文件夹信息页面
529
+ */
530
+ clearFolderInfoView() {
531
+ PopsSafeUtils.setSafeHTML(folderListBodyElement, "");
532
+ }
533
+ /**
534
+ * 创建顶部导航的箭头图标
535
+ */
536
+ createHeaderArrowIcon() {
537
+ const $arrowIcon = popsDOMUtils.createElement("div", {
538
+ className: "iconArrow",
539
+ });
540
+ return $arrowIcon;
541
+ }
542
+ /**
543
+ * 添加顶部导航元素
544
+ * @param folderName 文件夹名
545
+ * @param folderDataConfig 文件夹配置
546
+ */
547
+ createBreadcrumb(
548
+ folderName: string,
549
+ folderDataConfig: PopsFolderDownloadOption | PopsFolderDataConfig[] | null | undefined | void
550
+ ) {
551
+ const $breadcrumb = popsDOMUtils.createElement(
552
+ "span",
553
+ {
554
+ className: "pops-folder-file-list-breadcrumb-allFiles cursor-p",
555
+ innerHTML: `<a>${folderName}</a>`,
556
+ "data-config": folderDataConfig,
557
+ },
558
+ {
559
+ title: folderName,
560
+ }
561
+ );
562
+ return $breadcrumb;
563
+ }
564
+ /**
565
+ * 顶部导航的点击事件
566
+ * @param clickEvent
567
+ * @param isTop 是否是全部文件按钮
568
+ * @param dataConfigList 配置
569
+ */
570
+ setBreadcrumbClickEvent(
571
+ clickEvent: MouseEvent | PointerEvent,
572
+ isTop: boolean,
573
+ dataConfigList: PopsFolderDataConfig[]
574
+ ) {
575
+ this.clearFolderInfoView();
576
+ // 获取当前的导航元素
577
+ const $click = clickEvent.target as HTMLElement;
578
+ const currentBreadcrumb = $click.closest<HTMLSpanElement>("span.pops-folder-file-list-breadcrumb-allFiles");
579
+ if (currentBreadcrumb) {
580
+ while (currentBreadcrumb.nextElementSibling) {
581
+ currentBreadcrumb.nextElementSibling.remove();
582
+ }
583
+ } else {
584
+ console.error("获取导航按钮失败");
585
+ }
586
+ const loadingMask = PopsLoading.init({
587
+ $parent: $content,
588
+ content: {
589
+ text: "获取文件列表中...",
590
+ },
591
+ mask: {
592
+ enable: true,
593
+ clickEvent: {
594
+ toClose: false,
595
+ toHide: false,
596
+ },
597
+ },
598
+ addIndexCSS: false,
599
+ });
600
+ this.initFolderView(dataConfigList);
601
+ loadingMask.close();
602
+ }
603
+ /**
604
+ * 文件夹的点击事件 - 进入文件夹
605
+ *
606
+ * 先情况页面元素
607
+ * @param clickEvent
608
+ * @param dataConfig
609
+ */
610
+ async enterFolder(clickEvent: MouseEvent | PointerEvent, dataConfig: PopsFolderDataConfig) {
611
+ this.clearFolderInfoView();
612
+ const loadingMask = PopsLoading.init({
613
+ $parent: $content,
614
+ content: {
615
+ text: "获取文件列表中...",
616
+ },
617
+ mask: {
618
+ enable: true,
619
+ },
620
+ addIndexCSS: false,
621
+ });
622
+ if (typeof dataConfig.clickEvent === "function") {
623
+ const childConfig = await dataConfig.clickEvent(clickEvent, dataConfig);
624
+ // 添加顶部导航的箭头
625
+ folderFileListBreadcrumbPrimaryElement.appendChild(this.createHeaderArrowIcon());
626
+ // 添加顶部导航的链接文字
627
+ const $breadcrumbAllFiles = this.createBreadcrumb(dataConfig.fileName, childConfig);
628
+
629
+ folderFileListBreadcrumbPrimaryElement.appendChild($breadcrumbAllFiles);
630
+ // 设置顶部导航点击事件
631
+
632
+ popsDOMUtils.on<MouseEvent | PointerEvent>($breadcrumbAllFiles, "click", (event) => {
633
+ this.setBreadcrumbClickEvent(event, false, childConfig as PopsFolderDataConfig[]);
634
+ });
635
+
636
+ this.initFolderView(childConfig as PopsFolderDataConfig[]);
637
+ }
638
+ loadingMask.close();
639
+ }
640
+ /**
641
+ * 文件的点击事件 - 下载文件
642
+ * @param $target
643
+ * @param dataConfig
644
+ */
645
+ async downloadFile(clickEvent: MouseEvent | PointerEvent, $row: HTMLElement, dataConfig: PopsFolderDataConfig) {
646
+ popsDOMUtils.preventEvent(clickEvent);
647
+
648
+ const $link = $row.querySelector("a")!;
649
+ if (typeof dataConfig.clickEvent === "function") {
650
+ const downloadInfo = await dataConfig.clickEvent(clickEvent, dataConfig)!;
651
+ if (
652
+ downloadInfo != null &&
653
+ typeof downloadInfo === "object" &&
654
+ !Array.isArray(downloadInfo) &&
655
+ typeof downloadInfo.url === "string" &&
656
+ downloadInfo.url.trim() !== ""
657
+ ) {
658
+ $link.setAttribute("href", downloadInfo.url);
659
+ $link.setAttribute("target", "_blank");
660
+ if (downloadInfo.autoDownload) {
661
+ if (downloadInfo.mode == null || String(downloadInfo.mode) === "") {
662
+ // 未设置mode的话默认为aBlank
663
+ downloadInfo.mode = "aBlank";
664
+ }
665
+ if (downloadInfo.mode === "a" || downloadInfo.mode === "aBlank") {
666
+ // a标签下载
667
+ const $anchor = popsDOMUtils.createElement("a");
668
+
669
+ if (downloadInfo.mode === "aBlank") {
670
+ $anchor.setAttribute("target", "_blank");
671
+ }
672
+
673
+ $anchor.href = downloadInfo.url;
674
+ $anchor.click();
675
+ } else if (downloadInfo.mode === "open" || downloadInfo.mode === "openBlank") {
676
+ // window.open下载
677
+
678
+ if (downloadInfo.mode === "openBlank") {
679
+ globalThis.open(downloadInfo.url, "_blank");
680
+ } else {
681
+ globalThis.open(downloadInfo.url);
682
+ }
683
+ } else if (downloadInfo.mode === "iframe") {
684
+ // iframe下载
685
+ const $downloadIframe = popsDOMUtils.createElement("iframe");
686
+
687
+ $downloadIframe.src = downloadInfo.url;
688
+ $downloadIframe.onload = function () {
689
+ popsUtils.setTimeout(() => {
690
+ $downloadIframe.remove();
691
+ }, 1000);
692
+ };
693
+ $shadowRoot.appendChild($downloadIframe);
694
+ popsUtils.setTimeout(
695
+ () => {
696
+ $downloadIframe.remove();
697
+ },
698
+ 3 * 60 * 1000
699
+ );
700
+ } else {
701
+ console.error("未知的下载模式", downloadInfo);
702
+ }
703
+ }
704
+ }
705
+ }
706
+ }
707
+ /**
708
+ * 对配置进行排序
709
+ * @param folderDataConfigList
710
+ * @param sortName 比较的属性,默认fileName
711
+ * @param isDesc 是否降序,默认false(升序)
712
+ */
713
+ sortFolderConfig(
714
+ folderDataConfigList: PopsFolderDataConfig[],
715
+ sortName: "fileName" | "fileSize" | "latestTime" = "fileName",
716
+ isDesc = false
717
+ ) {
718
+ // 文件夹
719
+ const onlyFolderDataConfigList = folderDataConfigList.filter((value) => {
720
+ return value.isFolder;
721
+ });
722
+ // 文件
723
+ const onlyFileDataConfigList = folderDataConfigList.filter((value) => {
724
+ return !value.isFolder;
725
+ });
726
+ if (sortName === "fileName") {
727
+ // 文件夹排序
728
+ onlyFolderDataConfigList.sort((leftConfig, rightConfig) => {
729
+ const beforeVal = leftConfig[sortName].toString();
730
+ const afterVal = rightConfig[sortName].toString();
731
+ let compareVal = beforeVal.localeCompare(afterVal);
732
+ if (isDesc) {
733
+ // 降序
734
+ if (compareVal > 0) {
735
+ compareVal = -1;
736
+ } else if (compareVal < 0) {
737
+ compareVal = 1;
738
+ }
739
+ }
740
+ return compareVal;
741
+ });
742
+ // 文件名排序
743
+ onlyFileDataConfigList.sort((leftConfig, rightConfig) => {
744
+ const beforeVal = leftConfig[sortName].toString();
745
+ const afterVal = rightConfig[sortName].toString();
746
+ let compareVal = beforeVal.localeCompare(afterVal);
747
+ if (isDesc) {
748
+ // 降序
749
+ if (compareVal > 0) {
750
+ compareVal = -1;
751
+ } else if (compareVal < 0) {
752
+ compareVal = 1;
753
+ }
754
+ }
755
+ return compareVal;
756
+ });
757
+ } else {
758
+ // 文件夹排序
759
+ onlyFolderDataConfigList.sort((beforeConfig, afterConfig) => {
760
+ let beforeVal = beforeConfig[sortName];
761
+ let afterVal = afterConfig[sortName];
762
+ if (typeof beforeVal === "function") {
763
+ beforeVal = beforeVal().timeStamp;
764
+ }
765
+ if (typeof afterVal === "function") {
766
+ afterVal = afterVal().timeStamp;
767
+ }
768
+ if (sortName === "fileSize") {
769
+ // 文件大小,进行Float转换
770
+ beforeVal = parseFloat(beforeVal.toString());
771
+ afterVal = parseFloat(afterVal.toString());
772
+ } else if (sortName === "latestTime") {
773
+ // 文件时间
774
+ beforeVal = new Date(beforeVal || "").getTime();
775
+ afterVal = new Date(afterVal || "").getTime();
776
+ }
777
+ if (beforeVal > afterVal) {
778
+ if (isDesc) {
779
+ // 降序
780
+ return -1;
781
+ } else {
782
+ return 1;
783
+ }
784
+ } else if (beforeVal < afterVal) {
785
+ if (isDesc) {
786
+ // 降序
787
+ return 1;
788
+ } else {
789
+ return -1;
790
+ }
791
+ } else {
792
+ return 0;
793
+ }
794
+ });
795
+ // 文件排序
796
+ onlyFileDataConfigList.sort((beforeConfig, afterConfig) => {
797
+ let beforeVal = beforeConfig[sortName];
798
+ let afterVal = afterConfig[sortName];
799
+ if (typeof beforeVal === "function") {
800
+ beforeVal = beforeVal().timeStamp;
801
+ }
802
+ if (typeof afterVal === "function") {
803
+ afterVal = afterVal().timeStamp;
804
+ }
805
+ if (sortName === "fileSize") {
806
+ // 文件大小,进行Float转换
807
+ beforeVal = parseFloat(beforeVal.toString());
808
+ afterVal = parseFloat(afterVal.toString());
809
+ } else if (sortName === "latestTime") {
810
+ // 文件时间
811
+ beforeVal = new Date(beforeVal).getTime();
812
+ afterVal = new Date(afterVal).getTime();
813
+ }
814
+ if (beforeVal > afterVal) {
815
+ if (isDesc) {
816
+ // 降序
817
+ return -1;
818
+ } else {
819
+ return 1;
820
+ }
821
+ } else if (beforeVal < afterVal) {
822
+ if (isDesc) {
823
+ // 降序
824
+ return 1;
825
+ } else {
826
+ return -1;
827
+ }
828
+ } else {
829
+ return 0;
830
+ }
831
+ });
832
+ }
833
+
834
+ // 文件夹始终优先放前面
835
+ return [...onlyFolderDataConfigList, ...onlyFileDataConfigList];
836
+ }
837
+ /**
838
+ * 添加文件夹/文件行元素
839
+ * @param dataConfig 配置
840
+ */
841
+ initFolderView(dataConfig: PopsFolderDataConfig[]) {
842
+ // 先对文件夹、文件进行排序
843
+ const sortedConfigList = this.sortFolderConfig(dataConfig, config.sort.name, config.sort.isDesc);
844
+ sortedConfigList.forEach((item) => {
845
+ if (item.isFolder) {
846
+ const { folderElement, fileNameElement } = popsUtils.isPhone()
847
+ ? this.createFolderRowElementByMobile(item)
848
+ : this.createFolderRowElement(item);
849
+ // 文件夹 - 点击事件
850
+ popsDOMUtils.on<MouseEvent | PointerEvent>(fileNameElement, "click", (event) => {
851
+ // 进入文件夹
852
+ this.enterFolder(event, item);
853
+ });
854
+
855
+ folderListBodyElement.appendChild(folderElement);
856
+ } else {
857
+ const { folderElement, fileNameElement } = popsUtils.isPhone()
858
+ ? this.createFolderRowElementByMobile(item)
859
+ : this.createFolderRowElement(item);
860
+ // 文件 - 点击事件
861
+ popsDOMUtils.on<MouseEvent | PointerEvent>(fileNameElement, "click", (event) => {
862
+ // 下载文件
863
+ this.downloadFile(event, fileNameElement, item);
864
+ });
865
+
866
+ folderListBodyElement.appendChild(folderElement);
867
+ }
868
+ });
869
+ }
870
+ /**
871
+ * 移除所有箭头的被访问状态
872
+ */
873
+ removeArrowActiveStatus() {
874
+ [
875
+ ...Array.from(folderListSortFileNameElement.querySelectorAll<HTMLElement>(".pops-folder-icon-active")),
876
+ ...Array.from(folderListSortLatestTimeElement.querySelectorAll<HTMLElement>(".pops-folder-icon-active")),
877
+ ...Array.from(folderListSortFileSizeElement.querySelectorAll<HTMLElement>(".pops-folder-icon-active")),
878
+ ].forEach((ele) => ele.classList.remove("pops-folder-icon-active"));
879
+ }
880
+ /**
881
+ * 修改导航箭头的状态
882
+ */
883
+ changeArrowActive(arrowUp: HTMLElement, arrowDown: HTMLElement, isDesc: boolean) {
884
+ this.removeArrowActiveStatus();
885
+ if (isDesc) {
886
+ arrowDown.classList.add("pops-folder-icon-active");
887
+ } else {
888
+ arrowUp.classList.add("pops-folder-icon-active");
889
+ }
890
+ }
891
+ /**
892
+ * 排序按钮的点击事件
893
+ * @param $target
894
+ * @param event
895
+ * @param sortName
896
+ */
897
+ arrowToSortFolderInfoView($target: HTMLDivElement, event: MouseEvent | PointerEvent, sortName: string) {
898
+ const notChangeSortRule = Reflect.get(event, "notChangeSortRule");
899
+ if (!notChangeSortRule) {
900
+ config.sort.name = sortName as PopsFolderConfig["sort"]["name"];
901
+ config.sort.isDesc = !config.sort.isDesc;
902
+ }
903
+
904
+ const $arrowUp = $target.querySelector<HTMLDivElement>(".pops-folder-icon-arrow-up")!;
905
+ const $arrowDown = $target.querySelector<HTMLDivElement>(".pops-folder-icon-arrow-down")!;
906
+ this.changeArrowActive($arrowUp, $arrowDown, config.sort.isDesc);
907
+ if (
908
+ typeof config.sort.callback === "function" &&
909
+ config.sort.callback($target, event, config.sort.name, config.sort.isDesc)
910
+ ) {
911
+ return;
912
+ }
913
+
914
+ const childrenList: PopsFolderDataConfig[] = [];
915
+
916
+ Array.from(folderListBodyElement.children).forEach(($tr) => {
917
+ const __value__ = Reflect.get($tr, "__value__");
918
+ Reflect.set(__value__, "target", $tr);
919
+ childrenList.push(__value__);
920
+ });
921
+ const sortedConfigList = this.sortFolderConfig(childrenList, config.sort.name, config.sort.isDesc);
922
+ sortedConfigList.forEach((item) => {
923
+ folderListBodyElement.appendChild((item as any).target);
924
+ });
925
+ }
926
+ }
927
+
928
+ const popsFolder = new PopsFolder();
929
+ popsFolder.init();
930
+ Reflect.set($pops, "data-pops-folder", popsFolder);
931
+ // 拖拽
932
+ if (config.drag) {
933
+ PopsInstanceUtils.drag($pops, {
934
+ dragElement: $title,
935
+ limit: config.dragLimit,
936
+ extraDistance: config.dragExtraDistance,
937
+ moveCallBack: config.dragMoveCallBack,
938
+ endCallBack: config.dragEndCallBack,
939
+ });
940
+ }
941
+ PopsHandler.handlePush(popsType, {
942
+ guid: guid,
943
+ $anim: $anim,
944
+ $pops: $pops,
945
+ $mask: $mask!,
946
+ $shadowContainer: $shadowContainer,
947
+ $shadowRoot: $shadowRoot,
948
+ config: config,
949
+ destory: result.close,
950
+ });
951
+ return result;
952
+ },
953
+ };