From 011f7dac2bdf720f6024d6955de2e5a300a43588 Mon Sep 17 00:00:00 2001 From: jiannibang <271381693@qq.com> Date: Fri, 2 Jun 2023 14:45:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=9A=E8=BF=87=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E5=AE=9E=E7=8E=B0=E7=89=B9=E6=AE=8A=E4=B8=9A?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/composables/useInitConfigAndMallInfo.js | 13 +++++++++++-- src/http/api.js | 2 ++ src/store/root/actions.js | 3 +++ src/store/root/state.js | 3 ++- src/views/Foods/Foods.vue | 4 ++-- src/views/Index/Index.vue | 6 +++--- 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/composables/useInitConfigAndMallInfo.js b/src/composables/useInitConfigAndMallInfo.js index 91ff074..5a00e71 100644 --- a/src/composables/useInitConfigAndMallInfo.js +++ b/src/composables/useInitConfigAndMallInfo.js @@ -1,4 +1,4 @@ -import { getConfig, getCurrentFloor, getGuideList, getTheme, getQMGoShopData, getMenuList } from '@/http/api' +import { getConfig, getCurrentFloor, getGuideList, getTheme, getQMGoShopData, getMenuList, getFoodIIndustryList } from '@/http/api' import { useStore } from '@/store/root' import VConsole from 'vconsole' @@ -22,6 +22,14 @@ export const useInitConfigAndMallInfo = async () => { const { data: menuList } = await getMenuList() store.SET_MENU_LIST(menuList) } + + try { + const { data: foodIndustryList } = await getFoodIIndustryList() + store.SET_FOOD_INDUSTRY_MAP(foodIndustryList.reduce((acc, nxt) => ({ ...acc, [nxt.content.industryCode]: true }), {})) + } catch (error) { + console.log(error) + } + store.SET_CONFIG(_config.data) const _currentFloor = await getCurrentFloor() @@ -34,5 +42,6 @@ export const useInitConfigAndMallInfo = async () => { const { data: { searchList, recommendList } } = await getQMGoShopData() - store.SET_INDEX_LIST({ recommendList, hotSearch: searchList }) + const shopMap = shopList.reduce((acc, nxt) => ({ ...acc, [nxt.shopCode]: nxt }), {}) + store.SET_INDEX_LIST({ recommendList, hotSearch: searchList.map(item => ({ ...item, ...shopMap[item.shopCode] })) }) } diff --git a/src/http/api.js b/src/http/api.js index a3b46a8..56974b0 100644 --- a/src/http/api.js +++ b/src/http/api.js @@ -47,3 +47,5 @@ export const getQMGoShopData = () => get(`./static/offline/JSON/getQMGoShopData. export const getAD = () => get(`./static/offline/JSON/ad.json`) export const getMenuList = () => get(`./static/offline/JSON/menuList.json`) + +export const getFoodIIndustryList = () => get(`./static/offline/JSON/foodIIndustryList.json`) diff --git a/src/store/root/actions.js b/src/store/root/actions.js index 6f917f6..8f7589d 100644 --- a/src/store/root/actions.js +++ b/src/store/root/actions.js @@ -50,5 +50,8 @@ export const actions = { }, SET_THEME(data) { this.theme = data + }, + SET_FOOD_INDUSTRY_MAP(data) { + this.foodIndustryMap = data } } diff --git a/src/store/root/state.js b/src/store/root/state.js index c939203..58afa3a 100644 --- a/src/store/root/state.js +++ b/src/store/root/state.js @@ -15,7 +15,8 @@ export const state = () => ({ isUseSpeech: 1, //是否使用语音 0:不使用 1: 使用 mapData: null, theme: null, - facility: null + facility: null, + foodIndustryMap: {} }) export const is4k = () => { diff --git a/src/views/Foods/Foods.vue b/src/views/Foods/Foods.vue index a2e3918..a261f6c 100644 --- a/src/views/Foods/Foods.vue +++ b/src/views/Foods/Foods.vue @@ -14,7 +14,7 @@ import BrandScroll from '@/components/BrandScroll/BrandScroll.vue' const store = useStore() const storeRefs = storeToRefs(store) -const { config, shopList } = storeRefs +const { config, shopList, foodIndustryMap } = storeRefs const shop = ref(null) const selectedList = ref([]) @@ -22,7 +22,7 @@ Promise.all([getBrandListByFloor()]).then(([_brandList]) => { if (storeRefs.shop.value) shop.value = storeRefs.shop.value const list = _brandList.data.list.map(item => ({ name: item.name, - shopList: item.shopList.filter(_ => _.isSpecial) + shopList: item.shopList.filter(({ industryFatherCode }) => foodIndustryMap.value[industryFatherCode]) })) selectedList.value = list }) diff --git a/src/views/Index/Index.vue b/src/views/Index/Index.vue index 0cf3aca..db3b18a 100644 --- a/src/views/Index/Index.vue +++ b/src/views/Index/Index.vue @@ -156,10 +156,10 @@ const splitBy = (array, chunkSize = 4) => { const router = useRouter() const store = useStore() -const { indexList, currentFloor, buildingList, shopList, menuList, config, theme } = storeToRefs(store) +const { indexList, currentFloor, buildingList, shopList, menuList, config, theme, foodIndustryMap } = storeToRefs(store) const guideDesc = ref('') const foodList = computed(() => { - const arr = shopList.value.filter(({ isSpecial }) => isSpecial) + const arr = shopList.value.filter(({ industryFatherCode }) => foodIndustryMap.value[industryFatherCode]) if (arr.length > 12) { while (arr.length % 4 !== 0) { arr.push(arr[Math.floor(Math.random() * arr.length)]) @@ -184,7 +184,7 @@ const { currentHour } = useTime() const showFood = computed(() => (currentHour.value >= 11 && currentHour.value < 13) || (currentHour.value >= 17 && currentHour.value < 20)) getBrandList().then(({ data: { allShopNum, industryFatherList } }) => { - const spFormat = industryFatherList.find(({ isSpecial }) => isSpecial) + const spFormat = industryFatherList.find(({ industryCode }) => foodIndustryMap.value[industryCode]) guideDesc.value = `全场${allShopNum}个品牌${spFormat ? `,其中${spFormat.shopNum}个${spFormat.industryName}品牌` : ''}` })