|
@@ -2,7 +2,6 @@ import { getTokenid, removeTokenId, saveTokenId } from '@/basic/utils/common'
|
|
|
import consts from '@/consts'
|
|
import consts from '@/consts'
|
|
|
import { apiLogin } from '@/services/login'
|
|
import { apiLogin } from '@/services/login'
|
|
|
import { apiCurrent, apiGetRoles } from '@/services/user'
|
|
import { apiCurrent, apiGetRoles } from '@/services/user'
|
|
|
-import { setAuthority } from '@/utils/authority'
|
|
|
|
|
import { getPageQuery } from '@/utils/utils'
|
|
import { getPageQuery } from '@/utils/utils'
|
|
|
import { message } from 'antd'
|
|
import { message } from 'antd'
|
|
|
import { stringify } from 'qs'
|
|
import { stringify } from 'qs'
|
|
@@ -18,14 +17,21 @@ const UserModel = {
|
|
|
*login({ payload }, { call, put }) {
|
|
*login({ payload }, { call, put }) {
|
|
|
// 获取登录接口数据
|
|
// 获取登录接口数据
|
|
|
const response = yield call(apiLogin, payload)
|
|
const response = yield call(apiLogin, payload)
|
|
|
- saveTokenId(response.data.token)
|
|
|
|
|
- const { data: currentAuthority = [] } = yield call(apiGetRoles)
|
|
|
|
|
- yield put({
|
|
|
|
|
- type: 'changeLoginStatus',
|
|
|
|
|
- payload: { status: response?.code, currentAuthority }
|
|
|
|
|
- }) // Login successfully
|
|
|
|
|
-
|
|
|
|
|
- if (response && response.code === consts.RET_CODE.SUCCESS) {
|
|
|
|
|
|
|
+ if (response?.code !== consts.RET_CODE.SUCCESS) {
|
|
|
|
|
+ yield put({
|
|
|
|
|
+ type: 'changeLoginStatus',
|
|
|
|
|
+ payload: { status: response?.code || -1 }
|
|
|
|
|
+ })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ if (response?.code === consts.RET_CODE.SUCCESS) {
|
|
|
|
|
+ // Login successfully
|
|
|
|
|
+ saveTokenId(response.data.token)
|
|
|
|
|
+ const { data: currentAuthority = [] } = yield call(apiGetRoles)
|
|
|
|
|
+ yield put({
|
|
|
|
|
+ type: 'changeLoginStatus',
|
|
|
|
|
+ payload: { status: response?.code, currentAuthority }
|
|
|
|
|
+ })
|
|
|
const urlParams = new URL(window.location.href)
|
|
const urlParams = new URL(window.location.href)
|
|
|
const params = getPageQuery()
|
|
const params = getPageQuery()
|
|
|
message.success('🎉 🎉 🎉 登录成功')
|
|
message.success('🎉 🎉 🎉 登录成功')
|
|
@@ -61,7 +67,7 @@ const UserModel = {
|
|
|
}
|
|
}
|
|
|
// window.location.reload()
|
|
// window.location.reload()
|
|
|
},
|
|
},
|
|
|
- *fetchCurrent(_, { call, put, select }) {
|
|
|
|
|
|
|
+ *fetchCurrent(_, { call, put }) {
|
|
|
if (window.location.pathname === '/user/login') {
|
|
if (window.location.pathname === '/user/login') {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
@@ -76,27 +82,26 @@ const UserModel = {
|
|
|
type: 'saveCurrentUser',
|
|
type: 'saveCurrentUser',
|
|
|
payload: response.data
|
|
payload: response.data
|
|
|
})
|
|
})
|
|
|
- const { loginStatus } = yield select(state => state.user)
|
|
|
|
|
- console.log('loginStatus', loginStatus)
|
|
|
|
|
- if (!loginStatus) {
|
|
|
|
|
- const { data: currentAuthority = [] } = yield call(apiGetRoles)
|
|
|
|
|
- yield put({
|
|
|
|
|
- type: 'changeLoginStatus',
|
|
|
|
|
- payload: { status: consts.RET_CODE.SUCCESS, currentAuthority }
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // const { loginStatus } = yield select(state => state.user)
|
|
|
|
|
+ // if (!loginStatus) {
|
|
|
|
|
+ // const { data: currentAuthority = [] } = yield call(apiGetRoles)
|
|
|
|
|
+ // yield put({
|
|
|
|
|
+ // type: 'changeLoginStatus',
|
|
|
|
|
+ // payload: { status: consts.RET_CODE.SUCCESS, currentAuthority }
|
|
|
|
|
+ // })
|
|
|
|
|
+ // }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
reducers: {
|
|
reducers: {
|
|
|
saveCurrentUser(state, action) {
|
|
saveCurrentUser(state, action) {
|
|
|
return { ...state, currentUser: action.payload || {} }
|
|
return { ...state, currentUser: action.payload || {} }
|
|
|
- },
|
|
|
|
|
-
|
|
|
|
|
- changeLoginStatus(state, { payload }) {
|
|
|
|
|
- setAuthority(payload.currentAuthority)
|
|
|
|
|
- return { ...state, loginStatus: payload.status }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // changeLoginStatus(state, { payload }) {
|
|
|
|
|
+ // setAuthority(payload.currentAuthority)
|
|
|
|
|
+ // return { ...state, loginStatus: payload.status }
|
|
|
|
|
+ // }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
export default UserModel
|
|
export default UserModel
|