Browse Source

feat: 通过模型内容实现特殊业态

ShangHai_LongXiang
jiannibang 3 years ago
parent
commit
011f7dac2b
  1. 13
      src/composables/useInitConfigAndMallInfo.js
  2. 2
      src/http/api.js
  3. 3
      src/store/root/actions.js
  4. 3
      src/store/root/state.js
  5. 4
      src/views/Foods/Foods.vue
  6. 6
      src/views/Index/Index.vue

13
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] })) })
}

2
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`)

3
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
}
}

3
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 = () => {

4
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
})

6
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}品牌` : ''}`
})

Loading…
Cancel
Save