优化一些问题

This commit is contained in:
xiaowang
2026-03-02 10:13:20 +08:00
parent c95394260d
commit b9599b3ece
14 changed files with 256 additions and 331 deletions
+40 -34
View File
@@ -176,7 +176,7 @@
import { ref, reactive, onMounted } from 'vue'
import { message } from 'ant-design-vue'
import type { FormInstance } from 'ant-design-vue'
import { PlusOutlined, UploadOutlined } from '@ant-design/icons-vue'
import { PlusOutlined } from '@ant-design/icons-vue'
import { DEFAULT_SHOP_IMAGE } from '@/constants'
import { adminShopApi, adminFileApi, type Shop } from '@/api/admin'
import { usePermission } from '@/utils/permission'
@@ -229,7 +229,7 @@ const formState = reactive({
imageFileIds: ''
})
const formRules = {
const formRules: any = {
shopName: [{ required: true, message: '请输入店铺名称', trigger: 'blur' }],
description: [{ required: true, message: '请输入店铺描述', trigger: 'blur' }],
address: [{ required: true, message: '请输入店铺地址', trigger: 'blur' }],
@@ -272,8 +272,8 @@ const loadImageUrls = async (shops: Shop[]) => {
try {
// 检查缓存
if (!imageIdCache.value[id]) {
const signedUrl = await adminFileApi.getSignedUrl(Number(id))
imageIdCache.value[id] = signedUrl
const response = await adminFileApi.getSignedUrl(Number(id)) as any
imageIdCache.value[id] = response
}
urls.push(imageIdCache.value[id])
} catch (error) {
@@ -290,8 +290,9 @@ const loadImageUrls = async (shops: Shop[]) => {
}
}
const getShopImages = (shop: Shop): string[] => {
return shopImageUrls.value[shop.id] || [DEFAULT_SHOP_IMAGE]
const getShopImages = (shop: Shop | Record<string, any>): string[] => {
const shopId = 'id' in shop ? shop.id : (shop as any).id
return shopImageUrls.value[shopId] || [DEFAULT_SHOP_IMAGE]
}
const fetchShopList = async () => {
@@ -308,7 +309,8 @@ const fetchShopList = async () => {
params.shopId = currentUser.shopId
}
const res = await adminShopApi.listShops(params)
const response = await adminShopApi.listShops(params)
const res = typeof response === 'object' && 'list' in response ? response : (response as any).data
shopList.value = res.list || []
pagination.total = res.total || 0
@@ -347,7 +349,8 @@ const beforeUpload = (file: File) => {
const handleUploadImage = async (options: any) => {
const { file, onSuccess, onError } = options
try {
const res = await adminFileApi.uploadFile(file)
const response = await adminFileApi.uploadFile(file)
const res = typeof response === 'object' && 'id' in response ? response : (response as any).data
uploadedFileIds.value.push(String(res.id))
formState.imageFileIds = uploadedFileIds.value.join(',')
onSuccess({ url: String(res.id) })
@@ -363,10 +366,10 @@ const handlePreview = async (file: any) => {
try {
// 检查缓存
if (!imageIdCache.value[file.uid]) {
const signedUrl = await adminFileApi.getSignedUrl(Number(file.uid))
imageIdCache.value[file.uid] = signedUrl
const response = await adminFileApi.getSignedUrl(Number(file.uid)) as any
imageIdCache.value[file.uid] = response
}
previewImage.value = imageIdCache.value[file.uid]
previewImage.value = imageIdCache.value[file.uid] || ''
previewVisible.value = true
} catch (error) {
console.error('获取预览链接失败:', error)
@@ -396,19 +399,20 @@ const showAddModal = () => {
modalVisible.value = true
}
const showEditModal = async (record: Shop) => {
const showEditModal = async (record: Shop | Record<string, any>) => {
isEdit.value = true
currentShop.value = record
currentShop.value = record as Shop
Object.assign(formState, {
shopName: record.shopName,
description: record.description,
address: record.address,
businessHours: record.businessHours,
imageFileIds: record.imageFileIds
shopName: 'shopName' in record ? record.shopName : (record as any).shopName,
description: 'description' in record ? record.description : (record as any).description,
address: 'address' in record ? record.address : (record as any).address,
businessHours: 'businessHours' in record ? record.businessHours : (record as any).businessHours,
imageFileIds: 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
})
if (record.imageFileIds) {
const ids = record.imageFileIds.split(',')
const imageFileIds = 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
if (imageFileIds) {
const ids = imageFileIds.split(',')
uploadedFileIds.value = ids
// 加载所有图片签名链接
@@ -417,8 +421,8 @@ const showEditModal = async (record: Shop) => {
try {
// 检查缓存
if (!imageIdCache.value[id]) {
const signedUrl = await adminFileApi.getSignedUrl(Number(id))
imageIdCache.value[id] = signedUrl
const response = await adminFileApi.getSignedUrl(Number(id)) as any
imageIdCache.value[id] = response
}
fileList.push({
uid: id,
@@ -445,26 +449,27 @@ const showEditModal = async (record: Shop) => {
modalVisible.value = true
}
const showViewModal = async (record: Shop) => {
const showViewModal = async (record: Shop | Record<string, any>) => {
Object.assign(viewFormState, {
shopName: record.shopName,
description: record.description,
address: record.address,
businessHours: record.businessHours,
imageFileIds: record.imageFileIds
shopName: 'shopName' in record ? record.shopName : (record as any).shopName,
description: 'description' in record ? record.description : (record as any).description,
address: 'address' in record ? record.address : (record as any).address,
businessHours: 'businessHours' in record ? record.businessHours : (record as any).businessHours,
imageFileIds: 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
})
const imageFileIds = 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
// 加载图片URL
if (record.imageFileIds) {
const ids = record.imageFileIds.split(',')
if (imageFileIds) {
const ids = imageFileIds.split(',')
const urls: string[] = []
for (const id of ids) {
try {
// 检查缓存
if (!imageIdCache.value[id]) {
const signedUrl = await adminFileApi.getSignedUrl(Number(id))
imageIdCache.value[id] = signedUrl
const response = await adminFileApi.getSignedUrl(Number(id)) as any
imageIdCache.value[id] = response
}
urls.push(imageIdCache.value[id])
} catch (error) {
@@ -514,9 +519,10 @@ const handleModalCancel = () => {
uploadedFileIds.value = []
}
const handleDelete = async (record: Shop) => {
const handleDelete = async (record: Shop | Record<string, any>) => {
try {
await adminShopApi.deleteShop(record.id)
const shopId = 'id' in record ? record.id : (record as any).id
await adminShopApi.deleteShop(shopId)
message.success('删除成功')
fetchShopList()
} catch (error) {