const tokens = { admin: { token: 'admin-token' }, assistant: { token: 'assistant-token' }, runner: { token: 'runner-token' }, shoper: { token: 'shoper-token' } } const users = { 'admin-token': { //管理员 roles: ['admin'], introduction: 'I am a super administrator', avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif', name: 'Super Admin' }, 'assistant-token': { //管理员助理 roles: ['assistant'], introduction: 'I am a assistant of administrator', avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif', name: 'assistant Admin' }, 'runner-token': { //运营人员 roles: ['runner'], introduction: 'I am an runner', avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif', name: 'Normal runner' }, 'shoper-token': { //供应商 roles: ['shoper'], introduction: 'I am an shoper', avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif', name: 'Normal shoper' } } export default [{ // user login url: '/yp/user/login', type: 'post', response: config => { console.log('config-------->', config.body); const { username, password } = config.body; if (username == 'admin' && password == '111111') { const token = tokens[username]; if (!token) { return { code: 60204, message: 'Account and password are incorrect.' } } else { return { code: 20000, data: token } } } else { return { code: 60204, message: 'Account and password are incorrect.' } } } }, // get user info { url: '/yp/user/info\.*', type: 'get', response: config => { const { token } = config.query const info = users[token] // mock error if (!info) { return { code: 50008, message: 'Login failed, unable to get user details.' } } return { code: 20000, data: info } } }, // user logout { url: '/yp/user/logout', type: 'post', response: _ => { return { code: 20000, data: 'success' } } } ]