feat(user): 支持后台调整等级并限制极品专区可见性

This commit is contained in:
yml2213
2026-11-05 12:02:48 +08:00
parent 09f244a93d
commit 0d558bdce0
35 changed files with 934 additions and 131 deletions
@@ -45,8 +45,12 @@ 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(() => {
@@ -164,6 +168,14 @@ 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,
@@ -191,6 +203,9 @@ const {
restoreSnapshot,
getSnapshot,
} = useListingQuery(filters, sortBy, activeZone)
const visibleListings = computed(() =>
canViewPremium.value ? listings.value : listings.value.filter(item => !item.is_premium)
)
watch(
() => route.query,
@@ -206,69 +221,78 @@ watch(
}
)
const statCards = computed(() => [
{
label: '优质号主精选',
value: `${zoneCount('premium')}`,
hint: '认证优质号主 · 极品专区',
},
{ label: '可租账号', value: `${totalListings.value}`, hint: '当前筛选结果' },
{
label: '高哈夫币',
value: `${zoneCount('highCoin')}`,
hint: '100M 以上',
},
{
label: '账密登录',
value: `${zoneCount('password')}`,
hint: '交接更快',
},
])
const statCards = computed(() => {
const cards = [
{
key: 'premium',
label: '优质号主精选',
value: `${zoneCount('premium')}`,
hint: '认证优质号主 · 极品专区',
},
{ key: 'all', label: '可租账号', value: `${totalListings.value}`, hint: '当前筛选结果' },
{
key: 'highCoin',
label: '高哈夫币',
value: `${zoneCount('highCoin')}`,
hint: '100M 以上',
},
{
key: 'password',
label: '账密登录',
value: `${zoneCount('password')}`,
hint: '交接更快',
},
]
return canViewPremium.value ? cards : cards.filter(card => card.key !== 'premium')
})
const zoneOptions = computed(() => [
{
key: 'all',
label: '全部专区',
hint: '当前可租账号',
count: zoneCount('all'),
},
{
key: 'premium',
label: '极品专区',
hint: '优质号主精选',
count: zoneCount('premium'),
},
{
key: 'sale',
label: '特惠专区',
hint: '价格更划算',
count: zoneCount('sale'),
},
{
key: 'gift',
label: '赠送专区',
hint: '含赠送物品',
count: zoneCount('gift'),
},
{
key: 'night',
label: '夜间专区',
hint: '0-2点可响应上号',
count: zoneCount('night'),
},
{
key: 'password',
label: '账密专区',
hint: '交接更快',
count: zoneCount('password'),
},
{
key: 'highCoin',
label: '高币专区',
hint: '100M 以上',
count: zoneCount('highCoin'),
},
])
const zoneOptions = computed(() => {
const zones = [
{
key: 'all',
label: '全部专区',
hint: '当前可租账号',
count: zoneCount('all'),
},
{
key: 'premium',
label: '极品专区',
hint: '优质号主精选',
count: zoneCount('premium'),
},
{
key: 'sale',
label: '特惠专区',
hint: '价格更划算',
count: zoneCount('sale'),
},
{
key: 'gift',
label: '赠送专区',
hint: '含赠送物品',
count: zoneCount('gift'),
},
{
key: 'night',
label: '夜间专区',
hint: '0-2点可响应上号',
count: zoneCount('night'),
},
{
key: 'password',
label: '账密专区',
hint: '交接更快',
count: zoneCount('password'),
},
{
key: 'highCoin',
label: '高币专区',
hint: '100M 以上',
count: zoneCount('highCoin'),
},
]
return canViewPremium.value ? zones : zones.filter(zone => zone.key !== 'premium')
})
async function loadHome() {
loading.value = true
@@ -360,7 +384,10 @@ function applyRouteQueryToHomeState() {
}
function desktopHomeStateSignature() {
return JSON.stringify(buildDesktopHomeQueryValues())
return JSON.stringify({
filters: buildDesktopHomeQueryValues(),
premiumAccess: canViewPremium.value,
})
}
function syncHomeQuery() {
@@ -652,7 +679,7 @@ if (!restored) {
<el-empty v-else description="暂无展示图片" />
</el-dialog>
<section class="premium-spotlight" aria-label="优质号主精选">
<section v-if="canViewPremium" class="premium-spotlight" aria-label="优质号主精选">
<div class="premium-spotlight-mark">
<el-icon :size="24"><Trophy /></el-icon>
</div>
@@ -711,16 +738,16 @@ if (!restored) {
</div>
</div>
<div v-if="!loading && listings.length === 0" class="home-empty-state">
<div v-if="!loading && visibleListings.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 listings" :key="item.id" :listing="item" />
<ListingCard v-for="item in visibleListings" :key="item.id" :listing="item" />
</div>
<div v-if="!loading && listings.length" class="infinite-load-state">
<div v-if="!loading && visibleListings.length" class="infinite-load-state">
<span v-if="loadingMore">正在加载更多账号...</span>
<span v-else-if="!hasMoreListings">已经到底了</span>
</div>
@@ -72,10 +72,12 @@ 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()
@@ -167,7 +169,7 @@ const sortOptions: MobileSortOption[] = [
{ key: 'published', label: '最新发布', shortLabel: '最新发布' },
]
const zoneOptions = [
const allZoneOptions = [
{ key: 'all', label: '全部', hint: '当前可租' },
{ key: 'premium', label: '极品', hint: '优质号主精选' },
{ key: 'sale', label: '特惠', hint: '价格更划算' },
@@ -176,6 +178,9 @@ const zoneOptions = [
{ key: 'password', label: '账密', hint: '交接更快' },
{ key: 'highCoin', label: '高币', hint: '100M以上' },
]
const zoneOptions = computed(() =>
canViewPremium.value ? allZoneOptions : allZoneOptions.filter(zone => zone.key !== 'premium')
)
/** 统一使用领域层导出的预设区间,保证与桌面端完全一致 */
const rangePresets = defaultRangePresets
@@ -321,18 +326,32 @@ const activeFilterCount = computed(() => {
})
const displayListings = computed(() => {
return listings.value
return canViewPremium.value ? listings.value : listings.value.filter(item => !item.is_premium)
})
const visibleZoneOptions = computed(() =>
zoneOptions.map(zone => ({
...zone,
count: zoneCount(zone.key),
}))
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,
}
})
)
applyRouteQueryToMobileState()
watch(canViewPremium, allowed => {
homeCache.clearList()
if (!allowed && activeZone.value === 'premium') {
activeZone.value = 'all'
}
void loadListings(true)
})
function currentListSignature() {
return buildMobileHomeListSignature({
searchValue: searchValue.value,
@@ -340,6 +359,7 @@ function currentListSignature() {
activeZone: activeZone.value,
selectedFilters: selectedFilters.value,
rangeFilters: rangeFilters.value,
premiumAccess: canViewPremium.value,
})
}
@@ -675,7 +695,8 @@ function applyRouteQueryToMobileState() {
: storedQuery
const nextSearch = readQueryString(query, 'keyword')
const nextSort = readQueryString(query, 'sort') || 'recommended'
const nextZone = readQueryString(query, 'zone') || 'all'
const requestedZone = readQueryString(query, 'zone') || 'all'
const nextZone = requestedZone === 'premium' && !canViewPremium.value ? 'all' : requestedZone
const nextFilters = normalizeSelectedFilters(
decodeHomeQueryJson<Record<string, unknown>>(query, 'filters', {})
)
@@ -1008,6 +1029,7 @@ if (!restoreHomeConfigFromCache()) {
</div>
<button
v-if="canViewPremium"
type="button"
class="mobile-premium-spotlight"
aria-label="进入优质号主极品专区"