feat(listing): 极品专区改为无门槛可见

This commit is contained in:
yml
2026-11-27 21:24:29 +08:00
parent fab8301569
commit 17ca2f6672
15 changed files with 55 additions and 243 deletions
@@ -46,12 +46,8 @@ import HomeFilters from '../components/HomeFilters.vue'
import HomeZones from '../components/HomeZones.vue'
import ListingCard from '../components/ListingCard.vue'
import { mapDistributionHomeBanners, useDistributionSiteStore } from '@/stores/distributionSite'
import { useSessionStore } from '@/stores/session'
import { canViewPremiumZone } from '@/shared/utils/growthLevel'
const siteStore = useDistributionSiteStore()
const session = useSessionStore()
const canViewPremium = computed(() => canViewPremiumZone(session.renterGrowthLevel))
const announcements = ref<string[]>(defaultHomeAnnouncements)
const displayAnnouncements = computed(() => {
@@ -169,14 +165,6 @@ const activeZone = ref('all')
const route = useRoute()
const router = useRouter()
watch(canViewPremium, allowed => {
if (!allowed && activeZone.value === 'premium') {
activeZone.value = 'all'
}
pcHomeCache.clearList()
void loadListingsPage(true)
})
const {
filters,
regionOptions,
@@ -204,9 +192,6 @@ const {
restoreSnapshot,
getSnapshot,
} = useListingQuery(filters, sortBy, activeZone)
const visibleListings = computed(() =>
canViewPremium.value ? listings.value : listings.value.filter(item => !item.is_premium)
)
watch(
() => route.query,
@@ -244,7 +229,7 @@ const statCards = computed(() => {
hint: '交接更快',
},
]
return canViewPremium.value ? cards : cards.filter(card => card.key !== 'premium')
return cards
})
const zoneOptions = computed(() => {
@@ -292,7 +277,7 @@ const zoneOptions = computed(() => {
count: zoneCount('highCoin'),
},
]
return canViewPremium.value ? zones : zones.filter(zone => zone.key !== 'premium')
return zones
})
async function loadHome() {
@@ -387,7 +372,6 @@ function applyRouteQueryToHomeState() {
function desktopHomeStateSignature() {
return JSON.stringify({
filters: buildDesktopHomeQueryValues(),
premiumAccess: canViewPremium.value,
})
}
@@ -696,7 +680,7 @@ if (!restored) {
<el-empty v-else description="暂无展示图片" />
</el-dialog>
<section v-if="canViewPremium" class="premium-spotlight" aria-label="优质号主精选">
<section class="premium-spotlight" aria-label="优质号主精选">
<div class="premium-spotlight-mark">
<el-icon :size="24"><Trophy /></el-icon>
</div>
@@ -755,16 +739,16 @@ if (!restored) {
</div>
</div>
<div v-if="!loading && visibleListings.length === 0" class="home-empty-state">
<div v-if="!loading && listings.length === 0" class="home-empty-state">
<strong>没有符合条件的账号</strong>
<span>可以放宽筛选条件或切回全部专区。</span>
<button type="button" @click="handleResetFilters">重置条件</button>
</div>
<div v-else v-loading="loading" class="enhanced-desktop-list">
<ListingCard v-for="item in visibleListings" :key="item.id" :listing="item" />
<ListingCard v-for="item in listings" :key="item.id" :listing="item" />
</div>
<div v-if="!loading && visibleListings.length" class="infinite-load-state">
<div v-if="!loading && listings.length" class="infinite-load-state">
<span v-if="loadingMore">正在加载更多账号...</span>
<span v-else-if="!hasMoreListings">已经到底了</span>
</div>
@@ -75,12 +75,10 @@ import {
import { buildMobileHomeListSignature, useMobileHomeCacheStore } from '@/stores/mobileHomeCache'
import { mapDistributionHomeBanners, useDistributionSiteStore } from '@/stores/distributionSite'
import { useSessionStore } from '@/stores/session'
import { canViewPremiumZone } from '@/shared/utils/growthLevel'
const router = useRouter()
const route = useRoute()
const session = useSessionStore()
const canViewPremium = computed(() => canViewPremiumZone(session.renterGrowthLevel))
const siteStore = useDistributionSiteStore()
const homeCache = useMobileHomeCacheStore()
const { run: runBannerAction } = useBannerAction()
@@ -172,7 +170,7 @@ const sortOptions: MobileSortOption[] = [
{ key: 'published', label: '最新发布', shortLabel: '最新发布' },
]
const allZoneOptions = [
const zoneOptions = [
{ key: 'all', label: '全部', hint: '当前可租' },
{ key: 'premium', label: '极品', hint: '优质号主精选' },
{ key: 'sale', label: '特惠', hint: '价格更划算' },
@@ -181,9 +179,6 @@ const allZoneOptions = [
{ key: 'password', label: '账密', hint: '交接更快' },
{ key: 'highCoin', label: '高币', hint: '100M以上' },
]
const zoneOptions = computed(() =>
canViewPremium.value ? allZoneOptions : allZoneOptions.filter(zone => zone.key !== 'premium')
)
/** 统一使用领域层导出的预设区间,保证与桌面端完全一致 */
const rangePresets = defaultRangePresets
@@ -328,33 +323,15 @@ const activeFilterCount = computed(() => {
return chipCount + rangeCount
})
const displayListings = computed(() => {
return canViewPremium.value ? listings.value : listings.value.filter(item => !item.is_premium)
})
const visibleZoneOptions = computed(() =>
zoneOptions.value.map(zone => {
const count =
!canViewPremium.value && zone.key === 'all'
? Math.max(Number(zoneCounts.value.all || 0) - Number(zoneCounts.value.premium || 0), 0)
: zoneCount(zone.key)
return {
...zone,
count,
}
})
zoneOptions.map(zone => ({
...zone,
count: zoneCount(zone.key),
}))
)
applyRouteQueryToMobileState()
watch(canViewPremium, allowed => {
homeCache.clearList()
if (!allowed && activeZone.value === 'premium') {
activeZone.value = 'all'
}
void loadListings(true)
})
function currentListSignature() {
return buildMobileHomeListSignature({
searchValue: searchValue.value,
@@ -362,7 +339,6 @@ function currentListSignature() {
activeZone: activeZone.value,
selectedFilters: selectedFilters.value,
rangeFilters: rangeFilters.value,
premiumAccess: canViewPremium.value,
})
}
@@ -699,7 +675,7 @@ function applyRouteQueryToMobileState() {
const nextSearch = readQueryString(query, 'keyword')
const nextSort = readQueryString(query, 'sort') || 'recommended'
const requestedZone = readQueryString(query, 'zone') || 'all'
const nextZone = requestedZone === 'premium' && !canViewPremium.value ? 'all' : requestedZone
const nextZone = requestedZone
const nextFilters = normalizeSelectedFilters(
decodeHomeQueryJson<Record<string, unknown>>(query, 'filters', {})
)
@@ -1042,7 +1018,6 @@ if (!restoreHomeConfigFromCache()) {
</div>
<button
v-if="canViewPremium"
type="button"
class="mobile-premium-spotlight"
aria-label="进入优质号主极品专区"
@@ -1115,7 +1090,7 @@ if (!restoreHomeConfigFromCache()) {
text="接口暂不可用,请稍后刷新。"
/>
<van-empty
v-else-if="displayListings.length === 0"
v-else-if="listings.length === 0"
class="mobile-empty"
image="search"
description="没有符合条件的账号"
@@ -1126,7 +1101,7 @@ if (!restoreHomeConfigFromCache()) {
<!-- 列表卡片:现代结构化卡片(对齐PC首页体验) -->
<div class="mobile-list">
<RouterLink
v-for="item in displayListings"
v-for="item in listings"
:key="item.id"
class="mobile-card"
:to="`/m/listings/${item.id}`"
@@ -1290,7 +1265,7 @@ if (!restoreHomeConfigFromCache()) {
</div>
</RouterLink>
</div>
<div v-if="!loading && displayListings.length" class="mobile-load-state">
<div v-if="!loading && listings.length" class="mobile-load-state">
<span v-if="loadingMore">正在加载更多账号...</span>
<span v-else-if="!hasMoreListings">已经到底了</span>
</div>
@@ -1,13 +0,0 @@
import { describe, expect, it } from 'vitest'
import { canViewPremiumZone } from '../growthLevel'
describe('canViewPremiumZone', () => {
it('仅铂金及以上等级可以查看极品专区', () => {
expect(canViewPremiumZone('normal')).toBe(false)
expect(canViewPremiumZone('')).toBe(false)
expect(canViewPremiumZone('platinum')).toBe(true)
expect(canViewPremiumZone('diamond')).toBe(true)
expect(canViewPremiumZone('peak')).toBe(true)
})
})
-5
View File
@@ -1,5 +0,0 @@
const premiumZoneLevels = new Set(['platinum', 'diamond', 'peak'])
export function canViewPremiumZone(levelCode: string | undefined | null) {
return premiumZoneLevels.has(String(levelCode || '').trim())
}
-2
View File
@@ -24,7 +24,6 @@ export function buildMobileHomeListSignature(input: {
activeZone: string
selectedFilters: Record<string, string[]>
rangeFilters: MobileHomeRangeFilters
premiumAccess: boolean
}) {
return JSON.stringify({
keyword: input.searchValue.trim(),
@@ -32,7 +31,6 @@ export function buildMobileHomeListSignature(input: {
zone: input.activeZone,
selected: input.selectedFilters,
ranges: input.rangeFilters,
premiumAccess: input.premiumAccess,
})
}