feat:首页完成

This commit is contained in:
李伊帆
2026-09-11 08:02:01 +08:00
parent 5b31eac508
commit 173cd6b975
68 changed files with 3181 additions and 112 deletions

View File

@@ -1,41 +1,319 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import AppTabBar from '@/components/AppTabBar.vue'
import {
CASE_CATEGORIES,
CASE_LIBRARY_LIST,
CASE_PAGE_SIZE,
DEFAULT_CASE_FILTER,
} from '@/constants/case-library'
import type { CaseCategory, CaseFilterValues } from '@/types/case-library'
import { cloneCaseFilter, matchCaseFilter } from '@/utils/case-filter'
import CaseCard from './components/CaseCard.vue'
import CaseFilterPanel from './components/CaseFilterPanel.vue'
import LoadMoreFooter from './components/LoadMoreFooter.vue'
const LOAD_MORE_DELAY = 600
const keyword = ref('')
const activeCategory = ref<CaseCategory>('全部')
const caseList = ref(CASE_LIBRARY_LIST.map(item => ({ ...item })))
const pageSize = ref(CASE_PAGE_SIZE)
const loadingMore = ref(false)
const filterVisible = ref(false)
const appliedFilter = ref<CaseFilterValues>(cloneCaseFilter(DEFAULT_CASE_FILTER))
const filteredCases = computed(() => {
const text = keyword.value.trim()
return caseList.value.filter((item) => {
const matchCategory = activeCategory.value === '全部' || item.category === activeCategory.value
const matchKeyword = !text || item.title.includes(text) || item.industry.includes(text) || item.category.includes(text)
const matchFilter = matchCaseFilter(item, appliedFilter.value)
return matchCategory && matchKeyword && matchFilter
})
})
const visibleCases = computed(() => filteredCases.value.slice(0, pageSize.value))
const hasMore = computed(() => pageSize.value < filteredCases.value.length)
const loadFinished = computed(() => !hasMore.value && visibleCases.value.length > 0)
watch([keyword, activeCategory, appliedFilter], () => {
pageSize.value = CASE_PAGE_SIZE
})
function handleSelectCategory(category: CaseCategory) {
activeCategory.value = category
}
function handleToggleFavorite(id: string) {
caseList.value = caseList.value.map(item =>
item.id === id ? { ...item, favorite: !item.favorite } : item,
)
}
function handleLoadMore() {
if (loadingMore.value || !hasMore.value)
return
loadingMore.value = true
setTimeout(() => {
pageSize.value += CASE_PAGE_SIZE
loadingMore.value = false
}, LOAD_MORE_DELAY)
}
function handleOpenFilter() {
filterVisible.value = true
}
function handleCloseFilter() {
filterVisible.value = false
}
function handleConfirmFilter(value: CaseFilterValues) {
appliedFilter.value = cloneCaseFilter(value)
}
</script>
<template>
<view class="placeholder-page">
<text class="placeholder-page__title">
案例库
</text>
<text class="placeholder-page__desc">
功能开发中
</text>
<view class="case-library">
<view class="case-library__header">
<text class="case-library__title">
案例库
</text>
<view class="case-library__search-row">
<view class="case-library__search">
<image
class="case-library__search-icon"
src="/static/icons/icon-search.svg"
mode="aspectFit"
/>
<input
v-model="keyword"
class="case-library__search-input"
placeholder="搜索案例标题、描述、标签..."
placeholder-class="case-library__search-placeholder"
>
</view>
<view class="case-library__favorite-btn">
<image
class="case-library__favorite-btn-icon"
src="/static/icons/icon-heart.svg"
mode="aspectFit"
/>
</view>
</view>
<scroll-view
class="case-library__tabs"
scroll-x
:show-scrollbar="false"
>
<view class="case-library__tabs-inner">
<text
v-for="category in CASE_CATEGORIES"
:key="category"
class="case-library__tab"
:class="{ 'case-library__tab--active': activeCategory === category }"
@tap="handleSelectCategory(category)"
>
{{ category }}
</text>
</view>
</scroll-view>
<view class="case-library__toolbar">
<text class="case-library__count">
共 {{ filteredCases.length }}
</text>
<view
class="case-library__filter"
@tap="handleOpenFilter"
>
<image
class="case-library__filter-icon"
src="/static/icons/icon-filter.svg"
mode="aspectFit"
/>
<text class="case-library__filter-text">
筛选
</text>
</view>
</view>
</view>
<scroll-view
class="case-library__scroll"
scroll-y
:show-scrollbar="false"
:lower-threshold="120"
@scrolltolower="handleLoadMore"
>
<view class="case-library__list">
<CaseCard
v-for="item in visibleCases"
:key="item.id"
:item="item"
@toggle-favorite="handleToggleFavorite"
/>
<LoadMoreFooter
:loading="loadingMore"
:has-more="hasMore"
:finished="loadFinished"
@load-more="handleLoadMore"
/>
</view>
</scroll-view>
<AppTabBar active="case" />
<CaseFilterPanel
:visible="filterVisible"
:cases="caseList"
:value="appliedFilter"
@close="handleCloseFilter"
@confirm="handleConfirmFilter"
/>
</view>
</template>
<style scoped lang="scss">
@import '@/styles/variables.scss';
.placeholder-page {
.case-library {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
height: 100vh;
overflow: hidden;
background: $color-bg-section;
}
.case-library__header {
flex-shrink: 0;
padding: calc(var(--status-bar-height, 44px) + 12rpx) 24rpx 0;
background: $color-bg-page;
}
.placeholder-page__title {
.case-library__title {
display: block;
font-size: 36rpx;
font-weight: 600;
color: $color-text-primary;
text-align: center;
}
.placeholder-page__desc {
margin-top: 16rpx;
.case-library__search-row {
display: flex;
align-items: center;
margin-top: 24rpx;
}
.case-library__search {
display: flex;
flex: 1;
align-items: center;
height: 72rpx;
padding: 0 24rpx;
background: $color-bg-section;
border-radius: 36rpx;
}
.case-library__search-icon {
flex-shrink: 0;
width: 32rpx;
height: 32rpx;
margin-right: 12rpx;
}
.case-library__search-input {
flex: 1;
font-size: 26rpx;
color: $color-text-primary;
}
.case-library__search-placeholder {
color: $color-text-placeholder;
}
.case-library__favorite-btn {
display: flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
width: 72rpx;
height: 72rpx;
margin-left: 16rpx;
}
.case-library__favorite-btn-icon {
width: 40rpx;
height: 40rpx;
}
.case-library__tabs {
margin-top: 24rpx;
white-space: nowrap;
}
.case-library__tabs-inner {
display: inline-flex;
gap: 32rpx;
padding-right: 24rpx;
}
.case-library__tab {
flex-shrink: 0;
padding-bottom: 12rpx;
font-size: 28rpx;
color: $color-text-secondary;
&--active {
font-weight: 600;
color: $color-text-primary;
border-bottom: 4rpx solid $color-primary;
}
}
.case-library__toolbar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20rpx 0 24rpx;
}
.case-library__count {
font-size: 24rpx;
color: $color-text-secondary;
}
.case-library__filter {
display: flex;
align-items: center;
}
.case-library__filter-icon {
width: 28rpx;
height: 28rpx;
margin-right: 8rpx;
}
.case-library__filter-text {
font-size: 26rpx;
color: #666666;
}
.case-library__scroll {
flex: 1;
min-height: 0;
}
.case-library__list {
padding: 0 24rpx calc(140rpx + env(safe-area-inset-bottom));
}
</style>