| | |
| | | import { setStore, getStore } from '@/utils/store'; |
| | | import { validatenull } from '@/utils/validate'; |
| | | import { deepClone } from '@/utils/util'; |
| | | import defaultAva from '@/assets/images/defaultava.png' |
| | | import { |
| | | loginByUsername, |
| | | loginBySocial, |
| | |
| | | refreshToken, |
| | | getButtons, |
| | | registerUser, |
| | | getParentDeptInfo |
| | | } from '@/api/user'; |
| | | import { getRoutes, getTopMenu } from '@/api/system/menu'; |
| | | import { formatPath } from '@/router/avue-router'; |
| | | import { ElMessage } from 'element-plus'; |
| | | import { encrypt } from '@/utils/sm2'; |
| | | import md5 from 'js-md5'; |
| | | |
| | | |
| | | const user = { |
| | | state: { |
| | |
| | | menuAll: getStore({ name: 'menuAll' }) || [], |
| | | token: getStore({ name: 'token' }) || '', |
| | | refreshToken: getStore({ name: 'refreshToken' }) || '', |
| | | parentDeptInfo: getStore({ name: 'parentDeptInfo' }) || '', |
| | | |
| | | }, |
| | | actions: { |
| | | //根据用户名登录 |
| | |
| | | userInfo.deptId, |
| | | userInfo.roleId, |
| | | userInfo.username, |
| | | encrypt(userInfo.password), |
| | | md5(userInfo.password), |
| | | userInfo.type, |
| | | userInfo.key, |
| | | userInfo.code |
| | |
| | | commit('SET_REFRESH_TOKEN', data.refresh_token); |
| | | commit('SET_TENANT_ID', data.tenant_id); |
| | | commit('SET_USER_INFO', data); |
| | | commit('SET_PARENT_DEPT_INFO', data.dept_id); |
| | | commit('DEL_ALL_TAG'); |
| | | commit('CLEAR_LOCK'); |
| | | } |
| | |
| | | commit('CLEAR_LOCK'); |
| | | removeToken(); |
| | | removeRefreshToken(); |
| | | removeToken(); |
| | | resolve(); |
| | | }) |
| | | .catch(error => { |
| | |
| | | }); |
| | | }, |
| | | GetMenu({ commit, dispatch }, tenantId) { |
| | | const errLogOut = () => { |
| | | dispatch('LogOut').then(()=>{ |
| | | const env = import.meta.env.VITE_APP_ENV |
| | | const adminUrl = import.meta.env.VITE_APP_DASHBOARD_URL |
| | | env === 'development' |
| | | ? window.location.href = "/manage/login" |
| | | : window.location.replace(`${adminUrl}#/login`) |
| | | }) |
| | | } |
| | | return new Promise(resolve => { |
| | | getRoutes(tenantId).then(res => { |
| | | const data = res.data.data; |
| | | let menu = deepClone(data); |
| | | if (!res.data?.data?.length){ |
| | | errLogOut() |
| | | return |
| | | } |
| | | menu.forEach(ele => formatPath(ele, true)); |
| | | commit('SET_MENU', menu); |
| | | commit('SET_MENU_ALL', menu); |
| | | dispatch('GetButtons'); |
| | | resolve(menu); |
| | | }); |
| | | }).catch(err =>{ |
| | | errLogOut() |
| | | }) |
| | | }); |
| | | }, |
| | | GetButtons({ commit }) { |
| | |
| | | }, |
| | | }, |
| | | mutations: { |
| | | SET_PARENT_DEPT_INFO(state, deptId){ |
| | | getParentDeptInfo({deptId:deptId}).then(res=>{ |
| | | const data = res.data.data; |
| | | state.parentDeptInfo = data; |
| | | setStore({ name: 'parentDeptInfo', content: data }); |
| | | }) |
| | | }, |
| | | SET_TOKEN: (state, token) => { |
| | | setToken(token); |
| | | state.token = token; |
| | |
| | | state.userInfo = { user_name: 'unauth', role_name: 'unauth' }; |
| | | } else { |
| | | if (validatenull(userInfo.avatar)) { |
| | | userInfo.avatar = '/img/bg/img-logo.png'; |
| | | userInfo.avatar = defaultAva; |
| | | } |
| | | state.userInfo = userInfo; |
| | | } |