Skip to content

Commit 75a5b8d

Browse files
cf-pagesCopilot
andauthored
feat: enable filename search in admin dashboard (cf-pages#254)
* feat: add prefix search for admin * refactor: debounce admin search * Update admin.html Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent b9507b6 commit 75a5b8d

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

admin.html

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
</el-table-column>
100100
<el-table-column align="right">
101101
<template slot="header" slot-scope="scope">
102-
<el-input v-model="search" size="mini" placeholder="输入关键字搜索" />
102+
<el-input v-model="search" @input="handleSearch" size="mini" placeholder="输入关键字搜索" />
103103
</template>
104104
<template slot-scope="scope">
105105
<el-button size="mini" type="primary" @click="handleCopy(scope.$index,scope.row.name)">复制地址</el-button>
@@ -138,7 +138,8 @@
138138
id: ''
139139
},
140140
search: '',
141-
password: '123456'
141+
password: '123456',
142+
searchTimer: null
142143
},
143144
methods: {
144145
handleBlock(index, key) {
@@ -233,11 +234,33 @@
233234
type: 'success'
234235
});
235236
},
237+
handleSearch() {
238+
clearTimeout(this.searchTimer);
239+
this.searchTimer = setTimeout(() => {
240+
this.tableData = [];
241+
this.nextCursor = null;
242+
const opts = { method: 'GET', redirect: 'follow', credentials: 'include' };
243+
const base = this.search
244+
? `./api/manage/list?limit=100&prefix=${encodeURIComponent(this.search)}`
245+
: `./api/manage/list?limit=100`;
246+
fetch(base, opts)
247+
.then(r => r.json())
248+
.then(result => {
249+
this.tableData = result.keys || [];
250+
this.nextCursor = result.list_complete ? null : result.cursor;
251+
this.Number = this.tableData.length;
252+
})
253+
.catch(() => alert("搜索失败,请检查网络"));
254+
}, 300);
255+
},
236256
loadMore() {
237257
const opts = { method: 'GET', redirect: 'follow', credentials: 'include' };
238-
const url = this.nextCursor
239-
? `./api/manage/list?cursor=${encodeURIComponent(this.nextCursor)}`
258+
const base = this.search
259+
? `./api/manage/list?limit=100&prefix=${encodeURIComponent(this.search)}`
240260
: `./api/manage/list?limit=100`;
261+
const url = this.nextCursor
262+
? `${base}&cursor=${encodeURIComponent(this.nextCursor)}`
263+
: base;
241264

242265
fetch(url, opts)
243266
.then(r => r.json())

functions/api/manage/list.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export async function onRequest(context) {
88
if (limit > 1000) limit = 1000;
99

1010
const cursor = url.searchParams.get("cursor") || undefined;
11-
const value = await env.img_url.list({ limit, cursor });
11+
const prefix = url.searchParams.get("prefix") || undefined;
12+
const value = await env.img_url.list({ limit, cursor, prefix });
1213

1314
return new Response(JSON.stringify(value), {
1415
headers: { "Content-Type": "application/json" }

0 commit comments

Comments
 (0)