update at 2026-02-11 12:10:49
This commit is contained in:
@@ -104,6 +104,22 @@ function showExportError(title, error, fallback) {
|
||||
})
|
||||
}
|
||||
|
||||
function toPngSaveError(saveResult) {
|
||||
if (!saveResult || saveResult.success) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (saveResult.reason === 'private_api_banned') {
|
||||
return new Error('当前小程序账号不支持“保存到相册”(private api banned)。请改用“导出 SVG”分享,或更换支持该能力的账号/版本。')
|
||||
}
|
||||
|
||||
if (saveResult.reason === 'auth_denied') {
|
||||
return saveResult.error || new Error('保存失败,请检查相册权限')
|
||||
}
|
||||
|
||||
return saveResult.error || new Error('保存 PNG 失败')
|
||||
}
|
||||
|
||||
function writePngBufferToTempFile(pngBuffer, fontName) {
|
||||
const safeName = String(fontName || 'font').replace(/[<>:"/\\|?*\x00-\x1F]/g, '_').slice(0, 60) || 'font'
|
||||
const filePath = `${wx.env.USER_DATA_PATH}/${safeName}_${Date.now()}.png`
|
||||
@@ -906,7 +922,7 @@ Page({
|
||||
|
||||
const saveResult = await savePngToAlbum(pngPath)
|
||||
if (!saveResult.success) {
|
||||
throw saveResult.error || new Error('保存 PNG 失败')
|
||||
throw toPngSaveError(saveResult)
|
||||
}
|
||||
}
|
||||
wx.showToast({ title: 'PNG 已保存到相册', icon: 'success' })
|
||||
@@ -970,7 +986,7 @@ Page({
|
||||
if (saveResult.success) {
|
||||
wx.showToast({ title: 'PNG 已保存到相册', icon: 'success' })
|
||||
} else {
|
||||
showExportError('导出 PNG 失败', saveResult.error, '保存失败,请检查相册权限')
|
||||
showExportError('导出 PNG 失败', toPngSaveError(saveResult), '保存 PNG 失败')
|
||||
}
|
||||
} catch (error) {
|
||||
showExportError('导出 PNG 失败', error, '请稍后重试')
|
||||
@@ -1029,7 +1045,7 @@ Page({
|
||||
if (saveResult.success) {
|
||||
wx.showToast({ title: 'PNG 已保存到相册', icon: 'success' })
|
||||
} else {
|
||||
showExportError('导出 PNG 失败', saveResult.error, '保存失败,请检查相册权限')
|
||||
showExportError('导出 PNG 失败', toPngSaveError(saveResult), '保存 PNG 失败')
|
||||
}
|
||||
} catch (error) {
|
||||
showExportError('导出 PNG 失败', error, '请稍后重试')
|
||||
|
||||
@@ -104,7 +104,9 @@ async function savePngToAlbum(filePath) {
|
||||
return { success: true }
|
||||
} catch (error) {
|
||||
const errMsg = String(error && error.errMsg ? error.errMsg : error)
|
||||
const needAuth = errMsg.includes('auth deny') || errMsg.includes('authorize')
|
||||
const lowerErrMsg = errMsg.toLowerCase()
|
||||
const needAuth = lowerErrMsg.includes('auth deny') || lowerErrMsg.includes('authorize')
|
||||
const privateApiBanned = lowerErrMsg.includes('private api banned')
|
||||
|
||||
if (needAuth) {
|
||||
const modalRes = await showModal({
|
||||
@@ -120,6 +122,10 @@ async function savePngToAlbum(filePath) {
|
||||
return {
|
||||
success: false,
|
||||
needAuth,
|
||||
privateApiBanned,
|
||||
reason: privateApiBanned
|
||||
? 'private_api_banned'
|
||||
: (needAuth ? 'auth_denied' : 'save_failed'),
|
||||
error,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user