Blame view

mock/user.js 1.51 KB
d7d9c38c2   Adam   auto commit the c...
1

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