Blame view

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