2026-02-13 17:34:32 +08:00
< template >
< div class = "mobile-container" >
< header class = "header" >
< a-button class = "back-btn" type = "text" @click ="handleBackClick" >
< LeftOutlined : style = "{ fontSize: '20px' }" />
</ a-button >
2026-03-05 16:08:27 +08:00
< h1 v-if = "!showSearch" > 作品列表 </ h1 >
2026-03-05 16:02:34 +08:00
< div v-else class = "search-input-container" >
< a-input-search
v -model:value = "searchKeyword"
2026-05-13 12:43:01 +08:00
placeholder = "搜索标题、标签或描述"
2026-03-05 16:02:34 +08:00
class = "search-input"
enter -button
2026-03-26 10:28:28 +08:00
@search ="handleSearch"
2026-03-05 16:02:34 +08:00
/>
</ div >
< a-button class = "search-btn" type = "text" @click ="toggleSearch" >
2026-02-13 17:34:32 +08:00
< SearchOutlined : style = "{ fontSize: '20px' }" />
</ a-button >
</ header >
< div class = "main-content" >
< div class = "category-sidebar" >
2026-05-23 21:56:18 +08:00
< button
2026-02-13 17:34:32 +08:00
class = "category-item"
2026-05-23 21:56:18 +08:00
: class = "{ active: selectedCategory === '全部' }"
type = "button"
@click ="handleCategoryClick('全部')"
2026-02-13 17:34:32 +08:00
>
2026-05-23 21:56:18 +08:00
全部
</ button >
< div v-for = "group in filterGroups" :key="group.groupName" class="filter-group" >
< span class = "filter-group__title" >{{ group . groupName }}</ span >
< button
v-for = "tag in group.tags"
:key = "tag.id"
class = "category-item"
: class = "{ active: selectedTagId === String(tag.id) }"
type = "button"
@click ="handleTagClick(tag)"
>
{{ tag . displayName || tag . tagName }}
</ button >
2026-02-13 17:34:32 +08:00
</ div >
</ div >
< div class = "product-section" >
2026-03-26 10:28:28 +08:00
< a-alert
v-if = "activeBannerText"
class = "page-banner"
type = "info"
show -icon
:message = "activeBannerText"
/>
2026-02-13 17:34:32 +08:00
< div class = "product-grid" >
< a-card
v-for = "item in products"
:key = "item.id"
class = "product-card"
: body -style =" { padding : ' 12px ' } "
hoverable
@click ="handleProductClick(item)"
>
2026-02-24 09:59:22 +08:00
< div class = "product-img" >
2026-03-26 10:28:28 +08:00
< img
v-if = "getProductImages(item).length > 0"
:src = "getProductImages(item)[0]"
2026-03-03 17:50:10 +08:00
: alt = "item.title || item.name"
2026-02-24 09:59:22 +08:00
class = "product-image"
/>
< div v-else class = "product-img-placeholder" >
2026-03-26 10:28:28 +08:00
< span >{{ ( item . title || item . name ) ? .[ 0 ] || '作' }}</ span >
2026-02-24 09:59:22 +08:00
</ div >
</ div >
2026-03-26 10:28:28 +08:00
2026-02-24 09:59:22 +08:00
< div class = "product-info" >
2026-03-03 17:50:10 +08:00
< p class = "name" >{{ item . title || item . name }}</ p >
2026-05-18 09:46:11 +08:00
< p v-if = "item.shopName" class="shop-name" > 所属店铺 : {{ item.shopName }}</ p >
2026-02-24 09:59:22 +08:00
< div class = "product-meta" >
2026-03-26 10:28:28 +08:00
< span class = "duration" >{{ item . approximateDuration || '时长待定' }}</ span >
2026-02-24 09:59:22 +08:00
< div class = "stats" >
2026-03-26 10:28:28 +08:00
< span >{{ item . likeCount || 0 }} 点赞 </ span >
< span >{{ item . collectCount || 0 }} 收藏 </ span >
2026-02-24 09:59:22 +08:00
</ div >
</ div >
2026-03-26 10:28:28 +08:00
2026-02-24 09:59:22 +08:00
< div class = "product-tags" >
2026-03-26 10:28:28 +08:00
< template v-if = "item.tagInfos?.length" >
< a-tag
2026-03-03 17:50:10 +08:00
v-for = "tag in item.tagInfos"
:key = "tag.id"
size = "small"
: style = "{
2026-03-26 10:28:28 +08:00
marginRight: '4px',
2026-03-03 17:50:10 +08:00
marginBottom: '4px',
2026-03-26 10:28:28 +08:00
color: tag.textColor || '#333',
backgroundColor: tag.bgColor || '#f0f0f0',
borderColor: tag.borderColor || '#f0f0f0'
2026-03-03 17:50:10 +08:00
}"
>
{{ tag . tagName }}
</ a-tag >
</ template >
2026-03-26 10:28:28 +08:00
< a-tag v-else size = "small" color = "default" > 暂无标签 </ a-tag >
2026-02-24 09:59:22 +08:00
</ div >
2026-03-26 10:28:28 +08:00
2026-02-24 09:59:22 +08:00
< div class = "price-row" >
2026-03-26 10:28:28 +08:00
< p class = "price" > ¥ {{ Number ( item . price || 0 ). toFixed ( 2 ) }}</ p >
2026-05-13 12:43:01 +08:00
< div class = "cart-action" >
< span v-if = "item.inCart" class="cart-note" > 购物车已有 </ span >
< a-button
: type = "item.inCart ? 'default' : 'primary'"
size = "small"
shape = "circle"
class = "cart-btn"
: class = "{ 'cart-btn-in-cart': item.inCart }"
@click.stop ="handleAddToCart(item)"
>
< CheckOutlined v-if = "item.inCart" />
< ShoppingCartOutlined v-else />
</ a-button >
</ div >
2026-02-24 09:59:22 +08:00
</ div >
</ div >
</ a-card >
2026-02-13 17:34:32 +08:00
</ div >
2026-02-24 09:59:22 +08:00
< div v-if = "products.length === 0 && !loading" class="empty-state" >
2026-03-26 10:28:28 +08:00
< a-empty description = "暂时没有匹配的作品" >
< a-button type = "primary" @click ="resetFilters" > 查看全部作品 </ a -button >
</ a-empty >
2026-02-24 09:59:22 +08:00
</ div >
2026-03-26 10:28:28 +08:00
< div v-if = "loading" class="loading-state" >
< a-spin />
2026-02-24 09:59:22 +08:00
</ div >
2026-02-13 17:34:32 +08:00
</ div >
</ div >
</ div >
</ template >
< script setup lang = "ts" >
2026-05-18 09:46:11 +08:00
/**
* ProductListView page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
2026-03-26 10:28:28 +08:00
import { onMounted , ref , watch , inject , computed } from 'vue'
import { useRouter , useRoute } from 'vue-router'
2026-05-13 12:43:01 +08:00
import { CheckOutlined , LeftOutlined , SearchOutlined , ShoppingCartOutlined } from '@ant-design/icons-vue'
2026-02-13 17:34:32 +08:00
import { message } from 'ant-design-vue'
2026-05-23 18:44:57 +08:00
/**
* Purpose: ProductVO supports ProductListView.vue by holding or executing the product vo page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-24 09:59:22 +08:00
import { productApi , type ProductVO } from '@/api/product'
2026-05-23 18:44:57 +08:00
/**
* Purpose: TagVO supports ProductListView.vue by holding or executing the tag vo page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-05-23 21:56:18 +08:00
import { tagApi , type TagFilterGroupVO , type TagVO } from '@/api/tag'
2026-02-27 15:57:22 +08:00
import { cartApi } from '@/api/cart'
2026-03-03 17:50:10 +08:00
import { fileApi } from '@/api/file'
2026-05-13 12:43:01 +08:00
import { runWithGlobalLoading } from '@/utils/action-loading'
import { fetchCartProductIdSet , hasCartProduct , withAddedCartProduct } from '@/utils/cart-state'
2026-05-23 18:44:57 +08:00
/**
* Purpose: ProductListItem supports ProductListView.vue by holding or executing the product list item page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-05-13 12:43:01 +08:00
type ProductListItem = ProductVO & {
inCart ?: boolean
}
2026-02-13 17:34:32 +08:00
2026-05-23 18:44:57 +08:00
/**
* Purpose: router supports ProductListView.vue by holding or executing the router page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-03-26 10:28:28 +08:00
const router = useRouter ()
2026-05-23 18:44:57 +08:00
/**
* Purpose: route supports ProductListView.vue by holding or executing the route page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-03-26 10:28:28 +08:00
const route = useRoute ()
2026-05-23 18:44:57 +08:00
/**
* Purpose: updateCartCount supports ProductListView.vue by holding or executing the update cart count page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-03-19 20:51:07 +08:00
const updateCartCount = inject < () => Promise < void > > ( 'updateCartCount' , async () => {})
2026-03-05 16:28:05 +08:00
2026-05-23 21:56:18 +08:00
/** filterGroups stores scene-based tag filters shown above the product grid. */
const filterGroups = ref < TagFilterGroupVO [] >([])
/** allTags flattens filter groups for route/query lookup. */
const allTags = computed (() => filterGroups . value . flatMap ( group => group . tags || []))
2026-05-18 09:46:11 +08:00
/** selectedCategory is a reactive state variable used by the template and event handlers. */
2026-03-26 10:28:28 +08:00
const selectedCategory = ref ( '全部' )
2026-05-23 21:56:18 +08:00
/** selectedTagId tracks the grouped filter id sent to the backend. */
const selectedTagId = ref ( '' )
2026-05-23 18:44:57 +08:00
/**
* Purpose: products supports ProductListView.vue by holding or executing the products page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-05-13 12:43:01 +08:00
const products = ref < ProductListItem [] >([])
2026-05-18 09:46:11 +08:00
/** loading is a reactive state variable used by the template and event handlers. */
2026-02-24 09:59:22 +08:00
const loading = ref ( false )
2026-05-18 09:46:11 +08:00
/** showSearch is a reactive state variable used by the template and event handlers. */
2026-03-05 16:02:34 +08:00
const showSearch = ref ( false )
2026-05-18 09:46:11 +08:00
/** searchKeyword is a reactive state variable used by the template and event handlers. */
2026-03-05 16:02:34 +08:00
const searchKeyword = ref ( '' )
2026-05-23 18:44:57 +08:00
/**
* Purpose: imageIdCache supports ProductListView.vue by holding or executing the image id cache page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-03-03 17:50:10 +08:00
const imageIdCache = ref < Record < string , string > > ({})
2026-05-23 18:44:57 +08:00
/**
* Purpose: imageUrls supports ProductListView.vue by holding or executing the image urls page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-03-27 14:55:41 +08:00
const imageUrls = ref < Record < string , string [] > > ({})
2026-05-18 09:46:11 +08:00
/** cartProductIdSet is a reactive state variable used by the template and event handlers. */
2026-05-13 12:43:01 +08:00
const cartProductIdSet = ref ( new Set < string >())
2026-05-23 18:44:57 +08:00
/**
* Purpose: useGlobalLoadingForNextRouteSync supports ProductListView.vue by holding or executing the use global loading for next route sync page or API role.
* Usage: import, call, read, or update this let from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-05-13 12:43:01 +08:00
let useGlobalLoadingForNextRouteSync = false
2026-02-26 11:16:24 +08:00
2026-05-18 09:46:11 +08:00
/** isLoggedIn is a reactive state variable used by the template and event handlers. */
2026-03-26 10:28:28 +08:00
const isLoggedIn = computed (() => Boolean ( localStorage . getItem ( 'accessToken' ) || sessionStorage . getItem ( 'accessToken' )))
2026-05-18 09:46:11 +08:00
/** activeBannerText is a reactive state variable used by the template and event handlers. */
2026-03-26 10:28:28 +08:00
const activeBannerText = computed (() => {
if ( searchKeyword . value . trim ()) {
2026-05-13 12:43:01 +08:00
return `当前显示“ ${ searchKeyword . value . trim () } ”的匹配结果`
2026-03-26 10:28:28 +08:00
}
if ( selectedCategory . value !== '全部' ) {
2026-05-23 21:56:18 +08:00
return `当前按场景“ ${ selectedCategory . value } ”筛选`
2026-03-26 10:28:28 +08:00
}
return ''
})
2026-05-23 18:44:57 +08:00
/**
* Purpose: DEFAULT_PRODUCT_IMAGE supports ProductListView.vue by holding or executing the default product image page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-03-26 10:28:28 +08:00
const DEFAULT_PRODUCT_IMAGE = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCBmaWxsPSIjZjVmNWY1IiB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIvPjx0ZXh0IHg9IjUwJSIgeT0iNTAlIiBmaWxsPSIjYmZiZmJmIiBmb250LXNpemU9IjI0IiB0ZXh0LWFuY2hvcj0ibWlkZGxlIiBkeT0iLjNlbSI+YWFhPC90ZXh0Pjwvc3ZnPg=='
2026-05-18 09:46:11 +08:00
/** ensureLoginForAction is a local helper used by this page script. */
2026-03-26 10:28:28 +08:00
const ensureLoginForAction = ( actionText : string ) => {
if ( isLoggedIn . value ) {
return true
}
message . info ( ` ${ actionText } 前请先登录账号` )
router . push ( '/' )
return false
}
2026-05-18 09:46:11 +08:00
/** loadImageUrls is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-03-26 10:28:28 +08:00
const loadImageUrls = async ( productList : ProductVO []) => {
for ( const product of productList ) {
if ( ! product . imageFileIds ) {
2026-03-27 14:55:41 +08:00
imageUrls . value [ String ( product . id )] = [ DEFAULT_PRODUCT_IMAGE ]
2026-03-26 10:28:28 +08:00
continue
}
const ids = product . imageFileIds . split ( ',' ). map ( id => id . trim ()). filter ( Boolean )
const urls : string [] = []
for ( const id of ids ) {
try {
if ( ! imageIdCache . value [ id ]) {
2026-03-27 14:55:41 +08:00
imageIdCache . value [ id ] = await fileApi . getSignedUrl ( id ) as unknown as string
2026-03-26 10:28:28 +08:00
}
if ( imageIdCache . value [ id ]) {
urls . push ( imageIdCache . value [ id ])
}
} catch ( error ) {
console . error ( '获取作品图片失败:' , error )
}
}
2026-03-27 14:55:41 +08:00
imageUrls . value [ String ( product . id )] = urls . length ? urls : [ DEFAULT_PRODUCT_IMAGE ]
2026-03-26 10:28:28 +08:00
}
}
2026-05-18 09:46:11 +08:00
/** getProductImages is a local helper used by this page script. */
2026-03-27 14:55:41 +08:00
const getProductImages = ( product : ProductVO ) : string [] => imageUrls . value [ String ( product . id )] || [ DEFAULT_PRODUCT_IMAGE ]
2026-03-26 10:28:28 +08:00
2026-05-18 09:46:11 +08:00
/** markProductsInCart is a local helper used by this page script. */
2026-05-13 12:43:01 +08:00
const markProductsInCart = ( productList : ProductVO []) => {
return ( Array . isArray ( productList ) ? productList : []). map ( item => ({
... item ,
inCart : hasCartProduct ( cartProductIdSet . value , item . id )
}))
}
2026-05-18 09:46:11 +08:00
/** syncCartProductState is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-05-13 12:43:01 +08:00
const syncCartProductState = async () => {
if ( ! isLoggedIn . value ) {
cartProductIdSet . value = new Set ()
return
}
cartProductIdSet . value = await fetchCartProductIdSet ()
}
2026-05-18 09:46:11 +08:00
/** fetchTags is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-02-24 09:59:22 +08:00
const fetchTags = async () => {
try {
2026-05-23 21:56:18 +08:00
const response = await tagApi . getFilterOptions () as unknown as TagFilterGroupVO []
filterGroups . value = Array . isArray ( response ) ? response : []
2026-05-13 12:43:01 +08:00
} catch ( error : any ) {
2026-02-24 09:59:22 +08:00
console . error ( '获取标签失败:' , error )
2026-05-23 21:56:18 +08:00
filterGroups . value = []
2026-02-24 09:59:22 +08:00
}
}
2026-05-18 09:46:11 +08:00
/** fetchProducts is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-02-24 09:59:22 +08:00
const fetchProducts = async () => {
loading . value = true
try {
2026-03-26 10:28:28 +08:00
let response : ProductVO [] = []
const keyword = searchKeyword . value . trim ()
if ( keyword ) {
response = await productApi . searchProducts ( keyword )
2026-05-23 21:56:18 +08:00
} else if ( ! selectedTagId . value ) {
2026-03-26 10:28:28 +08:00
response = await productApi . getAllProducts ()
2026-02-24 09:59:22 +08:00
} else {
2026-05-23 21:56:18 +08:00
const pageResult = await productApi . getProductPage ({
page : 1 ,
size : 200 ,
tagIds : selectedTagId . value
})
response = pageResult . list || []
2026-02-24 09:59:22 +08:00
}
2026-03-26 10:28:28 +08:00
2026-05-13 12:43:01 +08:00
products . value = markProductsInCart ( Array . isArray ( response ) ? response : [])
2026-03-03 17:50:10 +08:00
await loadImageUrls ( products . value )
2026-05-13 12:43:01 +08:00
} catch ( error : any ) {
2026-03-26 10:28:28 +08:00
console . error ( '获取作品列表失败:' , error )
2026-05-13 12:43:01 +08:00
message . error ( error ? . message || '加载作品列表失败,请稍后重试' )
2026-03-26 10:28:28 +08:00
products . value = []
2026-02-24 09:59:22 +08:00
} finally {
loading . value = false
}
2026-02-26 11:16:24 +08:00
}
2026-05-18 09:46:11 +08:00
/** syncRouteFilters is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-03-26 10:28:28 +08:00
const syncRouteFilters = async () => {
2026-05-13 12:43:01 +08:00
await syncCartProductState ()
2026-03-26 10:28:28 +08:00
const keyword = typeof route . query . keyword === 'string' ? route . query . keyword . trim () : ''
const tag = typeof route . query . tag === 'string' ? route . query . tag . trim () : ''
2026-05-23 21:56:18 +08:00
const tagId = typeof route . query . tagId === 'string' ? route . query . tagId . trim () : ''
const matchedTag = tagId
? allTags . value . find ( item => String ( item . id ) === tagId )
: allTags . value . find ( item => item . tagName === tag || item . displayName === tag )
2026-02-26 11:16:24 +08:00
2026-03-26 10:28:28 +08:00
searchKeyword . value = keyword
showSearch . value = Boolean ( keyword )
2026-05-23 21:56:18 +08:00
selectedTagId . value = matchedTag ? String ( matchedTag . id ) : ''
selectedCategory . value = matchedTag ? ( matchedTag . displayName || matchedTag . tagName ) : '全部'
2026-05-13 12:43:01 +08:00
if ( useGlobalLoadingForNextRouteSync ) {
useGlobalLoadingForNextRouteSync = false
await runWithGlobalLoading (() => fetchProducts ())
return
}
2026-03-26 10:28:28 +08:00
await fetchProducts ()
}
2026-02-24 09:59:22 +08:00
2026-05-18 09:46:11 +08:00
/** handleBackClick is a local helper used by this page script. */
2026-02-13 17:34:32 +08:00
const handleBackClick = () => {
2026-03-26 10:28:28 +08:00
router . push ( '/home' )
2026-02-13 17:34:32 +08:00
}
2026-05-18 09:46:11 +08:00
/** handleCategoryClick is a local helper used by this page script. */
2026-02-13 17:34:32 +08:00
const handleCategoryClick = ( category : string ) => {
selectedCategory . value = category
2026-05-23 21:56:18 +08:00
selectedTagId . value = ''
searchKeyword . value = ''
showSearch . value = false
useGlobalLoadingForNextRouteSync = true
router . replace ({ path : '/products' , query : {} })
}
/** handleTagClick is a local helper used by grouped scene-filter chips. */
const handleTagClick = ( tag : TagVO ) => {
selectedCategory . value = tag . displayName || tag . tagName
selectedTagId . value = String ( tag . id )
2026-03-05 16:02:34 +08:00
searchKeyword . value = ''
2026-03-26 10:28:28 +08:00
showSearch . value = false
2026-05-13 12:43:01 +08:00
useGlobalLoadingForNextRouteSync = true
2026-03-26 10:28:28 +08:00
router . replace ({
path : '/products' ,
2026-05-23 21:56:18 +08:00
query : { tag : tag . displayName || tag . tagName , tagId : String ( tag . id ) }
2026-03-26 10:28:28 +08:00
})
2026-02-13 17:34:32 +08:00
}
2026-05-18 09:46:11 +08:00
/** handleProductClick is a local helper used by this page script. */
2026-03-26 10:28:28 +08:00
const handleProductClick = ( item : ProductVO ) => {
2026-02-13 17:34:32 +08:00
router . push ( `/product/ ${ item . id } ` )
}
2026-05-18 09:46:11 +08:00
/** handleAddToCart is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
2026-05-13 12:43:01 +08:00
const handleAddToCart = async ( item : ProductListItem ) => {
2026-03-26 10:28:28 +08:00
if ( ! ensureLoginForAction ( '加入购物车' )) {
return
}
2026-05-13 12:43:01 +08:00
if ( hasCartProduct ( cartProductIdSet . value , item . id )) {
message . info ( '购物车已有' )
return
}
2026-02-27 15:57:22 +08:00
try {
2026-05-13 12:43:01 +08:00
await runWithGlobalLoading (() => cartApi . addToCart ({ productId : item . id , quantity : 1 }))
cartProductIdSet . value = withAddedCartProduct ( cartProductIdSet . value , item . id )
products . value = markProductsInCart ( products . value )
2026-03-19 20:51:07 +08:00
await updateCartCount ()
2026-03-26 10:28:28 +08:00
message . success ( `已将 ${ item . title || item . name || '作品' } 加入购物车` )
2026-05-13 12:43:01 +08:00
} catch ( error : any ) {
2026-03-26 10:28:28 +08:00
console . error ( '加入购物车失败:' , error )
2026-05-13 12:43:01 +08:00
message . error ( error ? . message || '加入购物车失败,请稍后重试' )
2026-02-27 15:57:22 +08:00
}
2026-02-13 17:34:32 +08:00
}
2026-05-18 09:46:11 +08:00
/** handleSearch is a local helper used by this page script. */
2026-03-26 10:28:28 +08:00
const handleSearch = () => {
const keyword = searchKeyword . value . trim ()
2026-05-13 12:43:01 +08:00
useGlobalLoadingForNextRouteSync = true
2026-03-26 10:28:28 +08:00
router . replace ({
path : '/products' ,
query : keyword ? { keyword } : {}
})
2026-02-13 17:34:32 +08:00
}
2026-02-24 09:59:22 +08:00
2026-05-18 09:46:11 +08:00
/** toggleSearch is a local helper used by this page script. */
2026-03-05 16:02:34 +08:00
const toggleSearch = () => {
showSearch . value = ! showSearch . value
if ( ! showSearch . value ) {
searchKeyword . value = ''
2026-05-13 12:43:01 +08:00
useGlobalLoadingForNextRouteSync = true
2026-05-23 21:56:18 +08:00
router . replace ({
path : '/products' ,
query : selectedTagId . value ? { tag : selectedCategory . value , tagId : selectedTagId . value } : {}
})
2026-03-05 16:02:34 +08:00
}
}
2026-05-18 09:46:11 +08:00
/** resetFilters is a local helper used by this page script. */
2026-03-26 10:28:28 +08:00
const resetFilters = () => {
selectedCategory . value = '全部'
2026-05-23 21:56:18 +08:00
selectedTagId . value = ''
2026-03-26 10:28:28 +08:00
searchKeyword . value = ''
showSearch . value = false
2026-05-13 12:43:01 +08:00
useGlobalLoadingForNextRouteSync = true
2026-03-26 10:28:28 +08:00
router . replace ( '/products' )
2026-03-05 16:02:34 +08:00
}
2026-03-26 10:28:28 +08:00
watch (
() => route . query ,
async () => {
await syncRouteFilters ()
},
{ deep : true }
)
2026-02-24 11:34:25 +08:00
onMounted ( async () => {
await fetchTags ()
2026-03-26 10:28:28 +08:00
await syncRouteFilters ()
2026-02-24 09:59:22 +08:00
})
2026-02-13 17:34:32 +08:00
</ script >
< style scoped >
. mobile - container {
2026-05-21 18:43:59 +08:00
padding - top : 58 px ;
2026-02-13 17:34:32 +08:00
min - height : 100 vh ;
2026-05-21 18:43:59 +08:00
color : var ( -- text - primary );
background :
linear - gradient ( rgba ( 255 , 255 , 255 , 0.68 ), rgba ( 255 , 255 , 255 , 0.92 )),
var ( -- theme - background - image ),
var ( -- theme - page - bg );
background - size : cover , cover , auto ;
background - position : center top ;
2026-02-13 17:34:32 +08:00
}
. header {
position : fixed ;
top : 0 ;
left : 0 ;
right : 0 ;
z - index : 100 ;
display : flex ;
justify - content : space - between ;
align - items : center ;
2026-05-21 18:43:59 +08:00
gap : 12 px ;
height : 58 px ;
padding : 9 px 15 px ;
border - bottom : 1 px solid var ( -- theme - border );
background : rgba ( 255 , 255 , 255 , 0.94 );
background : color - mix ( in srgb , var ( -- theme - card - bg ) 92 % , transparent );
box - shadow : 0 10 px 28 px rgba ( 122 , 67 , 88 , 0.08 );
backdrop - filter : blur ( 16 px );
2026-02-13 17:34:32 +08:00
}
. header h1 {
margin : 0 ;
2026-03-26 10:28:28 +08:00
font - size : 18 px ;
font - weight : 700 ;
2026-05-21 18:43:59 +08:00
color : var ( -- text - primary );
letter - spacing : 0 ;
2026-02-13 17:34:32 +08:00
}
. back - btn ,
. search - btn {
width : 40 px ;
height : 40 px ;
display : flex ;
align - items : center ;
justify - content : center ;
2026-05-21 18:43:59 +08:00
border - radius : 999 px ;
color : var ( -- theme - primary );
background : var ( -- theme - primary - soft );
}
. back - btn : hover ,
. search - btn : hover ,
. back - btn : focus ,
. search - btn : focus {
color : var ( -- theme - accent );
background : var ( -- theme - primary - soft );
2026-02-13 17:34:32 +08:00
}
2026-03-05 16:02:34 +08:00
. search - input - container {
flex : 1 ;
2026-05-21 18:43:59 +08:00
margin : 0 ;
}
. search - input : deep (. ant - input ),
. search - input : deep (. ant - input - group - addon . ant - btn ) {
height : 38 px ;
}
. search - input : deep (. ant - input ) {
border - color : var ( -- theme - border );
color : var ( -- text - primary );
}
. search - input : deep (. ant - input : hover ),
. search - input : deep (. ant - input : focus ) {
border - color : var ( -- theme - primary );
box - shadow : var ( -- theme - focus - shadow );
}
. search - input : deep (. ant - input - group - addon . ant - btn ) {
border - color : var ( -- theme - primary );
background : var ( -- theme - gradient );
box - shadow : none ;
2026-03-05 16:02:34 +08:00
}
2026-02-13 17:34:32 +08:00
. main - content {
display : flex ;
2026-05-21 18:43:59 +08:00
flex - direction : column ;
min - height : calc ( 100 vh - 58 px );
2026-02-13 17:34:32 +08:00
}
. category - sidebar {
2026-05-21 18:43:59 +08:00
position : sticky ;
top : 58 px ;
z - index : 20 ;
display : flex ;
gap : 8 px ;
width : 100 % ;
padding : 10 px 14 px 11 px ;
overflow - x : auto ;
overflow - y : hidden ;
background : rgba ( 255 , 255 , 255 , 0.88 );
background : color - mix ( in srgb , var ( -- theme - card - bg ) 86 % , transparent );
border - bottom : 1 px solid var ( -- theme - border );
box - shadow : 0 8 px 22 px rgba ( 122 , 67 , 88 , 0.06 );
backdrop - filter : blur ( 16 px );
scrollbar - width : none ;
}
. category - sidebar ::- webkit - scrollbar {
display : none ;
2026-02-13 17:34:32 +08:00
}
. category - item {
2026-05-21 18:43:59 +08:00
flex : 0 0 auto ;
padding : 8 px 15 px ;
border - radius : 999 px ;
2026-02-13 17:34:32 +08:00
font - size : 13 px ;
2026-05-21 18:43:59 +08:00
font - weight : 600 ;
color : var ( -- theme - accent );
2026-02-13 17:34:32 +08:00
text - align : center ;
cursor : pointer ;
2026-03-26 10:28:28 +08:00
transition : all 0.2 s ease ;
2026-05-21 18:43:59 +08:00
background : var ( -- theme - primary - soft );
border : 1 px solid var ( -- theme - border );
}
2026-05-23 21:56:18 +08:00
. filter - group {
display : inline - flex ;
flex : 0 0 auto ;
align - items : center ;
gap : 8 px ;
}
. filter - group__title {
flex : 0 0 auto ;
color : var ( -- text - secondary );
font - size : 12 px ;
font - weight : 700 ;
}
2026-05-21 18:43:59 +08:00
. category - item : hover {
color : var ( -- theme - primary );
border - color : var ( -- theme - primary );
transform : translateY ( - 1 px );
2026-02-13 17:34:32 +08:00
}
. category - item . active {
2026-05-21 18:43:59 +08:00
color : # ffffff ;
background : var ( -- theme - gradient );
border - color : transparent ;
2026-03-26 10:28:28 +08:00
font - weight : 700 ;
2026-05-21 18:43:59 +08:00
box - shadow : var ( -- theme - button - shadow );
2026-02-13 17:34:32 +08:00
}
. product - section {
flex : 1 ;
2026-03-26 10:28:28 +08:00
padding : 16 px ;
2026-02-13 17:34:32 +08:00
overflow - y : auto ;
2026-03-26 10:28:28 +08:00
}
. page - banner {
margin - bottom : 16 px ;
border - radius : 14 px ;
2026-02-13 17:34:32 +08:00
}
. product - grid {
display : grid ;
2026-03-26 10:28:28 +08:00
grid - template - columns : repeat ( 2 , minmax ( 0 , 1 fr ));
gap : 14 px ;
2026-02-13 17:34:32 +08:00
}
. product - card {
2026-03-26 10:28:28 +08:00
border - radius : 18 px ;
2026-02-13 17:34:32 +08:00
}
. product - img {
width : 100 % ;
aspect - ratio : 1 ;
2026-02-24 09:59:22 +08:00
overflow : hidden ;
2026-03-26 10:28:28 +08:00
border - radius : 14 px ;
2026-05-21 18:43:59 +08:00
background : var ( -- theme - primary - soft );
2026-02-24 09:59:22 +08:00
}
. product - image {
width : 100 % ;
height : 100 % ;
object - fit : cover ;
}
. product - img - placeholder {
width : 100 % ;
height : 100 % ;
2026-02-13 17:34:32 +08:00
display : flex ;
align - items : center ;
2026-03-26 10:28:28 +08:00
justify - content : center ;
2026-02-13 17:34:32 +08:00
font - size : 40 px ;
2026-03-26 10:28:28 +08:00
font - weight : 700 ;
color : rgba ( 0 , 0 , 0 , 0.18 );
2026-02-13 17:34:32 +08:00
}
. name {
2026-03-26 10:28:28 +08:00
margin : 12 px 0 6 px ;
2026-02-13 17:34:32 +08:00
font - size : 14 px ;
2026-03-26 10:28:28 +08:00
font - weight : 700 ;
color : # 1 f1f1f ;
2026-02-13 17:34:32 +08:00
white - space : nowrap ;
overflow : hidden ;
text - overflow : ellipsis ;
}
2026-05-21 18:43:59 +08:00
. back - btn {
opacity : 0 ;
pointer - events : none ;
}
2026-05-18 09:46:11 +08:00
. shop - name {
margin : 0 0 6 px ;
font - size : 12 px ;
2026-05-21 18:43:59 +08:00
color : var ( -- text - secondary );
2026-05-18 09:46:11 +08:00
white - space : nowrap ;
overflow : hidden ;
text - overflow : ellipsis ;
}
2026-02-24 09:59:22 +08:00
. product - meta {
display : flex ;
justify - content : space - between ;
2026-03-26 10:28:28 +08:00
gap : 8 px ;
font - size : 12 px ;
color : # 8 b8b9a ;
2026-02-24 09:59:22 +08:00
}
. duration {
2026-03-26 10:28:28 +08:00
display : inline - flex ;
align - items : center ;
2026-02-24 09:59:22 +08:00
padding : 2 px 8 px ;
2026-03-26 10:28:28 +08:00
border - radius : 999 px ;
2026-05-21 18:43:59 +08:00
background : var ( -- theme - primary - soft );
2026-02-24 09:59:22 +08:00
}
. stats {
display : flex ;
gap : 8 px ;
}
2026-03-26 10:28:28 +08:00
. product - tags {
margin : 10 px 0 ;
min - height : 26 px ;
2026-02-24 09:59:22 +08:00
}
2026-02-13 17:34:32 +08:00
. price - row {
display : flex ;
justify - content : space - between ;
align - items : center ;
2026-05-13 12:43:01 +08:00
gap : 12 px ;
2026-02-13 17:34:32 +08:00
}
. price {
margin : 0 ;
2026-03-26 10:28:28 +08:00
font - size : 18 px ;
font - weight : 700 ;
2026-05-21 18:43:59 +08:00
color : var ( -- theme - accent );
2026-02-13 17:34:32 +08:00
}
2026-05-13 12:43:01 +08:00
. cart - action {
display : inline - flex ;
align - items : center ;
justify - content : flex - end ;
gap : 8 px ;
}
. cart - note {
font - size : 12 px ;
color : # 8 c8c8c ;
white - space : nowrap ;
}
. cart - btn {
flex - shrink : 0 ;
}
. cart - btn - in - cart {
2026-05-21 18:43:59 +08:00
color : var ( -- theme - primary );
border - color : var ( -- theme - border );
background : var ( -- theme - primary - soft );
2026-05-13 12:43:01 +08:00
}
2026-03-26 10:28:28 +08:00
. empty - state ,
. loading - state {
padding : 56 px 0 ;
2026-02-24 09:59:22 +08:00
}
2026-03-24 09:50:55 +08:00
2026-03-24 09:59:52 +08:00
@ media ( min - width : 992 px ) {
. main - content {
2026-03-26 10:28:28 +08:00
max - width : var ( -- frontend - content - max - width );
margin : 0 auto ;
width : 100 % ;
2026-03-24 09:59:52 +08:00
}
. category - sidebar {
2026-05-21 18:43:59 +08:00
width : 100 % ;
border - radius : 0 ;
2026-03-24 09:59:52 +08:00
}
. product - section {
padding : 24 px ;
}
. product - grid {
grid - template - columns : repeat ( 4 , minmax ( 0 , 1 fr ));
2026-03-24 09:50:55 +08:00
}
}
2026-03-19 20:51:07 +08:00
</ style >