功能(小程序):同步用户体验流程到小程序
This commit is contained in:
+45
-13
@@ -6,6 +6,17 @@ const fileApi = require('../api/file')
|
||||
const { DEFAULT_PRODUCT_IMAGE } = require('./config')
|
||||
const { CACHE_TTL } = require('./config')
|
||||
const { splitCsv } = require('./format')
|
||||
const { showRecoveryModal } = require('./recovery')
|
||||
|
||||
function handlePreviewRecoveryAction(action) {
|
||||
if (!action || action.key !== 'products') {
|
||||
return
|
||||
}
|
||||
wx.switchTab({
|
||||
url: '/pages/products/index',
|
||||
fail() {}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: urlCache supports file.js by holding or executing the url cache page or API role.
|
||||
@@ -91,24 +102,45 @@ async function resolveLegacyImage(value, fallbackImage) {
|
||||
* Purpose: previewImagesSafely opens wx.previewImage with a user-facing fallback when signed URLs expire or preview fails.
|
||||
* Usage: pass the current image URL and full URL list from image tap handlers instead of calling wx.previewImage directly.
|
||||
*/
|
||||
function previewImagesSafely(current, urls) {
|
||||
function previewImagesSafely(current, urls, options) {
|
||||
const config = options || {}
|
||||
const list = (Array.isArray(urls) ? urls : [current]).filter(Boolean)
|
||||
if (!current || !list.length) {
|
||||
wx.showToast({
|
||||
return showRecoveryModal({
|
||||
title: '图片暂不可预览',
|
||||
icon: 'none'
|
||||
message: config.emptyMessage || '没有可预览的图片,请返回作品列表查看其他款式。',
|
||||
actions: [
|
||||
{ key: 'dismiss', text: '知道了' },
|
||||
{ key: 'products', text: '看作品' }
|
||||
]
|
||||
}).then(action => {
|
||||
handlePreviewRecoveryAction(action)
|
||||
return action
|
||||
})
|
||||
return
|
||||
}
|
||||
wx.previewImage({
|
||||
current,
|
||||
urls: list,
|
||||
fail: () => {
|
||||
wx.showToast({
|
||||
title: '图片预览失败,请稍后重试',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
wx.previewImage({
|
||||
current,
|
||||
urls: list,
|
||||
success: () => resolve(null),
|
||||
fail: () => {
|
||||
showRecoveryModal({
|
||||
title: '图片预览失败',
|
||||
message: config.failMessage || '图片链接可能已过期,请重试;仍失败时可以返回作品列表重新进入。',
|
||||
actions: [
|
||||
{ key: 'retry', text: '重试' },
|
||||
{ key: 'products', text: '看作品' }
|
||||
]
|
||||
}).then(action => {
|
||||
if (action && action.key === 'retry') {
|
||||
previewImagesSafely(current, list, config).then(resolve)
|
||||
return
|
||||
}
|
||||
handlePreviewRecoveryAction(action)
|
||||
resolve(action)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user