Blame view

HHECS.Web/mock/user.js 1.85 KB
胡菁 authored
1
2

const tokens = {
陈嘉新 authored
3
4
5
6
7
8
    admin: {
        token: 'admin-token'
    },
    editor: {
        token: 'editor-token'
    }
胡菁 authored
9
10
11
}

const users = {
陈嘉新 authored
12
13
14
15
16
17
18
19
20
21
22
23
    'admin-token': {
        roles: ['admin'],
        introduction: 'I am a super administrator',
        avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
        name: 'admin'
    },
    'editor-token': {
        roles: ['editor'],
        introduction: 'I am an editor',
        avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
        name: 'Normal Editor'
    }
胡菁 authored
24
25
26
}

module.exports = [
陈嘉新 authored
27
28
29
30
31
32
33
    // user login
    {
        url: '/vue-admin-template/user/login',
        type: 'post',
        response: config => {
            const { username } = config.body
            const token = tokens[username]
胡菁 authored
34
陈嘉新 authored
35
36
37
38
39
40
41
42
43
44
45
46
            // mock error
            if (!token) {
                return {
                    code: 60204,
                    message: 'Account and password are incorrect.'
                }
            }

            return {
                code: "Success",
                data: token
            }
胡菁 authored
47
        }
陈嘉新 authored
48
    },
胡菁 authored
49
陈嘉新 authored
50
51
52
53
54
55
56
    // get user info
    {
        url: '/vue-admin-template/user/info\.*',
        type: 'get',
        response: config => {
            const { token } = config.query
            const info = users[token]
胡菁 authored
57
陈嘉新 authored
58
59
60
61
62
63
64
            // mock error
            if (!info) {
                return {
                    code: 50008,
                    message: 'Login failed, unable to get user details.'
                }
            }
胡菁 authored
65
陈嘉新 authored
66
67
68
69
            return {
                code: "Success",
                data: info
            }
胡菁 authored
70
        }
陈嘉新 authored
71
    },
胡菁 authored
72
陈嘉新 authored
73
74
75
76
77
78
79
80
81
82
    // user logout
    {
        url: '/vue-admin-template/user/logout',
        type: 'post',
        response: _ => {
            return {
                code: "Success",
                data: 'success'
            }
        }
胡菁 authored
83
84
    }
]