7ffae78919
引入 @playwright/test(mdEdge 通道),playwright.config 起 mock admin API + vite dev; e2e 覆盖宽/窄屏自动折叠、折叠持久化、无横向溢出等 8 用例;workspace 边界扫描 排除测试专用 e2e/scripts/playwright.config。
64 lines
2.0 KiB
JavaScript
64 lines
2.0 KiB
JavaScript
// 本地浏览器验收用 mock(仅测试,不随前端产物发布):模拟 Admin 壳层所需的最小 API。
|
|
import { createServer } from 'node:http'
|
|
|
|
const PORT = Number(process.env.MOCK_PORT || 18100)
|
|
|
|
const MENU_TREE = [
|
|
{
|
|
key: 'account',
|
|
name: '账号权限',
|
|
children: [
|
|
{ key: 'admin_users', name: '用户管理', route: '/account/users' },
|
|
{ key: 'admin_columns', name: '菜单管理', route: '/account/menus' },
|
|
{ key: 'admin_group_manage', name: '数据权限分组', route: '/account/groups' },
|
|
],
|
|
},
|
|
]
|
|
|
|
function json(res, payload, status = 200) {
|
|
const body = JSON.stringify(payload)
|
|
res.writeHead(status, {
|
|
'Content-Type': 'application/json; charset=utf-8',
|
|
'Cache-Control': 'no-store',
|
|
'Content-Length': Buffer.byteLength(body),
|
|
})
|
|
res.end(body)
|
|
}
|
|
|
|
const server = createServer((req, res) => {
|
|
const url = (req.url || '').split('?')[0]
|
|
const method = req.method || 'GET'
|
|
console.log(`[mock] ${method} ${url}`)
|
|
|
|
if (url === '/api/admin/current-user') {
|
|
return json(res, { success: true, data: { item: { id: 1, username: 'admin', role: 'super_admin' } } })
|
|
}
|
|
if (url === '/api/admin/current-user/menus') {
|
|
return json(res, { success: true, data: { items: MENU_TREE } })
|
|
}
|
|
if (url === '/api/admin/logout') {
|
|
return json(res, { success: true })
|
|
}
|
|
if (url === '/api/admin/users') {
|
|
return json(res, {
|
|
success: true,
|
|
data: {
|
|
items: [{ id: 1, username: 'admin', role: 'super_admin', creatorUsername: 'system', createdAt: '2026-01-01 00:00:00' }],
|
|
total: 1,
|
|
},
|
|
})
|
|
}
|
|
if (url === '/api/admin/permission-menus') {
|
|
return json(res, { success: true, data: { items: [] } })
|
|
}
|
|
if (url === '/api/admin/shop-manage-groups') {
|
|
return json(res, { success: true, data: { items: [] } })
|
|
}
|
|
if (url.startsWith('/api/')) {
|
|
return json(res, { success: true, data: { items: [], total: 0 } })
|
|
}
|
|
return json(res, { success: true }, 200)
|
|
})
|
|
|
|
server.listen(PORT, () => console.log(`mock admin api listening on ${PORT}`))
|