added ESlint 语法检测
This commit is contained in:
+12
-14
@@ -2,22 +2,20 @@ import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import VuexPersistence from 'vuex-persist'
|
||||
|
||||
import { user } from "@/store/module/user"
|
||||
import { router } from "@/store/module/router"
|
||||
import { dictionary } from "@/store/module/dictionary"
|
||||
import { user } from '@/store/module/user'
|
||||
import { router } from '@/store/module/router'
|
||||
import { dictionary } from '@/store/module/dictionary'
|
||||
Vue.use(Vuex)
|
||||
|
||||
|
||||
|
||||
const vuexLocal = new VuexPersistence({
|
||||
storage: window.localStorage,
|
||||
modules: ['user']
|
||||
storage: window.localStorage,
|
||||
modules: ['user']
|
||||
})
|
||||
export const store = new Vuex.Store({
|
||||
modules: {
|
||||
user,
|
||||
router,
|
||||
dictionary
|
||||
},
|
||||
plugins: [vuexLocal.plugin]
|
||||
})
|
||||
modules: {
|
||||
user,
|
||||
router,
|
||||
dictionary
|
||||
},
|
||||
plugins: [vuexLocal.plugin]
|
||||
})
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
import { findSysDictionary } from '@/api/sysDictionary'
|
||||
|
||||
export const dictionary = {
|
||||
namespaced: true,
|
||||
state: {
|
||||
dictionaryMap: {},
|
||||
},
|
||||
mutations: {
|
||||
setDictionaryMap(state, dictionaryMap) {
|
||||
state.dictionaryMap = { ...state.dictionaryMap, ...dictionaryMap }
|
||||
},
|
||||
|
||||
},
|
||||
actions: {
|
||||
// 从后台获取动态路由
|
||||
async getDictionary({ commit, state }, type) {
|
||||
if (state.dictionaryMap[type]) {
|
||||
return state.dictionaryMap[type]
|
||||
} else {
|
||||
const res = await findSysDictionary({ type })
|
||||
if (res.code == 0) {
|
||||
const dictionaryMap = {}
|
||||
const dict = []
|
||||
res.data.resysDictionary.sysDictionaryDetails && res.data.resysDictionary.sysDictionaryDetails.map(item => {
|
||||
dict.push({
|
||||
label: item.label,
|
||||
value: item.value
|
||||
})
|
||||
})
|
||||
dictionaryMap[res.data.resysDictionary.type] = dict
|
||||
commit("setDictionaryMap", dictionaryMap)
|
||||
return state.dictionaryMap[type]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
getters:{
|
||||
getDictionary(state){
|
||||
return state.dictionaryMap
|
||||
}
|
||||
namespaced: true,
|
||||
state: {
|
||||
dictionaryMap: {}
|
||||
},
|
||||
mutations: {
|
||||
setDictionaryMap(state, dictionaryMap) {
|
||||
state.dictionaryMap = { ...state.dictionaryMap, ...dictionaryMap }
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
actions: {
|
||||
// 从后台获取动态路由
|
||||
async getDictionary({ commit, state }, type) {
|
||||
if (state.dictionaryMap[type]) {
|
||||
return state.dictionaryMap[type]
|
||||
} else {
|
||||
const res = await findSysDictionary({ type })
|
||||
if (res.code === 0) {
|
||||
const dictionaryMap = {}
|
||||
const dict = []
|
||||
res.data.resysDictionary.sysDictionaryDetails && res.data.resysDictionary.sysDictionaryDetails.map(item => {
|
||||
dict.push({
|
||||
label: item.label,
|
||||
value: item.value
|
||||
})
|
||||
})
|
||||
dictionaryMap[res.data.resysDictionary.type] = dict
|
||||
commit('setDictionaryMap', dictionaryMap)
|
||||
return state.dictionaryMap[type]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
getDictionary(state) {
|
||||
return state.dictionaryMap
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +1,82 @@
|
||||
import { asyncRouterHandle } from '@/utils/asyncRouter';
|
||||
import { asyncRouterHandle } from '@/utils/asyncRouter'
|
||||
|
||||
import { asyncMenu } from '@/api/menu'
|
||||
|
||||
const routerList = []
|
||||
const formatRouter = (routes) => {
|
||||
routes && routes.map(item => {
|
||||
if ((!item.children || item.children.every(ch => ch.hidden)) && item.name != '404') {
|
||||
routerList.push({ label: item.meta.title, value: item.name })
|
||||
}
|
||||
if (item.children && item.children.length > 0) {
|
||||
formatRouter(item.children)
|
||||
}
|
||||
})
|
||||
routes && routes.map(item => {
|
||||
if ((!item.children || item.children.every(ch => ch.hidden)) && item.name !== '404') {
|
||||
routerList.push({ label: item.meta.title, value: item.name })
|
||||
}
|
||||
if (item.children && item.children.length > 0) {
|
||||
formatRouter(item.children)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const router = {
|
||||
namespaced: true,
|
||||
state: {
|
||||
asyncRouters: [],
|
||||
routerList: routerList,
|
||||
namespaced: true,
|
||||
state: {
|
||||
asyncRouters: [],
|
||||
routerList: routerList
|
||||
},
|
||||
mutations: {
|
||||
setRouterList(state, routerList) {
|
||||
state.routerList = routerList
|
||||
},
|
||||
mutations: {
|
||||
setRouterList(state, routerList) {
|
||||
state.routerList = routerList
|
||||
},
|
||||
// 设置动态路由
|
||||
setAsyncRouter(state, asyncRouters) {
|
||||
state.asyncRouters = asyncRouters
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
// 从后台获取动态路由
|
||||
async SetAsyncRouter({ commit }) {
|
||||
const baseRouter = [{
|
||||
path: '/layout',
|
||||
name: 'layout',
|
||||
component: "view/layout/index.vue",
|
||||
meta: {
|
||||
title: "底层layout"
|
||||
},
|
||||
children: []
|
||||
}]
|
||||
const asyncRouterRes = await asyncMenu()
|
||||
if(asyncRouterRes.code !=0){
|
||||
return
|
||||
}
|
||||
const asyncRouter = asyncRouterRes.data&&asyncRouterRes.data.menus
|
||||
asyncRouter.push({
|
||||
path: "404",
|
||||
name: "404",
|
||||
hidden: true,
|
||||
meta: {
|
||||
title: "迷路了*。*",
|
||||
},
|
||||
component: 'view/error/index.vue'
|
||||
})
|
||||
formatRouter(asyncRouter)
|
||||
baseRouter[0].children = asyncRouter
|
||||
baseRouter.push({
|
||||
path: '*',
|
||||
redirect: '/layout/404'
|
||||
|
||||
})
|
||||
asyncRouterHandle(baseRouter)
|
||||
commit('setAsyncRouter', baseRouter)
|
||||
commit('setRouterList', routerList)
|
||||
return true
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
// 获取动态路由
|
||||
asyncRouters(state) {
|
||||
return state.asyncRouters
|
||||
},
|
||||
routerList(state) {
|
||||
return state.routerList
|
||||
},
|
||||
defaultRouter(state) {
|
||||
return state.defaultRouter
|
||||
}
|
||||
// 设置动态路由
|
||||
setAsyncRouter(state, asyncRouters) {
|
||||
state.asyncRouters = asyncRouters
|
||||
}
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
// 从后台获取动态路由
|
||||
async SetAsyncRouter({ commit }) {
|
||||
const baseRouter = [{
|
||||
path: '/layout',
|
||||
name: 'layout',
|
||||
component: 'view/layout/index.vue',
|
||||
meta: {
|
||||
title: '底层layout'
|
||||
},
|
||||
children: []
|
||||
}]
|
||||
const asyncRouterRes = await asyncMenu()
|
||||
if (asyncRouterRes.code !== 0) {
|
||||
return
|
||||
}
|
||||
const asyncRouter = asyncRouterRes.data && asyncRouterRes.data.menus
|
||||
asyncRouter.push({
|
||||
path: '404',
|
||||
name: '404',
|
||||
hidden: true,
|
||||
meta: {
|
||||
title: '迷路了*。*'
|
||||
},
|
||||
component: 'view/error/index.vue'
|
||||
})
|
||||
formatRouter(asyncRouter)
|
||||
baseRouter[0].children = asyncRouter
|
||||
baseRouter.push({
|
||||
path: '*',
|
||||
redirect: '/layout/404'
|
||||
})
|
||||
asyncRouterHandle(baseRouter)
|
||||
commit('setAsyncRouter', baseRouter)
|
||||
commit('setRouterList', routerList)
|
||||
return true
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
// 获取动态路由
|
||||
asyncRouters(state) {
|
||||
return state.asyncRouters
|
||||
},
|
||||
routerList(state) {
|
||||
return state.routerList
|
||||
},
|
||||
defaultRouter(state) {
|
||||
return state.defaultRouter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,78 +2,77 @@ import { login } from '@/api/user'
|
||||
import { jsonInBlacklist } from '@/api/jwt'
|
||||
import router from '@/router/index'
|
||||
export const user = {
|
||||
namespaced: true,
|
||||
state: {
|
||||
userInfo: {
|
||||
uuid: "",
|
||||
nickName: "",
|
||||
headerImg: "",
|
||||
authority: "",
|
||||
},
|
||||
token: "",
|
||||
namespaced: true,
|
||||
state: {
|
||||
userInfo: {
|
||||
uuid: '',
|
||||
nickName: '',
|
||||
headerImg: '',
|
||||
authority: ''
|
||||
},
|
||||
mutations: {
|
||||
setUserInfo(state, userInfo) {
|
||||
// 这里的 `state` 对象是模块的局部状态
|
||||
state.userInfo = userInfo
|
||||
},
|
||||
setToken(state, token) {
|
||||
// 这里的 `state` 对象是模块的局部状态
|
||||
state.token = token
|
||||
},
|
||||
NeedInit(state){
|
||||
state.userInfo = {}
|
||||
state.token = ""
|
||||
sessionStorage.clear()
|
||||
router.push({ name: 'init', replace: true })
|
||||
|
||||
},
|
||||
LoginOut(state) {
|
||||
state.userInfo = {}
|
||||
state.token = ""
|
||||
sessionStorage.clear()
|
||||
router.push({ name: 'login', replace: true })
|
||||
window.location.reload()
|
||||
},
|
||||
ResetUserInfo(state, userInfo = {}) {
|
||||
state.userInfo = {...state.userInfo,
|
||||
...userInfo
|
||||
}
|
||||
}
|
||||
token: ''
|
||||
},
|
||||
mutations: {
|
||||
setUserInfo(state, userInfo) {
|
||||
// 这里的 `state` 对象是模块的局部状态
|
||||
state.userInfo = userInfo
|
||||
},
|
||||
actions: {
|
||||
async LoginIn({ commit, dispatch, rootGetters, getters }, loginInfo) {
|
||||
const res = await login(loginInfo)
|
||||
if (res.code == 0) {
|
||||
commit('setUserInfo', res.data.user)
|
||||
commit('setToken', res.data.token)
|
||||
await dispatch('router/SetAsyncRouter', {}, { root: true })
|
||||
const asyncRouters = rootGetters['router/asyncRouters']
|
||||
router.addRoutes(asyncRouters)
|
||||
// const redirect = router.history.current.query.redirect
|
||||
// console.log(redirect)
|
||||
// if (redirect) {
|
||||
// router.push({ path: redirect })
|
||||
// } else {
|
||||
router.push({ name: getters["userInfo"].authority.defaultRouter })
|
||||
// }
|
||||
return true
|
||||
}
|
||||
},
|
||||
async LoginOut({ commit }) {
|
||||
const res = await jsonInBlacklist()
|
||||
if (res.code == 0) {
|
||||
commit("LoginOut")
|
||||
}
|
||||
}
|
||||
setToken(state, token) {
|
||||
// 这里的 `state` 对象是模块的局部状态
|
||||
state.token = token
|
||||
},
|
||||
getters: {
|
||||
userInfo(state) {
|
||||
return state.userInfo
|
||||
},
|
||||
token(state) {
|
||||
return state.token
|
||||
},
|
||||
|
||||
NeedInit(state) {
|
||||
state.userInfo = {}
|
||||
state.token = ''
|
||||
sessionStorage.clear()
|
||||
router.push({ name: 'Init', replace: true })
|
||||
},
|
||||
LoginOut(state) {
|
||||
state.userInfo = {}
|
||||
state.token = ''
|
||||
sessionStorage.clear()
|
||||
router.push({ name: 'Login', replace: true })
|
||||
window.location.reload()
|
||||
},
|
||||
ResetUserInfo(state, userInfo = {}) {
|
||||
state.userInfo = { ...state.userInfo,
|
||||
...userInfo
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async LoginIn({ commit, dispatch, rootGetters, getters }, loginInfo) {
|
||||
const res = await login(loginInfo)
|
||||
if (res.code === 0) {
|
||||
commit('setUserInfo', res.data.user)
|
||||
commit('setToken', res.data.token)
|
||||
await dispatch('router/SetAsyncRouter', {}, { root: true })
|
||||
const asyncRouters = rootGetters['router/asyncRouters']
|
||||
router.addRoutes(asyncRouters)
|
||||
// const redirect = router.history.current.query.redirect
|
||||
// console.log(redirect)
|
||||
// if (redirect) {
|
||||
// router.push({ path: redirect })
|
||||
// } else {
|
||||
router.push({ name: getters['userInfo'].authority.defaultRouter })
|
||||
// }
|
||||
return true
|
||||
}
|
||||
},
|
||||
async LoginOut({ commit }) {
|
||||
const res = await jsonInBlacklist()
|
||||
if (res.code === 0) {
|
||||
commit('LoginOut')
|
||||
}
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
userInfo(state) {
|
||||
return state.userInfo
|
||||
},
|
||||
token(state) {
|
||||
return state.token
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user