小程序端
onDown() {uni.authorize({scope: 'scope.writePhotosAlbum',success: () => {this.downloadImage();},fail: () => {uni.showToast({title: "请授权相册权限",icon: "none"});}});
},
downloadImage() {common.request('post', '/agent/Managestart/downQrcode', {device_id: this.device_id}).then(res => {if (res.code === 1) {uni.downloadFile({url: res.data,success: (downloadRes) => {if (downloadRes.statusCode === 200) {uni.saveImageToPhotosAlbum({filePath: downloadRes.tempFilePath,success: () => {uni.showToast({title: "保存成功"});},fail: () => {uni.showToast({title: "保存失败",icon: "none"});}});}}});}});
}
微信打开
onDown() {common.request('post', '/agent/Managestart/downQrcode', {device_id: this.device_id}).then(res => {if (res.code == 1) {const imageData = common.image(res.data);const isWeixin = /MicroMessenger/i.test(navigator.userAgent);if (isWeixin) {window.location.href = imageData;} else {const link = document.createElement("a");link.href = imageData;link.download = "qrcode.png";document.body.appendChild(link);link.click();document.body.removeChild(link);}} else {uni.showToast({title: "获取图片失败",icon: "none"});}}).catch(() => {uni.showToast({title: "网络异常",icon: "none"});});
},