chore: 忽略 tools/ 目录并从版本库移除历史脚本
@@ -9,6 +9,8 @@ export const homeApi = {
|
||||
banners: () => get('/home/banners', {}, { silent: true }),
|
||||
/** 分类导航 */
|
||||
categories: () => get('/home/categories', {}, { silent: true }),
|
||||
/** 首页金刚区推荐二级分类 */
|
||||
navCategories: () => get('/home/nav-categories', {}, { silent: true }),
|
||||
/**
|
||||
* 信息流(LBS + 筛选排序)
|
||||
* 入参:{ page, size, categoryId, subCategoryId, keyword, areaId, area, sort, lat, lng }
|
||||
|
||||
@@ -53,8 +53,8 @@
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
|
||||
<!-- 分类导航:8宫格微质感骨架屏(高度精确预留,零 CLS) / 真实金刚区 -->
|
||||
<view v-if="loading && !categories.length" class="fc-card home__cats">
|
||||
<!-- 分类导航:8宫格微质感骨架屏(高度精确预留,零 CLS) / 真实金刚区精选二级品类 -->
|
||||
<view v-if="loading && !displayNavCategories.length" class="fc-card home__cats">
|
||||
<view class="home__cats-head">
|
||||
<view class="fc-skeleton" style="width: 130rpx; height: 34rpx; border-radius: 8rpx;"></view>
|
||||
<view class="fc-skeleton" style="width: 90rpx; height: 26rpx; border-radius: 8rpx;"></view>
|
||||
@@ -68,13 +68,13 @@
|
||||
</view>
|
||||
<view v-else class="fc-card home__cats">
|
||||
<view class="home__cats-head">
|
||||
<text class="home__cats-title">同城分类</text>
|
||||
<text class="home__cats-title">热门品类</text>
|
||||
<text class="home__cats-more" @click="goCategoryTab">全部分类 ›</text>
|
||||
</view>
|
||||
<view class="home__cats-grid">
|
||||
<view v-for="c in categories" :key="c.id" class="home__cat" @click="goCategory(c)">
|
||||
<view v-for="c in displayNavCategories" :key="c.id || c.name" class="home__cat" @click="goCategory(c)">
|
||||
<view class="home__cat-icon">
|
||||
<image class="home__cat-badge" :src="catIcon(c)" mode="aspectFit" />
|
||||
<image class="home__cat-badge" :src="catIcon(c)" mode="aspectFill" />
|
||||
</view>
|
||||
<text class="home__cat-name">{{ c.name }}</text>
|
||||
</view>
|
||||
@@ -219,6 +219,7 @@ import { getNavMetrics } from '@/common/utils/navbar.js'
|
||||
// 本地离线快照缓存 Key(Stale-While-Revalidate,实现首屏 0ms 秒开)
|
||||
const STORAGE_KEY_BANNERS = 'fc_cache_home_banners_v2'
|
||||
const STORAGE_KEY_CATEGORIES = 'fc_cache_home_categories'
|
||||
const STORAGE_KEY_NAV_CATEGORIES = 'fc_cache_home_nav_cats_v2'
|
||||
const STORAGE_KEY_AREAS = 'fc_cache_home_areas'
|
||||
const STORAGE_KEY_SELECTED_AREA = 'fc_user_selected_area'
|
||||
|
||||
@@ -253,6 +254,7 @@ export default {
|
||||
// 优先从本地缓存提取首屏数据,达到即开即显零白屏体验
|
||||
const cachedBanners = safeGetStorage(STORAGE_KEY_BANNERS, [])
|
||||
const cachedCats = safeGetStorage(STORAGE_KEY_CATEGORIES, [])
|
||||
const cachedNavCats = safeGetStorage(STORAGE_KEY_NAV_CATEGORIES, [])
|
||||
const cachedAreas = safeGetStorage(STORAGE_KEY_AREAS, [])
|
||||
const savedUserArea = safeGetStorage(STORAGE_KEY_SELECTED_AREA, null)
|
||||
|
||||
@@ -270,6 +272,7 @@ export default {
|
||||
{ id: 3, title: '本地便民到家', image: '', link: '/pages/category/channel?categoryId=5' },
|
||||
],
|
||||
categories: Array.isArray(cachedCats) ? cachedCats : [],
|
||||
navCategories: Array.isArray(cachedNavCats) ? cachedNavCats : [],
|
||||
list: [],
|
||||
page: 1,
|
||||
size: 10,
|
||||
@@ -305,6 +308,33 @@ export default {
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
/**
|
||||
* 首页金刚区展示的 8 个二级分类
|
||||
* 规则:优先取后端 navCategories(带有 is_home 推荐标记的高频果蔬二级品类),
|
||||
* 若未就绪则从 categories 的 children 提取降级,保证零跳动稳定展示刚好 8 个
|
||||
*/
|
||||
displayNavCategories() {
|
||||
if (Array.isArray(this.navCategories) && this.navCategories.length) {
|
||||
return this.navCategories.slice(0, 8)
|
||||
}
|
||||
// 兜底降级:从一级分类树的 children 中展平提取二级分类
|
||||
if (Array.isArray(this.categories) && this.categories.length) {
|
||||
const allSubs = []
|
||||
for (const p of this.categories) {
|
||||
if (Array.isArray(p.children)) {
|
||||
for (const s of p.children) {
|
||||
allSubs.push(s)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (allSubs.length) {
|
||||
const homeFirst = allSubs.filter((s) => s.isHome)
|
||||
const others = allSubs.filter((s) => !s.isHome)
|
||||
return homeFirst.concat(others).slice(0, 8)
|
||||
}
|
||||
}
|
||||
return []
|
||||
},
|
||||
/**
|
||||
* 用户是否是有效会员
|
||||
*/
|
||||
@@ -521,13 +551,20 @@ export default {
|
||||
}
|
||||
}).catch((e) => console.warn('分类拉取异常', e))
|
||||
|
||||
const pNavCategories = homeApi.navCategories().then((res) => {
|
||||
if (Array.isArray(res) && res.length) {
|
||||
this.navCategories = res
|
||||
safeSetStorage(STORAGE_KEY_NAV_CATEGORIES, res)
|
||||
}
|
||||
}).catch((e) => console.warn('金刚区二级分类拉取异常', e))
|
||||
|
||||
const pAreas = this.loadAreas()
|
||||
const pFeed = this.fetchFeed(true)
|
||||
const pMember = this.loadMemberCard()
|
||||
const pUnread = this.loadUnread()
|
||||
|
||||
try {
|
||||
await Promise.allSettled([pBanners, pCategories, pAreas, pFeed, pMember, pUnread])
|
||||
await Promise.allSettled([pBanners, pCategories, pNavCategories, pAreas, pFeed, pMember, pUnread])
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
@@ -832,10 +869,15 @@ export default {
|
||||
},
|
||||
|
||||
/**
|
||||
* 点击金刚区分类项
|
||||
* @param {Object} c 分类数据
|
||||
* 点击金刚区分类项(直达二级分类频道页,自动激活选中该二级分类并筛选其同城帖子)
|
||||
* @param {Object} c 二级分类数据
|
||||
*/
|
||||
goCategory(c) {
|
||||
if (!c) return
|
||||
if (c.isAll || c.id === 0) {
|
||||
this.goCategoryTab()
|
||||
return
|
||||
}
|
||||
uni.navigateTo({ url: `/pages/category/channel?categoryId=${c.id}&name=${encodeURIComponent(c.name)}` })
|
||||
},
|
||||
|
||||
|
||||
|
之前 宽度: | 高度: | 大小: 3.4 KiB |
|
之前 宽度: | 高度: | 大小: 4.0 KiB |
|
之前 宽度: | 高度: | 大小: 6.7 KiB |
|
之前 宽度: | 高度: | 大小: 4.1 KiB |
|
之前 宽度: | 高度: | 大小: 4.3 KiB |
|
之前 宽度: | 高度: | 大小: 4.5 KiB |
|
之前 宽度: | 高度: | 大小: 3.4 KiB |
|
之前 宽度: | 高度: | 大小: 4.0 KiB |
|
之前 宽度: | 高度: | 大小: 4.0 KiB |
|
之前 宽度: | 高度: | 大小: 4.5 KiB |
|
之前 宽度: | 高度: | 大小: 4.4 KiB |
|
之前 宽度: | 高度: | 大小: 3.9 KiB |
|
之前 宽度: | 高度: | 大小: 4.4 KiB |
|
之前 宽度: | 高度: | 大小: 4.9 KiB |
|
之前 宽度: | 高度: | 大小: 3.4 KiB |
|
之前 宽度: | 高度: | 大小: 4.7 KiB |