feat: rbac初步对接完成
This commit is contained in:
+16
-64
@@ -1,70 +1,22 @@
|
||||
import { mockDate, mockId } from '../index'
|
||||
import type { OperationLog } from '@/api/system'
|
||||
|
||||
const methods = ['GET', 'POST', 'PUT', 'DELETE']
|
||||
const clients = [
|
||||
{ id: 'gateway', name: 'API 网关' },
|
||||
{ id: 'plant', name: 'Plant 服务' },
|
||||
{ id: 'radio', name: 'Radio 服务' },
|
||||
]
|
||||
const operators = [
|
||||
{ id: 'u1', name: '超级管理员' },
|
||||
{ id: 'u2', name: '张三' },
|
||||
{ id: 'u3', name: '李四' },
|
||||
]
|
||||
const apis = [
|
||||
{ method: 'POST', path: '/api/auth/login', title: '用户登录', status: 200 },
|
||||
{ method: 'GET', path: '/api/auth/captcha', title: '获取验证码', status: 200 },
|
||||
{ method: 'POST', path: '/api/user/getUserList', title: '查询用户列表', status: 200 },
|
||||
{ method: 'POST', path: '/api/user/save', title: '创建用户', status: 200 },
|
||||
{ method: 'POST', path: '/api/user/update', title: '更新用户', status: 200 },
|
||||
{ method: 'POST', path: '/api/user/delete', title: '删除用户', status: 200 },
|
||||
{ method: 'POST', path: '/api/user/grantRole', title: '分配角色', status: 200 },
|
||||
{ method: 'POST', path: '/api/role/getRoleList', title: '查询角色列表', status: 200 },
|
||||
{ method: 'POST', path: '/api/role/grantMenu', title: '角色授权菜单', status: 200 },
|
||||
{ method: 'POST', path: '/api/menu/getAllMenuTree', title: '查询菜单树', status: 200 },
|
||||
{ method: 'POST', path: '/api/oss/upload', title: '上传文件', status: 200 },
|
||||
{ method: 'POST', path: '/api/plant/wiki/list', title: '百科列表', status: 200 },
|
||||
{ method: 'POST', path: '/api/plant/wiki/save', title: '新增百科', status: 200 },
|
||||
{ method: 'POST', path: '/api/plant/banner/list', title: '轮播图列表', status: 200 },
|
||||
{ method: 'POST', path: '/api/radio/channel/list', title: '频道列表', status: 200 },
|
||||
{ method: 'POST', path: '/api/radio/program/save', title: '新增节目', status: 200 },
|
||||
{ method: 'GET', path: '/api/radio/subscription/list', title: '订阅列表', status: 200 },
|
||||
{ method: 'POST', path: '/api/user/changePassword', title: '修改密码', status: 200 },
|
||||
{ method: 'GET', path: '/api/client/getClientList', title: '客户端列表', status: 200 },
|
||||
{ method: 'POST', path: '/api/auth/logout', title: '用户登出', status: 200 },
|
||||
{ method: 'POST', path: '/api/user/save', title: '创建用户', status: 400 },
|
||||
{ method: 'POST', path: '/api/oss/upload', title: '上传文件', status: 500 },
|
||||
]
|
||||
|
||||
const ips = ['192.168.1.100', '10.0.0.15', '172.16.0.42', '192.168.2.88']
|
||||
const uas = [
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
|
||||
'PostmanRuntime/7.37.3',
|
||||
]
|
||||
|
||||
function rand<T>(arr: T[]): T { return arr[Math.floor(Math.random() * arr.length)] }
|
||||
const clients = ['sundynix-admin', 'plant', 'radio', 'system']
|
||||
|
||||
export const mockLogs: OperationLog[] = Array.from({ length: 120 }, (_, i) => {
|
||||
const api = rand(apis)
|
||||
const client = rand(clients)
|
||||
const op = rand(operators)
|
||||
const method = ['GET', 'POST', 'PUT', 'DELETE'][Math.floor(Math.random() * 4)]
|
||||
return {
|
||||
id: mockId(),
|
||||
operatorId: op.id,
|
||||
operatorName: op.name,
|
||||
clientId: client.id,
|
||||
clientName: client.name,
|
||||
method: api.method,
|
||||
path: api.path,
|
||||
title: api.title,
|
||||
statusCode: api.status,
|
||||
duration: Math.floor(Math.random() * 500) + 5,
|
||||
ip: rand(ips),
|
||||
userAgent: rand(uas),
|
||||
requestBody: api.method === 'GET' ? undefined : '{"page":1}',
|
||||
responseBody: api.status === 200 ? '{"code":0,"msg":"ok"}' : '{"code":1,"msg":"error"}',
|
||||
createdAt: mockDate(i * 0.3),
|
||||
id: `log-${i + 1}`,
|
||||
userId: 'admin',
|
||||
clientId: clients[Math.floor(Math.random() * clients.length)],
|
||||
ip: `192.168.1.${Math.floor(Math.random() * 255)}`,
|
||||
method,
|
||||
path: `/api/v1/resource/${Math.floor(Math.random() * 10)}`,
|
||||
status: Math.random() > 0.1 ? 200 : 500,
|
||||
latency: Math.floor(Math.random() * 500) * 1000000,
|
||||
agent: 'Mozilla/5.0',
|
||||
errorMessage: '',
|
||||
body: method === 'GET' ? '' : '{"key": "value"}',
|
||||
resp: '{"code": 200}',
|
||||
createdAt: Date.now() / 1000 - Math.floor(Math.random() * 86400 * 30),
|
||||
}
|
||||
}).sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())
|
||||
}).sort((a, b) => b.createdAt - a.createdAt)
|
||||
|
||||
Reference in New Issue
Block a user