商品收藏功能
This commit is contained in:
@@ -6,8 +6,17 @@
|
||||
<a-button class="back-btn" type="text" @click="handleBackClick">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>商品列表</h1>
|
||||
<a-button class="search-btn" type="text">
|
||||
<h1 v-if="!showSearch">商品列表</h1>
|
||||
<div v-else class="search-input-container">
|
||||
<a-input-search
|
||||
v-model:value="searchKeyword"
|
||||
placeholder="搜索商品"
|
||||
class="search-input"
|
||||
@search="handleSearch"
|
||||
enter-button
|
||||
/>
|
||||
</div>
|
||||
<a-button class="search-btn" type="text" @click="toggleSearch">
|
||||
<SearchOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
</header>
|
||||
@@ -195,6 +204,11 @@ const hasMore = ref(true)
|
||||
// 加载状态
|
||||
const loading = ref(false)
|
||||
|
||||
// 搜索相关状态
|
||||
const showSearch = ref(false)
|
||||
const searchKeyword = ref('')
|
||||
const isSearching = ref(false)
|
||||
|
||||
// 图片ID缓存
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
const imageUrls = ref<Record<number, string[]>>({})
|
||||
@@ -280,7 +294,9 @@ const handleBackClick = () => {
|
||||
// 处理分类点击
|
||||
const handleCategoryClick = (category: string) => {
|
||||
selectedCategory.value = category
|
||||
// 这里可以添加筛选逻辑
|
||||
showSearch.value = false
|
||||
searchKeyword.value = ''
|
||||
isSearching.value = false
|
||||
fetchProducts()
|
||||
}
|
||||
|
||||
@@ -305,6 +321,37 @@ const handleLoadMore = () => {
|
||||
hasMore.value = false
|
||||
}
|
||||
|
||||
// 切换搜索框显示/隐藏
|
||||
const toggleSearch = () => {
|
||||
showSearch.value = !showSearch.value
|
||||
if (!showSearch.value) {
|
||||
searchKeyword.value = ''
|
||||
isSearching.value = false
|
||||
fetchProducts() // 重置为默认商品列表
|
||||
}
|
||||
}
|
||||
|
||||
// 处理搜索操作
|
||||
const handleSearch = async () => {
|
||||
if (!searchKeyword.value.trim()) {
|
||||
message.info('请输入搜索关键词')
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const response = await productApi.searchProducts(searchKeyword.value.trim()) as any
|
||||
products.value = response || []
|
||||
await loadImageUrls(products.value)
|
||||
hasMore.value = false
|
||||
isSearching.value = true
|
||||
} catch (error) {
|
||||
message.error('搜索失败,请重试')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 页面挂载时获取标签和商品数据
|
||||
onMounted(async () => {
|
||||
await fetchTags()
|
||||
@@ -349,6 +396,15 @@ onMounted(async () => {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.search-input-container {
|
||||
flex: 1;
|
||||
margin: 0 10px;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* 主内容区域 */
|
||||
.main-content {
|
||||
display: flex;
|
||||
|
||||
Reference in New Issue
Block a user