1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
function createUserList() { return [ { userId: 1, avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif', username: 'admin', password: '111111', desc: '平台管理员', roles: ['平台管理员'], buttons: ['cuser.detail'], routes: ['home'], token: 'Admin Token', }, { userId: 2, avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif', username: 'system', password: '111111', desc: '系统管理员', roles: ['系统管理员'], buttons: ['cuser.detail', 'cuser.user'], routes: ['home'], token: 'System Token', }, ] }
export default [ { url: '/api/user/login', method: 'post', response: ({ body }) => { const { username, password } = body; const checkUser = createUserList().find( (item) => item.username === username && item.password === password, ) if (!checkUser) { return { code: 201, data: { message: '账号或者密码不正确' } } } const { token } = checkUser return { code: 200, data: { token } } }, }, { url: '/api/user/info', method: 'get', response: (request) => { const token = request.headers.token; const checkUser = createUserList().find((item) => item.token === token) if (!checkUser) { return { code: 201, data: { message: '获取用户信息失败' } } } return { code: 200, data: {checkUser} } }, }, ]
|