Blame view

mock/user.js 2.39 KB
80a28914e   吉鹏   init
1
2
3
4
  const tokens = {
    admin: {
      token: 'admin-token'
    },
c44ba96f6   Adam   auto commit the c...
5
6
7
    assistant: {
      token: 'assistant-token'
    },
60fa0be9d   Adam   auto commit the c...
8
9
    runner: {
      token: 'runner-token'
c44ba96f6   Adam   auto commit the c...
10
11
12
    },
    shoper: {
      token: 'shoper-token'
80a28914e   吉鹏   init
13
14
15
16
    }
  }
  
  const users = {
60fa0be9d   Adam   auto commit the c...
17
    'admin-token': { //管理员
80a28914e   吉鹏   init
18
19
20
21
22
      roles: ['admin'],
      introduction: 'I am a super administrator',
      avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
      name: 'Super Admin'
    },
60fa0be9d   Adam   auto commit the c...
23
    'assistant-token': { //管理员助理
c44ba96f6   Adam   auto commit the c...
24
25
26
      roles: ['assistant'],
      introduction: 'I am a assistant of administrator',
      avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
60fa0be9d   Adam   auto commit the c...
27
      name: 'assistant Admin'
c44ba96f6   Adam   auto commit the c...
28
    },
60fa0be9d   Adam   auto commit the c...
29
30
31
    'runner-token': { //运营人员
      roles: ['runner'],
      introduction: 'I am an runner',
80a28914e   吉鹏   init
32
      avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
60fa0be9d   Adam   auto commit the c...
33
      name: 'Normal runner'
c44ba96f6   Adam   auto commit the c...
34
    },
60fa0be9d   Adam   auto commit the c...
35
    'shoper-token': { //供应商
c44ba96f6   Adam   auto commit the c...
36
37
38
      roles: ['shoper'],
      introduction: 'I am an shoper',
      avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
60fa0be9d   Adam   auto commit the c...
39
      name: 'Normal shoper'
80a28914e   吉鹏   init
40
41
    }
  }
60fa0be9d   Adam   auto commit the c...
42
  export default [{ // user login
c44ba96f6   Adam   auto commit the c...
43
      url: '/yp/user/login',
80a28914e   吉鹏   init
44
45
      type: 'post',
      response: config => {
c40d344e2   Adam   auto commit the c...
46
        console.log('config-----111--->', config.body);
60fa0be9d   Adam   auto commit the c...
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
        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 {
c40d344e2   Adam   auto commit the c...
65
          console.log('passwordpasswordpassword', username, password);
80a28914e   吉鹏   init
66
67
          return {
            code: 60204,
c40d344e2   Adam   auto commit the c...
68
            message: 'Account and password are incorrect///.'
80a28914e   吉鹏   init
69
70
          }
        }
80a28914e   吉鹏   init
71
72
73
74
75
      }
    },
  
    // get user info
    {
c44ba96f6   Adam   auto commit the c...
76
      url: '/yp/user/info\.*',
80a28914e   吉鹏   init
77
78
      type: 'get',
      response: config => {
60fa0be9d   Adam   auto commit the c...
79
80
81
        const {
          token
        } = config.query
80a28914e   吉鹏   init
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
        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
    {
c44ba96f6   Adam   auto commit the c...
101
      url: '/yp/user/logout',
80a28914e   吉鹏   init
102
103
104
105
106
107
108
109
110
      type: 'post',
      response: _ => {
        return {
          code: 20000,
          data: 'success'
        }
      }
    }
  ]