|
@@ -1,8 +1,8 @@
|
|
|
-import { login, loginUp } from '@/api/newLogin'
|
|
|
import { getToken, setToken, removeToken, setUserId, TokenKey } from '@/utils/auth'
|
|
|
import { resetRouter } from '@/router'
|
|
|
import { Query } from '@/api/dataIntegration'
|
|
|
-import { isValue } from "@/utils/validate";
|
|
|
+import { isValue } from "@/utils/validate"
|
|
|
+import { getAuth, signIn, loginOut } from '@/api/login'
|
|
|
const getDefaultState = () => {
|
|
|
return {
|
|
|
token: getToken(),
|
|
@@ -63,17 +63,17 @@ const actions = {
|
|
|
// user login
|
|
|
login ({ commit }, userInfo) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- login(userInfo)
|
|
|
+ signIn(userInfo)
|
|
|
.then(response => {
|
|
|
if (response.code == 0 && isValue(response.returnData)) {
|
|
|
- const { date, token, userid } = response.returnData
|
|
|
- commit('SET_TOKEN', token)
|
|
|
+ const { user_token, user_id } = response.returnData
|
|
|
+ commit('SET_TOKEN', user_token)
|
|
|
commit('SET_UserType', 1)
|
|
|
- commit('SET_UserId', userid)
|
|
|
+ commit('SET_UserId', user_id)
|
|
|
setToken('userName', userInfo.username)
|
|
|
- setToken(TokenKey, token)
|
|
|
- setUserId(userid)
|
|
|
- setToken('userid', userid)
|
|
|
+ setToken(TokenKey, user_token)
|
|
|
+ setUserId(user_id)
|
|
|
+ setToken('userid', user_id)
|
|
|
resolve(true)
|
|
|
} else {
|
|
|
reject(false)
|
|
@@ -85,82 +85,11 @@ const actions = {
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- // get user info
|
|
|
- getInfo ({ commit, state }) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- Query({
|
|
|
- id: DATACONTENT_ID.loginId,
|
|
|
- dataContent: [getToken('userid')]
|
|
|
- })
|
|
|
- .then(res => {
|
|
|
- if (res.code == 0) {
|
|
|
- const { listValues } = res.returnData
|
|
|
- const datas = listValues
|
|
|
- if (datas && datas.length) {
|
|
|
- const arrs = []
|
|
|
- for (const item of datas) {
|
|
|
- if (item.ident) {
|
|
|
- arrs.push(item.ident)
|
|
|
- }
|
|
|
- }
|
|
|
- // arrs.push('transit');
|
|
|
- sessionStorage.setItem('userAuthList', JSON.stringify(arrs))
|
|
|
- setTimeout(() => {
|
|
|
- const data = {
|
|
|
- roles: arrs,
|
|
|
- introduction: '',
|
|
|
- avatar: '',
|
|
|
- name: getToken('userName'),
|
|
|
- token: state.token
|
|
|
- }
|
|
|
-
|
|
|
- const { name, avatar, roles } = data
|
|
|
-
|
|
|
- commit('SET_NAME', name)
|
|
|
- commit('SET_AVATAR', avatar)
|
|
|
- commit('SET_ROLES', roles ? roles : ['admin'])
|
|
|
- commit('SET_UserPoewrList', roles ? roles : ['admin'])
|
|
|
- resolve(data)
|
|
|
- }, 100)
|
|
|
- } else {
|
|
|
- sessionStorage.setItem('userAuthList', [])
|
|
|
- setTimeout(() => {
|
|
|
- const data = {
|
|
|
- roles: state.userPoewrList,
|
|
|
- introduction: '',
|
|
|
- avatar: '',
|
|
|
- name: getToken('userName'),
|
|
|
- token: state.token
|
|
|
- }
|
|
|
-
|
|
|
- const { name, avatar, roles } = data
|
|
|
-
|
|
|
- commit('SET_NAME', name)
|
|
|
- commit('SET_AVATAR', avatar)
|
|
|
- commit('SET_ROLES', roles ? roles : ['admin'])
|
|
|
- commit('SET_UserPoewrList', roles ? roles : ['admin'])
|
|
|
- resolve(data)
|
|
|
- }, 100)
|
|
|
- }
|
|
|
- } else {
|
|
|
- reject(res.returnData)
|
|
|
- }
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- reject(err)
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
getMenuInfo ({ commit }) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- Query({
|
|
|
- serviceId: SERVICE_ID.sysMenuId,
|
|
|
- dataContent: {
|
|
|
- user_id: '',
|
|
|
- },
|
|
|
- page: 1,
|
|
|
- pageSize: 9999
|
|
|
+ getAuth({
|
|
|
+ user_id: getToken('userid'),
|
|
|
+ user_token: getToken(TokenKey)
|
|
|
})
|
|
|
.then((res) => {
|
|
|
if (res.code == 0 && isValue(res.returnData)) {
|
|
@@ -177,31 +106,26 @@ const actions = {
|
|
|
},
|
|
|
|
|
|
// user logout
|
|
|
- logout ({ commit, state }) {
|
|
|
+ logout ({ commit }) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- loginUp().then(result => {
|
|
|
- // sessionStorage.removeItem("userName");
|
|
|
- // sessionStorage.removeItem("UserType");
|
|
|
- // sessionStorage.removeItem("User_Id");
|
|
|
- sessionStorage.clear()
|
|
|
- removeToken() // must remove token first
|
|
|
- removeToken('codeToken')
|
|
|
- removeToken('systemSet')
|
|
|
- removeToken('userid')
|
|
|
- resetRouter()
|
|
|
- commit('RESET_STATE')
|
|
|
- commit('SET_ROLES', [])
|
|
|
- resolve()
|
|
|
+ loginOut({
|
|
|
+ user_id: getToken('userid'),
|
|
|
+ user_token: getToken(TokenKey)
|
|
|
+ }).then(result => {
|
|
|
+ if (result) {
|
|
|
+ sessionStorage.clear()
|
|
|
+ removeToken() // must remove token first
|
|
|
+ removeToken('codeToken')
|
|
|
+ removeToken('systemSet')
|
|
|
+ removeToken('userid')
|
|
|
+ resetRouter()
|
|
|
+ commit('RESET_STATE')
|
|
|
+ commit('SET_ROLES', [])
|
|
|
+ resolve(true)
|
|
|
+ } else {
|
|
|
+ reject(false)
|
|
|
+ }
|
|
|
})
|
|
|
-
|
|
|
- // logout(state.token).then(() => {
|
|
|
- // removeToken() // must remove token first
|
|
|
- // resetRouter()
|
|
|
- // commit('RESET_STATE')
|
|
|
- // resolve()
|
|
|
- // }).catch(error => {
|
|
|
- // reject(error)
|
|
|
- // })
|
|
|
})
|
|
|
},
|
|
|
|