缓存字典

This commit is contained in:
aihe 2024-04-24 16:59:00 +08:00
parent 5afaa5b472
commit e228cf5d80
4 changed files with 24 additions and 7 deletions

View File

@ -14,7 +14,7 @@
}, },
onLaunch: function() { onLaunch: function() {
this.$store.dispatch(USERKEY.GETUSERINFO) this.$store.dispatch(USERKEY.GETUSERINFO)
this.$store.dispatch(COMMONKEY.GETDIST) this.$store.dispatch(COMMONKEY.GETDIC)
// #ifdef H5 // #ifdef H5
console.log( console.log(

View File

@ -6,5 +6,5 @@ export const USERKEY = {
export const COMMONKEY = { export const COMMONKEY = {
GETDIST: 'GETDIST' GETDIC: 'GETDIC'
} }

View File

@ -78,7 +78,10 @@ const store = createStore({
getters: { getters: {
userInfo: (state)=> { userInfo: (state)=> {
return state.user?.info || {} return state.user?.info || {}
} },
dicData: (state)=> {
return state.common?.dicData || {}
},
}, },
actions: { actions: {
// lazy loading openid // lazy loading openid

View File

@ -10,10 +10,10 @@ import { goto } from "@/common/untool"
export default { export default {
state: { state: {
dicData: [] dicData: {}
}, },
mutations: { mutations: {
[COMMONKEY.GETDIST](state, provider) { [COMMONKEY.GETDIC](state, provider) {
state.dicData = provider state.dicData = provider
}, },
@ -31,8 +31,22 @@ export default {
rootState rootState
}, options) { }, options) {
const resInfo = await getDicDataJson() const resInfo = await getDicDataJson()
commit(COMMONKEY.GETDIST, resInfo.data) let data = {}
// 转换接口返回的数据字典
resInfo?.data?.map?.((item)=> {
let key = Object.keys(item).filter(i=> i != 'desc')[0]
if(key) {
item[key]?.map?.(tmp=> {
tmp.title = tmp.label
tmp.val = tmp.value
})
data[key] = {
desc: item.desc || '',
list: item[key] || []
}
}
})
commit(COMMONKEY.GETDIC, data)
}, },
} }
} }