修复一些前端问题
This commit is contained in:
+12
-12
@@ -61,28 +61,28 @@ export interface UpdateProductRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const productApi = {
|
export const productApi = {
|
||||||
getAllProducts: () => {
|
getAllProducts: async (): Promise<ProductVO[]> => {
|
||||||
return api.get<ProductVO[]>('/product/list/all')
|
return await api.get<ProductVO[]>('/product/list/all')
|
||||||
},
|
},
|
||||||
|
|
||||||
getProductById: (id: number) => {
|
getProductById: async (id: number): Promise<ProductVO> => {
|
||||||
return api.get<ProductVO>(`/product/get/${id}`)
|
return await api.get<ProductVO>(`/product/get/${id}`)
|
||||||
},
|
},
|
||||||
|
|
||||||
getProductsByTag: (tag: string) => {
|
getProductsByTag: async (tag: string): Promise<ProductVO[]> => {
|
||||||
return api.get<ProductVO[]>(`/product/list/tag/${tag}`)
|
return await api.get<ProductVO[]>(`/product/list/tag/${tag}`)
|
||||||
},
|
},
|
||||||
|
|
||||||
likeProduct: (productId: number) => {
|
likeProduct: async (productId: number): Promise<boolean> => {
|
||||||
return api.post<boolean>(`/product/like/${productId}`)
|
return await api.post<boolean>(`/product/like/${productId}`)
|
||||||
},
|
},
|
||||||
|
|
||||||
unlikeProduct: (productId: number) => {
|
unlikeProduct: async (productId: number): Promise<boolean> => {
|
||||||
return api.post<boolean>(`/product/unlike/${productId}`)
|
return await api.post<boolean>(`/product/unlike/${productId}`)
|
||||||
},
|
},
|
||||||
|
|
||||||
searchProducts: (keyword: string) => {
|
searchProducts: async (keyword: string): Promise<ProductVO[]> => {
|
||||||
return api.get<ProductVO[]>('/product/list/search', {
|
return await api.get<ProductVO[]>('/product/list/search', {
|
||||||
params: {
|
params: {
|
||||||
keyword: keyword
|
keyword: keyword
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
-1
@@ -49,7 +49,6 @@ declare module 'vue' {
|
|||||||
AModal: typeof import('ant-design-vue/es')['Modal']
|
AModal: typeof import('ant-design-vue/es')['Modal']
|
||||||
APageHeader: typeof import('ant-design-vue/es')['PageHeader']
|
APageHeader: typeof import('ant-design-vue/es')['PageHeader']
|
||||||
APopconfirm: typeof import('ant-design-vue/es')['Popconfirm']
|
APopconfirm: typeof import('ant-design-vue/es')['Popconfirm']
|
||||||
ARadio: typeof import('ant-design-vue/es')['Radio']
|
|
||||||
ARadioButton: typeof import('ant-design-vue/es')['RadioButton']
|
ARadioButton: typeof import('ant-design-vue/es')['RadioButton']
|
||||||
ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup']
|
ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup']
|
||||||
ARow: typeof import('ant-design-vue/es')['Row']
|
ARow: typeof import('ant-design-vue/es')['Row']
|
||||||
|
|||||||
@@ -115,7 +115,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, inject } from 'vue'
|
import { ref, onMounted, inject } from 'vue'
|
||||||
import { ArrowLeft, Star, Clock, Collection, ShoppingCart, Right, StarFilled } from '@element-plus/icons-vue'
|
import { ArrowLeft, Star, Clock, Collection, ShoppingCart, Right } from '@element-plus/icons-vue'
|
||||||
import { Icon } from '@iconify/vue'
|
import { Icon } from '@iconify/vue'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
@@ -179,7 +179,7 @@ const checkWishlistStatus = async () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const status = await wishlistApi.checkWishlist(product.value.id)
|
const status = await wishlistApi.checkWishlist(product.value.id)
|
||||||
isFavorite.value = status
|
isFavorite.value = status as boolean
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('检查收藏状态失败:', error)
|
console.error('检查收藏状态失败:', error)
|
||||||
isFavorite.value = false
|
isFavorite.value = false
|
||||||
@@ -198,7 +198,7 @@ const checkLikeStatus = async () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const status = await productLikeApi.checkLikeStatus(product.value.id)
|
const status = await productLikeApi.checkLikeStatus(product.value.id)
|
||||||
isLiked.value = status
|
isLiked.value = status as boolean
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('检查点赞状态失败:', error)
|
console.error('检查点赞状态失败:', error)
|
||||||
isLiked.value = false
|
isLiked.value = false
|
||||||
@@ -219,7 +219,9 @@ const loadProductImages = async () => {
|
|||||||
const response = await fileApi.getSignedUrl(Number(id)) as any
|
const response = await fileApi.getSignedUrl(Number(id)) as any
|
||||||
imageIdCache.value[id] = response
|
imageIdCache.value[id] = response
|
||||||
}
|
}
|
||||||
urls.push(imageIdCache.value[id])
|
if (imageIdCache.value[id]) {
|
||||||
|
urls.push(imageIdCache.value[id] as string)
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取签名链接失败:', error)
|
console.error('获取签名链接失败:', error)
|
||||||
urls.push(DEFAULT_PRODUCT_IMAGE)
|
urls.push(DEFAULT_PRODUCT_IMAGE)
|
||||||
|
|||||||
@@ -155,7 +155,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, computed } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import {
|
import {
|
||||||
LeftOutlined,
|
LeftOutlined,
|
||||||
@@ -169,20 +169,7 @@ import { tagApi, type TagVO } from '@/api/tag'
|
|||||||
import { cartApi } from '@/api/cart'
|
import { cartApi } from '@/api/cart'
|
||||||
import { fileApi } from '@/api/file'
|
import { fileApi } from '@/api/file'
|
||||||
|
|
||||||
// 格式化分钟数显示
|
|
||||||
const formatDuration = (minutes: number): string => {
|
|
||||||
if (minutes < 60) {
|
|
||||||
return `${minutes} 分钟`
|
|
||||||
} else {
|
|
||||||
const hours = Math.floor(minutes / 60)
|
|
||||||
const remainingMinutes = minutes % 60
|
|
||||||
if (remainingMinutes === 0) {
|
|
||||||
return `${hours} 小时`
|
|
||||||
} else {
|
|
||||||
return `${hours} 小时 ${remainingMinutes} 分钟`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
@@ -239,7 +226,9 @@ const loadImageUrls = async (productList: ProductVO[]) => {
|
|||||||
const response = await fileApi.getSignedUrl(Number(id)) as any
|
const response = await fileApi.getSignedUrl(Number(id)) as any
|
||||||
imageIdCache.value[id] = response
|
imageIdCache.value[id] = response
|
||||||
}
|
}
|
||||||
urls.push(imageIdCache.value[id])
|
if (imageIdCache.value[id]) {
|
||||||
|
urls.push(imageIdCache.value[id] as string)
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取签名链接失败:', error)
|
console.error('获取签名链接失败:', error)
|
||||||
urls.push(DEFAULT_PRODUCT_IMAGE)
|
urls.push(DEFAULT_PRODUCT_IMAGE)
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
<div class="shop-images" v-if="shopImages.length > 0">
|
<div class="shop-images" v-if="shopImages.length > 0">
|
||||||
<h3 class="section-title">店铺环境图</h3>
|
<h3 class="section-title">店铺环境图</h3>
|
||||||
<div class="image-carousel">
|
<div class="image-carousel">
|
||||||
<a-carousel autoplay :autoplay-speed="3000" effect="slide" dots>
|
<a-carousel autoplay :autoplay-speed="3000" dots>
|
||||||
<div v-for="(url, index) in shopImages" :key="index" class="carousel-item" @click="showImageModal(url)">
|
<div v-for="(url, index) in shopImages" :key="index" class="carousel-item" @click="showImageModal(url)">
|
||||||
<img :src="url" :alt="`店铺环境图 ${index + 1}`" class="carousel-image" />
|
<img :src="url" :alt="`店铺环境图 ${index + 1}`" class="carousel-image" />
|
||||||
</div>
|
</div>
|
||||||
@@ -67,7 +67,7 @@
|
|||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
import { LeftOutlined, ShopOutlined } from '@ant-design/icons-vue'
|
import { LeftOutlined, ShopOutlined } from '@ant-design/icons-vue'
|
||||||
import { message, Modal } 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/file'
|
import { fileApi } from '@/api/file'
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ const loadShopImages = async () => {
|
|||||||
const fileIdPromises = fileIds.map(idStr => {
|
const fileIdPromises = fileIds.map(idStr => {
|
||||||
const fileId = parseInt(idStr)
|
const fileId = parseInt(idStr)
|
||||||
if (!isNaN(fileId)) {
|
if (!isNaN(fileId)) {
|
||||||
return fileApi.getSignedUrl(fileId).catch(err => {
|
return fileApi.getSignedUrl(fileId).catch(() => {
|
||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,12 @@ const loadShopImages = async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const results = await Promise.all(fileIdPromises)
|
const results = await Promise.all(fileIdPromises)
|
||||||
const filteredResults = results.filter((url): url is string => url !== null).map(url => url.replace(/[`]/g, '').trim())
|
const filteredResults = results
|
||||||
|
.filter((url): url is any => url !== null)
|
||||||
|
.map(url => {
|
||||||
|
const urlStr = typeof url === 'string' ? url : String(url)
|
||||||
|
return urlStr.replace(/[`]/g, '').trim()
|
||||||
|
})
|
||||||
shopImages.value = filteredResults
|
shopImages.value = filteredResults
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -68,8 +68,8 @@ const handleBackClick = () => {
|
|||||||
const fetchWishlist = async () => {
|
const fetchWishlist = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await wishlistApi.getWishlist()
|
const response = await wishlistApi.getWishlist()
|
||||||
wishlistItems.value = response
|
wishlistItems.value = response as WishlistItem[]
|
||||||
await loadImageUrls(response)
|
await loadImageUrls(response as WishlistItem[])
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取收藏列表失败:', error)
|
console.error('获取收藏列表失败:', error)
|
||||||
ElMessage.error('获取收藏列表失败')
|
ElMessage.error('获取收藏列表失败')
|
||||||
@@ -89,7 +89,9 @@ const loadImageUrls = async (items: WishlistItem[]) => {
|
|||||||
const response = await fileApi.getSignedUrl(Number(id)) as any
|
const response = await fileApi.getSignedUrl(Number(id)) as any
|
||||||
imageIdCache.value[id] = response
|
imageIdCache.value[id] = response
|
||||||
}
|
}
|
||||||
urls.push(imageIdCache.value[id])
|
if (imageIdCache.value[id]) {
|
||||||
|
urls.push(imageIdCache.value[id] as string)
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取签名链接失败:', error)
|
console.error('获取签名链接失败:', error)
|
||||||
urls.push(DEFAULT_PRODUCT_IMAGE)
|
urls.push(DEFAULT_PRODUCT_IMAGE)
|
||||||
|
|||||||
Reference in New Issue
Block a user