This commit is contained in:
2026-10-27 23:26:21 +08:00
parent 0699995c16
commit feaf90bb78
10 changed files with 476 additions and 2 deletions
+62
View File
@@ -1,6 +1,8 @@
import {
files,
menuRoutes,
miniApps,
type MockFile,
users,
USER_STATUS,
type MockMiniApp,
@@ -197,6 +199,66 @@ export const mockRules: MockRule[] = [
return true
},
},
{
method: 'GET',
pattern: /^\/api\/v1\/api\/admin\/files$/,
handler: (ctx) => {
const { keyword, uploader_type, page, size } = ctx.query
const pageNum = toNumber(page, 1)
const pageSize = toNumber(size, 20)
const kw = (keyword as string) || ''
const type = (uploader_type as string) || ''
const filtered = files.filter((item) => {
if (type && item.uploader_type !== type) return false
if (kw && !item.origin_name.includes(kw) && !item.filename.includes(kw)) return false
return true
})
const start = (pageNum - 1) * pageSize
return { list: filtered.slice(start, start + pageSize), total: filtered.length }
},
},
{
method: 'POST',
pattern: /^\/api\/v1\/api\/admin\/files\/upload$/,
handler: () => {
const id = files.length + 1
const rand = Math.random().toString(36).slice(2, 10)
const created: MockFile = {
id,
storage_key: `2026/10/27/${rand}.png`,
filename: `${rand}.png`,
origin_name: 'mock-upload.png',
mime_type: 'image/png',
ext: 'png',
size: 1024,
uploader_type: 'admin',
uploader_id: 1,
url: `/files/static/2026/10/27/${rand}.png`,
created_at: new Date().toISOString().slice(0, 19).replace('T', ' '),
}
files.unshift(created)
return {
id,
url: created.url,
filename: created.filename,
origin_name: created.origin_name,
mime_type: created.mime_type,
size: created.size,
}
},
},
{
method: 'DELETE',
pattern: /^\/api\/v1\/api\/admin\/files\/(\d+)$/,
handler: (ctx) => {
const id = toNumber(ctx.params[0])
const index = files.findIndex((item) => item.id === id)
if (index > -1) files.splice(index, 1)
return { id }
},
},
{
// 统计每个小程序的用户数(有真实用户的取真实值,其余返回稳定模拟值)
method: 'GET',