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

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
+83 -1
View File
@@ -26,6 +26,14 @@
/>
</div>
<div v-if="announcements.length" class="announcement-bar">
<div class="announcement-track">
<span v-for="item in announcementLoop" :key="`${item.id}-${item.loopKey}`">
<b>{{ item.publisherName || '平台' }}</b>:{{ item.content }}
</span>
</div>
</div>
<a-alert
v-if="!isLoggedIn"
class="guest-alert"
@@ -82,6 +90,7 @@
</div>
<div class="product-info">
<p class="name">{{ item.name }}</p>
<p v-if="item.shopName" class="meta">所属店铺:{{ item.shopName }}</p>
<p class="meta">{{ item.meta }}</p>
<p class="price">¥{{ item.price }}</p>
</div>
@@ -109,6 +118,7 @@
</div>
<div class="product-info">
<p class="name">{{ item.name }}</p>
<p v-if="item.shopName" class="meta">所属店铺:{{ item.shopName }}</p>
<p class="meta">{{ item.meta }}</p>
<p class="price">¥{{ item.price }}</p>
</div>
@@ -130,10 +140,14 @@
</template>
<script setup lang="ts">
/**
* HomeView 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 { computed, onMounted, onUnmounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { message } from 'ant-design-vue'
import { userApi, type UserVO } from '../api/user'
import { userApi, type AnnouncementVO, type UserVO } from '../api/user'
import { productApi, type ProductVO } from '../api/product'
import { shopApi, type ShopVO } from '../api/shop'
import { fileApi } from '../api/file'
@@ -153,6 +167,7 @@ interface ProductCardItem {
name: string
price: string
meta: string
shopName?: string
coverUrl: string
bgColor: string
}
@@ -165,22 +180,34 @@ const bannerImages = ref<BannerImage[]>([])
const featuredItems = ref<ProductCardItem[]>([])
const popularSource = ref<ProductCardItem[]>([])
const popularItems = ref<ProductCardItem[]>([])
const announcements = ref<AnnouncementVO[]>([])
const productImageCache = ref<Record<string, string>>({})
/** searchQuery is a reactive state variable used by the template and event handlers. */
const searchQuery = ref('')
/** loading is a reactive state variable used by the template and event handlers. */
const loading = ref(false)
/** hasMore is a reactive state variable used by the template and event handlers. */
const hasMore = ref(true)
/** page is a reactive state variable used by the template and event handlers. */
const page = ref(1)
const pageSize = 8
/** isLoggedIn is a reactive state variable used by the template and event handlers. */
const isLoggedIn = computed(() => Boolean(localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')))
/** greeting is a reactive state variable used by the template and event handlers. */
const greeting = computed(() => (isLoggedIn.value ? '欢迎回来' : '游客模式'))
/** displayName is a reactive state variable used by the template and event handlers. */
const displayName = computed(() => userInfo.value?.nickname || (isLoggedIn.value ? '用户' : '先看看门店和作品'))
/** announcementLoop is a reactive state variable used by the template and event handlers. */
const announcementLoop = computed(() => [...announcements.value, ...announcements.value].map((item, index) => ({ ...item, loopKey: index })))
/** getRandomColor is a local helper used by this page script. */
const getRandomColor = (): string => {
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
return colors[Math.floor(Math.random() * colors.length)] ?? '#ffe4d6'
}
/** getProductCoverUrl is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const getProductCoverUrl = async (product: ProductVO): Promise<string> => {
const firstImageId = product.imageFileIds?.split(',').map(id => id.trim()).find(Boolean)
if (!firstImageId) {
@@ -197,16 +224,19 @@ const getProductCoverUrl = async (product: ProductVO): Promise<string> => {
return productImageCache.value[firstImageId] || DEFAULT_PRODUCT_IMAGE
}
/** formatProductCards is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const formatProductCards = async (products: ProductVO[]): Promise<ProductCardItem[]> =>
Promise.all(products.map(async item => ({
id: item.id,
name: item.title || item.name || '未命名作品',
price: Number(item.price || 0).toFixed(2),
meta: item.approximateDuration || item.shopName || '支持预约',
shopName: item.shopName,
coverUrl: await getProductCoverUrl(item),
bgColor: getRandomColor()
})))
/** appendPopularItems is a local helper used by this page script. */
const appendPopularItems = (loadMore = false) => {
const nextItems = popularSource.value.slice(0, page.value * pageSize)
popularItems.value = nextItems
@@ -216,6 +246,7 @@ const appendPopularItems = (loadMore = false) => {
}
}
/** loadUserInfo is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadUserInfo = async () => {
if (!isLoggedIn.value) {
userInfo.value = null
@@ -230,6 +261,7 @@ const loadUserInfo = async () => {
}
}
/** loadPublicShops is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadPublicShops = async () => {
try {
const shops = await shopApi.getPublicShops()
@@ -242,6 +274,7 @@ const loadPublicShops = async () => {
}
}
/** loadBannerImages is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadBannerImages = async () => {
const banners: BannerImage[] = []
for (const shop of publicShops.value) {
@@ -269,6 +302,7 @@ const loadBannerImages = async () => {
bannerImages.value = banners.slice(0, 8)
}
/** loadFeaturedProducts is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadFeaturedProducts = async () => {
try {
let products = await productApi.getProductsByTag('精选')
@@ -282,6 +316,7 @@ const loadFeaturedProducts = async () => {
}
}
/** loadPopularProducts is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadPopularProducts = async () => {
loading.value = true
try {
@@ -302,6 +337,21 @@ const loadPopularProducts = async () => {
}
}
/** loadAnnouncements is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadAnnouncements = async () => {
if (!isLoggedIn.value) {
announcements.value = []
return
}
try {
announcements.value = (await userApi.listMyAnnouncements()) || []
} catch (error) {
console.error('加载公告失败:', error)
announcements.value = []
}
}
/** handleScroll is a local helper used by this page script. */
const handleScroll = () => {
if (loading.value || !hasMore.value) {
return
@@ -315,6 +365,7 @@ const handleScroll = () => {
}
}
/** handleUserClick is a local helper used by this page script. */
const handleUserClick = () => {
if (isLoggedIn.value) {
router.push('/profile')
@@ -324,11 +375,13 @@ const handleUserClick = () => {
router.push('/')
}
/** handleSearch is a local helper used by this page script. */
const handleSearch = () => {
const keyword = searchQuery.value.trim()
router.push(keyword ? { path: '/products', query: { keyword } } : '/products')
}
/** handleSeeAll is a local helper used by this page script. */
const handleSeeAll = (type: 'featured' | 'popular') => {
router.push({
path: '/products',
@@ -336,10 +389,12 @@ const handleSeeAll = (type: 'featured' | 'popular') => {
})
}
/** handleProductClick is a local helper used by this page script. */
const handleProductClick = (item: ProductCardItem) => {
router.push(`/product/${item.id}`)
}
/** openShopById is a local helper used by this page script. */
const openShopById = (shopId: IdType) => {
router.push(`/shop/${shopId}`)
}
@@ -347,6 +402,7 @@ const openShopById = (shopId: IdType) => {
onMounted(async () => {
await Promise.all([
loadUserInfo(),
loadAnnouncements(),
loadPublicShops(),
loadFeaturedProducts(),
loadPopularProducts()
@@ -395,6 +451,32 @@ onUnmounted(() => {
padding: 8px 20px 0;
}
.announcement-bar {
margin: 12px 20px 0;
overflow: hidden;
border-radius: 8px;
background: #fff7ed;
border: 1px solid #fed7aa;
}
.announcement-track {
display: flex;
width: max-content;
gap: 32px;
padding: 9px 14px;
color: #7c2d12;
animation: announcement-scroll 22s linear infinite;
}
.announcement-track span {
white-space: nowrap;
}
@keyframes announcement-scroll {
from { transform: translateX(0); }
to { transform: translateX(-50%); }
}
.guest-alert {
margin: 16px 20px 0;
border-radius: 16px;