优化登录 mock ,通过请求头里的 token 信息判断用户

This commit is contained in:
Hooray Hu 2023-04-12 00:16:24 +08:00
parent c74f435bc6
commit 58d4a56663
3 changed files with 8 additions and 12 deletions

View File

@ -11,11 +11,11 @@
"rules": {
"stylistic/max-line-length": null,
"stylistic/block-closing-brace-newline-after": [
"always",
{
"ignoreAtRules": ["if", "else"]
}
],
"always",
{
"ignoreAtRules": ["if", "else"]
}
],
"at-rule-no-unknown": null,
"no-descending-specificity": null,
"property-no-unknown": null,

View File

@ -8,7 +8,7 @@ export default [
status: 1,
data: {
account: option.body.account,
token: '@string',
token: `${option.body.account}_@string`,
failure_time: Math.ceil(new Date().getTime() / 1000) + 24 * 60 * 60,
},
}
@ -19,7 +19,7 @@ export default [
method: 'get',
response: (option: any) => {
let permissions: string[] = []
if (option.query.account === 'admin') {
if (option.headers.token.indexOf('admin') === 0) {
permissions = [
'permission.browse',
'permission.create',
@ -27,7 +27,7 @@ export default [
'permission.remove',
]
}
else if (option.query.account === 'test') {
else if (option.headers.token.indexOf('test') === 0) {
permissions = [
'permission.browse',
]

View File

@ -55,9 +55,6 @@ const useUserStore = defineStore(
// 通过 mock 获取权限
const res = await api.get('member/permission', {
baseURL: '/mock/',
params: {
account: account.value,
},
})
permissions.value = res.data.permissions
return permissions.value
@ -68,7 +65,6 @@ const useUserStore = defineStore(
newpassword: string
}) {
await api.post('member/edit/password', {
account: account.value,
password: data.password,
newpassword: data.newpassword,
}, {