Commit 99c46c24 authored by 罗超's avatar 罗超

1

parent 5c3af45a
......@@ -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))
......
......@@ -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
......
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
})
}
}
}
......
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; password: string }) {
userLogin(params: { Account: string; Password: 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment