feat:消息中心和案例库
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { onShow } from '@dcloudio/uni-app'
|
||||
import AppTabBar from '@/components/AppTabBar.vue'
|
||||
import { useCaseFavorites } from '@/hooks/use-case-favorites'
|
||||
import {
|
||||
CASE_CATEGORIES,
|
||||
CASE_LIBRARY_LIST,
|
||||
@@ -8,6 +10,7 @@ import {
|
||||
DEFAULT_CASE_FILTER,
|
||||
} from '@/constants/case-library'
|
||||
import type { CaseCategory, CaseFilterValues } from '@/types/case-library'
|
||||
import filterIcon from '@/static/icons/icon-filter.svg'
|
||||
import { cloneCaseFilter, matchCaseFilter } from '@/utils/case-filter'
|
||||
import CaseCard from './components/CaseCard.vue'
|
||||
import CaseFilterPanel from './components/CaseFilterPanel.vue'
|
||||
@@ -15,9 +18,11 @@ import LoadMoreFooter from './components/LoadMoreFooter.vue'
|
||||
|
||||
const LOAD_MORE_DELAY = 600
|
||||
|
||||
const { applyFavoritesToList, syncFavoriteIds, toggleFavorite } = useCaseFavorites()
|
||||
|
||||
const keyword = ref('')
|
||||
const activeCategory = ref<CaseCategory>('全部')
|
||||
const caseList = ref(CASE_LIBRARY_LIST.map(item => ({ ...item })))
|
||||
const caseList = ref(applyFavoritesToList(CASE_LIBRARY_LIST.map(item => ({ ...item }))))
|
||||
const pageSize = ref(CASE_PAGE_SIZE)
|
||||
const loadingMore = ref(false)
|
||||
const filterVisible = ref(false)
|
||||
@@ -44,14 +49,24 @@ watch([keyword, activeCategory, appliedFilter], () => {
|
||||
pageSize.value = CASE_PAGE_SIZE
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
syncFavoriteIds()
|
||||
caseList.value = applyFavoritesToList(CASE_LIBRARY_LIST.map(item => ({ ...item })))
|
||||
})
|
||||
|
||||
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,
|
||||
)
|
||||
toggleFavorite(id)
|
||||
caseList.value = applyFavoritesToList(CASE_LIBRARY_LIST.map(item => ({ ...item })))
|
||||
}
|
||||
|
||||
function handleOpenFavorites() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/case-library/favorites/index',
|
||||
})
|
||||
}
|
||||
|
||||
function handleLoadMore() {
|
||||
@@ -77,6 +92,12 @@ function handleCloseFilter() {
|
||||
function handleConfirmFilter(value: CaseFilterValues) {
|
||||
appliedFilter.value = cloneCaseFilter(value)
|
||||
}
|
||||
|
||||
function handleCaseTap(id: string) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/case-library/detail/index?id=${id}`,
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -100,7 +121,10 @@ function handleConfirmFilter(value: CaseFilterValues) {
|
||||
placeholder-class="case-library__search-placeholder"
|
||||
>
|
||||
</view>
|
||||
<view class="case-library__favorite-btn">
|
||||
<view
|
||||
class="case-library__favorite-btn"
|
||||
@tap="handleOpenFavorites"
|
||||
>
|
||||
<image
|
||||
class="case-library__favorite-btn-icon"
|
||||
src="/static/icons/icon-heart.svg"
|
||||
@@ -137,7 +161,7 @@ function handleConfirmFilter(value: CaseFilterValues) {
|
||||
>
|
||||
<image
|
||||
class="case-library__filter-icon"
|
||||
src="/static/icons/icon-filter.svg"
|
||||
:src="filterIcon"
|
||||
mode="aspectFit"
|
||||
/>
|
||||
<text class="case-library__filter-text">
|
||||
@@ -160,6 +184,7 @@ function handleConfirmFilter(value: CaseFilterValues) {
|
||||
:key="item.id"
|
||||
:item="item"
|
||||
@toggle-favorite="handleToggleFavorite"
|
||||
@tap="handleCaseTap(item.id)"
|
||||
/>
|
||||
|
||||
<LoadMoreFooter
|
||||
@@ -196,7 +221,7 @@ function handleConfirmFilter(value: CaseFilterValues) {
|
||||
|
||||
.case-library__header {
|
||||
flex-shrink: 0;
|
||||
padding: calc(var(--status-bar-height, 44px) + 12rpx) 24rpx 0;
|
||||
padding: calc(var(--status-bar-height, 44px) + 60rpx) 24rpx 0;
|
||||
background: $color-bg-page;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user