@@ -1,6 +1,8 @@ | |||
import { useUserStore } from '@/store/modules/user.js' | |||
import { usePermissionStore } from '@/store/modules/permission.js' | |||
import { NOT_FOUND_ROUTE, REDIRECT_ROUTE } from '@/router/routes' | |||
import { getQuestion } from '@/utils/question.js' | |||
import { getQuestionList } from '@/utils/dictionary.js' | |||
import { getToken } from '@/utils/token' | |||
const WHITE_LIST = ['/login', '/redirect'] | |||
@@ -15,7 +17,9 @@ export function createPermissionGuard(router) { | |||
} else { | |||
const hasUsers = !!Object.keys(userStore.userInfoMsg).length | |||
const hasRoutes = !!permissionStore.permissionRoutes.length | |||
const hasQuestions = getQuestion() | |||
if (!hasUsers) { await userStore.getUserInfo() } | |||
if (!hasQuestions) { await getQuestionList() } | |||
if (hasRoutes) { | |||
next() | |||
} else { |
@@ -1,7 +1,8 @@ | |||
import { defineStore } from 'pinia' | |||
import { userLogin, loginOut } from '@/api/login' | |||
import { getUser } from '@/api/login/index.js' | |||
import { setToken, removeToken } from '@/utils/token' | |||
import { setToken, removeToken } from '@/utils/token.js' | |||
import { removeQuestion } from '@/utils/question.js' | |||
import { useTagsMenuStore } from './tagsMenu.js' | |||
import { usePermissionStore } from './permission.js' | |||
@@ -48,7 +49,6 @@ export const useUserStore = defineStore('user', { | |||
try { | |||
const res = await loginOut() | |||
if (res.code === 0) { | |||
removeToken() | |||
this.reset() | |||
return Promise.resolve(res) | |||
} else { | |||
@@ -60,6 +60,8 @@ export const useUserStore = defineStore('user', { | |||
}, | |||
reset() { | |||
removeToken() | |||
removeQuestion() | |||
this.$reset() | |||
const tagsMenuStore = useTagsMenuStore() | |||
const permissionStore = usePermissionStore() |
@@ -1,9 +1,10 @@ | |||
import { getQuestionType } from '@/api/task/index.js' | |||
import { dataToSelect } from '@/utils/handleData.js' | |||
import { setQuestion } from './question.js' | |||
import { ref } from 'vue' | |||
export const QUESTION_TYPE = ref([]) | |||
export const QUESTION_TYPE_ALL = ref([]) | |||
export const QUESTION_TYPE_ALL = ref([{ label: '全部', value: 'all' }]) | |||
export const TASK_STATUS = [ | |||
{ label: '待飞行', value: 1 }, | |||
@@ -53,11 +54,12 @@ export const MENU_STATUS = [ | |||
{ label: '停用', value: 2 } | |||
] | |||
const getQuestionList = (async function() { | |||
export const getQuestionList = async function() { | |||
const res = await getQuestionType() | |||
if (res.code === 0) { | |||
const data = dataToSelect(res.data, { label: 'content', value: 'code' }) | |||
setQuestion(data) | |||
QUESTION_TYPE.value = data | |||
QUESTION_TYPE_ALL.value = [{ label: '全部', value: 'all' }].concat(data) | |||
} | |||
})() | |||
} |
@@ -1,5 +1,6 @@ | |||
import { router } from '@/router' | |||
import { getToken, removeToken } from '@/utils/token' | |||
import { getToken, removeToken } from '@/utils/token.js' | |||
import { removeQuestion } from '@/utils/question.js' | |||
import { isWithoutToken } from './help' | |||
export function setupInterceptor(service) { | |||
@@ -52,6 +53,7 @@ export function setupInterceptor(service) { | |||
case 401: | |||
// 未登录(可能是token过期或者无效了) | |||
removeToken() | |||
removeQuestion() | |||
router.replace({ | |||
path: '/login', | |||
query: { ...currentRoute.query, redirect: currentRoute.path } |
@@ -0,0 +1,21 @@ | |||
import { createLocalStorage } from './cache' | |||
const STORAGE_CODE = 'question_type' | |||
const DURATION = 24 * 60 * 60 | |||
export const lsQuestion = createLocalStorage() | |||
/* 获取Question */ | |||
export function getQuestion() { | |||
return lsQuestion.get(STORAGE_CODE) | |||
} | |||
/* 设置Question */ | |||
export function setQuestion(value) { | |||
lsQuestion.set(STORAGE_CODE, value, DURATION) | |||
} | |||
/* 移出Question */ | |||
export function removeQuestion() { | |||
lsQuestion.remove(STORAGE_CODE) | |||
} |