调整登陆和获取用户信息的接口
This commit is contained in:
parent
c163c1e726
commit
00be3d537c
3
.eslintignore
Normal file
3
.eslintignore
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dist/*.js
|
||||||
|
src/assets
|
||||||
|
tests/unit/coverage
|
54
.eslintrc.js
Normal file
54
.eslintrc.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
env: {
|
||||||
|
node: true
|
||||||
|
},
|
||||||
|
extends: [
|
||||||
|
'plugin:vue/essential',
|
||||||
|
'@vue/standard',
|
||||||
|
'@vue/typescript/recommended'
|
||||||
|
],
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 2020
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
'@typescript-eslint/ban-types': 'off',
|
||||||
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||||
|
'@typescript-eslint/member-delimiter-style': ['error',
|
||||||
|
{
|
||||||
|
multiline: {
|
||||||
|
delimiter: 'none'
|
||||||
|
},
|
||||||
|
singleline: {
|
||||||
|
delimiter: 'comma'
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
'@typescript-eslint/no-explicit-any': 'off',
|
||||||
|
'@typescript-eslint/no-var-requires': 'off',
|
||||||
|
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
|
||||||
|
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
|
||||||
|
'space-before-function-paren': ['error', 'never'],
|
||||||
|
'vue/array-bracket-spacing': 'error',
|
||||||
|
'vue/arrow-spacing': 'error',
|
||||||
|
'vue/block-spacing': 'error',
|
||||||
|
'vue/brace-style': 'error',
|
||||||
|
'vue/camelcase': 'error',
|
||||||
|
'vue/comma-dangle': 'error',
|
||||||
|
'vue/component-name-in-template-casing': ['error', 'kebab-case'],
|
||||||
|
'vue/eqeqeq': 'error',
|
||||||
|
'vue/key-spacing': 'error',
|
||||||
|
'vue/match-component-file-name': 'error',
|
||||||
|
'vue/object-curly-spacing': 'error'
|
||||||
|
},
|
||||||
|
overrides: [
|
||||||
|
{
|
||||||
|
files: [
|
||||||
|
'**/__tests__/*.{j,t}s?(x)',
|
||||||
|
'**/tests/unit/**/*.spec.{j,t}s?(x)'
|
||||||
|
],
|
||||||
|
env: {
|
||||||
|
jest: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -2,20 +2,20 @@ import request from '@/utils/request'
|
|||||||
|
|
||||||
export const getUserInfo = (data: any) =>
|
export const getUserInfo = (data: any) =>
|
||||||
request({
|
request({
|
||||||
url: '/users/info',
|
url: '/user/info',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data
|
data
|
||||||
})
|
})
|
||||||
|
|
||||||
export const login = (data: any) =>
|
export const login = (data: any) =>
|
||||||
request({
|
request({
|
||||||
url: '/users/login',
|
url: '/user/login',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data
|
data
|
||||||
})
|
})
|
||||||
|
|
||||||
export const logout = () =>
|
export const logout = () =>
|
||||||
request({
|
request({
|
||||||
url: '/users/logout',
|
url: '/user/logout',
|
||||||
method: 'post'
|
method: 'post'
|
||||||
})
|
})
|
||||||
|
@ -49,8 +49,9 @@ class User extends VuexModule implements IUserState {
|
|||||||
let { username, password } = userInfo
|
let { username, password } = userInfo
|
||||||
username = username.trim()
|
username = username.trim()
|
||||||
const { data } = await login({ username, password })
|
const { data } = await login({ username, password })
|
||||||
setToken(data.accessToken)
|
console.log(data);
|
||||||
this.SET_TOKEN(data.accessToken)
|
setToken(data.token)
|
||||||
|
this.SET_TOKEN(data.token)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Action
|
@Action
|
||||||
@ -66,16 +67,17 @@ class User extends VuexModule implements IUserState {
|
|||||||
throw Error('GetUserInfo: token is undefined!')
|
throw Error('GetUserInfo: token is undefined!')
|
||||||
}
|
}
|
||||||
const { data } = await getUserInfo({ /* Your params here */ })
|
const { data } = await getUserInfo({ /* Your params here */ })
|
||||||
|
console.log(data);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
throw Error('Verification failed, please Login again.')
|
throw Error('Verification failed, please Login again.')
|
||||||
}
|
}
|
||||||
const { roles, name, avatar, introduction } = data.user
|
const { roles, showname, avatar, introduction } = data
|
||||||
// roles must be a non-empty array
|
// roles must be a non-empty array
|
||||||
if (!roles || roles.length <= 0) {
|
if (!roles || roles.length <= 0) {
|
||||||
throw Error('GetUserInfo: roles must be a non-null array!')
|
throw Error('GetUserInfo: roles must be a non-null array!')
|
||||||
}
|
}
|
||||||
this.SET_ROLES(roles)
|
this.SET_ROLES(roles)
|
||||||
this.SET_NAME(name)
|
this.SET_NAME(showname)
|
||||||
this.SET_AVATAR(avatar)
|
this.SET_AVATAR(avatar)
|
||||||
this.SET_INTRODUCTION(introduction)
|
this.SET_INTRODUCTION(introduction)
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,9 @@ service.interceptors.request.use(
|
|||||||
(config) => {
|
(config) => {
|
||||||
// Add X-Access-Token header to every request, you can add other custom headers here
|
// Add X-Access-Token header to every request, you can add other custom headers here
|
||||||
if (UserModule.token) {
|
if (UserModule.token) {
|
||||||
config.headers['X-Access-Token'] = UserModule.token
|
config.headers['authorization'] = 'Bearer ' + UserModule.token
|
||||||
}
|
}
|
||||||
|
config.headers['Content-Type'] = 'application/json'
|
||||||
return config
|
return config
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
@ -25,15 +26,15 @@ service.interceptors.request.use(
|
|||||||
service.interceptors.response.use(
|
service.interceptors.response.use(
|
||||||
(response) => {
|
(response) => {
|
||||||
// Some example codes here:
|
// Some example codes here:
|
||||||
// code == 20000: success
|
// code == 0: success
|
||||||
// code == 50001: invalid access token
|
// code == 50001: invalid access token
|
||||||
// code == 50002: already login in other place
|
// code == 50002: already login in other place
|
||||||
// code == 50003: access token expired
|
// code == 50003: access token expired
|
||||||
// code == 50004: invalid user (user not exist)
|
// code == 50004: invalid user (user not exist)
|
||||||
// code == 50005: username or password is incorrect
|
// code == 10: username or password is incorrect
|
||||||
// You can change this part for your own usage.
|
// You can change this part for your own usage.
|
||||||
const res = response.data
|
const res = response.data
|
||||||
if (res.code !== 20000) {
|
if (res.code ) {
|
||||||
Message({
|
Message({
|
||||||
message: res.message || 'Error',
|
message: res.message || 'Error',
|
||||||
type: 'error',
|
type: 'error',
|
||||||
|
@ -62,7 +62,6 @@
|
|||||||
<div style="position:relative">
|
<div style="position:relative">
|
||||||
<div class="tips">
|
<div class="tips">
|
||||||
<span> username: admin </span>
|
<span> username: admin </span>
|
||||||
<span> password: any </span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-form>
|
</el-form>
|
||||||
@ -99,7 +98,7 @@ export default class extends Vue {
|
|||||||
|
|
||||||
private loginForm = {
|
private loginForm = {
|
||||||
username: 'admin',
|
username: 'admin',
|
||||||
password: '111111'
|
password: '7654321'
|
||||||
}
|
}
|
||||||
|
|
||||||
private loginRules = {
|
private loginRules = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user