mirror of
https://gitee.com/fantastic-admin/basic.git
synced 2024-12-02 03:57:37 +08:00
fix: 修复主页无法引入请求 api 并使用的问题
This commit is contained in:
parent
fab8f2cfdb
commit
d6d7dadab7
@ -2,20 +2,8 @@ import axios from 'axios'
|
||||
|
||||
// import qs from 'qs'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import router from '@/router/index'
|
||||
import useUserStore from '@/store/modules/user'
|
||||
|
||||
function toLogin() {
|
||||
useUserStore().logout().then(() => {
|
||||
router.push({
|
||||
path: '/login',
|
||||
query: {
|
||||
redirect: router.currentRoute.value.path !== '/login' ? router.currentRoute.value.fullPath : undefined,
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: (import.meta.env.DEV && import.meta.env.VITE_OPEN_PROXY === 'true') ? '/proxy/' : import.meta.env.VITE_APP_API_BASEURL,
|
||||
timeout: 1000 * 60,
|
||||
@ -58,7 +46,7 @@ api.interceptors.response.use(
|
||||
}
|
||||
}
|
||||
else {
|
||||
toLogin()
|
||||
useUserStore().logout()
|
||||
}
|
||||
return Promise.resolve(response.data)
|
||||
},
|
||||
|
@ -28,11 +28,7 @@ function userCommand(command: 'home' | 'setting' | 'hotkeys' | 'logout') {
|
||||
eventBus.emit('global-hotkeys-intro-toggle')
|
||||
break
|
||||
case 'logout':
|
||||
userStore.logout().then(() => {
|
||||
router.push({
|
||||
name: 'login',
|
||||
})
|
||||
})
|
||||
userStore.logout()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import useRouteStore from './route'
|
||||
import useMenuStore from './menu'
|
||||
import router from '@/router'
|
||||
import apiUser from '@/api/modules/user'
|
||||
|
||||
const useUserStore = defineStore(
|
||||
@ -38,7 +39,7 @@ const useUserStore = defineStore(
|
||||
failure_time.value = res.data.failure_time
|
||||
}
|
||||
// 登出
|
||||
async function logout() {
|
||||
async function logout(redirect = router.currentRoute.value.fullPath) {
|
||||
localStorage.removeItem('account')
|
||||
localStorage.removeItem('token')
|
||||
localStorage.removeItem('failure_time')
|
||||
@ -47,6 +48,12 @@ const useUserStore = defineStore(
|
||||
failure_time.value = ''
|
||||
routeStore.removeRoutes()
|
||||
menuStore.setActived(0)
|
||||
router.push({
|
||||
name: 'login',
|
||||
query: {
|
||||
...(router.currentRoute.value.path !== '/' && router.currentRoute.value.name !== 'login' && { redirect }),
|
||||
},
|
||||
})
|
||||
}
|
||||
// 获取我的权限
|
||||
async function getPermissions() {
|
||||
|
@ -52,14 +52,7 @@ function onSubmit() {
|
||||
type: 'success',
|
||||
message: '模拟修改成功,请重新登录',
|
||||
})
|
||||
userStore.logout().then(() => {
|
||||
router.push({
|
||||
name: 'login',
|
||||
query: {
|
||||
redirect: route.fullPath,
|
||||
},
|
||||
})
|
||||
})
|
||||
userStore.logout()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user