功能(网页):新增客户体验流程

This commit is contained in:
xiaowang
2026-05-23 21:56:18 +08:00
parent c2c985b2f8
commit 861eea933b
28 changed files with 2236 additions and 108 deletions
+73 -27
View File
@@ -21,14 +21,26 @@
<div class="main-content">
<div class="category-sidebar">
<div
v-for="category in categories"
:key="category"
<button
class="category-item"
:class="{ active: selectedCategory === category }"
@click="handleCategoryClick(category)"
:class="{ active: selectedCategory === '全部' }"
type="button"
@click="handleCategoryClick('全部')"
>
{{ category }}
全部
</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>
</div>
</div>
@@ -146,7 +158,7 @@ import { productApi, type ProductVO } from '@/api/product'
* 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.
*/
import { tagApi, type TagVO } from '@/api/tag'
import { tagApi, type TagFilterGroupVO, type TagVO } from '@/api/tag'
import { cartApi } from '@/api/cart'
import { fileApi } from '@/api/file'
import { runWithGlobalLoading } from '@/utils/action-loading'
@@ -176,18 +188,14 @@ const route = useRoute()
*/
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
/**
* Purpose: allTags supports ProductListView.vue by holding or executing the all tags 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.
*/
const allTags = ref<TagVO[]>([])
/**
* Purpose: categories supports ProductListView.vue by holding or executing the categories 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.
*/
const categories = ref<string[]>(['全部'])
/** 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 || []))
/** selectedCategory is a reactive state variable used by the template and event handlers. */
const selectedCategory = ref('全部')
/** selectedTagId tracks the grouped filter id sent to the backend. */
const selectedTagId = ref('')
/**
* 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.
@@ -225,7 +233,7 @@ const activeBannerText = computed(() => {
return `当前显示“${searchKeyword.value.trim()}”的匹配结果`
}
if (selectedCategory.value !== '全部') {
return `当前按标签“${selectedCategory.value}”筛选`
return `当前按场景“${selectedCategory.value}”筛选`
}
return ''
})
@@ -297,12 +305,11 @@ const syncCartProductState = async () => {
/** fetchTags is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const fetchTags = async () => {
try {
const response = await tagApi.getAllTags() as unknown as TagVO[]
allTags.value = Array.isArray(response) ? response : []
categories.value = ['全部', ...allTags.value.map(tag => tag.tagName)]
const response = await tagApi.getFilterOptions() as unknown as TagFilterGroupVO[]
filterGroups.value = Array.isArray(response) ? response : []
} catch (error: any) {
console.error('获取标签失败:', error)
categories.value = ['全部']
filterGroups.value = []
}
}
@@ -315,10 +322,15 @@ const fetchProducts = async () => {
if (keyword) {
response = await productApi.searchProducts(keyword)
} else if (selectedCategory.value === '全部') {
} else if (!selectedTagId.value) {
response = await productApi.getAllProducts()
} else {
response = await productApi.getProductsByTag(selectedCategory.value)
const pageResult = await productApi.getProductPage({
page: 1,
size: 200,
tagIds: selectedTagId.value
})
response = pageResult.list || []
}
products.value = markProductsInCart(Array.isArray(response) ? response : [])
@@ -337,10 +349,15 @@ const syncRouteFilters = async () => {
await syncCartProductState()
const keyword = typeof route.query.keyword === 'string' ? route.query.keyword.trim() : ''
const tag = typeof route.query.tag === 'string' ? route.query.tag.trim() : ''
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)
searchKeyword.value = keyword
showSearch.value = Boolean(keyword)
selectedCategory.value = tag && categories.value.includes(tag) ? tag : '全部'
selectedTagId.value = matchedTag ? String(matchedTag.id) : ''
selectedCategory.value = matchedTag ? (matchedTag.displayName || matchedTag.tagName) : '全部'
if (useGlobalLoadingForNextRouteSync) {
useGlobalLoadingForNextRouteSync = false
await runWithGlobalLoading(() => fetchProducts())
@@ -357,12 +374,23 @@ const handleBackClick = () => {
/** handleCategoryClick is a local helper used by this page script. */
const handleCategoryClick = (category: string) => {
selectedCategory.value = category
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)
searchKeyword.value = ''
showSearch.value = false
useGlobalLoadingForNextRouteSync = true
router.replace({
path: '/products',
query: category === '全部' ? {} : { tag: category }
query: { tag: tag.displayName || tag.tagName, tagId: String(tag.id) }
})
}
@@ -408,13 +436,17 @@ const toggleSearch = () => {
if (!showSearch.value) {
searchKeyword.value = ''
useGlobalLoadingForNextRouteSync = true
router.replace({ path: '/products', query: selectedCategory.value === '全部' ? {} : { tag: selectedCategory.value } })
router.replace({
path: '/products',
query: selectedTagId.value ? { tag: selectedCategory.value, tagId: selectedTagId.value } : {}
})
}
}
/** resetFilters is a local helper used by this page script. */
const resetFilters = () => {
selectedCategory.value = '全部'
selectedTagId.value = ''
searchKeyword.value = ''
showSearch.value = false
useGlobalLoadingForNextRouteSync = true
@@ -564,6 +596,20 @@ onMounted(async () => {
border: 1px solid var(--theme-border);
}
.filter-group {
display: inline-flex;
flex: 0 0 auto;
align-items: center;
gap: 8px;
}
.filter-group__title {
flex: 0 0 auto;
color: var(--text-secondary);
font-size: 12px;
font-weight: 700;
}
.category-item:hover {
color: var(--theme-primary);
border-color: var(--theme-primary);