微信小程序bug
一、小程序分享到好友,需要带上path
//分享微信小程序给好友
onShareAppMessage(res) {
if (res.from === "button") {
// 来自页面内转发按钮
this.isShare = false;
}
return {
title: this.detailData.ProName,
path:
"/pages/goods/goodsDetail/goodsDetail?ClubSN=" +
this.ClubSN +
"&ProId=" +
this.ProId
};
}
二、canvas画图需要使用本地临时路径
Taro.downloadFile({
url: ShopLogo, //仅为示例,并非真实的资源
success: res => {
that.ShopLogo = res.tempFilePath;
console.log("店铺图标", that.ShopLogo);
resolve(1);
}
});
三、canvas不支持base64格式图片,需要先转换
//base64src.js方法
const fsm = wx.getFileSystemManager();
const FILE_BASE_NAME = 'tmp_base64src'; //自定义文件名
function base64src(base64data, cb) {
const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64data) || [];
if (!format) {
return (new Error('ERROR_BASE64SRC_PARSE'));
}
const filePath = `${wx.env.USER_DATA_PATH}/${FILE_BASE_NAME}.${format}`;
const buffer = wx.base64ToArrayBuffer(bodyData);
fsm.writeFile({
filePath,
data: buffer,
encoding: 'binary',
success() {
cb(filePath);
},
fail() {
return (new Error('ERROR_BASE64SRC_WRITE'));
},
});
};
export default base64src;
使用
import base64src from "@/utils/base64src.js";
//使用
base64src(qrCode, res => {
console.log(res); // 返回图片地址,直接赋值到image标签即可
let path = res;
ctx.drawImage(
path,
0 * rpx,
0 * rpx,
530 * rpx,
530 * rpx,
qrCode1,
435 * rpx,
qrCodeWidth * rpx,
qrCodeWidth * rpx
);
});
四、canvas获取屏幕宽度,获取自适应单位变量rpx
<canvas id="poster"
:style="{width:canvasWidth+'px', height:canvasHeight+'px'}"
canvasId="poster"
@longtap="clickCanvas" />
//获取屏幕宽度,获取自适应单位
let that = this;
wx.getSystemInfo({
success: function(res) {
that.rpx = res.windowWidth / 375;
that.deviceWidth = res.windowWidth;
that.deviceHeight = res.windowHeight;
that.canvasWidth = res.windowWidth - 36 * that.rpx;
that.canvasHeight = 579 * that.rpx;
console.log(that.rpx, "倍");
console.log("设备宽", that.deviceWidth);
console.log("canvas宽", that.canvasWidth);
console.log("canvas高", that.canvasHeight);
}
});
//设备像素比
const dpr = wx.getSystemInfoSync().pixelRatio
canvas.width = res[0].width * dpr
canvas.height = res[0].height * dpr
注:以上内容仅用于日常学习

浙公网安备 33010602011771号