问题如上。
<snapshot id="view" class="intro">
<view class="snapshot-box">
<view class="pages"> </view>
</view>
</snapshot>
tap() {
// Ensure all elements are rendered before taking a snapshot
setTimeout(() => {
this.createSelectorQuery().select("#view")
.node().exec(res => {
const node = res[0].node;
node.takeSnapshot({
type: 'arraybuffer',
format: 'png',
success: (res) => {
const f = `${wx.env.USER_DATA_PATH}/snapshot.png`;
const fs = wx.getFileSystemManager();
fs.writeFileSync(f, res.data, 'binary');
wx.showToast({
title: '保存成功'
});
wx.saveImageToPhotosAlbum({
filePath: f,
complete: (res) => {
console.log("saveImageToPhotosAlbum:", res);
}
});
},
fail: (res) => {
console.log("takeSnapshot fail:", res);
}
});
});
}, 500); // Delay to ensure rendering is complete
}
});
try { // ...省略canvas绘制代码 // 获取snapshotNode:仅Skyline const { node } = await new Promise<{ node : any }>(resolve => { this.createSelectorQuery() .select('#snapshot') .node(resolve) .exec() }) // 截图,延迟10ms是为了确保canvas绘制二维码完成 const { tempFilePath: path } = await new Promise<{ tempFilePath : string }>((resolve, reject) => { setTimeout(() => { node.takeSnapshot({ type: 'file', format: 'png', success: resolve, fail: reject }) }, 10) }) // console.log('path:', path); // 分享 wx.showShareImageMenu({ path, style: 'v2' }) } catch(error) {}
取消ABtest 全量skyline发布 限制线上最低版本库在3.1.1以上