修复小程序上传图片预览

This commit is contained in:
2026-07-21 19:48:31 +08:00
parent e3f5ad1ba1
commit a84646ea60
4 changed files with 40 additions and 8 deletions
@@ -1,6 +1,6 @@
const planningApi = require('../../api/planning')
const { markPlanningRefresh } = require('../../utils/planning-refresh')
const { chooseImageFilePaths, uploadObjectFile } = require('../../utils/upload')
const { chooseImageFilePaths, uploadObjectFile, resolveUploadedImagePreviewUrl } = require('../../utils/upload')
function canTransferAppointment() {
const app = getApp()
@@ -30,7 +30,7 @@ async function uploadAppointmentImageFiles(limit) {
const filePath = filePaths[index]
const uploadResult = await uploadObjectFile(filePath)
const fileId = uploadResult.id || uploadResult.fileId
const fileUrl = uploadResult.fileUrl || uploadResult.primaryUrl || filePath
const fileUrl = resolveUploadedImagePreviewUrl(uploadResult, filePath)
if (!fileId) {
throw new Error('预约图片上传成功但未返回文件ID')
}
@@ -121,12 +121,15 @@ Page({
wx.navigateTo({ url: `/pages/artist-transfer/index?id=${this.data.id}` })
},
async persistAppointmentImages(fileIds) {
async persistAppointmentImages(fileIds, previewImageUrls) {
const appointment = await planningApi.updateAppointmentImages(this.data.id, {
imageFileIds: fileIds.join(',')
})
markPlanningRefresh()
this.applyAppointment(appointment)
if (Array.isArray(previewImageUrls) && previewImageUrls.length > 0) {
this.setData({ productImageUrls: previewImageUrls })
}
},
async chooseAppointmentImages() {
@@ -145,7 +148,10 @@ Page({
if (uploaded.fileIds.length === 0) {
return
}
await this.persistAppointmentImages(currentFileIds.concat(uploaded.fileIds))
await this.persistAppointmentImages(
currentFileIds.concat(uploaded.fileIds),
this.data.productImageUrls.concat(uploaded.imageUrls)
)
wx.showToast({ title: '图片已保存' })
} catch (error) {
wx.showToast({ title: error.message || '图片上传失败', icon: 'none' })
@@ -164,7 +170,7 @@ Page({
if (uploaded.fileIds.length === 0) {
return
}
await this.persistAppointmentImages(uploaded.fileIds)
await this.persistAppointmentImages(uploaded.fileIds, uploaded.imageUrls)
wx.showToast({ title: '图片已保存' })
} catch (error) {
wx.showToast({ title: error.message || '图片上传失败', icon: 'none' })
@@ -182,10 +188,12 @@ Page({
if (!Number.isInteger(index) || index < 0 || index >= currentFileIds.length) {
return
}
const currentImageUrls = Array.isArray(this.data.productImageUrls) ? this.data.productImageUrls : []
const nextFileIds = currentFileIds.filter((item, itemIndex) => itemIndex !== index)
const nextImageUrls = currentImageUrls.filter((item, itemIndex) => itemIndex !== index)
this.setData({ imageUploading: true })
try {
await this.persistAppointmentImages(nextFileIds)
await this.persistAppointmentImages(nextFileIds, nextImageUrls)
wx.showToast({ title: '图片已保存' })
} catch (error) {
wx.showToast({ title: error.message || '图片保存失败', icon: 'none' })
@@ -4,7 +4,7 @@ const tagsApi = require('../../api/tags')
const customersApi = require('../../api/customers')
const dateUtil = require('../../utils/date')
const { markPlanningRefresh } = require('../../utils/planning-refresh')
const { chooseImageFilePaths, uploadObjectFile } = require('../../utils/upload')
const { chooseImageFilePaths, uploadObjectFile, resolveUploadedImagePreviewUrl } = require('../../utils/upload')
const DRAFT_STORAGE_PREFIX = 'managerAppointmentDraft'
const TIME_SLOT_MINUTES = 15
@@ -792,7 +792,7 @@ Page({
const filePath = filePaths[index]
const uploadResult = await uploadObjectFile(filePath)
const fileId = uploadResult.id || uploadResult.fileId
const fileUrl = uploadResult.fileUrl || uploadResult.primaryUrl || filePath
const fileUrl = resolveUploadedImagePreviewUrl(uploadResult, filePath)
if (!fileId) {
throw new Error('作品图片上传成功但未返回文件ID')
}