修复本地上传图片预览

This commit is contained in:
2026-10-29 14:28:55 +08:00
parent 5793bf2390
commit 8f8f89e3b7
4 changed files with 66 additions and 20 deletions
@@ -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><text class="manual-style-character-count">\{\{manualProductTitleLength\}\} \/ 100/)
assert.match(wxml, /名称<\/text><text class="manual-style-character-count">\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"><button class="manual-style-confirm"[^>]*>用于本次预约<\/button><button class="manual-style-library-link"[^>]*>从款式库中选择/)
assert.match(wxml, /class="manual-style-more-toggle" bindtap="toggleManualProductMore"/)
assert.match(wxml, /更多款式信息(选填)/)
assert.match(wxml, /点击展开补充信息/)
assert.match(wxml, /bind:openmanual="openManualProductFromLibrary"/)
assert.match(wxml, /show-manual-action="\{\{true\}\}"/)
assert.match(wxml, /本次 \{\{form\.amount \|\| '待填'\}\} 元/)
assert.match(wxml, /wx:for="\{\{form\.manualProductImages\}\}"/)
assert.match(wxml, /src="\{\{item\.previewUrl \|\| item\.fileUrl\}\}"/)
assert.match(wxml, /form\.manualProductImages\[0\]\.previewUrl \|\| form\.manualProductImages\[0\]\.fileUrl/)
assert.match(wxml, /manualProductImages\.length < 9/)
assert.match(wxml, /data-index="\{\{index\}\}"[^>]*catchtap="removeManualProductImage"/)
assert.match(wxml, /manualProductImages\.length\}\} \/ 9/)
@@ -173,16 +175,18 @@ async function testManualProductImages() {
assert.strictEqual(requestedImageCount, 9)
assert.deepStrictEqual(uploadCalls.slice(-3), selectedImagePaths)
assert.deepStrictEqual(page.data.form.manualProductImages, [
{ fileId: '11', fileUrl: 'https://img.example/1.jpg' },
{ fileId: '12', fileUrl: 'https://img.example/2.jpg' },
{ fileId: '13', fileUrl: 'https://img.example/3.jpg' }
{ fileId: '11', fileUrl: 'https://img.example/1.jpg', previewUrl: '/tmp/style-1.jpg' },
{ fileId: '12', fileUrl: 'https://img.example/2.jpg', previewUrl: '/tmp/style-2.jpg' },
{ fileId: '13', fileUrl: 'https://img.example/3.jpg', previewUrl: '/tmp/style-3.jpg' }
])
assert.strictEqual(page.data.form.manualProductImageFileIds, '11,12,13')
assert.strictEqual(page.data.form.manualProductImageUrl, 'https://img.example/1.jpg')
assert.strictEqual(page.data.form.manualProductImageUrl, '/tmp/style-1.jpg')
page.onManualProductImageError({ currentTarget: { dataset: { index: 0 } } })
assert.strictEqual(page.data.form.manualProductImages[0].previewUrl, 'https://img.example/1.jpg')
page.removeManualProductImage({ currentTarget: { dataset: { index: 0 } } })
assert.strictEqual(page.data.form.manualProductImageFileIds, '12,13')
assert.strictEqual(page.data.form.manualProductImageUrl, 'https://img.example/2.jpg')
assert.strictEqual(page.data.form.manualProductImageUrl, '/tmp/style-2.jpg')
page.data.form.manualProductImages = Array.from({ length: 8 }, (_, index) => ({ fileId: String(index + 20), fileUrl: `https://img.example/${index + 20}.jpg` }))
selectedImagePaths = ['/tmp/style-9.jpg', '/tmp/ignored.jpg']
@@ -196,7 +200,7 @@ async function testManualProductImages() {
uploadResults = [{ id: 29, fileUrl: 'https://img.example/29.jpg' }, new Error('第二张上传失败')]
await page.chooseManualProductImage()
assert.deepStrictEqual(page.data.form.manualProductImages, [
{ fileId: '29', fileUrl: 'https://img.example/29.jpg' }
{ fileId: '29', fileUrl: 'https://img.example/29.jpg', previewUrl: '/tmp/style-partial-1.jpg' }
])
assert.strictEqual(toastMessages.pop(), '第二张上传失败')
@@ -213,9 +217,24 @@ async function testManualProductImages() {
legacyDraftPage.loadOptions = () => {}
legacyDraftPage.onLoad({})
assert.deepStrictEqual(legacyDraftPage.data.form.manualProductImages, [
{ fileId: '44', fileUrl: 'https://img.example/legacy.jpg' }
{ fileId: '44', fileUrl: 'https://img.example/legacy.jpg', previewUrl: 'https://img.example/legacy.jpg' }
])
assert.strictEqual(legacyDraftPage.data.form.manualProductImageFileIds, '44')
global.wx.getStorageSync = () => ({ form: {
appointmentDate: '2026-10-21',
manualProductImages: [{
fileId: '45',
fileUrl: 'https://img.example/restored.jpg',
previewUrl: '/tmp/stale-style.jpg'
}]
} })
const restoredDraftPage = createPage()
restoredDraftPage.loadOptions = () => {}
restoredDraftPage.onLoad({})
restoredDraftPage.onManualProductImageError({ currentTarget: { dataset: { index: 0 } } })
assert.strictEqual(restoredDraftPage.data.form.manualProductImages[0].previewUrl, 'https://img.example/restored.jpg')
assert.strictEqual(restoredDraftPage.data.form.manualProductImageUrl, 'https://img.example/restored.jpg')
}
page.openProductModal()