Browse Source

change question type

tags/v1.0.0^2
zhangtao 2 years ago
parent
commit
4b3e824492
5 changed files with 37 additions and 6 deletions
  1. +4
    -0
      src/router/guard/permission-guard.js
  2. +4
    -2
      src/store/modules/user.js
  3. +5
    -3
      src/utils/dictionary.js
  4. +3
    -1
      src/utils/http/interceptors.js
  5. +21
    -0
      src/utils/question.js

+ 4
- 0
src/router/guard/permission-guard.js View File

import { useUserStore } from '@/store/modules/user.js' import { useUserStore } from '@/store/modules/user.js'
import { usePermissionStore } from '@/store/modules/permission.js' import { usePermissionStore } from '@/store/modules/permission.js'
import { NOT_FOUND_ROUTE, REDIRECT_ROUTE } from '@/router/routes' 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' import { getToken } from '@/utils/token'


const WHITE_LIST = ['/login', '/redirect'] const WHITE_LIST = ['/login', '/redirect']
} else { } else {
const hasUsers = !!Object.keys(userStore.userInfoMsg).length const hasUsers = !!Object.keys(userStore.userInfoMsg).length
const hasRoutes = !!permissionStore.permissionRoutes.length const hasRoutes = !!permissionStore.permissionRoutes.length
const hasQuestions = getQuestion()
if (!hasUsers) { await userStore.getUserInfo() } if (!hasUsers) { await userStore.getUserInfo() }
if (!hasQuestions) { await getQuestionList() }
if (hasRoutes) { if (hasRoutes) {
next() next()
} else { } else {

+ 4
- 2
src/store/modules/user.js View File

import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { userLogin, loginOut } from '@/api/login' import { userLogin, loginOut } from '@/api/login'
import { getUser } from '@/api/login/index.js' 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 { useTagsMenuStore } from './tagsMenu.js'
import { usePermissionStore } from './permission.js' import { usePermissionStore } from './permission.js'
try { try {
const res = await loginOut() const res = await loginOut()
if (res.code === 0) { if (res.code === 0) {
removeToken()
this.reset() this.reset()
return Promise.resolve(res) return Promise.resolve(res)
} else { } else {
}, },


reset() { reset() {
removeToken()
removeQuestion()
this.$reset() this.$reset()
const tagsMenuStore = useTagsMenuStore() const tagsMenuStore = useTagsMenuStore()
const permissionStore = usePermissionStore() const permissionStore = usePermissionStore()

+ 5
- 3
src/utils/dictionary.js View File

import { getQuestionType } from '@/api/task/index.js' import { getQuestionType } from '@/api/task/index.js'
import { dataToSelect } from '@/utils/handleData.js' import { dataToSelect } from '@/utils/handleData.js'
import { setQuestion } from './question.js'
import { ref } from 'vue' import { ref } from 'vue'


export const QUESTION_TYPE = ref([]) export const QUESTION_TYPE = ref([])
export const QUESTION_TYPE_ALL = ref([])
export const QUESTION_TYPE_ALL = ref([{ label: '全部', value: 'all' }])


export const TASK_STATUS = [ export const TASK_STATUS = [
{ label: '待飞行', value: 1 }, { label: '待飞行', value: 1 },
{ label: '停用', value: 2 } { label: '停用', value: 2 }
] ]


const getQuestionList = (async function() {
export const getQuestionList = async function() {
const res = await getQuestionType() const res = await getQuestionType()
if (res.code === 0) { if (res.code === 0) {
const data = dataToSelect(res.data, { label: 'content', value: 'code' }) const data = dataToSelect(res.data, { label: 'content', value: 'code' })
setQuestion(data)
QUESTION_TYPE.value = data QUESTION_TYPE.value = data
QUESTION_TYPE_ALL.value = [{ label: '全部', value: 'all' }].concat(data) QUESTION_TYPE_ALL.value = [{ label: '全部', value: 'all' }].concat(data)
} }
})()
}

+ 3
- 1
src/utils/http/interceptors.js View File

import { router } from '@/router' 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' import { isWithoutToken } from './help'


export function setupInterceptor(service) { export function setupInterceptor(service) {
case 401: case 401:
// 未登录(可能是token过期或者无效了) // 未登录(可能是token过期或者无效了)
removeToken() removeToken()
removeQuestion()
router.replace({ router.replace({
path: '/login', path: '/login',
query: { ...currentRoute.query, redirect: currentRoute.path } query: { ...currentRoute.query, redirect: currentRoute.path }

+ 21
- 0
src/utils/question.js View File

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)
}

Loading…
Cancel
Save