update at 2026-02-08 22:31:25

This commit is contained in:
douboer
2026-02-08 22:31:25 +08:00
parent 0f5a7f0d85
commit f078dd3261
39 changed files with 587 additions and 213 deletions

View File

@@ -25,6 +25,17 @@ async function saveSvgToUserPath(svgText, fontName, text) {
return writeTextToUserPath(svgText, 'svg', filename)
}
function saveSvgToUserPathSync(svgText, fontName, text) {
const filename = buildFilename(fontName, text, 'svg')
const filePath = `${wx.env.USER_DATA_PATH}/${filename}`
const fs = wx.getFileSystemManager()
fs.writeFileSync(filePath, svgText, 'utf8')
return {
filePath,
fileName: filename,
}
}
async function shareLocalFile(filePath, fileName) {
if (typeof wx.shareFileMessage !== 'function') {
throw new Error('当前微信版本不支持文件分享')
@@ -40,10 +51,29 @@ async function shareLocalFile(filePath, fileName) {
})
}
function shareSvgFromUserTap(svgText, fontName, text) {
if (typeof wx.shareFileMessage !== 'function') {
throw new Error('当前微信版本不支持文件分享')
}
const { filePath, fileName } = saveSvgToUserPathSync(svgText, fontName, text)
return new Promise((resolve, reject) => {
wx.shareFileMessage({
filePath,
fileName,
success: resolve,
fail: reject,
})
})
}
module.exports = {
sanitizeFilename,
buildFilename,
writeTextToUserPath,
saveSvgToUserPath,
saveSvgToUserPathSync,
shareLocalFile,
shareSvgFromUserTap,
}