前端utils中封装了前端获取字典并缓存到内存的方法getDict
This commit is contained in:
@@ -4,7 +4,7 @@ import VuexPersistence from 'vuex-persist'
|
||||
|
||||
import { user } from "@/store/module/user"
|
||||
import { router } from "@/store/module/router"
|
||||
|
||||
import { dictionary } from "@/store/module/dictionary"
|
||||
Vue.use(Vuex)
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@ const vuexLocal = new VuexPersistence({
|
||||
export const store = new Vuex.Store({
|
||||
modules: {
|
||||
user,
|
||||
router
|
||||
router,
|
||||
dictionary
|
||||
},
|
||||
plugins: [vuexLocal.plugin]
|
||||
})
|
||||
@@ -0,0 +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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user