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