功能:同步小程序流程

This commit is contained in:
xiaowang
2026-05-23 18:45:41 +08:00
parent 844516988b
commit 30ae763e18
117 changed files with 8823 additions and 76 deletions
+54
View File
@@ -1,10 +1,22 @@
/**
* Purpose: fileApi supports file.js by holding or executing the file api 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 fileApi = require('../api/file')
const { DEFAULT_PRODUCT_IMAGE } = require('./config')
const { CACHE_TTL } = require('./config')
const { splitCsv } = require('./format')
/**
* Purpose: urlCache supports file.js by holding or executing the url 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 urlCache = {}
/**
* Purpose: getSignedUrl supports file.js by holding or executing the get signed url page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
async function getSignedUrl(fileId) {
const key = String(fileId || '')
if (!key) {
@@ -24,6 +36,10 @@ async function getSignedUrl(fileId) {
return urlCache[key].value
}
/**
* Purpose: extractLegacyFileId supports file.js by holding or executing the extract legacy file id page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function extractLegacyFileId(value) {
const match = String(value || '')
.replace(/<[^>]*>/g, '')
@@ -32,6 +48,10 @@ function extractLegacyFileId(value) {
return match && match[1] ? match[1] : ''
}
/**
* Purpose: resolveImageList supports file.js by holding or executing the resolve image list page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
async function resolveImageList(fileIds, fallbackImage) {
const ids = Array.isArray(fileIds) ? fileIds : splitCsv(fileIds)
if (!ids.length) {
@@ -49,6 +69,10 @@ async function resolveImageList(fileIds, fallbackImage) {
return urls.length ? urls : [fallbackImage || DEFAULT_PRODUCT_IMAGE]
}
/**
* Purpose: resolveLegacyImage supports file.js by holding or executing the resolve legacy image page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
async function resolveLegacyImage(value, fallbackImage) {
const fileId = extractLegacyFileId(value)
if (!fileId) {
@@ -63,11 +87,41 @@ 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) {
const list = (Array.isArray(urls) ? urls : [current]).filter(Boolean)
if (!current || !list.length) {
wx.showToast({
title: '图片暂不可预览',
icon: 'none'
})
return
}
wx.previewImage({
current,
urls: list,
fail: () => {
wx.showToast({
title: '图片预览失败,请稍后重试',
icon: 'none'
})
}
})
}
module.exports = {
getSignedUrl,
extractLegacyFileId,
resolveImageList,
resolveLegacyImage,
previewImagesSafely,
/**
* Purpose: clearSignedUrlCache supports file.js by holding or executing the clear signed url cache page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
clearSignedUrlCache(fileId) {
if (fileId === undefined || fileId === null || fileId === '') {
Object.keys(urlCache).forEach(key => delete urlCache[key])