华为p40pro 微信80.010
chooseImg() {
let that = this;
let url = window.location.href;
getSignature({ url: url }).then((res) => {
if (res.success) {
that.registerWeChat(res.result);
}
});
},
registerWeChat(data) {
let that = this;
wx.config({
debug: false,
appId: process.env.VUE_APP_APP_ID,
timestamp: data.timestamp,
nonceStr: data.nonceStr,
signature: data.signature,
jsApiList: [
"uploadImage",
"downloadImage",
"getLocalImgData",
"chooseImage",
],
});
wx.ready(function () {
wx.chooseImage({
count: 1,
sizeType: ["original", "compressed"],
sourceType: ["album", "camera"],
success: function (res) {
var localIds = res.localIds;
wx.getLocalImgData({
localId: localIds[0],
success: function (res) {
var localData = res.localData;
if (localData.indexOf("data:image") != 0) {
localData = "data:image/jpeg;base64," + localData;
}
localData = localData
.replace(/\r|\n/g, "")
.replace("data:image/jgp", "data:image/jpeg");
that.uploadHeader(localData);
},
});
},
});
});
wx.error(function (res) {
alert('错了')
});
},
base64toFile(dataurl, filename = "file") {
let arr = dataurl.split(",");
let mime = arr[0].match(/:(.*?);/)[1];
let suffix = mime.split("/")[1];
let bstr = atob(arr[1]);
let n = bstr.length;
let u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
let datas = new File([u8arr], `${filename}.${suffix}`, {
type: mime,
});
return datas;
},
uploadHeader(fileData) {
let that = this;
let files = that.base64toFile(fileData, timestamp());
this.$nextTick(() => {
let param = new FormData();
param.append("file", files);
param.append("biz", 'temp');
uploadFile(param).then((res) => {
if (res.success) {
that.updateUserInfo(res.message);
}
});
});
},
updateUserInfo(urls) {
let that = this;
let params = {
avatar: urls,
id: that.userInfo.id,
};
editUserInfo(params).then((res) => {
if (res.success) {
that.getUser();
} else {
Toast.fail(res.message);
}
});
},
chooseImage会触发app.js里的onShow和当前页面的onShow、onHide。是不是在里面写了什么跳转了