diff --git a/App.vue b/App.vue index e080a22..3c19485 100644 --- a/App.vue +++ b/App.vue @@ -14,7 +14,7 @@ }, onLaunch: function() { this.$store.dispatch(USERKEY.GETUSERINFO) - this.$store.dispatch(COMMONKEY.GETDIST) + this.$store.dispatch(COMMONKEY.GETDIC) // #ifdef H5 console.log( diff --git a/store/actionKey.js b/store/actionKey.js index 5fb575d..603cbcd 100644 --- a/store/actionKey.js +++ b/store/actionKey.js @@ -6,5 +6,5 @@ export const USERKEY = { export const COMMONKEY = { - GETDIST: 'GETDIST' + GETDIC: 'GETDIC' } \ No newline at end of file diff --git a/store/index.js b/store/index.js index 44cf76e..bc4163f 100644 --- a/store/index.js +++ b/store/index.js @@ -78,7 +78,10 @@ const store = createStore({ getters: { userInfo: (state)=> { return state.user?.info || {} - } + }, + dicData: (state)=> { + return state.common?.dicData || {} + }, }, actions: { // lazy loading openid diff --git a/store/modules/common.js b/store/modules/common.js index 017ed94..36b9b25 100644 --- a/store/modules/common.js +++ b/store/modules/common.js @@ -10,10 +10,10 @@ import { goto } from "@/common/untool" export default { state: { - dicData: [] + dicData: {} }, mutations: { - [COMMONKEY.GETDIST](state, provider) { + [COMMONKEY.GETDIC](state, provider) { state.dicData = provider }, @@ -31,8 +31,22 @@ export default { rootState }, options) { 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) }, - } } \ No newline at end of file