功能:完善门店能力与用户安全配置

This commit is contained in:
xiaowang
2026-05-18 10:04:57 +08:00
parent 4563dd2538
commit 3797938616
356 changed files with 24983 additions and 1858 deletions
@@ -64,6 +64,7 @@
<div class="product-info">
<p class="name">{{ item.title || item.name }}</p>
<p v-if="item.shopName" class="shop-name">所属店铺:{{ item.shopName }}</p>
<div class="product-meta">
<span class="duration">{{ item.approximateDuration || '时长待定' }}</span>
<div class="stats">
@@ -128,6 +129,10 @@
</template>
<script setup lang="ts">
/**
* 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.
*/
import { onMounted, ref, watch, inject, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { CheckOutlined, LeftOutlined, SearchOutlined, ShoppingCartOutlined } from '@ant-design/icons-vue'
@@ -149,17 +154,24 @@ const updateCartCount = inject<() => Promise<void>>('updateCartCount', async ()
const allTags = ref<TagVO[]>([])
const categories = ref<string[]>(['全部'])
/** selectedCategory is a reactive state variable used by the template and event handlers. */
const selectedCategory = ref('全部')
const products = ref<ProductListItem[]>([])
/** loading is a reactive state variable used by the template and event handlers. */
const loading = ref(false)
/** showSearch is a reactive state variable used by the template and event handlers. */
const showSearch = ref(false)
/** searchKeyword is a reactive state variable used by the template and event handlers. */
const searchKeyword = ref('')
const imageIdCache = ref<Record<string, string>>({})
const imageUrls = ref<Record<string, string[]>>({})
/** cartProductIdSet is a reactive state variable used by the template and event handlers. */
const cartProductIdSet = ref(new Set<string>())
let useGlobalLoadingForNextRouteSync = false
/** isLoggedIn is a reactive state variable used by the template and event handlers. */
const isLoggedIn = computed(() => Boolean(localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')))
/** activeBannerText is a reactive state variable used by the template and event handlers. */
const activeBannerText = computed(() => {
if (searchKeyword.value.trim()) {
return `当前显示“${searchKeyword.value.trim()}”的匹配结果`
@@ -172,6 +184,7 @@ const activeBannerText = computed(() => {
const DEFAULT_PRODUCT_IMAGE = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCBmaWxsPSIjZjVmNWY1IiB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIvPjx0ZXh0IHg9IjUwJSIgeT0iNTAlIiBmaWxsPSIjYmZiZmJmIiBmb250LXNpemU9IjI0IiB0ZXh0LWFuY2hvcj0ibWlkZGxlIiBkeT0iLjNlbSI+YWFhPC90ZXh0Pjwvc3ZnPg=='
/** ensureLoginForAction is a local helper used by this page script. */
const ensureLoginForAction = (actionText: string) => {
if (isLoggedIn.value) {
return true
@@ -181,6 +194,7 @@ const ensureLoginForAction = (actionText: string) => {
return false
}
/** loadImageUrls is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadImageUrls = async (productList: ProductVO[]) => {
for (const product of productList) {
if (!product.imageFileIds) {
@@ -208,8 +222,10 @@ const loadImageUrls = async (productList: ProductVO[]) => {
}
}
/** getProductImages is a local helper used by this page script. */
const getProductImages = (product: ProductVO): string[] => imageUrls.value[String(product.id)] || [DEFAULT_PRODUCT_IMAGE]
/** markProductsInCart is a local helper used by this page script. */
const markProductsInCart = (productList: ProductVO[]) => {
return (Array.isArray(productList) ? productList : []).map(item => ({
...item,
@@ -217,6 +233,7 @@ const markProductsInCart = (productList: ProductVO[]) => {
}))
}
/** syncCartProductState is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const syncCartProductState = async () => {
if (!isLoggedIn.value) {
cartProductIdSet.value = new Set()
@@ -225,6 +242,7 @@ const syncCartProductState = async () => {
cartProductIdSet.value = await fetchCartProductIdSet()
}
/** 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[]
@@ -236,6 +254,7 @@ const fetchTags = async () => {
}
}
/** fetchProducts is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const fetchProducts = async () => {
loading.value = true
try {
@@ -261,6 +280,7 @@ const fetchProducts = async () => {
}
}
/** syncRouteFilters is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const syncRouteFilters = async () => {
await syncCartProductState()
const keyword = typeof route.query.keyword === 'string' ? route.query.keyword.trim() : ''
@@ -277,10 +297,12 @@ const syncRouteFilters = async () => {
await fetchProducts()
}
/** handleBackClick is a local helper used by this page script. */
const handleBackClick = () => {
router.push('/home')
}
/** handleCategoryClick is a local helper used by this page script. */
const handleCategoryClick = (category: string) => {
selectedCategory.value = category
searchKeyword.value = ''
@@ -292,10 +314,12 @@ const handleCategoryClick = (category: string) => {
})
}
/** handleProductClick is a local helper used by this page script. */
const handleProductClick = (item: ProductVO) => {
router.push(`/product/${item.id}`)
}
/** handleAddToCart is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleAddToCart = async (item: ProductListItem) => {
if (!ensureLoginForAction('加入购物车')) {
return
@@ -316,6 +340,7 @@ const handleAddToCart = async (item: ProductListItem) => {
}
}
/** handleSearch is a local helper used by this page script. */
const handleSearch = () => {
const keyword = searchKeyword.value.trim()
useGlobalLoadingForNextRouteSync = true
@@ -325,6 +350,7 @@ const handleSearch = () => {
})
}
/** toggleSearch is a local helper used by this page script. */
const toggleSearch = () => {
showSearch.value = !showSearch.value
if (!showSearch.value) {
@@ -334,6 +360,7 @@ const toggleSearch = () => {
}
}
/** resetFilters is a local helper used by this page script. */
const resetFilters = () => {
selectedCategory.value = '全部'
searchKeyword.value = ''
@@ -483,6 +510,15 @@ onMounted(async () => {
text-overflow: ellipsis;
}
.shop-name {
margin: 0 0 6px;
font-size: 12px;
color: #7a5262;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.product-meta {
display: flex;
justify-content: space-between;