From 409f005d0b854d27a9995b3f5b8019cf3ac9e633 Mon Sep 17 00:00:00 2001 From: jiannibang <271381693@qq.com> Date: Fri, 3 Feb 2023 14:26:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=89=80=E6=9C=89=E5=93=81=E7=89=8C?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=8E=A8=E8=8D=90=E5=93=81=E7=89=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/BrandScroll/BrandScroll.vue | 18 ++++++++---------- src/views/Brand/Brand.vue | 6 +++--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/components/BrandScroll/BrandScroll.vue b/src/components/BrandScroll/BrandScroll.vue index f2eca06..ee4c925 100644 --- a/src/components/BrandScroll/BrandScroll.vue +++ b/src/components/BrandScroll/BrandScroll.vue @@ -43,7 +43,7 @@ import ShopItem from '@/base/ShopItem/ShopItem.vue' import ScrollView from '@/base/ScrollView/ScrollView.vue' import { storeToRefs } from 'pinia' import { useStore } from '@/store/root' -import { useElementSize, useMutationObserver } from '@vueuse/core' +import { useElementSize, useMutationObserver, useThrottleFn } from '@vueuse/core' import { getTranslateValues } from './getTranslateValues' const store = useStore() @@ -75,15 +75,13 @@ const indicatorIndex = computed(() => return start > bounds.value[i - 1] && start <= el }) ) -useMutationObserver( - content, - ([{ attributeName, target }]) => { - if (attributeName === 'style') y.value = getTranslateValues(target).y - }, - { - attributes: true - } -) +const throttledFn = useThrottleFn(([{ attributeName, target }]) => { + if (attributeName === 'style') y.value = getTranslateValues(target).y +}, 500) + +useMutationObserver(content, throttledFn, { + attributes: true +}) const props = defineProps({ list: Array, config: Object, diff --git a/src/views/Brand/Brand.vue b/src/views/Brand/Brand.vue index fb0c80c..9950427 100644 --- a/src/views/Brand/Brand.vue +++ b/src/views/Brand/Brand.vue @@ -13,14 +13,14 @@ import View from '@/layouts/View.vue' import BrandScroll from '@/components/BrandScroll/BrandScroll.vue' const store = useStore() -const { config, shopList } = storeToRefs(store) +const { config, shopList, indexList } = storeToRefs(store) const shop = ref(null) const selectedList = ref([]) Promise.all([getBrandListByFloor()]).then(([_brandList]) => { + const recMap = indexList.value.recommendList.reduce((acc, { shopId }) => ({ ...acc, [shopId]: true }), {}) const list = _brandList.data.list - - selectedList.value = list + selectedList.value = list.map(({ name, shopList }) => ({ name, shopList: shopList.filter(({ shopId }) => recMap[shopId]) })) }) function handleShop(item) {