优化一些问题
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user