Files
cz-web/src/views/cases/index.vue
2026-10-13 15:12:51 +08:00

162 lines
3.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!-- 页面:成功案例库(Cases) -->
<script setup lang="ts">
import { onMounted } from 'vue'
import { storeToRefs } from 'pinia'
import { useRouter } from 'vue-router'
import { CasesFilter, CasesGrid, CasesSearchBar, PaginationBar } from '@/components'
import { useCasesStore } from '@/stores/modules/cases'
import type { CaseQuery } from '@/types/business/cases'
const router = useRouter()
const casesStore = useCasesStore()
const { query, list, total, previewTotal, typeOptions, industryOptions, scaleOptions, caseTotal }
= storeToRefs(casesStore)
function onUpdateQuery(next: CaseQuery): void {
casesStore.setQuery(next)
}
function onUpdateKeyword(keyword: string): void {
casesStore.setQuery({ ...query.value, keyword })
}
function onSearch(): void {
void casesStore.search()
}
function onReset(): void {
void casesStore.resetQuery()
}
function onToggleFavoriteOnly(): void {
void casesStore.toggleFavoriteOnly()
}
function onFavorite(id: string): void {
void casesStore.toggleFavorite(id)
}
function onPageChange(page: number): void {
void casesStore.changePage(page)
}
function onViewDetail(id: string): void {
void router.push(`/cases/${id}`)
}
onMounted(() => {
// 收藏页复用本 store 并会置 favoriteOnly=true,进入案例库时重置,避免状态残留
casesStore.resetQuery()
void Promise.all([casesStore.fetchCategories(), casesStore.fetchCases()])
})
</script>
<template>
<div class="cases">
<header class="cases__hero">
<div class="container cases__hero-inner">
<h1 class="cases__title">
成功案例库
</h1>
<p class="cases__slogan">
海量软硬件研发与量产落地真实案例,借鉴成熟实践,降低项目试错成本。
</p>
</div>
</header>
<div class="container cases__body">
<CasesFilter
:query="query"
:type-options="typeOptions"
:industry-options="industryOptions"
:scale-options="scaleOptions"
:case-total="caseTotal"
:preview-total="previewTotal"
@update:query="onUpdateQuery"
@search="onSearch"
@reset="onReset"
/>
<div class="cases__main">
<CasesSearchBar
:keyword="query.keyword"
:favorite-only="query.favoriteOnly"
@update:keyword="onUpdateKeyword"
@search="onSearch"
@reset="onReset"
@toggle-favorite-only="onToggleFavoriteOnly"
/>
<CasesGrid
:cases="list"
:total="total"
@view="onViewDetail"
@favorite="onFavorite"
/>
<div class="cases__pager">
<PaginationBar
:page="query.page"
:page-size="query.pageSize"
:total="total"
@page-change="onPageChange"
/>
</div>
</div>
</div>
</div>
</template>
<style lang="less" scoped>
.cases {
min-height: 100%;
padding-bottom: @spacing-page-bottom;
background: @bg-color;
&__hero {
box-sizing: border-box;
padding: @spacing-lg 0;
background: @white;
border-bottom: 1px solid @border-color;
}
&__hero-inner {
padding-left: @spacing-xl;
padding-right: @spacing-xl;
}
&__title {
margin: 0;
font-size: @font-size-title;
font-weight: 600;
line-height: 1.3;
color: @cases-hero-title;
}
&__slogan {
margin: @spacing-sm 0 0;
font-size: @font-size-base;
font-weight: 400;
line-height: 1.5;
color: @cases-muted;
}
&__body {
.flex(row, flex-start, flex-start);
gap: @spacing-lg;
padding-top: @spacing-lg;
}
&__main {
.flex(column, flex-start, stretch);
flex: 1;
min-width: 0;
gap: @spacing-lg;
}
&__pager {
.flex(row, flex-end);
}
}
</style>