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

1

parent 5c3af45a
...@@ -109,7 +109,7 @@ service.interceptors.response.use( ...@@ -109,7 +109,7 @@ service.interceptors.response.use(
/** 请求有响应 */ /** 请求有响应 */
async (response: AxiosResponse) => { async (response: AxiosResponse) => {
if (response.status === 200) { if (response.status === 200) {
return Promise.resolve(response.data) return Promise.resolve(response)
} else { } else {
const __text = getErrorCode2text(response) const __text = getErrorCode2text(response)
return Promise.reject(new Error(__text)) return Promise.reject(new Error(__text))
......
...@@ -28,7 +28,7 @@ router.beforeEach((to, from, next) => { ...@@ -28,7 +28,7 @@ router.beforeEach((to, from, next) => {
// 判断当前用户是否获取权限 // 判断当前用户是否获取权限
loadAsyncRouter = true loadAsyncRouter = true
const allAuth = getUserAllMenu() const allAuth = getUserAllMenu()
console.log(allAuth) console.log('allAuth',allAuth)
next({ next({
...to, ...to,
replace: true replace: true
......
import { ResultType } from '@/@types/enumHelper' // import { ResultType } from '@/@types/enumHelper'
import router from '@/router' // import router from '@/router'
import { UserActionsType } from '@/store/modules/user/actions' import UserActions from '@/store/modules/user/actions'//{ UserActionsType }
import { UserGetter } from '@/store/modules/user/getters' // import { UserGetter } from '@/store/modules/user/getters'
import { dispatchAction, getStoreGetter, setStoreState } from '@/store/utils' // import { dispatchAction, getStoreGetter, setStoreState } from '@/store/utils'
import message from '@/utils/message' import message from '@/utils/message'
import { reactive, ref } from 'vue' import { reactive, ref } from 'vue'
import UserService from '@/api/user'
interface LoginParams { interface LoginParams {
username: string username: string
password: string password: string
...@@ -30,7 +29,7 @@ const userUserLoginModule = () => { ...@@ -30,7 +29,7 @@ const userUserLoginModule = () => {
const usernameRef = ref(null) const usernameRef = ref(null)
const passwordRef = ref(null) const passwordRef = ref(null)
const loginSubmit = () => { const loginSubmit = async () => {
if (!stateManager.subLogin) { if (!stateManager.subLogin) {
stateManager.subLogin = true stateManager.subLogin = true
const ur = usernameRef as any //断言任意类型 const ur = usernameRef as any //断言任意类型
...@@ -46,24 +45,11 @@ const userUserLoginModule = () => { ...@@ -46,24 +45,11 @@ const userUserLoginModule = () => {
Password: userModel.password Password: userModel.password
} }
dispatchAction<UserActionsType>('user', 'userLogin', param) // dispatchAction<UserActionsType>('user', 'userLogin', param)
UserService.login(param).then(res => { UserActions.userLogin(param)
// 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('登录成功')
stateManager.subLogin = false stateManager.subLogin = false
})
} }
} }
} }
......
import UserService from '@/api/user' import UserService from '@/api/user'
import { setStoreState } from '../../utils' import { setStoreState } from '../../utils'
import Store from '@/store' import Store from '@/store'
import router from '@/router'
import message from '@/utils/message'
/** /**
* @description 所有跟用户相关的内容 * @description 所有跟用户相关的内容
* @return status 返回状态 err_code:1,逻辑正确,err_code:0,发生错误。 * @return status 返回状态 err_code:1,逻辑正确,err_code:0,发生错误。
...@@ -36,21 +38,37 @@ const userActions = { ...@@ -36,21 +38,37 @@ const userActions = {
setStoreState('user', 'token', { ...token, expireTime }) setStoreState('user', 'token', { ...token, expireTime })
//清除菜单权限 //清除菜单权限
setStoreState('user', 'menuList', []) setStoreState('user', 'menuList', [])
}, },
userLogin(params: { username: string; password: string }) { userLogin(params: { Account: string; Password: string }) {
//TODO: 实现用户登录 //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 = { const loginUser = {
email: 'alex9012@vip.qq.com', email: 'alex9012@vip.qq.com',
type: 0, // 用户账号本身类型 0:主账号,1:子账号 type: 0, // 用户账号本身类型 0:主账号,1:子账号
userId: 1, userId: 1,
username: params.username, username: params.Account,
description: '', description: '',
nickName: '罗超', nickName: '罗超',
phone: '17308037817', phone: '17308037817',
...@@ -59,17 +77,12 @@ const userActions = { ...@@ -59,17 +77,12 @@ const userActions = {
userAvatar: 'https://preview.keenthemes.com/metronic8/demo7/assets/media/avatars/150-26.jpg' userAvatar: 'https://preview.keenthemes.com/metronic8/demo7/assets/media/avatars/150-26.jpg'
} }
setStoreState('user', 'userDetail', loginUser) 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 type UserActionsType = typeof userActions
console.log(73, typeof userActions)
export { UserActionsType } export { UserActionsType }
export default userActions 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