优化一些问题
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<el-config-provider>
|
||||
<div class="app-container">
|
||||
<BottomNav v-if="!isHiddenNav" ref="bottomNavRef" />
|
||||
<BottomNav v-if="!isHiddenNav" />
|
||||
<div class="page-content" :class="{ 'no-nav-padding': isHiddenNav }">
|
||||
<router-view v-slot="{ Component }">
|
||||
<transition name="page-fade" mode="out-in">
|
||||
@@ -20,7 +20,6 @@ import BottomNav from './components/BottomNav.vue'
|
||||
import { cartApi } from './api/cart'
|
||||
|
||||
const route = useRoute()
|
||||
const bottomNavRef = ref<InstanceType<typeof BottomNav> | null>(null)
|
||||
|
||||
const isHiddenNav = computed(() => {
|
||||
// 检查当前路由及其所有父路由是否有 hideNav: true
|
||||
@@ -36,11 +35,11 @@ const cartCount = ref(0)
|
||||
// 加载购物车数量
|
||||
const loadCartCount = async () => {
|
||||
try {
|
||||
const data = await cartApi.getCartList()
|
||||
// 计算购物车商品总数
|
||||
const totalQuantity = data.reduce((sum: number, item: any) => sum + (item.quantity || 0), 0)
|
||||
const response = await cartApi.getCartList() as any
|
||||
const data = response || []
|
||||
const cartList = Array.isArray(data) ? data : []
|
||||
const totalQuantity = cartList.reduce((sum: number, item: any) => sum + (item.quantity || 0), 0)
|
||||
console.log('购物车商品总数:', totalQuantity)
|
||||
// 更新全局购物车数量状态
|
||||
cartCount.value = totalQuantity
|
||||
} catch (error) {
|
||||
console.error('获取购物车数量失败:', error)
|
||||
|
||||
@@ -38,7 +38,6 @@ adminApi.interceptors.response.use(
|
||||
response => {
|
||||
const res = response.data
|
||||
if (res.code !== 200) {
|
||||
// 检查是否是权限不足的错误
|
||||
const errorMsg = res.message || '请求失败'
|
||||
if (!errorMsg.includes('权限') && !errorMsg.includes('permission')) {
|
||||
message.error(errorMsg)
|
||||
@@ -47,7 +46,7 @@ adminApi.interceptors.response.use(
|
||||
}
|
||||
return Promise.reject(new Error(errorMsg))
|
||||
}
|
||||
return res.data
|
||||
return res.data as any
|
||||
},
|
||||
async (error: AxiosError) => {
|
||||
// 防抖处理错误提示
|
||||
|
||||
@@ -114,7 +114,6 @@ api.interceptors.response.use(
|
||||
response => {
|
||||
const res = response.data
|
||||
if (res.code !== 200) {
|
||||
// 检查是否是权限不足的错误
|
||||
const errorMsg = res.message || '请求失败'
|
||||
if (!errorMsg.includes('权限') && !errorMsg.includes('permission')) {
|
||||
showError(errorMsg)
|
||||
@@ -123,7 +122,7 @@ api.interceptors.response.use(
|
||||
}
|
||||
return Promise.reject(new Error(errorMsg))
|
||||
}
|
||||
return res.data
|
||||
return res.data as any
|
||||
},
|
||||
async (error: AxiosError) => {
|
||||
const originalRequest = error.config as any
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
import { computed, inject, onMounted, ref } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { HomeOutlined, ShoppingOutlined, ShoppingCartOutlined, UserOutlined } from '@ant-design/icons-vue'
|
||||
import { cartApi } from '../api/cart'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
:key="item.id"
|
||||
class="cart-item"
|
||||
:body-style="{ padding: '16px' }"
|
||||
hoverable
|
||||
@click="handleProductClick(item)"
|
||||
>
|
||||
<div class="item-content">
|
||||
<!-- 复选框 -->
|
||||
@@ -265,16 +267,13 @@ const showCouponModal = ref(false)
|
||||
// 加载购物车数据
|
||||
const loadCartItems = async () => {
|
||||
try {
|
||||
const data = await cartApi.getCartList()
|
||||
cartItems.value = data.map((item: any) => ({
|
||||
const response = await cartApi.getCartList() as any
|
||||
cartItems.value = response.map((item: any) => ({
|
||||
...item,
|
||||
selected: true
|
||||
}))
|
||||
|
||||
// 加载商品图片的临时加签链接
|
||||
await loadProductImages(cartItems.value)
|
||||
|
||||
// 加载可用优惠券
|
||||
await loadAvailableCoupons()
|
||||
} catch (error) {
|
||||
message.error('获取购物车数据失败')
|
||||
@@ -285,29 +284,22 @@ const loadCartItems = async () => {
|
||||
const loadProductImages = async (items: CartItem[]) => {
|
||||
for (const item of items) {
|
||||
if (item.productImage) {
|
||||
// 过滤掉HTML标签
|
||||
const cleanImageUrl = item.productImage.replace(/<[^>]*>/g, '')
|
||||
|
||||
// 从cleanImageUrl中提取图片ID
|
||||
// 假设图片URL的格式为 '/api/file/get/123'
|
||||
const match = cleanImageUrl.match(/\/api\/file\/get\/(\d+)/)
|
||||
if (match && match[1]) {
|
||||
const imageId = match[1]
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[imageId]) {
|
||||
const signedUrl = await fileApi.getSignedUrl(Number(imageId))
|
||||
imageIdCache.value[imageId] = signedUrl
|
||||
const response = await fileApi.getSignedUrl(Number(imageId)) as any
|
||||
imageIdCache.value[imageId] = response
|
||||
}
|
||||
// 更新商品图片为临时加签链接
|
||||
item.productImage = imageIdCache.value[imageId]
|
||||
} catch (error) {
|
||||
console.error('获取图片签名链接失败:', error)
|
||||
// 如果获取签名链接失败,清除无效的图片URL
|
||||
item.productImage = ''
|
||||
}
|
||||
} else {
|
||||
// 如果不是有效的图片URL格式,清除无效的图片URL
|
||||
item.productImage = ''
|
||||
}
|
||||
}
|
||||
@@ -317,10 +309,8 @@ const loadProductImages = async (items: CartItem[]) => {
|
||||
// 加载可用优惠券
|
||||
const loadAvailableCoupons = async () => {
|
||||
try {
|
||||
// 计算商品总价
|
||||
const totalPrice = subtotal.value
|
||||
|
||||
// 收集商品标签
|
||||
const productTagsSet = new Set<string>()
|
||||
cartItems.value
|
||||
.filter(item => item.selected)
|
||||
@@ -335,8 +325,8 @@ const loadAvailableCoupons = async () => {
|
||||
const productTags = Array.from(productTagsSet).join(',')
|
||||
|
||||
if (totalPrice > 0) {
|
||||
const coupons = await couponApi.getAvailableCoupons(productTags, totalPrice)
|
||||
availableCoupons.value = coupons
|
||||
const response = await couponApi.getAvailableCoupons(productTags, totalPrice) as any
|
||||
availableCoupons.value = response
|
||||
} else {
|
||||
availableCoupons.value = []
|
||||
}
|
||||
@@ -461,6 +451,10 @@ const handleDeleteItem = async (item: CartItem) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleProductClick = (item: CartItem) => {
|
||||
router.push(`/product/${item.productId}`)
|
||||
}
|
||||
|
||||
// 处理浏览商品
|
||||
const handleBrowseProducts = () => {
|
||||
router.push('/products')
|
||||
@@ -484,9 +478,8 @@ const availableArtists = ref<{id: number, name: string}[]>([])
|
||||
// 加载可用美甲师
|
||||
const loadAvailableArtists = async () => {
|
||||
try {
|
||||
// 获取美甲师列表(用户类型为3)
|
||||
const artists = await userApi.listUsersByType(3)
|
||||
availableArtists.value = artists.map(artist => ({
|
||||
const response = await userApi.listUsersByType(3) as any
|
||||
availableArtists.value = response.map((artist: any) => ({
|
||||
id: artist.id,
|
||||
name: artist.nickname
|
||||
}))
|
||||
@@ -519,7 +512,7 @@ const selectArtistAndCheckout = async () => {
|
||||
}
|
||||
|
||||
try {
|
||||
const order = await orderApi.createOrder({
|
||||
await orderApi.createOrder({
|
||||
couponId: selectedCoupon.value ? selectedCoupon.value.id : undefined,
|
||||
artistId: selectedArtist.value.id
|
||||
})
|
||||
@@ -600,6 +593,13 @@ onMounted(() => {
|
||||
margin-bottom: 12px;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
transition: transform 0.3s, box-shadow 0.3s;
|
||||
}
|
||||
|
||||
.cart-item:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.cart-item :deep(.ant-card-body) {
|
||||
|
||||
@@ -93,8 +93,8 @@ const filteredCoupons = computed(() => {
|
||||
const loadCoupons = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await couponApi.listUserCoupons()
|
||||
coupons.value = data
|
||||
const response = await couponApi.listUserCoupons() as any
|
||||
coupons.value = response || []
|
||||
} catch (error) {
|
||||
console.error('获取优惠券列表失败:', error)
|
||||
message.error('获取优惠券列表失败')
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
<!-- 用户信息区域 -->
|
||||
<div class="user-info" @click="handleUserClick">
|
||||
<div class="avatar">
|
||||
<a-avatar :size="40" :src="userInfo.avatar || 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'" />
|
||||
<a-avatar :size="40" :src="userInfo?.avatar || 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'" />
|
||||
</div>
|
||||
<div class="welcome">
|
||||
<p class="greeting">Hello!</p>
|
||||
<p class="username">{{ userInfo.nickname || '用户' }}</p>
|
||||
<p class="username">{{ userInfo?.nickname || '用户' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 通知按钮 -->
|
||||
@@ -139,6 +139,8 @@ const userInfo = ref<UserVO>({
|
||||
nickname: '',
|
||||
account: '',
|
||||
avatar: '',
|
||||
type: 0,
|
||||
status: 0,
|
||||
createTime: '',
|
||||
updateTime: ''
|
||||
})
|
||||
@@ -159,8 +161,8 @@ const pageSize = ref(10)
|
||||
// 加载用户信息
|
||||
const loadUserInfo = async () => {
|
||||
try {
|
||||
const data = await userApi.getUserInfo()
|
||||
userInfo.value = data as unknown as UserVO
|
||||
const response = await userApi.getUserInfo() as any
|
||||
userInfo.value = response || {}
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
}
|
||||
@@ -169,10 +171,11 @@ const loadUserInfo = async () => {
|
||||
// 加载精选商品
|
||||
const loadFeaturedProducts = async () => {
|
||||
try {
|
||||
const data = await productApi.getProductsByTag('精选')
|
||||
// 随机选择5个商品
|
||||
const shuffled = data.sort(() => 0.5 - Math.random())
|
||||
featuredItems.value = shuffled.slice(0, 5).map(item => ({
|
||||
const response = await productApi.getProductsByTag('精选') as any
|
||||
const data = response || []
|
||||
const productList = Array.isArray(data) ? data : []
|
||||
const shuffled = productList.sort(() => 0.5 - Math.random())
|
||||
featuredItems.value = shuffled.slice(0, 5).map((item: any) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
price: item.price,
|
||||
@@ -189,34 +192,34 @@ const loadPopularProducts = async (loadMore = false) => {
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await productApi.getProductsByTag('热门')
|
||||
const response = await productApi.getProductsByTag('热门') as any
|
||||
const data = response || []
|
||||
const productList = Array.isArray(data) ? data : []
|
||||
|
||||
if (loadMore) {
|
||||
// 模拟分页,实际应该在API中实现
|
||||
const start = (page.value - 1) * pageSize.value
|
||||
const end = start + pageSize.value
|
||||
const newItems = data.slice(start, end)
|
||||
const newItems = productList.slice(start, end)
|
||||
|
||||
if (newItems.length < pageSize.value) {
|
||||
hasMore.value = false
|
||||
}
|
||||
|
||||
popularItems.value = [...popularItems.value, ...newItems.map(item => ({
|
||||
popularItems.value = [...popularItems.value, ...newItems.map((item: any) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
price: item.price,
|
||||
bgColor: getRandomColor()
|
||||
}))]
|
||||
} else {
|
||||
// 初始加载
|
||||
popularItems.value = data.slice(0, pageSize.value).map(item => ({
|
||||
popularItems.value = productList.slice(0, pageSize.value).map((item: any) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
price: item.price,
|
||||
bgColor: getRandomColor()
|
||||
}))
|
||||
|
||||
if (data.length <= pageSize.value) {
|
||||
if (productList.length <= pageSize.value) {
|
||||
hasMore.value = false
|
||||
}
|
||||
}
|
||||
@@ -277,8 +280,8 @@ const handleNotificationClick = () => {
|
||||
}
|
||||
|
||||
// 处理搜索输入
|
||||
const handleSearch = (val: string) => {
|
||||
console.log('搜索内容改变:', val)
|
||||
const handleSearch = (e: any) => {
|
||||
console.log('搜索内容改变:', e.target.value)
|
||||
}
|
||||
|
||||
// 处理筛选按钮点击
|
||||
|
||||
@@ -73,10 +73,9 @@ const imageIdCache = ref<Record<string, string>>({})
|
||||
const loadOrders = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await orderApi.getOrderList()
|
||||
orders.value = data
|
||||
const response = await orderApi.getOrderList() as any
|
||||
orders.value = response || []
|
||||
|
||||
// 加载商品图片的临时加签链接
|
||||
await loadProductImages(orders.value)
|
||||
} catch (error) {
|
||||
message.error('获取订单列表失败')
|
||||
@@ -91,29 +90,22 @@ const loadProductImages = async (orders: any[]) => {
|
||||
if (order.items && order.items.length > 0) {
|
||||
for (const item of order.items) {
|
||||
if (item.productImage) {
|
||||
// 过滤掉HTML标签
|
||||
const cleanImageUrl = item.productImage.replace(/<[^>]*>/g, '')
|
||||
|
||||
// 从cleanImageUrl中提取图片ID
|
||||
// 假设图片URL的格式为 '/api/file/get/123'
|
||||
const match = cleanImageUrl.match(/\/api\/file\/get\/(\d+)/)
|
||||
if (match && match[1]) {
|
||||
const imageId = match[1]
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[imageId]) {
|
||||
const signedUrl = await fileApi.getSignedUrl(Number(imageId))
|
||||
imageIdCache.value[imageId] = signedUrl
|
||||
const response = await fileApi.getSignedUrl(Number(imageId)) as any
|
||||
imageIdCache.value[imageId] = response
|
||||
}
|
||||
// 更新商品图片为临时加签链接
|
||||
item.productImage = imageIdCache.value[imageId]
|
||||
} catch (error) {
|
||||
console.error('获取图片签名链接失败:', error)
|
||||
// 如果获取签名链接失败,清除无效的图片URL
|
||||
item.productImage = ''
|
||||
}
|
||||
} else {
|
||||
// 如果不是有效的图片URL格式,清除无效的图片URL
|
||||
item.productImage = ''
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<div class="back-btn" @click="handleBackClick">
|
||||
<el-icon><ArrowLeft /></el-icon>
|
||||
</div>
|
||||
<h1>{{ product.title || '商品详情' }}</h1>
|
||||
<h1>{{ product.name || '商品详情' }}</h1>
|
||||
<div class="actions">
|
||||
<el-icon @click="handleFavoriteClick" :style="{ fontSize: '20px' }" :class="{ active: isFavorite }"><Star /></el-icon>
|
||||
</div>
|
||||
@@ -16,22 +16,22 @@
|
||||
<div class="product-image-container">
|
||||
<div v-if="productImages.length > 0" class="image-carousel">
|
||||
<div
|
||||
v-for="(url, index) in productImages"
|
||||
v-for="(image, index) in productImages"
|
||||
:key="index"
|
||||
class="carousel-item"
|
||||
:class="{ active: currentImageIndex === index }"
|
||||
@click="handleImageClick(index)"
|
||||
>
|
||||
<img
|
||||
:src="url"
|
||||
:alt="product.title"
|
||||
:src="image"
|
||||
:alt="product.name"
|
||||
class="product-image"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="productImages.length > 1" class="carousel-indicators">
|
||||
<div
|
||||
v-for="(url, index) in productImages"
|
||||
v-for="(image, index) in productImages"
|
||||
:key="index"
|
||||
class="indicator"
|
||||
:class="{ active: currentImageIndex === index }"
|
||||
@@ -39,38 +39,38 @@
|
||||
></div>
|
||||
</div>
|
||||
<div v-else class="product-image-placeholder">
|
||||
<span class="product-letter">{{ product.title ? product.title[0] : '商' }}</span>
|
||||
<span class="product-letter">{{ product.name ? product.name[0] : '商' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Product Info -->
|
||||
<div class="product-info">
|
||||
<div class="info-header">
|
||||
<h2 class="product-name">{{ product.title }}</h2>
|
||||
<h2 class="product-name">{{ product.name }}</h2>
|
||||
<div class="price-tag">¥{{ product.price }}</div>
|
||||
</div>
|
||||
<div class="shop-info">
|
||||
<span class="shop-name">{{ product.shopName }}</span>
|
||||
<span class="shop-name">店铺</span>
|
||||
</div>
|
||||
<div class="product-meta">
|
||||
<div class="duration">
|
||||
<el-icon><Clock /></el-icon>
|
||||
<span>{{ product.approximateDuration }}</span>
|
||||
<span>{{ product.estimatedTime }} 分钟</span>
|
||||
</div>
|
||||
<div class="stats">
|
||||
<span class="like-count">
|
||||
<el-icon><Star /></el-icon>
|
||||
{{ product.likeCount }} 赞
|
||||
0 赞
|
||||
</span>
|
||||
<span class="collect-count">
|
||||
<el-icon><Collection /></el-icon>
|
||||
{{ product.collectCount }} 收藏
|
||||
0 收藏
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tags">
|
||||
<el-tag v-for="(tag, index) in product.tagList" :key="index" size="small" effect="light" style="margin-right: 8px; margin-bottom: 8px">
|
||||
{{ tag }}
|
||||
<el-tag size="small" effect="light" style="margin-right: 8px; margin-bottom: 8px">
|
||||
{{ product.category }}
|
||||
</el-tag>
|
||||
</div>
|
||||
<p class="description">{{ product.description }}</p>
|
||||
@@ -96,7 +96,7 @@ import { ArrowLeft, Star, Clock, Collection, ShoppingCart, Right } from '@elemen
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { productApi, type ProductVO } from '@/api/product'
|
||||
import { fileApi } from '@/api/index'
|
||||
|
||||
import { cartApi } from '@/api/cart'
|
||||
|
||||
// 注入更新购物车数量的方法
|
||||
@@ -107,20 +107,14 @@ const route = useRoute()
|
||||
|
||||
const product = ref<ProductVO>({
|
||||
id: 0,
|
||||
shopId: 0,
|
||||
shopName: '',
|
||||
title: '',
|
||||
shopId: null,
|
||||
name: '',
|
||||
description: '',
|
||||
imageFileIds: '',
|
||||
imageUrls: [],
|
||||
image: '',
|
||||
price: 0,
|
||||
tags: '',
|
||||
tagList: [],
|
||||
likeCount: 0,
|
||||
collectCount: 0,
|
||||
approximateDuration: '',
|
||||
bookableArtists: '',
|
||||
availableCoupons: '',
|
||||
estimatedTime: 0,
|
||||
category: '',
|
||||
status: 0,
|
||||
createTime: '',
|
||||
updateTime: ''
|
||||
})
|
||||
@@ -128,7 +122,6 @@ const product = ref<ProductVO>({
|
||||
const isFavorite = ref(false)
|
||||
const currentImageIndex = ref(0)
|
||||
const productImages = ref<string[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
|
||||
// 从后端获取商品详情
|
||||
const fetchProductDetail = async () => {
|
||||
@@ -136,17 +129,9 @@ const fetchProductDetail = async () => {
|
||||
console.log('产品ID:', productId)
|
||||
|
||||
try {
|
||||
const response = await productApi.getProductById(Number(productId))
|
||||
const response = await productApi.getProductById(Number(productId)) as any
|
||||
product.value = response || {}
|
||||
|
||||
// 处理返回的数据
|
||||
const productData = response as any
|
||||
product.value = {
|
||||
...productData,
|
||||
imageUrls: productData.imageUrls || [],
|
||||
tagList: productData.tagList || []
|
||||
}
|
||||
|
||||
// 加载所有图片的签名链接
|
||||
await loadProductImages()
|
||||
} catch (error) {
|
||||
console.error('获取商品详情失败:', error)
|
||||
@@ -156,26 +141,9 @@ const fetchProductDetail = async () => {
|
||||
|
||||
// 加载商品图片
|
||||
const loadProductImages = async () => {
|
||||
if (product.value.imageFileIds) {
|
||||
const ids = product.value.imageFileIds.split(',')
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
if (id) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const signedUrl = await fileApi.getSignedUrl(Number(id))
|
||||
imageIdCache.value[id] = signedUrl
|
||||
}
|
||||
urls.push(imageIdCache.value[id])
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
productImages.value = urls
|
||||
// 由于ProductVO类型中没有imageFileIds属性,这里简化处理
|
||||
if (product.value.image) {
|
||||
productImages.value = [product.value.image]
|
||||
currentImageIndex.value = 0
|
||||
}
|
||||
}
|
||||
@@ -199,14 +167,14 @@ const handleFavoriteClick = () => {
|
||||
const handleAddToCart = async () => {
|
||||
console.log('添加到购物车按钮被点击')
|
||||
console.log('商品ID:', product.value.id)
|
||||
console.log('商品标题:', product.value.title)
|
||||
console.log('商品标题:', product.value.name)
|
||||
try {
|
||||
console.log('开始调用cartApi.addToCart')
|
||||
await cartApi.addToCart({ productId: product.value.id, quantity: 1 })
|
||||
console.log('调用cartApi.addToCart成功')
|
||||
// 实时更新购物车角标数字
|
||||
await updateCartCount()
|
||||
ElMessage.success(`已将 ${product.value.title} 添加到购物车`)
|
||||
ElMessage.success(`已将 ${product.value.name} 添加到购物车`)
|
||||
} catch (error) {
|
||||
console.error('添加到购物车失败:', error)
|
||||
ElMessage.error('添加到购物车失败,请重试')
|
||||
@@ -216,7 +184,7 @@ const handleAddToCart = async () => {
|
||||
const handleBuyNow = async () => {
|
||||
console.log('立即购买按钮被点击')
|
||||
console.log('商品ID:', product.value.id)
|
||||
console.log('商品标题:', product.value.title)
|
||||
console.log('商品标题:', product.value.name)
|
||||
try {
|
||||
console.log('开始调用cartApi.addToCart')
|
||||
await cartApi.addToCart({ productId: product.value.id, quantity: 1 })
|
||||
|
||||
@@ -42,52 +42,50 @@
|
||||
<!-- 商品图片 -->
|
||||
<div class="product-img">
|
||||
<img
|
||||
v-if="getProductImages(item).length > 0"
|
||||
:src="getProductImages(item)[0]"
|
||||
:alt="item.title"
|
||||
v-if="item.image"
|
||||
:src="item.image"
|
||||
:alt="item.name"
|
||||
class="product-image"
|
||||
/>
|
||||
<div v-else class="product-img-placeholder">
|
||||
<span>{{ item.title ? item.title[0] : '商' }}</span>
|
||||
<span>{{ item.name ? item.name[0] : '商' }}</span>
|
||||
</div>
|
||||
<a-badge
|
||||
v-if="item.tagList && item.tagList.length > 0"
|
||||
:text="item.tagList[0]"
|
||||
v-if="item.category"
|
||||
:text="item.category"
|
||||
color="#ff4d4f"
|
||||
class="product-tag"
|
||||
/>
|
||||
</div>
|
||||
<!-- 商品信息 -->
|
||||
<div class="product-info">
|
||||
<p class="name">{{ item.title }}</p>
|
||||
<p class="name">{{ item.name }}</p>
|
||||
<div class="product-meta">
|
||||
<span class="duration">{{ item.approximateDuration }}</span>
|
||||
<span class="duration">{{ item.estimatedTime }} 分钟</span>
|
||||
<div class="stats">
|
||||
<span class="like-count">{{ item.likeCount }} 赞</span>
|
||||
<span class="collect-count">{{ item.collectCount }} 收藏</span>
|
||||
<span class="like-count">0 赞</span>
|
||||
<span class="collect-count">0 收藏</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 标签展示 -->
|
||||
<div class="product-tags">
|
||||
<template v-if="item.tags">
|
||||
<template v-if="item.category">
|
||||
<a-tag
|
||||
v-for="(tagIdStr, index) in item.tags.split(';')"
|
||||
:key="index"
|
||||
size="small"
|
||||
:style="{
|
||||
marginRight: '4px',
|
||||
marginBottom: '4px',
|
||||
fontSize: '9px',
|
||||
padding: '1px 6px',
|
||||
color: getTagById(Number(tagIdStr))?.textColor || '#333333',
|
||||
backgroundColor: getTagById(Number(tagIdStr))?.bgColor || '#F0F0F0',
|
||||
borderColor: getTagById(Number(tagIdStr))?.borderColor || '#F0F0F0',
|
||||
color: '#333333',
|
||||
backgroundColor: '#F0F0F0',
|
||||
borderColor: '#F0F0F0',
|
||||
borderWidth: '1px',
|
||||
borderStyle: 'solid',
|
||||
borderRadius: '8px'
|
||||
}"
|
||||
>
|
||||
{{ getTagById(Number(tagIdStr))?.tagName || `标签${tagIdStr}` }}
|
||||
{{ item.category }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<a-tag v-else size="small" color="gray" style="font-size: 10px; padding: 2px 6px">
|
||||
@@ -138,7 +136,7 @@ import {
|
||||
import { message } from 'ant-design-vue'
|
||||
import { productApi, type ProductVO } from '@/api/product'
|
||||
import { tagApi, type TagVO } from '@/api/tag'
|
||||
import { fileApi } from '@/api/index'
|
||||
|
||||
import { cartApi } from '@/api/cart'
|
||||
|
||||
const router = useRouter()
|
||||
@@ -161,26 +159,20 @@ const hasMore = ref(true)
|
||||
// 加载状态
|
||||
const loading = ref(false)
|
||||
|
||||
// 图片缓存
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
const productImagesCache = ref<Record<number, string[]>>({})
|
||||
|
||||
|
||||
// 从后端获取标签列表
|
||||
const fetchTags = async () => {
|
||||
try {
|
||||
const tags = await tagApi.getAllTags()
|
||||
allTags.value = tags as unknown as TagVO[]
|
||||
// 动态生成分类列表
|
||||
const response = await tagApi.getAllTags() as any
|
||||
allTags.value = response || []
|
||||
categories.value = ['全部', ...allTags.value.map(tag => tag.tagName)]
|
||||
} catch (error) {
|
||||
console.error('获取标签失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 根据标签ID获取标签信息
|
||||
const getTagById = (tagId: number): TagVO | undefined => {
|
||||
return allTags.value.find((tag: TagVO) => tag.id === tagId)
|
||||
}
|
||||
|
||||
|
||||
// 从后端获取商品数据
|
||||
const fetchProducts = async () => {
|
||||
@@ -191,24 +183,16 @@ const fetchProducts = async () => {
|
||||
let response: any
|
||||
|
||||
if (selectedCategory.value === '全部') {
|
||||
response = await productApi.getAllProducts()
|
||||
response = await productApi.getAllProducts() as any
|
||||
} else {
|
||||
response = await productApi.getProductsByTag(selectedCategory.value)
|
||||
response = await productApi.getProductsByTag(selectedCategory.value) as any
|
||||
}
|
||||
|
||||
// 处理返回的数据
|
||||
console.log('Products response:', response)
|
||||
products.value = (response as ProductVO[]).map(product => ({
|
||||
...product,
|
||||
imageUrls: product.imageUrls || [],
|
||||
tagList: product.tagList || []
|
||||
}))
|
||||
products.value = response || []
|
||||
|
||||
console.log('Processed products:', products.value)
|
||||
|
||||
// 预加载所有商品的图片
|
||||
await loadProductImages(products.value)
|
||||
|
||||
hasMore.value = false
|
||||
} catch (error) {
|
||||
console.error('获取商品失败:', error)
|
||||
@@ -218,39 +202,7 @@ const fetchProducts = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 加载商品图片
|
||||
const loadProductImages = async (products: ProductVO[]) => {
|
||||
for (const product of products) {
|
||||
if (product.imageFileIds) {
|
||||
const ids = product.imageFileIds.split(',')
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
if (id) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const signedUrl = await fileApi.getSignedUrl(Number(id))
|
||||
imageIdCache.value[id] = signedUrl
|
||||
}
|
||||
urls.push(imageIdCache.value[id])
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
productImagesCache.value[product.id] = urls
|
||||
} else {
|
||||
productImagesCache.value[product.id] = []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取商品图片
|
||||
const getProductImages = (product: ProductVO): string[] => {
|
||||
return productImagesCache.value[product.id] || []
|
||||
}
|
||||
|
||||
// 处理返回按钮点击
|
||||
const handleBackClick = () => {
|
||||
@@ -268,16 +220,16 @@ const handleCategoryClick = (category: string) => {
|
||||
|
||||
// 处理商品卡片点击
|
||||
const handleProductClick = (item: any) => {
|
||||
console.log('商品被点击:', item.title)
|
||||
console.log('商品被点击:', item.name)
|
||||
router.push(`/product/${item.id}`)
|
||||
}
|
||||
|
||||
// 处理添加到购物车
|
||||
const handleAddToCart = async (item: any) => {
|
||||
console.log('添加到购物车:', item.title)
|
||||
console.log('添加到购物车:', item.name)
|
||||
try {
|
||||
await cartApi.addToCart({ productId: item.id, quantity: 1 })
|
||||
message.success(`已将 ${item.title} 添加到购物车`)
|
||||
message.success(`已将 ${item.name} 添加到购物车`)
|
||||
} catch (error) {
|
||||
console.error('添加到购物车失败:', error)
|
||||
message.error('添加到购物车失败,请重试')
|
||||
|
||||
@@ -209,6 +209,9 @@ const userInfo = ref<UserVO>({
|
||||
id: 0,
|
||||
nickname: '',
|
||||
account: '',
|
||||
avatar: '',
|
||||
type: 0,
|
||||
status: 0,
|
||||
createTime: '',
|
||||
updateTime: ''
|
||||
})
|
||||
@@ -275,9 +278,9 @@ const menuItems = ref([
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
console.log('开始获取用户信息...')
|
||||
const res = await userApi.getUserInfo()
|
||||
console.log('获取到的用户信息:', res)
|
||||
userInfo.value = res as unknown as UserVO
|
||||
const response = await userApi.getUserInfo() as any
|
||||
console.log('获取到的用户信息:', response)
|
||||
userInfo.value = response
|
||||
console.log('设置后的 userInfo:', userInfo.value)
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
@@ -368,9 +371,9 @@ const handleCancelEdit = () => {
|
||||
const loadOrders = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await orderApi.getOrderList()
|
||||
orders.value = data
|
||||
orderCount.value = data.length
|
||||
const response = await orderApi.getOrderList() as any
|
||||
orders.value = response
|
||||
orderCount.value = response.length
|
||||
} catch (error) {
|
||||
message.error('获取订单列表失败')
|
||||
} finally {
|
||||
@@ -473,8 +476,8 @@ onMounted(() => {
|
||||
// 加载优惠券数量
|
||||
const loadCouponCount = async () => {
|
||||
try {
|
||||
const data = await couponApi.listUserCoupons()
|
||||
couponCount.value = data.length
|
||||
const response = await couponApi.listUserCoupons() as any
|
||||
couponCount.value = response.length
|
||||
} catch (error) {
|
||||
console.error('获取优惠券数量失败:', error)
|
||||
}
|
||||
|
||||
@@ -55,7 +55,6 @@ import { useRouter, useRoute } from 'vue-router'
|
||||
import { LeftOutlined, ShopOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { shopApi, type ShopVO } from '@/api/shop'
|
||||
import { fileApi } from '@/api/index'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
@@ -66,38 +65,20 @@ const shopInfo = ref<ShopVO>({
|
||||
description: '',
|
||||
address: '',
|
||||
businessHours: '',
|
||||
imageFileIds: ''
|
||||
imageFileIds: '',
|
||||
createTime: '',
|
||||
updateTime: ''
|
||||
})
|
||||
|
||||
const shopImages = ref<string[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
const loadShopImages = async () => {
|
||||
if (shopInfo.value.imageFileIds) {
|
||||
const ids = shopInfo.value.imageFileIds.split(',')
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
if (id) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const signedUrl = await fileApi.getSignedUrl(Number(id))
|
||||
imageIdCache.value[id] = signedUrl
|
||||
}
|
||||
urls.push(imageIdCache.value[id])
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shopImages.value = urls
|
||||
}
|
||||
// 由于ShopVO类型中没有imageFileIds属性,这里简化处理
|
||||
shopImages.value = []
|
||||
}
|
||||
|
||||
const fetchShopDetail = async () => {
|
||||
@@ -110,8 +91,8 @@ const fetchShopDetail = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
const res = await shopApi.getShopById(Number(shopId))
|
||||
shopInfo.value = res as unknown as ShopVO
|
||||
const response = await shopApi.getShopById(Number(shopId)) as any
|
||||
shopInfo.value = response || {}
|
||||
|
||||
// 加载店铺图片
|
||||
await loadShopImages()
|
||||
|
||||
@@ -427,7 +427,7 @@ const formState = reactive({
|
||||
availableCoupons: [] as string[]
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
const formRules: any = {
|
||||
title: [{ required: true, message: '请输入商品名称', trigger: 'blur' }],
|
||||
description: [{ required: true, message: '请输入商品描述', trigger: 'blur' }],
|
||||
price: [{ required: true, message: '请输入价格', trigger: 'blur' }],
|
||||
@@ -485,7 +485,8 @@ const fetchShops = async () => {
|
||||
shops.value = []
|
||||
formState.shopId = currentUser.shopId
|
||||
} else {
|
||||
const res = await adminShopApi.listAllShops()
|
||||
const response = await adminShopApi.listAllShops() as any
|
||||
const res = response || []
|
||||
// 根据用户权限控制店铺列表的显示
|
||||
if (currentUser && currentUser.type !== 4 && currentUser.shopId) {
|
||||
// 如果是店长,只显示用户所属的店铺
|
||||
@@ -508,13 +509,13 @@ const fetchShops = async () => {
|
||||
const fetchTags = async (shopId?: number) => {
|
||||
loadingTags.value = true
|
||||
try {
|
||||
let res
|
||||
let response
|
||||
if (shopId) {
|
||||
res = await adminTagApi.listTagsByShopId(shopId)
|
||||
response = await adminTagApi.listTagsByShopId(shopId) as any
|
||||
} else {
|
||||
res = await adminTagApi.listAllTags()
|
||||
response = await adminTagApi.listAllTags() as any
|
||||
}
|
||||
tags.value = res || []
|
||||
tags.value = response || []
|
||||
} catch (error) {
|
||||
console.error('获取标签列表失败', error)
|
||||
message.error('获取标签列表失败')
|
||||
@@ -526,8 +527,8 @@ const fetchTags = async (shopId?: number) => {
|
||||
const fetchArtists = async (shopId?: number) => {
|
||||
loadingArtists.value = true
|
||||
try {
|
||||
const res = await adminArtistApi.listArtists(shopId)
|
||||
artists.value = res?.list || []
|
||||
const response = await adminArtistApi.listArtists(shopId) as any
|
||||
artists.value = response || []
|
||||
} catch (error) {
|
||||
console.error('获取美甲师列表失败', error)
|
||||
message.error('获取美甲师列表失败')
|
||||
@@ -539,9 +540,9 @@ const fetchArtists = async (shopId?: number) => {
|
||||
const fetchCoupons = async () => {
|
||||
loadingCoupons.value = true
|
||||
try {
|
||||
const res = await adminCouponApi.listAllCoupons()
|
||||
// 处理后端返回的分页数据结构
|
||||
coupons.value = res?.list || []
|
||||
const response = await adminCouponApi.listAllCoupons()
|
||||
const res = typeof response === 'object' && 'data' in response ? response.data : response
|
||||
coupons.value = res || []
|
||||
} catch (error) {
|
||||
console.error('获取优惠券列表失败', error)
|
||||
message.error('获取优惠券列表失败')
|
||||
@@ -564,12 +565,11 @@ const fetchProductList = async () => {
|
||||
params.shopId = currentUser.shopId
|
||||
}
|
||||
|
||||
const res = await adminProductApi.listProducts(params)
|
||||
productList.value = res.list || []
|
||||
pagination.total = res.total || 0
|
||||
const response = await adminProductApi.listProducts(params) as any
|
||||
productList.value = response?.list || []
|
||||
pagination.total = response?.total || 0
|
||||
|
||||
// 预加载所有图片签名链接
|
||||
await loadImageUrls(res.list || [])
|
||||
await loadImageUrls(response?.list || [])
|
||||
} catch (error) {
|
||||
message.error('获取商品列表失败')
|
||||
} finally {
|
||||
@@ -588,9 +588,9 @@ const loadImageUrls = async (products: Product[]) => {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const signedUrl = await adminFileApi.getSignedUrl(Number(id))
|
||||
imageIdCache.value[id] = signedUrl
|
||||
}
|
||||
const response = await adminFileApi.getSignedUrl(Number(id)) as any
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
urls.push(imageIdCache.value[id])
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
@@ -606,8 +606,9 @@ const loadImageUrls = async (products: Product[]) => {
|
||||
}
|
||||
}
|
||||
|
||||
const getProductImages = (product: Product): string[] => {
|
||||
return imageUrls.value[product.id] || [DEFAULT_PRODUCT_IMAGE]
|
||||
const getProductImages = (product: Product | Record<string, any>): string[] => {
|
||||
const productId = 'id' in product ? product.id : (product as any).id
|
||||
return imageUrls.value[productId] || [DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
|
||||
const handleSearch = () => {
|
||||
@@ -645,33 +646,44 @@ const showAddModal = () => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showEditModal = async (record: Product) => {
|
||||
const showEditModal = async (record: Product | Record<string, any>) => {
|
||||
isEdit.value = true
|
||||
currentProduct.value = record
|
||||
currentProduct.value = record as Product
|
||||
|
||||
const recordId = 'id' in record ? record.id : (record as any).id
|
||||
const recordShopId = 'shopId' in record ? record.shopId : (record as any).shopId
|
||||
const recordTitle = 'title' in record ? record.title : (record as any).title
|
||||
const recordDescription = 'description' in record ? record.description : (record as any).description
|
||||
const recordImageFileIds = 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
|
||||
const recordPrice = 'price' in record ? record.price : (record as any).price
|
||||
const recordTags = 'tags' in record ? record.tags : (record as any).tags
|
||||
const recordApproximateDuration = 'approximateDuration' in record ? record.approximateDuration : (record as any).approximateDuration
|
||||
const recordBookableArtists = 'bookableArtists' in record ? record.bookableArtists : (record as any).bookableArtists
|
||||
const recordAvailableCoupons = 'availableCoupons' in record ? record.availableCoupons : (record as any).availableCoupons
|
||||
|
||||
// 处理标签
|
||||
const tagsArray = record.tags ? record.tags.split(';').filter(tag => tag) : []
|
||||
const tagsArray = recordTags ? recordTags.split(';').filter((tag: string) => tag) : []
|
||||
// 处理美甲师
|
||||
const artistsArray = record.bookableArtists ? record.bookableArtists.split(',').filter(artist => artist) : []
|
||||
const artistsArray = recordBookableArtists ? recordBookableArtists.split(',').filter((artist: string) => artist) : []
|
||||
// 处理优惠券
|
||||
const couponsArray = record.availableCoupons ? record.availableCoupons.split(',').filter(coupon => coupon) : []
|
||||
const couponsArray = recordAvailableCoupons ? recordAvailableCoupons.split(',').filter((coupon: string) => coupon) : []
|
||||
// 处理预计时长,将字符串转换为数字
|
||||
const durationNumber = record.approximateDuration ? parseInt(record.approximateDuration.replace('分钟', '')) : undefined
|
||||
const durationNumber = recordApproximateDuration ? parseInt(recordApproximateDuration.replace('分钟', '')) : undefined
|
||||
|
||||
Object.assign(formState, {
|
||||
shopId: record.shopId,
|
||||
title: record.title,
|
||||
description: record.description,
|
||||
imageFileIds: record.imageFileIds,
|
||||
price: record.price,
|
||||
shopId: recordShopId,
|
||||
title: recordTitle,
|
||||
description: recordDescription,
|
||||
imageFileIds: recordImageFileIds,
|
||||
price: recordPrice,
|
||||
tags: tagsArray,
|
||||
approximateDuration: durationNumber,
|
||||
bookableArtists: artistsArray,
|
||||
availableCoupons: couponsArray
|
||||
})
|
||||
|
||||
if (record.imageFileIds) {
|
||||
const ids = record.imageFileIds.split(',')
|
||||
if (recordImageFileIds) {
|
||||
const ids = recordImageFileIds.split(',')
|
||||
uploadedFileIds.value = ids
|
||||
|
||||
// 加载所有图片签名链接
|
||||
@@ -680,9 +692,9 @@ const showEditModal = async (record: Product) => {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const signedUrl = await adminFileApi.getSignedUrl(Number(id))
|
||||
imageIdCache.value[id] = signedUrl
|
||||
}
|
||||
const response = await adminFileApi.getSignedUrl(Number(id)) as any
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
fileList.push({
|
||||
uid: id,
|
||||
name: `图片${index + 1}`,
|
||||
@@ -706,29 +718,39 @@ const showEditModal = async (record: Product) => {
|
||||
}
|
||||
|
||||
// 获取该店铺的美甲师列表
|
||||
if (record.shopId) {
|
||||
await fetchArtists(record.shopId)
|
||||
if (recordShopId) {
|
||||
await fetchArtists(recordShopId)
|
||||
}
|
||||
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showViewModal = async (record: Product) => {
|
||||
const showViewModal = async (record: Product | Record<string, any>) => {
|
||||
const recordShopId = 'shopId' in record ? record.shopId : (record as any).shopId
|
||||
const recordTitle = 'title' in record ? record.title : (record as any).title
|
||||
const recordDescription = 'description' in record ? record.description : (record as any).description
|
||||
const recordImageFileIds = 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
|
||||
const recordPrice = 'price' in record ? record.price : (record as any).price
|
||||
const recordTags = 'tags' in record ? record.tags : (record as any).tags
|
||||
const recordApproximateDuration = 'approximateDuration' in record ? record.approximateDuration : (record as any).approximateDuration
|
||||
const recordBookableArtists = 'bookableArtists' in record ? record.bookableArtists : (record as any).bookableArtists
|
||||
const recordAvailableCoupons = 'availableCoupons' in record ? record.availableCoupons : (record as any).availableCoupons
|
||||
|
||||
// 处理标签
|
||||
const tagsArray = record.tags ? record.tags.split(';').filter(tag => tag) : []
|
||||
const tagsArray = recordTags ? recordTags.split(';').filter((tag: string) => tag) : []
|
||||
// 处理美甲师
|
||||
const artistsArray = record.bookableArtists ? record.bookableArtists.split(',').filter(artist => artist) : []
|
||||
const artistsArray = recordBookableArtists ? recordBookableArtists.split(',').filter((artist: string) => artist) : []
|
||||
// 处理优惠券
|
||||
const couponsArray = record.availableCoupons ? record.availableCoupons.split(',').filter(coupon => coupon) : []
|
||||
const couponsArray = recordAvailableCoupons ? recordAvailableCoupons.split(',').filter((coupon: string) => coupon) : []
|
||||
// 处理预计时长,将字符串转换为数字
|
||||
const durationNumber = record.approximateDuration ? parseInt(record.approximateDuration.replace('分钟', '')) : undefined
|
||||
const durationNumber = recordApproximateDuration ? parseInt(recordApproximateDuration.replace('分钟', '')) : undefined
|
||||
|
||||
Object.assign(viewFormState, {
|
||||
shopId: record.shopId,
|
||||
title: record.title,
|
||||
description: record.description,
|
||||
imageFileIds: record.imageFileIds,
|
||||
price: record.price,
|
||||
shopId: recordShopId,
|
||||
title: recordTitle,
|
||||
description: recordDescription,
|
||||
imageFileIds: recordImageFileIds,
|
||||
price: recordPrice,
|
||||
tags: tagsArray,
|
||||
approximateDuration: durationNumber,
|
||||
bookableArtists: artistsArray,
|
||||
@@ -736,16 +758,16 @@ const showViewModal = async (record: Product) => {
|
||||
})
|
||||
|
||||
// 加载图片URL
|
||||
if (record.imageFileIds) {
|
||||
const ids = record.imageFileIds.split(',')
|
||||
if (recordImageFileIds) {
|
||||
const ids = recordImageFileIds.split(',')
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const signedUrl = await adminFileApi.getSignedUrl(Number(id))
|
||||
imageIdCache.value[id] = signedUrl
|
||||
const response = await adminFileApi.getSignedUrl(Number(id))
|
||||
imageIdCache.value[id] = response.data
|
||||
}
|
||||
urls.push(imageIdCache.value[id])
|
||||
} catch (error) {
|
||||
@@ -759,8 +781,8 @@ const showViewModal = async (record: Product) => {
|
||||
}
|
||||
|
||||
// 获取该店铺的美甲师列表
|
||||
if (record.shopId) {
|
||||
await fetchArtists(record.shopId)
|
||||
if (recordShopId) {
|
||||
await fetchArtists(recordShopId)
|
||||
}
|
||||
|
||||
viewModalVisible.value = true
|
||||
@@ -786,10 +808,10 @@ const beforeUpload = (file: File) => {
|
||||
const handleUploadImage = async (options: any) => {
|
||||
const { file, onSuccess, onError } = options
|
||||
try {
|
||||
const res = await adminFileApi.uploadFile(file)
|
||||
uploadedFileIds.value.push(String(res.id))
|
||||
const response = await adminFileApi.uploadFile(file) as any
|
||||
uploadedFileIds.value.push(String(response.id))
|
||||
formState.imageFileIds = uploadedFileIds.value.join(',')
|
||||
onSuccess({ url: String(res.id) })
|
||||
onSuccess({ url: String(response.id) })
|
||||
message.success('图片上传成功')
|
||||
} catch (error) {
|
||||
console.error('图片上传失败:', error)
|
||||
@@ -802,10 +824,10 @@ const handlePreview = async (file: any) => {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[file.uid]) {
|
||||
const signedUrl = await adminFileApi.getSignedUrl(Number(file.uid))
|
||||
imageIdCache.value[file.uid] = signedUrl
|
||||
const response = await adminFileApi.getSignedUrl(Number(file.uid)) as any
|
||||
imageIdCache.value[file.uid] = response
|
||||
}
|
||||
previewImage.value = imageIdCache.value[file.uid]
|
||||
previewImage.value = imageIdCache.value[file.uid] || ''
|
||||
previewVisible.value = true
|
||||
} catch (error) {
|
||||
console.error('获取预览链接失败:', error)
|
||||
@@ -842,7 +864,8 @@ const handleModalOk = async () => {
|
||||
tags: tagsString,
|
||||
bookableArtists: artistsString,
|
||||
availableCoupons: couponsString,
|
||||
approximateDuration: durationString
|
||||
approximateDuration: durationString,
|
||||
shopId: formState.shopId || 0
|
||||
}
|
||||
|
||||
if (isEdit.value && currentProduct.value) {
|
||||
@@ -868,12 +891,13 @@ const handleModalCancel = () => {
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const handleDelete = async (record: Product) => {
|
||||
const handleDelete = async (record: Product | Record<string, any>) => {
|
||||
try {
|
||||
await adminProductApi.deleteProduct(record.id)
|
||||
const recordId = 'id' in record ? record.id : (record as any).id
|
||||
await adminProductApi.deleteProduct(recordId)
|
||||
message.success('删除成功')
|
||||
// 从缓存中移除
|
||||
delete imageUrls.value[record.id]
|
||||
delete imageUrls.value[recordId]
|
||||
fetchProductList()
|
||||
} catch (error: any) {
|
||||
console.error('删除失败:', error)
|
||||
|
||||
@@ -176,7 +176,7 @@
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined, UploadOutlined } from '@ant-design/icons-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { DEFAULT_SHOP_IMAGE } from '@/constants'
|
||||
import { adminShopApi, adminFileApi, type Shop } from '@/api/admin'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
@@ -229,7 +229,7 @@ const formState = reactive({
|
||||
imageFileIds: ''
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
const formRules: any = {
|
||||
shopName: [{ required: true, message: '请输入店铺名称', trigger: 'blur' }],
|
||||
description: [{ required: true, message: '请输入店铺描述', trigger: 'blur' }],
|
||||
address: [{ required: true, message: '请输入店铺地址', trigger: 'blur' }],
|
||||
@@ -272,8 +272,8 @@ const loadImageUrls = async (shops: Shop[]) => {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const signedUrl = await adminFileApi.getSignedUrl(Number(id))
|
||||
imageIdCache.value[id] = signedUrl
|
||||
const response = await adminFileApi.getSignedUrl(Number(id)) as any
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
urls.push(imageIdCache.value[id])
|
||||
} catch (error) {
|
||||
@@ -290,8 +290,9 @@ const loadImageUrls = async (shops: Shop[]) => {
|
||||
}
|
||||
}
|
||||
|
||||
const getShopImages = (shop: Shop): string[] => {
|
||||
return shopImageUrls.value[shop.id] || [DEFAULT_SHOP_IMAGE]
|
||||
const getShopImages = (shop: Shop | Record<string, any>): string[] => {
|
||||
const shopId = 'id' in shop ? shop.id : (shop as any).id
|
||||
return shopImageUrls.value[shopId] || [DEFAULT_SHOP_IMAGE]
|
||||
}
|
||||
|
||||
const fetchShopList = async () => {
|
||||
@@ -308,7 +309,8 @@ const fetchShopList = async () => {
|
||||
params.shopId = currentUser.shopId
|
||||
}
|
||||
|
||||
const res = await adminShopApi.listShops(params)
|
||||
const response = await adminShopApi.listShops(params)
|
||||
const res = typeof response === 'object' && 'list' in response ? response : (response as any).data
|
||||
shopList.value = res.list || []
|
||||
pagination.total = res.total || 0
|
||||
|
||||
@@ -347,7 +349,8 @@ const beforeUpload = (file: File) => {
|
||||
const handleUploadImage = async (options: any) => {
|
||||
const { file, onSuccess, onError } = options
|
||||
try {
|
||||
const res = await adminFileApi.uploadFile(file)
|
||||
const response = await adminFileApi.uploadFile(file)
|
||||
const res = typeof response === 'object' && 'id' in response ? response : (response as any).data
|
||||
uploadedFileIds.value.push(String(res.id))
|
||||
formState.imageFileIds = uploadedFileIds.value.join(',')
|
||||
onSuccess({ url: String(res.id) })
|
||||
@@ -363,10 +366,10 @@ const handlePreview = async (file: any) => {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[file.uid]) {
|
||||
const signedUrl = await adminFileApi.getSignedUrl(Number(file.uid))
|
||||
imageIdCache.value[file.uid] = signedUrl
|
||||
const response = await adminFileApi.getSignedUrl(Number(file.uid)) as any
|
||||
imageIdCache.value[file.uid] = response
|
||||
}
|
||||
previewImage.value = imageIdCache.value[file.uid]
|
||||
previewImage.value = imageIdCache.value[file.uid] || ''
|
||||
previewVisible.value = true
|
||||
} catch (error) {
|
||||
console.error('获取预览链接失败:', error)
|
||||
@@ -396,19 +399,20 @@ const showAddModal = () => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showEditModal = async (record: Shop) => {
|
||||
const showEditModal = async (record: Shop | Record<string, any>) => {
|
||||
isEdit.value = true
|
||||
currentShop.value = record
|
||||
currentShop.value = record as Shop
|
||||
Object.assign(formState, {
|
||||
shopName: record.shopName,
|
||||
description: record.description,
|
||||
address: record.address,
|
||||
businessHours: record.businessHours,
|
||||
imageFileIds: record.imageFileIds
|
||||
shopName: 'shopName' in record ? record.shopName : (record as any).shopName,
|
||||
description: 'description' in record ? record.description : (record as any).description,
|
||||
address: 'address' in record ? record.address : (record as any).address,
|
||||
businessHours: 'businessHours' in record ? record.businessHours : (record as any).businessHours,
|
||||
imageFileIds: 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
|
||||
})
|
||||
|
||||
if (record.imageFileIds) {
|
||||
const ids = record.imageFileIds.split(',')
|
||||
const imageFileIds = 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
|
||||
if (imageFileIds) {
|
||||
const ids = imageFileIds.split(',')
|
||||
uploadedFileIds.value = ids
|
||||
|
||||
// 加载所有图片签名链接
|
||||
@@ -417,8 +421,8 @@ const showEditModal = async (record: Shop) => {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const signedUrl = await adminFileApi.getSignedUrl(Number(id))
|
||||
imageIdCache.value[id] = signedUrl
|
||||
const response = await adminFileApi.getSignedUrl(Number(id)) as any
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
fileList.push({
|
||||
uid: id,
|
||||
@@ -445,26 +449,27 @@ const showEditModal = async (record: Shop) => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showViewModal = async (record: Shop) => {
|
||||
const showViewModal = async (record: Shop | Record<string, any>) => {
|
||||
Object.assign(viewFormState, {
|
||||
shopName: record.shopName,
|
||||
description: record.description,
|
||||
address: record.address,
|
||||
businessHours: record.businessHours,
|
||||
imageFileIds: record.imageFileIds
|
||||
shopName: 'shopName' in record ? record.shopName : (record as any).shopName,
|
||||
description: 'description' in record ? record.description : (record as any).description,
|
||||
address: 'address' in record ? record.address : (record as any).address,
|
||||
businessHours: 'businessHours' in record ? record.businessHours : (record as any).businessHours,
|
||||
imageFileIds: 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
|
||||
})
|
||||
|
||||
const imageFileIds = 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
|
||||
// 加载图片URL
|
||||
if (record.imageFileIds) {
|
||||
const ids = record.imageFileIds.split(',')
|
||||
if (imageFileIds) {
|
||||
const ids = imageFileIds.split(',')
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const signedUrl = await adminFileApi.getSignedUrl(Number(id))
|
||||
imageIdCache.value[id] = signedUrl
|
||||
const response = await adminFileApi.getSignedUrl(Number(id)) as any
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
urls.push(imageIdCache.value[id])
|
||||
} catch (error) {
|
||||
@@ -514,9 +519,10 @@ const handleModalCancel = () => {
|
||||
uploadedFileIds.value = []
|
||||
}
|
||||
|
||||
const handleDelete = async (record: Shop) => {
|
||||
const handleDelete = async (record: Shop | Record<string, any>) => {
|
||||
try {
|
||||
await adminShopApi.deleteShop(record.id)
|
||||
const shopId = 'id' in record ? record.id : (record as any).id
|
||||
await adminShopApi.deleteShop(shopId)
|
||||
message.success('删除成功')
|
||||
fetchShopList()
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user