user.js
2.39 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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-----111--->', 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 {
console.log('passwordpasswordpassword', username, password);
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'
}
}
}
]