From 978b480e35d740ca84b7705c2c80b3900de88141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E5=AE=8F=E6=9D=B0?= <1943105267@qq.com> Date: Tue, 29 Aug 2023 08:59:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E5=85=B8=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/dict.js | 23 +++++++++++++++++++++++ src/utils/common.js | 19 ++++++++++++------- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/store/modules/dict.js b/src/store/modules/dict.js index 5d34fdc..6d9acbb 100644 --- a/src/store/modules/dict.js +++ b/src/store/modules/dict.js @@ -12,6 +12,7 @@ const dict = { state: { dictObject: {}, townList: [], + townList2: [], }, mutations: { SET_DICT: (state, dict) => { @@ -20,6 +21,9 @@ const dict = { SET_TOWN: (state, town) => { state.townList = town; }, + SET_TOWN2: (state, town) => { + state.townList2 = town; + }, }, actions: { getDictType({ commit }) { @@ -35,6 +39,10 @@ const dict = { commit("SET_TOWN", town); resolve(); }); + // getownList2().then((town) => { + // commit("SET_TOWN2", town); + // resolve(); + // }); }) .catch((error) => { reject(error); @@ -56,4 +64,19 @@ function getownList() { }); }); } +function getownList2() { + return new Promise((resolve, reject) => { + const lsit = []; + listTown({ pageNum: 1, pageSize: 200 }) + .then((res) => { + res.rows.forEach((item) => { + lsit.push({ value: item.id, label: item.name }); + }); + resolve(lsit); + }) + .catch((error) => { + reject(error); + }); + }); +} export default dict; diff --git a/src/utils/common.js b/src/utils/common.js index 9491d60..076d8d9 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -3,7 +3,13 @@ import store from "@/store"; export function filterDict(type, value, isTown = false) { if (!value) return; if (isTown) { - return filterTown(value); + let ids = JSON.parse(value); + if (Array.isArray(ids)) { + return filterTown(ids); + } else { + // return filterTowns(ids); + return filterTown([ids]); + } } else { const dict = store.getters.dictObject; const result = dict[type].filter((item) => item.dictValue == value); @@ -15,18 +21,17 @@ export function filterDict(type, value, isTown = false) { } } -// export function filterTown(id) { -// const townList = store.state.dict.townList -// const result = townList.filter((item) => item.value == id) +// export function filterTowns(id) { +// const townList = store.state.dict.townList2; +// const result = townList.filter((item) => item.value == id); // if (result.length > 0) { -// return result[0].label +// return result[0].label; // } else { -// return '未匹配到' +// return "未匹配到"; // } // } function filterTown(ids) { - ids = JSON.parse(ids); if (ids && Array.isArray(ids)) { let data = store.state.dict.townList; const targetIds = ids;