sijun.li | 9646230 | 2020-07-24 10:08:05 +0800 | [diff] [blame] | 1 | |
| 2 | const tokens = { |
| 3 | admin: { |
| 4 | token: 'admin-token' |
| 5 | }, |
| 6 | editor: { |
| 7 | token: 'editor-token' |
| 8 | } |
| 9 | } |
| 10 | |
| 11 | const users = { |
| 12 | 'admin-token': { |
| 13 | roles: ['admin'], |
| 14 | introduction: 'I am a super administrator', |
| 15 | avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif', |
| 16 | name: 'Super Admin' |
| 17 | }, |
| 18 | 'editor-token': { |
| 19 | roles: ['editor'], |
| 20 | introduction: 'I am an editor', |
| 21 | avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif', |
| 22 | name: 'Normal Editor' |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | module.exports = [ |
| 27 | // user login |
| 28 | { |
| 29 | url: '/vue-element-admin/user/login', |
| 30 | type: 'post', |
| 31 | response: config => { |
| 32 | const { username } = config.body |
| 33 | const token = tokens[username] |
| 34 | |
| 35 | // mock error |
| 36 | if (!token) { |
| 37 | return { |
| 38 | code: 60204, |
| 39 | message: 'Account and password are incorrect.' |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | return { |
| 44 | code: 20000, |
| 45 | data: token |
| 46 | } |
| 47 | } |
| 48 | }, |
| 49 | |
| 50 | // get user info |
| 51 | { |
| 52 | url: '/vue-element-admin/user/info\.*', |
| 53 | type: 'get', |
| 54 | response: config => { |
| 55 | const { token } = config.query |
| 56 | const info = users[token] |
| 57 | |
| 58 | // mock error |
| 59 | if (!info) { |
| 60 | return { |
| 61 | code: 50008, |
| 62 | message: 'Login failed, unable to get user details.' |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return { |
| 67 | code: 20000, |
| 68 | data: info |
| 69 | } |
| 70 | } |
| 71 | }, |
| 72 | |
| 73 | // user logout |
| 74 | { |
| 75 | url: '/vue-element-admin/user/logout', |
| 76 | type: 'post', |
| 77 | response: _ => { |
| 78 | return { |
| 79 | code: 20000, |
| 80 | data: 'success' |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | ] |