Blame view

mock/user.js 2.31 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 => {
60fa0be9d   Adam   auto commit the c...
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
        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 {
80a28914e   吉鹏   init
65
66
67
68
69
          return {
            code: 60204,
            message: 'Account and password are incorrect.'
          }
        }
80a28914e   吉鹏   init
70
71
72
73
74
      }
    },
  
    // get user info
    {
c44ba96f6   Adam   auto commit the c...
75
      url: '/yp/user/info\.*',
80a28914e   吉鹏   init
76
77
      type: 'get',
      response: config => {
60fa0be9d   Adam   auto commit the c...
78
79
80
        const {
          token
        } = config.query
80a28914e   吉鹏   init
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
        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...
100
      url: '/yp/user/logout',
80a28914e   吉鹏   init
101
102
103
104
105
106
107
108
109
      type: 'post',
      response: _ => {
        return {
          code: 20000,
          data: 'success'
        }
      }
    }
  ]