|
240 | 240 | </template> |
241 | 241 | </template> |
242 | 242 | </div> |
243 | | - <div class="pagination-container"> |
244 | | - <el-pagination |
245 | | - background layout="prev, pager, next" |
246 | | - :total="filteredTableData.length" :page-size="pageSize" |
247 | | - @current-change="handlePageChange" :current-page.sync="currentPage" /> |
248 | | - </div> |
249 | | - <el-footer class="footer"> |
| 243 | + <div class="pagination-container"> |
| 244 | + <el-pagination |
| 245 | + background layout="prev, pager, next" |
| 246 | + :total="filteredTableData.length" :page-size="pageSize" |
| 247 | + @current-change="handlePageChange" :current-page.sync="currentPage" /> |
| 248 | + </div> |
| 249 | + <div style="text-align:center;margin-top:16px;"> |
| 250 | + <el-button v-if="nextCursor" @click="loadMore">加载更多</el-button> |
| 251 | + </div> |
| 252 | + <el-footer class="footer"> |
250 | 253 | <div>Powered By</div> |
251 | 254 | <a href="https://github.com/cf-pages/Telegraph-Image" target="_blank" rel="noopener noreferrer"> |
252 | 255 | <div><i class="fa-brands fa-github"></i> Telegraph-Image</div> |
|
294 | 297 | maxSize: 20 * 1024 * 1024, // 最大上传20MB |
295 | 298 | maxConcurrent: 3 |
296 | 299 | }, |
297 | | - tableData: [], |
| 300 | + tableData: [], |
| 301 | + nextCursor: null, |
298 | 302 | search: '', |
299 | 303 | currentPage: 1, |
300 | 304 | pageSize: 15, |
|
373 | 377 | refreshDashboard() {location.reload();}, // 刷新页面 |
374 | 378 | handleLogout() { window.location.href = '/'; }, // 退出登录 |
375 | 379 | handlePageChange(page) { this.currentPage = page; }, // 切换页面 |
376 | | - handleUpload() { this.$refs.fileInput.click(); }, // 打开文件选择对话框 |
377 | | - sort(command) { this.sortOption = command; }, // 切换排序方式 |
378 | | - filter(command) { this.filterOption = command; }, // 切换筛选方式 |
379 | | - sortData(data) { |
380 | | - return this.sortOption === 'nameAsc' ? data.sort((a, b) => a.name.localeCompare(b.name)) : |
381 | | - this.sortOption === 'sizeDesc' ? data.sort((a, b) => b.metadata.fileSize - a.metadata.fileSize) : |
382 | | - data.sort((a, b) => b.metadata.TimeStamp - a.metadata.TimeStamp); |
| 380 | + handleUpload() { this.$refs.fileInput.click(); }, // 打开文件选择对话框 |
| 381 | + sort(command) { this.sortOption = command; }, // 切换排序方式 |
| 382 | + filter(command) { this.filterOption = command; }, // 切换筛选方式 |
| 383 | + loadMore() { |
| 384 | + const opts = { method: 'GET', credentials: 'include' }; |
| 385 | + const url = this.nextCursor |
| 386 | + ? `./api/manage/list?cursor=${encodeURIComponent(this.nextCursor)}` |
| 387 | + : `./api/manage/list?limit=100`; |
| 388 | + |
| 389 | + fetch(url, opts) |
| 390 | + .then(r => r.json()) |
| 391 | + .then(result => { |
| 392 | + const files = result.keys || []; |
| 393 | + const mapped = files.map(file => ({ |
| 394 | + ...file, |
| 395 | + selected: false, |
| 396 | + metadata: { |
| 397 | + ...file.metadata, |
| 398 | + liked: file.metadata.liked ?? false, |
| 399 | + fileName: file.metadata.fileName ?? file.name, |
| 400 | + fileSize: file.metadata.fileSize ?? 0 |
| 401 | + } |
| 402 | + })); |
| 403 | + this.tableData = this.tableData.concat(mapped); |
| 404 | + this.nextCursor = result.list_complete ? null : result.cursor; |
| 405 | + this.updateStats(); |
| 406 | + }) |
| 407 | + .catch(() => this.$message.error('同步数据时出错,请检查网络连接')); |
| 408 | + }, |
| 409 | + sortData(data) { |
| 410 | + return this.sortOption === 'nameAsc' ? data.sort((a, b) => a.name.localeCompare(b.name)) : |
| 411 | + this.sortOption === 'sizeDesc' ? data.sort((a, b) => b.metadata.fileSize - a.metadata.fileSize) : |
| 412 | + data.sort((a, b) => b.metadata.TimeStamp - a.metadata.TimeStamp); |
383 | 413 | }, |
384 | 414 | formattedFileDetails(item) { |
385 | 415 | const metadata = item.metadata; |
|
504 | 534 | } |
505 | 535 | event.target.value = ''; |
506 | 536 | }, |
507 | | - refreshFileList() { // 不刷新页面,仅更新数据 |
508 | | - fetch("./api/manage/list", { method: 'GET', credentials: 'include' }) |
509 | | - .then(response => response.json()) |
510 | | - .then(result => { |
511 | | - this.tableData = result.map(file => ({ ...file, selected: false })); |
512 | | - this.updateStats(); |
513 | | - this.sortData(this.tableData); |
514 | | - }) |
515 | | - .catch(() => this.$message.error('刷新文件列表失败,请检查网络连接')); |
516 | | - }, |
| 537 | + refreshFileList() { // 不刷新页面,仅更新数据 |
| 538 | + fetch("./api/manage/list?limit=100", { method: 'GET', credentials: 'include' }) |
| 539 | + .then(response => response.json()) |
| 540 | + .then(result => { |
| 541 | + const files = result.keys || []; |
| 542 | + this.tableData = files.map(file => ({ |
| 543 | + ...file, |
| 544 | + selected: false, |
| 545 | + metadata: { |
| 546 | + ...file.metadata, |
| 547 | + liked: file.metadata.liked ?? false, |
| 548 | + fileName: file.metadata.fileName ?? file.name, |
| 549 | + fileSize: file.metadata.fileSize ?? 0 |
| 550 | + } |
| 551 | + })); |
| 552 | + this.nextCursor = result.list_complete ? null : result.cursor; |
| 553 | + this.updateStats(); |
| 554 | + this.sortData(this.tableData); |
| 555 | + }) |
| 556 | + .catch(() => this.$message.error('刷新文件列表失败,请检查网络连接')); |
| 557 | + }, |
517 | 558 | toggleSelect(index, name) { |
518 | 559 | const fileIndex = this.tableData.findIndex(file => file.name === name); |
519 | 560 | this.tableData[fileIndex].selected = !this.tableData[fileIndex].selected; |
|
830 | 871 | .catch(() => this.$message.error('同步数据时出错,请检查网络连接')); |
831 | 872 |
|
832 | 873 | // 获取文件列表数据 |
833 | | - fetch("./api/manage/list", { method: 'GET', credentials: 'include' }) |
834 | | - .then(response => response.json()) |
835 | | - .then(result => { |
836 | | - console.log("result: ", result); |
837 | | - this.tableData = result.map(file => ({ |
838 | | - ...file, |
839 | | - selected: false, |
840 | | - metadata: { |
841 | | - ...file.metadata, |
842 | | - liked: file.metadata.liked ?? false, |
843 | | - fileName: file.metadata.fileName ?? file.name, |
844 | | - fileSize: file.metadata.fileSize ?? 0 |
845 | | - } |
846 | | - })); |
847 | | - this.updateStats(); |
848 | | - // 恢复设置 |
849 | | - this.sortOption = localStorage.getItem('sortOption') || this.sortOption; |
850 | | - this.sortData(this.tableData); |
851 | | - this.fileType = localStorage.getItem('fileType') || this.fileType; |
852 | | - this.switchFileType(this.fileType); |
853 | | - }) |
854 | | - .catch(() => this.$message.error('同步数据时出错,请检查网络连接')); |
| 874 | + fetch("./api/manage/list?limit=100", { method: 'GET', credentials: 'include' }) |
| 875 | + .then(response => response.json()) |
| 876 | + .then(result => { |
| 877 | + console.log("result: ", result); |
| 878 | + const files = result.keys || []; |
| 879 | + this.nextCursor = result.list_complete ? null : result.cursor; |
| 880 | + this.tableData = files.map(file => ({ |
| 881 | + ...file, |
| 882 | + selected: false, |
| 883 | + metadata: { |
| 884 | + ...file.metadata, |
| 885 | + liked: file.metadata.liked ?? false, |
| 886 | + fileName: file.metadata.fileName ?? file.name, |
| 887 | + fileSize: file.metadata.fileSize ?? 0 |
| 888 | + } |
| 889 | + })); |
| 890 | + this.updateStats(); |
| 891 | + // 恢复设置 |
| 892 | + this.sortOption = localStorage.getItem('sortOption') || this.sortOption; |
| 893 | + this.sortData(this.tableData); |
| 894 | + this.fileType = localStorage.getItem('fileType') || this.fileType; |
| 895 | + this.switchFileType(this.fileType); |
| 896 | + }) |
| 897 | + .catch(() => this.$message.error('同步数据时出错,请检查网络连接')); |
855 | 898 |
|
856 | 899 | if (localStorage.getItem('quickWebsites')) { |
857 | 900 | this.quickWebsites = JSON.parse(localStorage.getItem('quickWebsites')); |
|
0 commit comments