forked from cf-pages/Telegraph-Image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin-imgtc.html
759 lines (698 loc) · 26.2 KB
/
admin-imgtc.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ImgTC | Admin</title>
<!-- Import CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/lib/theme-chalk/index.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css">
<script src="https://js.sentry-cdn.com/219f636ac7bde5edab2c3e16885cb535.min.js" crossorigin="anonymous"></script>
<style>
body {
background: linear-gradient(90deg, #ffd7e4 0%, #c8f1ff 100%);
font-family: 'Arial', sans-serif;
color: #333;
margin: 0;
padding: 0;
}
.header-content {
position: fixed;
top: 0;
left: 1%;
right: 1%;
z-index: 999;
height: clamp(40px, 8vh, 60px);
display: flex;
align-items: center;
padding: 10px 20px;
background-color: rgba(255, 255, 255, 0.75);
-webkit-backdrop-filter: blur(10px);
backdrop-filter: blur(10px);
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
transition: background-color 0.5s ease, box-shadow 0.5s ease;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
.header-content:hover {
background-color: rgba(255, 255, 255, 0.85);
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.2);
}
.title {
font-size: clamp(1.2em, 2vw, 1.8em);
font-weight: bold;
cursor: pointer;
transition: color 0.3s ease;
margin-right: 4px;
color: #333;
}
.title:hover {
color: #B39DDB; /* 使用柔和的淡紫色 */
}
.search-card {
margin-left: auto;
margin-right: 16px;
}
.stats {
display: flex;
align-items: center;
cursor: pointer;
font-size: clamp(0.9em, 1.5vw, 1.2em);
background: rgba(255, 255, 255, 0.9);
margin-right: 8px;
padding: 2px 8px;
border-radius: 12px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
transition: background-color 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
color: #333;
}
.stats:hover {
background-color: #f0eaf8; /* 柔和的淡紫色 */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
transform: scale(1.02);
color: #B39DDB;
}
/* 上传图标样式优化 */
.upload-icon {
margin-right: 10px;
font-size: clamp(1.2em, 1.5vw, 1.6em);
transition: color 0.3s ease, transform 0.3s ease, background-color 0.3s ease;
color: inherit;
cursor: pointer;
border-radius: 50%;
padding: 8px;
background-color: rgba(179, 157, 219, 0.15); /* 淡紫色的背景,与整体风格一致 */
border: 1px solid transparent;
}
.header-content .actions {
display: flex;
align-items: center;
}
.header-content .actions i {
font-size: clamp(1.2em, 1.5vw, 1.6em);
cursor: pointer;
transition: color 0.3s, transform 0.3s;
color: #333;
margin: 0 8px;
}
.header-content .actions i:hover {
color: #B39DDB; /* 使用柔和的淡紫色 */
transform: scale(1.1);
}
.header-content .actions .el-dropdown-link i {
color: #333;
}
.header-content .actions .el-dropdown-link i:hover {
color: #B39DDB; /* 使用柔和的淡紫色 */
}
.header-content .actions .disabled {
color: #bbb;
pointer-events: none;
}
.header-content .actions .enabled {
color: #B39DDB; /* 使用柔和的淡紫色 */
}
.search-card .el-input__inner {
border-radius: 20px;
width: clamp(200px, 25vw, 300px);
height: clamp(30px, 5vh, 40px);
font-size: 1.2em;
border: none;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
transition: width 0.3s;
}
.search-card .el-input__inner:focus {
width: clamp(250px, 30vw, 400px);
}
.main-container {
display: flex;
flex-direction: column;
margin-top: 20px;
padding: 20px;
min-height: calc(100vh - 80px);
}
.content {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
gap: 20px;
padding: 10px;
flex-grow: 1;
}
.el-card {
width: 100%;
aspect-ratio: 4 / 3;
background: rgba(255, 255, 255, 0.6);
border-radius: 8px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
overflow: hidden;
position: relative;
object-fit: cover;
transition: transform 0.3s ease;
border: none;
}
.el-card:hover {
transform: scale(1.02);
cursor: pointer;
}
.el-image {
object-fit: cover;
transition: opacity 0.3s ease;
}
.el-image:hover {
opacity: 0.8;
}
.file-info {
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
padding: 10px;
background: rgba(0, 0, 0, 0.6);
color: white;
text-align: center;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
box-sizing: border-box;
}
.image-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background: rgba(0, 0, 0, 0.6);
opacity: 0;
transition: opacity 0.3s ease;
}
.el-card:hover .image-overlay {
opacity: 1;
}
.overlay-buttons {
display: flex;
gap: 10px;
pointer-events: auto;
}
.pagination-container {
display: flex;
justify-content: center;
margin-top: 16px;
}
.collect-icon {
position: absolute;
top: -1.3px;
left: 10px;
cursor: pointer;
font-size: 1.5em;
z-index: 10;
transition: color 0.3s ease, transform 0.3s ease;
}
.collect-icon:hover {transform: scale(1.2);}
.liked {color: #FFD7E4;}
.not-liked {color: #b39edb80;}
.el-checkbox {
position: absolute;
top: 10px;
right: 10px;
transform: scale(1.5);
z-index: 10;
}
.footer {
display: flex;
justify-content: center;
align-items: center;
gap: 15px;
margin-top: 20px;
font-size: 0.9em;
color: #555; /* 字体颜色改为黑色 */
}
.footer a {
color: #555; /* 链接颜色 */
text-decoration: none;
transition: color 0.3s ease;
}
.footer a:hover {
color: #333; /* 悬停时的链接颜色改为黑色 */
}
.footer i {
color: #333; /* 图标颜色改为黑色 */
}
/* 适配移动端 */
@media (max-width: 768px) {
.content {
grid-template-columns: 1fr; /* 单列布局 */
gap: 10px;
}
.header-content{padding: 8px 12px;}
.stats, .actions i{margin: 0;}
.el-card{aspect-ratio: unset; min-height: 180px;}
.el-card__body{padding: 0;}
.search-card {display: none;}
}
</style>
</head>
<body>
<div id="app">
<el-container>
<el-header>
<div class="header-content">
<span class="title" @click="refreshDashboard">Dashboard</span>
<div class="search-card">
<el-input v-model="search" size="mini" placeholder="输入关键字搜索"></el-input>
</div>
<el-tooltip content="批量上传" placement="bottom">
<span class="stats" @click="handleUpload">
<i class="fas fa-upload upload-icon"></i>记录数: {{ Number }}
</span>
</el-tooltip>
<input type="file" ref="fileInput" style="display: none;" multiple @change="uploadFiles">
<div class="actions">
<el-tooltip content="排序" placement="bottom">
<el-dropdown @command="sort" :hide-on-click="false">
<span class="el-dropdown-link">
<i :class="sortIcon"></i>
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="dateDesc" :class="{ 'el-dropdown-menu__item--selected': sortOption === 'dateDesc' }">按时间倒序</el-dropdown-item>
<el-dropdown-item command="nameAsc" :class="{ 'el-dropdown-menu__item--selected': sortOption === 'nameAsc' }">按名称升序</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</el-tooltip>
<el-tooltip content="批量复制" placement="bottom">
<i class="fas fa-link" :class="{ disabled: selectedFiles.length === 0 }" @click="handleBatchCopy"></i>
</el-tooltip>
<el-tooltip content="批量删除" placement="bottom">
<i class="fas fa-trash-alt" :class="{ disabled: selectedFiles.length === 0 }" @click="handleBatchDelete"></i>
</el-tooltip>
<el-tooltip content="退出登录" placement="bottom">
<i class="fas fa-home" @click="handleLogout"></i>
</el-tooltip>
</div>
</div>
</el-header>
<el-main class="main-container">
<div class="content">
<template v-for="(item, index) in paginatedTableData" :key="index">
<el-card>
<span class="collect-icon" @click.stop="toggleLike(index, item.name)">
<i :class="item.metadata.liked ? 'fa-solid fa-bookmark liked' : 'fa-regular fa-bookmark not-liked'"></i>
</span>
<el-checkbox v-model="item.selected" :ref="'checkbox-' + index"></el-checkbox>
<el-image
:src="'/file/' + item.name"
:preview-src-list="['/file/' + item.name]"
fit="cover"
lazy></el-image>
<div class="image-overlay">
<div class="overlay-buttons">
<el-button size="mini" type="primary" @click.stop="handleCopy(index, item.name)">复制地址</el-button>
<el-button size="mini" type="danger" @click.stop="handleDelete(index, item.name)">删除</el-button>
</div>
</div>
<div class="file-info">{{ item.name }}</div>
</el-card>
</template>
</div>
<div class="pagination-container">
<el-pagination
background
layout="prev, pager, next"
:total="filteredTableData.length"
:page-size="pageSize"
@current-change="handlePageChange"
:current-page.sync="currentPage">
</el-pagination>
</div>
<el-footer class="footer">
<div>Powered By</div>
<a href="https://github.com/cf-pages/Telegraph-Image" target="_blank" rel="noopener noreferrer">
<div><i class="fa-brands fa-github"></i> Telegraph-Image</div>
</a>
</el-footer>
</el-main>
</el-container>
</div>
</body>
<!-- Import Vue before Element -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js"></script>
<!-- Import JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/index.js"></script>
<script>
new Vue({
el: '#app',
data: {
baseURL: document.location.origin,
Number: 0,
tableData: [],
search: '',
currentPage: 1,
pageSize: 15,
selectedFiles: [],
sortOption: 'dateDesc',
},
computed: {
filteredTableData() {
return this.tableData.filter(data => !this.search || data.name.toLowerCase().includes(this.search.toLowerCase()));
},
paginatedTableData() {
const sortedData = this.sortData(this.filteredTableData);
const start = (this.currentPage - 1) * this.pageSize;
const end = start + this.pageSize;
return sortedData.slice(start, end);
},
sortIcon() {
return this.sortOption === 'dateDesc' ? 'fas fa-sort-amount-down' : 'fas fa-sort-alpha-up';
}
},
watch: {
tableData: {
handler(newData) {
this.selectedFiles = newData.filter(file => file.selected);
},
deep: true
},
sortOption(newOption) {
localStorage.setItem('sortOption', newOption);
}
},
methods: {
refreshDashboard() {
location.reload();
},
calculatePageSize() {
const minPageSize = 15;
const cardMinWidth = 240; // 卡片最小宽度
const cardAspectRatio = 3 / 4; // 卡片的高宽比
const gap = 20; // 卡片间的间隙
const contentElement = document.querySelector('.content');
const containerWidth = contentElement ? contentElement.clientWidth : 800;
const columns = Math.floor(containerWidth / (cardMinWidth + gap));
const headerElement = document.querySelector('.header-content');
const headerHeight = headerElement ? headerElement.offsetHeight : 60; // 使用默认值60px
const containerHeight = window.innerHeight - headerHeight;
const cardHeight = (containerWidth / columns - gap) * cardAspectRatio;
const rows = Math.floor(containerHeight / (cardHeight + gap));
this.pageSize = Math.max(rows * columns, minPageSize);
},
updateWindowWidth() {
this.windowWidth = window.innerWidth;
this.calculatePageSize();
},
handleUpload() {
this.$refs.fileInput.click();
},
uploadFiles(event) {
const files = event.target.files;
if (files.length === 0) return;
// 过滤文件类型和大小
const validFiles = [];
const invalidTypeFiles = [];
const oversizedFiles = [];
Array.from(files).forEach(file => {
const isValidType = file.type.startsWith('image/') || file.type.startsWith('video/');
const isValidSize = file.size <= 5 * 1024 * 1024; // 5MB
if (!isValidType) {
invalidTypeFiles.push(file.name);
} else if (!isValidSize) {
oversizedFiles.push(file.name);
} else {
validFiles.push(file);
}
});
// 显示错误消息
if (invalidTypeFiles.length > 0) {
this.$message.error(`以下文件类型不支持: ${invalidTypeFiles.join(', ')}`);
}
if (oversizedFiles.length > 0) {
this.$message.error(`以下文件超过5MB: ${oversizedFiles.join(', ')}`);
}
if (validFiles.length === 0) {
this.$message.info('没有符合条件的文件');
return;
}
console.log("ValidFiles: ", validFiles);
this.$confirm(`确定要上传这 ${validFiles.length} 个文件吗?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// 显示上传进度
const loadingMessage = this.$message({
message: '上传中...',
duration: 0,
showClose: false,
});
const maxConcurrent = 3; // 最大并发数
let current = 0;
let successCount = 0;
let failedUploads = [];
const uploadNext = () => {
if (current >= validFiles.length) {
// 检查是否所有文件都已处理
if (successCount + failedUploads.length === validFiles.length) {
loadingMessage.close();
if (successCount > 0) {
this.$message.success(`成功上传 ${successCount} 个文件!`);
}
if (failedUploads.length > 0) {
this.$message.error(`上传失败: ${failedUploads.join(', ')}`);
}
// 刷新文件列表
this.refreshFileList();
}
return;
}
const file = validFiles[current];
current++;
const formData = new FormData();
formData.append('file', file);
fetch(this.baseURL + '/upload', {
method: 'POST',
body: formData,
credentials: 'include'
}).then(response => {
if (!response.ok) {
throw new Error(`上传失败: ${file.name}`);
}
return response.json();
}).then(result => {
if (Array.isArray(result) && result.length > 0 && result[0].error) {
// 响应内容中包含错误
throw new Error(result[0].error || `上传失败: ${file.name}`);
}
// 确保 result[0].src 存在
if (!result[0].src) {
throw new Error(`上传成功但未返回文件路径: ${file.name}`);
}
successCount++;
// 处理成功上传的文件
const previewUrl = `${this.baseURL}${result[0].src}`;
if (result[0].src) {
fetch(previewUrl, { method: 'GET', credentials: 'include' })
.then(response => {
if (!response.ok) {
console.error(`无法获取文件: ${previewUrl}`);
} else {
this.tableData.unshift({
name: result[0].src.replace(/^\/file\//, ''),
selected: false,
metadata: { TimeStamp: Date.now() }
});
}
}).catch(error => {
console.error(`获取文件时出错: ${previewUrl}`, error);
});
}
}).catch(error => {
failedUploads.push(file.name); // 记录失败的文件名称
console.error(error.message);
}).finally(() => {
uploadNext(); // 继续上传下一个文件
});
};
// 启动初始的并发上传任务
for (let i = 0; i < maxConcurrent && i < validFiles.length; i++) {
uploadNext();
}
}).catch(() => {
this.$message.info('已取消上传');
});
// 清空文件输入,以便可以重复选择相同的文件
event.target.value = '';
},
refreshFileList() {
// 重新获取文件列表
fetch("./api/manage/list", { method: 'GET', credentials: 'include' })
.then(response => response.json())
.then(result => {
this.tableData = result.map(file => ({ ...file, selected: false }));
this.updateStats();
this.sortData(this.tableData);
})
.catch(() => this.$message.error('刷新文件列表失败,请检查网络连接'));
},
handleDelete(index, key) {
this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
fetch(`./api/manage/delete/${key}`, { method: 'GET', credentials: 'include' })
.then(response => response.ok ? this.tableData.splice(index, 1) : Promise.reject())
.then(() => {
this.updateStats();
this.$message.success('删除成功!');
})
.catch(() => this.$message.error('删除失败,请检查网络连接'));
}).catch(() => this.$message.info('已取消删除'));
},
handleBatchDelete() {
this.$confirm('此操作将永久删除选中的文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const promises = this.selectedFiles.map(file => fetch(`./api/manage/delete/${file.name}`, { method: 'GET', credentials: 'include' }));
Promise.all(promises)
.then(results => {
results.forEach((response, index) => {
if (response.ok) {
const fileIndex = this.tableData.findIndex(file => file.name === this.selectedFiles[index].name);
if (fileIndex !== -1) {
this.tableData.splice(fileIndex, 1);
}
}
});
this.selectedFiles = [];
this.updateStats();
this.$message.success('批量删除成功!');
})
.catch(() => this.$message.error('批量删除失败,请检查网络连接'));
}).catch(() => this.$message.info('已取消批量删除'));
},
handleBatchCopy() {
const links = this.selectedFiles.map(file => `${document.location.origin}/file/${file.name}`).join('\n');
navigator.clipboard ? navigator.clipboard.writeText(links).then(() => this.$message.success('批量复制链接成功~')) :
this.copyToClipboardFallback(links);
},
copyToClipboardFallback(text) {
const textarea = document.createElement('textarea');
document.body.appendChild(textarea);
textarea.style.position = 'fixed';
textarea.style.clip = 'rect(0 0 0 0)';
textarea.style.top = '10px';
textarea.value = text;
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
this.$message.success('批量复制链接成功~');
},
handleLogout() {
window.location.href = '/';
},
handleCopy(index, key) {
const text = `${this.baseURL}/file/${key}`;
navigator.clipboard ? navigator.clipboard.writeText(text).then(() => this.$message.success('复制文件链接成功~')) :
this.copyToClipboardFallback(text);
},
handlePageChange(page) {
this.currentPage = page;
},
// 处理收藏事件
toggleLike(index, key) {
console.log(`Toggling like for image: ${key}`);
// 乐观更新收藏状态
if (this.tableData[index].metadata.liked === undefined) {
this.tableData[index].metadata.liked = false;
}
this.tableData[index].metadata.liked = !this.tableData[index].metadata.liked;
// 发送请求更新服务器数据
var requestOptions = {
method: 'GET',
redirect: 'follow',
credentials: 'include'
};
fetch(`./api/manage/toggleLike/${key}`, requestOptions)
.then(response => response.json())
.then(result => {
if (!result.success) {
// 如果服务器更新失败,将状态还原
this.tableData[index].metadata.liked = !this.tableData[index].metadata.liked;
this.$message({
message: '更新收藏状态失败,请稍后重试',
type: 'error'
});
} else {
this.$message.success('更新收藏状态成功');
}
})
.catch(error => {
console.error("An error occurred while synchronizing data with the server", error);
// 如果服务器响应错误,将状态还原
this.tableData[index].metadata.liked = !this.tableData[index].metadata.liked;
this.$message({
message: '同步服务器失败,请检查网络连接',
type: 'error'
});
});
},
updateStats() {
this.Number = this.tableData.length;
},
sort(command) {
this.sortOption = command;
},
sortData(data) {
return this.sortOption === 'nameAsc' ? data.sort((a, b) => a.name.localeCompare(b.name)) :
data.sort((a, b) => b.metadata.TimeStamp - a.metadata.TimeStamp);
}
},
mounted() {
window.addEventListener('resize', this.calculatePageSize);
this.updateWindowWidth();
fetch("./api/manage/check", { method: 'GET', credentials: 'include' })
.then(response => response.text())
.then(result => {
if (result == "true") {
this.showLogoutButton = true;
} else if (result == "Not using basic auth.") {
// Do nothing
} else {
window.location.href = "./api/manage/login";
}
})
.catch(() => this.$message.error('同步数据时出错,请检查网络连接'));
fetch("./api/manage/list", { method: 'GET', credentials: 'include' })
.then(response => response.json())
.then(result => {
console.log("result: ", result);
this.tableData = result.map(file => ({
...file,
selected: false,
metadata: {
...file.metadata,
liked: file.metadata.liked !== undefined ? file.metadata.liked : false
}
}));
this.updateStats();
const savedSortOption = localStorage.getItem('sortOption');
if (savedSortOption) {
this.sortOption = savedSortOption;
}
this.sortData(this.tableData);
})
.catch(() => this.$message.error('同步数据时出错,请检查网络连接'));
},
beforeDestroy() {
window.removeEventListener('resize', this.calculatePageSize);
}
});
</script>
</html>