Commit 06b394af authored by youjie's avatar youjie

no message

parent 3ec2c0c4
......@@ -189,7 +189,6 @@
// 1. 清理 Base64 前缀(如 data:image/png;base64,)
const base64Data = this.list[this.current].data
// 2. 解码 Base64 为二进制字符串
// 3. 转换为 Uint8Array(二进制数组)
const arrayBuffer = wx.base64ToArrayBuffer(base64Data);
// 3. 转换为临时文件路径(微信小程序需通过临时文件)
const tempDir = wx.env.USER_DATA_PATH; // 临时目录(无需权限)
......@@ -203,8 +202,8 @@
data: arrayBuffer, // 直接写入 ArrayBuffer
encoding: 'binary', // 必须指定为 binary
success: () => {
uni.showToast({ title: '临时文件:' + filePath });
// uni.showToast({ title: '临时文件:' + filePath });
console.log(filePath,'----')
// 可选:保存到相册(需授权)
that.saveFileToPhone(filePath);
},
......@@ -215,16 +214,32 @@
});
},
saveFileToPhone(tempFilePath) {
uni.saveFile({
tempFilePath: tempFilePath,
success: (saveRes) => {
uni.showToast({ title: '文件已保存至:' + saveRes.savedFilePath });
},
fail: (err) => {
uni.showToast({ title: '保存失败', icon: 'none' });
console.error('保存错误', err);
}
});
const platform = uni.getSystemInfoSync().platform;
if (platform === 'mp-weixin'||platform === 'devtools') {
// 微信小程序:使用 wx.saveImageToPhotosAlbum
wx.saveImageToPhotosAlbum({
filePath: tempFilePath,
success: (saveRes) => {
uni.showToast({ title: '保存成功'});
console.log(saveRes,'----文件地址');
},
fail: (err) => {
uni.showToast({ title: '保存失败', icon: 'none' });
console.error('保存错误', err);
}
});
}
// uni.saveFile({
// tempFilePath: tempFilePath,
// success: (saveRes) => {
// uni.showToast({ title: '文件已保存至:' + saveRes.savedFilePath });
// console.log(saveRes.savedFilePath,'----文件地址');
// },
// fail: (err) => {
// uni.showToast({ title: '保存失败', icon: 'none' });
// console.error('保存错误', err);
// }
// });
},
canvasToTempFilePath(){
uni.canvasToTempFilePath({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment