From e228cf5d80ff6933bdde5e741f7a33edbee49cd0 Mon Sep 17 00:00:00 2001 From: aihe <961836564@qq.com> Date: Wed, 24 Apr 2024 16:59:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=AD=97=E5=85=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 2 +- store/actionKey.js | 2 +- store/index.js | 5 ++++- store/modules/common.js | 22 ++++++++++++++++++---- 4 files changed, 24 insertions(+), 7 deletions(-) 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