前端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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { store } from '@/store/index'
|
||||
|
||||
export const getDict = async (type) => {
|
||||
await store.dispatch("dictionary/getDictionary", type)
|
||||
return store.getters["dictionary/getDictionary"][type]
|
||||
}
|
||||
+2
-3
@@ -114,10 +114,9 @@ import {
|
||||
updateSysDictionary,
|
||||
findSysDictionary,
|
||||
getSysDictionaryList
|
||||
} from "@/api/sys_dictionary"; // 此处请自行替换地址
|
||||
} from "@/api/sysDictionary"; // 此处请自行替换地址
|
||||
import { formatTimeToStr } from "@/utils/data";
|
||||
import infoList from "@/components/mixins/infoList";
|
||||
|
||||
export default {
|
||||
name: "SysDictionary",
|
||||
mixins: [infoList],
|
||||
@@ -239,7 +238,7 @@ export default {
|
||||
this.dialogFormVisible = true;
|
||||
}
|
||||
},
|
||||
created() {
|
||||
async created() {
|
||||
this.getTableData();
|
||||
}
|
||||
};
|
||||
+1
-1
@@ -113,7 +113,7 @@ import {
|
||||
updateSysDictionaryDetail,
|
||||
findSysDictionaryDetail,
|
||||
getSysDictionaryDetailList
|
||||
} from "@/api/sys_dictionary_detail"; // 此处请自行替换地址
|
||||
} from "@/api/sysDictionaryDetail"; // 此处请自行替换地址
|
||||
import { formatTimeToStr } from "@/utils/data";
|
||||
import infoList from "@/components/mixins/infoList";
|
||||
|
||||
Reference in New Issue
Block a user