提交开发分支未提交代码并修正配置
This commit is contained in:
@@ -69,6 +69,7 @@
|
||||
:src="url"
|
||||
style="object-fit: cover; border-radius: 4px; margin-right: 4px;"
|
||||
:preview="false"
|
||||
@error="handleProductImageError(record, index)"
|
||||
/>
|
||||
<a-image
|
||||
v-if="getProductImages(record).length === 0"
|
||||
@@ -128,6 +129,7 @@
|
||||
class="admin-mobile-card__cover admin-mobile-card__cover--wide"
|
||||
:src="getProductImages(item)[0] || DEFAULT_PRODUCT_IMAGE"
|
||||
:preview="false"
|
||||
@error="handleProductImageError(item, 0)"
|
||||
/>
|
||||
<div class="admin-mobile-card__head" style="margin-top: 14px">
|
||||
<div class="admin-mobile-card__body">
|
||||
@@ -244,7 +246,7 @@
|
||||
<div style="margin-top: 8px">上传图片</div>
|
||||
</div>
|
||||
</a-upload>
|
||||
<div class="upload-tip">支持多选上传,不限制上传张数,单张图片超过 5MB 会自动压缩后再上传。</div>
|
||||
<div class="upload-tip">支持多选上传,不限制上传张数,大图将自动使用分片并发上传。</div>
|
||||
<div v-if="isUploadPending" class="upload-pending-tip">图片正在上传中,上传完成前不可提交。</div>
|
||||
<a-modal v-model:open="previewVisible" :footer="null" :mask-closable="false" @cancel="previewVisible = false">
|
||||
<img alt="预览" style="width: 100%" :src="previewImage" />
|
||||
@@ -536,6 +538,7 @@
|
||||
*/
|
||||
import { computed, ref, reactive, onMounted, watch } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { UploadProps } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import DraftActions from '@/components/DraftActions.vue'
|
||||
import TableEllipsisText from '@/components/TableEllipsisText.vue'
|
||||
@@ -552,10 +555,20 @@ import { adminProductApi, type Product, adminShopApi, type Shop, adminFileApi, a
|
||||
import { createChunkUploadTask, type ChunkUploadTask } from '@/utils/chunk-upload'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import { MAX_IMAGE_UPLOAD_SIZE, compressImageIfNeeded, formatFileSize } from '@/utils/image-upload'
|
||||
import {
|
||||
buildAdminUploadFileList,
|
||||
buildSignedImageUrlMap,
|
||||
getRecordImageUrls,
|
||||
refreshSignedImageUrl,
|
||||
resolveSignedImageUrl,
|
||||
resolveSignedImageUrls
|
||||
} from '@/utils/admin-image-assets'
|
||||
import { parseImageFileIds } from '@/utils/signed-image-cache'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { sameId } from '@/utils/id'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { createAdminPagination, applyAdminTablePaginationChange, type AdminTablePaginationChange } from '@/utils/admin-table'
|
||||
import { resolveUploadedFileId, type AdminUploadFileLike, type AdminUploadTaskFile } from '@/utils/admin-upload-file'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminMobileFab from '@/components/admin/AdminMobileFab.vue'
|
||||
@@ -671,11 +684,6 @@ const imageUrls = ref<Record<string, string[]>>({})
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const viewImageUrls = ref<string[]>([])
|
||||
/**
|
||||
* Purpose: imageIdCache supports ProductsView.vue by holding or executing the image id cache page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
/** isAdmin is a reactive state variable used by the template and event handlers. */
|
||||
const isAdmin = ref(false)
|
||||
/**
|
||||
@@ -751,14 +759,7 @@ const viewFormState = reactive({
|
||||
* Purpose: pagination supports ProductsView.vue by holding or executing the pagination page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total: number) => `共 ${total} 条`
|
||||
})
|
||||
const pagination = reactive(createAdminPagination())
|
||||
|
||||
/**
|
||||
* Purpose: formState supports ProductsView.vue by holding or executing the form state page or API role.
|
||||
@@ -1053,53 +1054,35 @@ const resetFilters = () => {
|
||||
|
||||
/** loadImageUrls is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const loadImageUrls = async (products: Product[], requestToken?: number) => {
|
||||
const nextImageUrls: Record<string, string[]> = {}
|
||||
for (const product of products) {
|
||||
if (requestToken && !isLatestRequestToken('products', requestToken)) {
|
||||
return null
|
||||
}
|
||||
if (product.imageFileIds) {
|
||||
const ids = product.imageFileIds.split(',')
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
if (requestToken && !isLatestRequestToken('products', requestToken)) {
|
||||
return null
|
||||
}
|
||||
if (id) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const response = await adminFileApi.getSignedUrl(id.trim()) as any
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
urls.push(imageIdCache.value[id]!)
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
urls.push(DEFAULT_PRODUCT_IMAGE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (product.id) {
|
||||
nextImageUrls[String(product.id)] = urls
|
||||
}
|
||||
} else {
|
||||
if (product.id) {
|
||||
nextImageUrls[String(product.id)] = [DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
}
|
||||
}
|
||||
return nextImageUrls
|
||||
return buildSignedImageUrlMap(
|
||||
products,
|
||||
'imageFileIds',
|
||||
DEFAULT_PRODUCT_IMAGE,
|
||||
true,
|
||||
() => Boolean(requestToken && !isLatestRequestToken('products', requestToken))
|
||||
)
|
||||
}
|
||||
|
||||
/** getProductImages is a local helper used by this page script. */
|
||||
const getProductImages = (product: Product | Record<string, any>): string[] => {
|
||||
const productId = 'id' in product ? product.id : (product as any).id
|
||||
if (productId !== undefined) {
|
||||
return imageUrls.value[String(productId)] || [DEFAULT_PRODUCT_IMAGE]
|
||||
const getProductImages = (product: { id?: IdType }): string[] =>
|
||||
getRecordImageUrls(product, imageUrls.value, [DEFAULT_PRODUCT_IMAGE])
|
||||
|
||||
const handleProductImageError = async (product: { id?: IdType; imageFileIds?: string }, imageIndex: number) => {
|
||||
if (product.id === undefined || product.id === null) return
|
||||
const fileId = parseImageFileIds(product.imageFileIds)[imageIndex]
|
||||
if (!fileId) return
|
||||
|
||||
const refreshedUrl = await refreshSignedImageUrl(fileId, DEFAULT_PRODUCT_IMAGE)
|
||||
if (!refreshedUrl || refreshedUrl === DEFAULT_PRODUCT_IMAGE) return
|
||||
|
||||
const productKey = String(product.id)
|
||||
const currentUrls = imageUrls.value[productKey] || []
|
||||
const nextUrls = [...currentUrls]
|
||||
nextUrls[imageIndex] = refreshedUrl
|
||||
imageUrls.value = {
|
||||
...imageUrls.value,
|
||||
[productKey]: nextUrls
|
||||
}
|
||||
return [DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
|
||||
/** handleSearch is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
@@ -1109,9 +1092,10 @@ const handleSearch = async () => {
|
||||
}
|
||||
|
||||
/** handleTableChange is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleTableChange = async (pag: any) => {
|
||||
pagination.current = pag.current
|
||||
pagination.pageSize = pag.pageSize
|
||||
const handleTableChange = async (pag: AdminTablePaginationChange) => {
|
||||
const nextPagination = applyAdminTablePaginationChange(pagination, pag)
|
||||
pagination.current = nextPagination.current
|
||||
pagination.pageSize = nextPagination.pageSize
|
||||
await runWithGlobalLoading(() => fetchProductList())
|
||||
}
|
||||
|
||||
@@ -1252,27 +1236,7 @@ const showViewModal = async (record: Product | Record<string, any>) => {
|
||||
})
|
||||
|
||||
// 加载图片URL
|
||||
if (recordImageFileIds) {
|
||||
const ids = recordImageFileIds.split(',').filter((id: string) => id)
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const response = await adminFileApi.getSignedUrl(id) as unknown as string
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
urls.push(imageIdCache.value[id])
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
urls.push(DEFAULT_PRODUCT_IMAGE)
|
||||
}
|
||||
}
|
||||
viewImageUrls.value = urls
|
||||
} else {
|
||||
viewImageUrls.value = [DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
viewImageUrls.value = await resolveSignedImageUrls(recordImageFileIds, DEFAULT_PRODUCT_IMAGE, true)
|
||||
|
||||
// 获取该店铺的美甲师列表
|
||||
if (recordShopId) {
|
||||
@@ -1319,32 +1283,7 @@ const buildDraftPayload = () => ({
|
||||
|
||||
/** buildImageFileListByIds is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const buildImageFileListByIds = async (ids: string[]) => {
|
||||
const fileList = []
|
||||
for (const [index, id] of ids.entries()) {
|
||||
try {
|
||||
if (!imageIdCache.value[id]) {
|
||||
const response = await adminFileApi.getSignedUrl(id) as any
|
||||
imageIdCache.value[id] = response
|
||||
}
|
||||
fileList.push({
|
||||
uid: id,
|
||||
fileId: id,
|
||||
name: `图片${index + 1}`,
|
||||
status: 'done',
|
||||
url: imageIdCache.value[id]
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
fileList.push({
|
||||
uid: id,
|
||||
fileId: id,
|
||||
name: `图片${index + 1}`,
|
||||
status: 'done',
|
||||
url: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
return fileList
|
||||
return buildAdminUploadFileList(ids, '图片', DEFAULT_PRODUCT_IMAGE)
|
||||
}
|
||||
|
||||
/** restoreDraft is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
@@ -1390,37 +1329,8 @@ const syncUploadedFileIds = (fileIds: string[]) => {
|
||||
formState.imageFileIds = uploadedFileIds.value.join(',')
|
||||
}
|
||||
|
||||
/** getUploadResponse is a local helper used by this page script. */
|
||||
const getUploadResponse = (file: any) => {
|
||||
if (!file || typeof file !== 'object') {
|
||||
return null
|
||||
}
|
||||
return file.response || null
|
||||
}
|
||||
|
||||
/** resolveUploadedFileId is a local helper used by this page script. */
|
||||
const resolveUploadedFileId = (file: any) => {
|
||||
const response = getUploadResponse(file)
|
||||
const responseId = response?.id ?? response?.data?.id ?? file?.fileId
|
||||
if (responseId !== undefined && responseId !== null && responseId !== '') {
|
||||
return String(responseId)
|
||||
}
|
||||
|
||||
const fileUid = String(file?.uid || '')
|
||||
if (/^\d+$/.test(fileUid)) {
|
||||
return fileUid
|
||||
}
|
||||
|
||||
const fileUrl = String(file?.url || '')
|
||||
if (/^\d+$/.test(fileUrl)) {
|
||||
return fileUrl
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
/** getPreviewUrlFromFile is a local helper used by this page script. */
|
||||
const getPreviewUrlFromFile = (file: any) => {
|
||||
const getPreviewUrlFromFile = (file: AdminUploadFileLike) => {
|
||||
const fileUrl = typeof file?.url === 'string' ? file.url : ''
|
||||
if (fileUrl && !/^\d+$/.test(fileUrl)) {
|
||||
return fileUrl
|
||||
@@ -1445,41 +1355,25 @@ const beforeUpload = (file: File) => {
|
||||
|
||||
// 作品图片走分片上传,并在上传前做压缩兜底,保证大图也能稳定进入对象存储。
|
||||
/** handleUploadImage is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleUploadImage = async (options: any) => {
|
||||
const handleUploadImage: UploadProps['customRequest'] = async (options) => {
|
||||
const { file, onSuccess, onError, onProgress } = options
|
||||
let successMessage = '图片上传成功'
|
||||
const uploadFile = file as AdminUploadTaskFile
|
||||
const task = createChunkUploadTask({
|
||||
file: file as File,
|
||||
file: uploadFile,
|
||||
scene: 'admin-product-image',
|
||||
concurrency: 3,
|
||||
api: {
|
||||
initUpload: adminFileApi.initChunkUpload,
|
||||
uploadChunk: adminFileApi.uploadChunk,
|
||||
completeUpload: adminFileApi.completeChunkUpload,
|
||||
cancelUpload: adminFileApi.cancelChunkUpload
|
||||
},
|
||||
preprocessFile: async (originalFile) => {
|
||||
const compressedResult = await compressImageIfNeeded(originalFile, MAX_IMAGE_UPLOAD_SIZE)
|
||||
|
||||
if (compressedResult.skippedReason) {
|
||||
throw new Error(compressedResult.skippedReason)
|
||||
}
|
||||
|
||||
if (compressedResult.finalSize > MAX_IMAGE_UPLOAD_SIZE) {
|
||||
throw new Error('图片压缩后仍超过 5MB,请裁剪后重试')
|
||||
}
|
||||
|
||||
if (compressedResult.compressed && compressedResult.originalSize !== compressedResult.finalSize) {
|
||||
successMessage = `${originalFile.name} 已压缩并上传成功(${formatFileSize(compressedResult.originalSize)} -> ${formatFileSize(compressedResult.finalSize)})`
|
||||
}
|
||||
|
||||
return compressedResult.file
|
||||
},
|
||||
onProgress: (percent) => {
|
||||
onProgress?.({ percent })
|
||||
}
|
||||
})
|
||||
|
||||
uploadTaskMap.set(String(file.uid), task)
|
||||
uploadTaskMap.set(String(uploadFile.uid), task)
|
||||
activeUploadCount.value += 1
|
||||
|
||||
try {
|
||||
@@ -1487,42 +1381,37 @@ const handleUploadImage = async (options: any) => {
|
||||
const fileId = String((response as any).id)
|
||||
syncUploadedFileIds([...uploadedFileIds.value, fileId])
|
||||
onSuccess?.({ id: fileId, fileId })
|
||||
message.success(successMessage)
|
||||
message.success('图片上传成功')
|
||||
} catch (error) {
|
||||
const errorMessage = (error as Error)?.message || '图片上传失败'
|
||||
if (errorMessage !== '上传已取消' && errorMessage !== 'canceled') {
|
||||
console.error('图片上传失败:', error)
|
||||
message.error(errorMessage)
|
||||
onError?.(error)
|
||||
onError?.(error as never)
|
||||
}
|
||||
} finally {
|
||||
uploadTaskMap.delete(String(file.uid))
|
||||
uploadTaskMap.delete(String(uploadFile.uid))
|
||||
activeUploadCount.value = Math.max(0, activeUploadCount.value - 1)
|
||||
}
|
||||
}
|
||||
|
||||
// Ant Upload 的文件对象来源很多,预览时优先复用已有 URL,缺失时再回源签名地址。
|
||||
/** handlePreview is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handlePreview = async (file: any) => {
|
||||
const handlePreview: UploadProps['onPreview'] = async (file) => {
|
||||
try {
|
||||
const cachedPreviewUrl = getPreviewUrlFromFile(file)
|
||||
const cachedPreviewUrl = getPreviewUrlFromFile(file as AdminUploadFileLike)
|
||||
if (cachedPreviewUrl) {
|
||||
previewImage.value = cachedPreviewUrl
|
||||
previewVisible.value = true
|
||||
return
|
||||
}
|
||||
|
||||
const fileId = resolveUploadedFileId(file)
|
||||
const fileId = resolveUploadedFileId(file as AdminUploadFileLike)
|
||||
if (!fileId) {
|
||||
throw new Error('未找到图片文件标识')
|
||||
}
|
||||
|
||||
if (!imageIdCache.value[fileId]) {
|
||||
const response = await adminFileApi.getSignedUrl(fileId) as any
|
||||
imageIdCache.value[fileId] = response
|
||||
}
|
||||
|
||||
previewImage.value = imageIdCache.value[fileId] || ''
|
||||
previewImage.value = await resolveSignedImageUrl(fileId, '')
|
||||
previewVisible.value = true
|
||||
} catch (error) {
|
||||
console.error('获取预览链接失败:', error)
|
||||
@@ -1531,14 +1420,14 @@ const handlePreview = async (file: any) => {
|
||||
}
|
||||
|
||||
/** handleRemove is a local helper used by this page script. */
|
||||
const handleRemove = (file: any) => {
|
||||
const handleRemove: UploadProps['onRemove'] = (file) => {
|
||||
const uploadTask = uploadTaskMap.get(String(file.uid))
|
||||
if (uploadTask) {
|
||||
uploadTask.cancel()
|
||||
return true
|
||||
}
|
||||
|
||||
const fileId = resolveUploadedFileId(file)
|
||||
const fileId = resolveUploadedFileId(file as AdminUploadFileLike)
|
||||
if (fileId) {
|
||||
syncUploadedFileIds(uploadedFileIds.value.filter(id => id !== fileId))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user