Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
horse
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
向伟
horse
Commits
99c46c24
Commit
99c46c24
authored
Nov 10, 2021
by
罗超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
5c3af45a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
41 deletions
+40
-41
axios.ts
src/api/axios.ts
+1
-1
permission.ts
src/boot/permission.ts
+1
-1
loginModule.ts
src/module/user/loginModule.ts
+10
-24
actions.ts
src/store/modules/user/actions.ts
+28
-15
No files found.
src/api/axios.ts
View file @
99c46c24
...
...
@@ -109,7 +109,7 @@ service.interceptors.response.use(
/** 请求有响应 */
async
(
response
:
AxiosResponse
)
=>
{
if
(
response
.
status
===
200
)
{
return
Promise
.
resolve
(
response
.
data
)
return
Promise
.
resolve
(
response
)
}
else
{
const
__text
=
getErrorCode2text
(
response
)
return
Promise
.
reject
(
new
Error
(
__text
))
...
...
src/boot/permission.ts
View file @
99c46c24
...
...
@@ -28,7 +28,7 @@ router.beforeEach((to, from, next) => {
// 判断当前用户是否获取权限
loadAsyncRouter
=
true
const
allAuth
=
getUserAllMenu
()
console
.
log
(
allAuth
)
console
.
log
(
'allAuth'
,
allAuth
)
next
({
...
to
,
replace
:
true
...
...
src/module/user/loginModule.ts
View file @
99c46c24
import
{
ResultType
}
from
'@/@types/enumHelper'
import
router
from
'@/router'
import
{
UserActionsType
}
from
'@/store/modules/user/actions'
//
import { ResultType } from '@/@types/enumHelper'
//
import router from '@/router'
import
UserActions
from
'@/store/modules/user/actions'
//{ UserActionsType }
import
{
UserGetter
}
from
'@/store/modules/user/getters'
import
{
dispatchAction
,
getStoreGetter
,
setStoreState
}
from
'@/store/utils'
//
import { UserGetter } from '@/store/modules/user/getters'
//
import { dispatchAction, getStoreGetter, setStoreState } from '@/store/utils'
import
message
from
'@/utils/message'
import
{
reactive
,
ref
}
from
'vue'
import
UserService
from
'@/api/user'
interface
LoginParams
{
username
:
string
password
:
string
...
...
@@ -30,7 +29,7 @@ const userUserLoginModule = () => {
const
usernameRef
=
ref
(
null
)
const
passwordRef
=
ref
(
null
)
const
loginSubmit
=
()
=>
{
const
loginSubmit
=
async
()
=>
{
if
(
!
stateManager
.
subLogin
)
{
stateManager
.
subLogin
=
true
const
ur
=
usernameRef
as
any
//断言任意类型
...
...
@@ -46,24 +45,11 @@ const userUserLoginModule = () => {
Password
:
userModel
.
password
}
dispatchAction
<
UserActionsType
>
(
'user'
,
'userLogin'
,
param
)
UserService
.
login
(
param
).
then
(
res
=>
{
// let menus: Array<any> = []
const
auths
=
getStoreGetter
<
UserGetter
>
(
'user'
,
'getUserAllAuth'
)
console
.
log
(
70
,
auths
,
ResultType
.
EmptyArray
)
// if (auths != ResultType.EmptyArray) {
// Object.assign(menus, ...auths)
// }
// menus.push(menu)
// menus.push(menu2)
console
.
log
(
72
,
res
.
data
.
Data
.
MenuList
)
setStoreState
(
'user'
,
'menuList'
,
res
.
data
.
Data
.
MenuList
)
router
.
push
({
path
:
'/index'
})
message
.
successMsg
(
'登录成功'
)
// dispatchAction<UserActionsType>('user', 'userLogin', param)
UserActions
.
userLogin
(
param
)
stateManager
.
subLogin
=
false
})
}
}
}
...
...
src/store/modules/user/actions.ts
View file @
99c46c24
import
UserService
from
'@/api/user'
import
{
setStoreState
}
from
'../../utils'
import
Store
from
'@/store'
import
router
from
'@/router'
import
message
from
'@/utils/message'
/**
* @description 所有跟用户相关的内容
* @return status 返回状态
err_code:1,逻辑正确,err_code:0,发生错误。
* @return status 返回状态 err_code:1,逻辑正确,err_code:0,发生错误。
*/
const
userActions
=
{
...
...
@@ -36,21 +38,37 @@ const userActions = {
setStoreState
(
'user'
,
'token'
,
{
...
token
,
expireTime
})
//清除菜单权限
setStoreState
(
'user'
,
'menuList'
,
[])
},
userLogin
(
params
:
{
username
:
string
;
p
assword
:
string
})
{
userLogin
(
params
:
{
Account
:
string
;
P
assword
:
string
})
{
//TODO: 实现用户登录
// UserService.login(params).then(res=>{
// })
UserService
.
login
(
params
).
then
(
res
=>
{
// const auths = getStoreGetter<UserGetter>('user', 'getUserAllAuth')
// console.log(70, auths, ResultType.EmptyArray)
// if (auths != ResultType.EmptyArray) {
// Object.assign(menus, ...auths)
// }
message
.
successMsg
(
'登录成功'
)
setStoreState
(
'user'
,
'menuList'
,
res
.
data
.
Data
.
MenuList
)
console
.
log
(
55
,
res
)
const
token
=
{
token_type
:
'login_auth'
,
access_token
:
res
.
data
.
Data
.
Token
}
console
.
log
(
56
,
token
)
const
expireTime
=
60
*
72
*
1000
+
new
Date
().
getTime
()
setStoreState
(
'user'
,
'token'
,
{
...
token
,
expireTime
})
router
.
push
({
path
:
'/index'
})
})
//测试伪造数据
const
loginUser
=
{
email
:
'alex9012@vip.qq.com'
,
type
:
0
,
// 用户账号本身类型
0:主账号,1:子账号
type
:
0
,
// 用户账号本身类型 0:主账号,1:子账号
userId
:
1
,
username
:
params
.
username
,
username
:
params
.
Account
,
description
:
''
,
nickName
:
'罗超'
,
phone
:
'17308037817'
,
...
...
@@ -59,17 +77,12 @@ const userActions = {
userAvatar
:
'https://preview.keenthemes.com/metronic8/demo7/assets/media/avatars/150-26.jpg'
}
setStoreState
(
'user'
,
'userDetail'
,
loginUser
)
const
token
=
{
token_type
:
'login_auth'
,
access_token
:
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}
const
expireTime
=
60
*
72
*
1000
+
new
Date
().
getTime
()
setStoreState
(
'user'
,
'token'
,
{
...
token
,
expireTime
})
}
}
type
UserActionsType
=
typeof
userActions
console
.
log
(
73
,
typeof
userActions
)
export
{
UserActionsType
}
export
default
userActions
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment