diff --git a/JC-Salon-WeChat/pages/appointment-form/index.js b/JC-Salon-WeChat/pages/appointment-form/index.js index f9b69406..80413b1d 100644 --- a/JC-Salon-WeChat/pages/appointment-form/index.js +++ b/JC-Salon-WeChat/pages/appointment-form/index.js @@ -83,15 +83,20 @@ function removeDraftForm() { function normalizeManualProductImages(form) { const savedImages = form && Array.isArray(form.manualProductImages) ? form.manualProductImages : null if (savedImages) { - return savedImages.map(image => ({ - fileId: image && image.fileId !== undefined ? String(image.fileId) : '', - fileUrl: image && (image.fileUrl || image.url) ? String(image.fileUrl || image.url) : '' - })).filter(image => image.fileId).slice(0, 9) + return savedImages.map(image => { + const fileUrl = image && (image.fileUrl || image.url) ? String(image.fileUrl || image.url) : '' + return { + fileId: image && image.fileId !== undefined ? String(image.fileId) : '', + fileUrl, + previewUrl: image && image.previewUrl ? String(image.previewUrl) : fileUrl + } + }).filter(image => image.fileId).slice(0, 9) } const fileIds = String(form && form.manualProductImageFileIds || '').split(',').map(fileId => fileId.trim()).filter(Boolean) return fileIds.slice(0, 9).map((fileId, index) => ({ fileId, - fileUrl: index === 0 && form && form.manualProductImageUrl ? String(form.manualProductImageUrl) : '' + fileUrl: index === 0 && form && form.manualProductImageUrl ? String(form.manualProductImageUrl) : '', + previewUrl: index === 0 && form && form.manualProductImageUrl ? String(form.manualProductImageUrl) : '' })) } @@ -100,7 +105,7 @@ function buildManualProductImagePatch(images) { return { 'form.manualProductImages': normalizedImages, 'form.manualProductImageFileIds': normalizedImages.map(image => image.fileId).filter(Boolean).join(','), - 'form.manualProductImageUrl': normalizedImages[0] ? normalizedImages[0].fileUrl || '' : '' + 'form.manualProductImageUrl': normalizedImages[0] ? normalizedImages[0].previewUrl || normalizedImages[0].fileUrl || '' : '' } } @@ -548,7 +553,7 @@ Page({ ...baseForm, manualProductImages, manualProductImageFileIds: manualProductImages.map(image => image.fileId).join(','), - manualProductImageUrl: manualProductImages[0] ? manualProductImages[0].fileUrl : '', + manualProductImageUrl: manualProductImages[0] ? manualProductImages[0].previewUrl || manualProductImages[0].fileUrl : '', customerName: options.customerName ? decodeURIComponent(options.customerName) : (baseForm.customerName || ''), phone: options.phone ? decodeURIComponent(options.phone) : (baseForm.phone || ''), appointmentDate, @@ -1036,11 +1041,15 @@ Page({ for (const filePath of filePaths) { const uploadResult = await uploadObjectFile(filePath) const fileId = uploadResult.id || uploadResult.fileId - const fileUrl = uploadResult.fileUrl || uploadResult.primaryUrl || filePath + const fileUrl = uploadResult.fileUrl || uploadResult.primaryUrl || '' if (!fileId) { throw new Error('作品图片上传成功但未返回文件ID') } - const images = (this.data.form.manualProductImages || []).concat({ fileId: String(fileId), fileUrl }).slice(0, 9) + const images = (this.data.form.manualProductImages || []).concat({ + fileId: String(fileId), + fileUrl, + previewUrl: filePath + }).slice(0, 9) this.setData({ ...buildManualProductImagePatch(images), 'form.productId': '', @@ -1058,6 +1067,18 @@ Page({ } }, + onManualProductImageError(event) { + const index = Number(event && event.currentTarget && event.currentTarget.dataset.index) + const images = this.data.form.manualProductImages || [] + const image = images[index] + if (!Number.isInteger(index) || !image || !image.previewUrl || !image.fileUrl || image.previewUrl === image.fileUrl) { + return + } + const fallbackImages = images.slice() + fallbackImages[index] = { ...image, previewUrl: image.fileUrl } + this.setData(buildManualProductImagePatch(fallbackImages)) + }, + removeManualProductImage(event) { if (this.data.manualImageUploading) { return diff --git a/JC-Salon-WeChat/pages/appointment-form/index.wxml b/JC-Salon-WeChat/pages/appointment-form/index.wxml index b86cbbc2..3ac94fa2 100644 --- a/JC-Salon-WeChat/pages/appointment-form/index.wxml +++ b/JC-Salon-WeChat/pages/appointment-form/index.wxml @@ -15,7 +15,7 @@ diff --git a/JC-Salon-WeChat/pages/appointment-form/product-selector.test.js b/JC-Salon-WeChat/pages/appointment-form/product-selector.test.js index 5791f724..d4f7c9fd 100644 --- a/JC-Salon-WeChat/pages/appointment-form/product-selector.test.js +++ b/JC-Salon-WeChat/pages/appointment-form/product-selector.test.js @@ -139,7 +139,7 @@ assert.match(wxml, /placeholder="留空时默认使用客户姓名"/) assert.match(wxml, /appointmentDateBadge/) assert.match(wxml, /class="customer-fields"/) assert.match(wxml, /class="manual-style-sheet"/) -assert.match(wxml, /名称<\/text>\{\{manualProductTitleLength\}\} \/ 100/) +assert.match(wxml, /名称<\/text>\s*\{\{manualProductTitleLength\}\} \/ 100/) assert.match(wxml, /maxlength="100"[^>]*bindinput="onStyleTitleInput"/) assert.match(wxml, /disabled="\{\{form\.productId\}\}" bindinput="onStyleTitleInput"/) assert.match(wxml, /class="manual-style-price-duration-row"/) @@ -153,11 +153,13 @@ assert.doesNotMatch(wxml, /class="style-remark-field"/) assert.doesNotMatch(wxml, /class="style-number-row"/) assert.match(wxml, /class="manual-style-footer">