wechat.js 1.03 KB
Page({
	onLoad(opt){
		//导航栏自适应
		let systemInfo = wx.getSystemInfoSync();
		let reg = /ios/i;
		let pt = 20;//导航状态栏上内边距
		let h = 44;//导航状态栏高度
		if (reg.test(systemInfo.system)) {
		  pt = systemInfo.statusBarHeight;
		  h = 44;
		} else {
		  pt = systemInfo.statusBarHeight;
		  h = 48;
		}
		this.setData({
		  height: systemInfo.windowHeight,
		  statusBarHeight: pt,
		  titleBarHeight: h,
		  qrcode:opt.qrcode
		})
	},
	saveimage(){
		wx.downloadFile({
		  url: this.data.qrcode, //仅为示例,并非真实的资源
		  success (res) {
		    // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
		    if (res.statusCode === 200) {
		      wx.saveImageToPhotosAlbum({
				filePath:res.tempFilePath,  
		        success:(res)=>{ 
					wx.showToast({
						title:'保存成功',
						duration:2000,
						mask:true,
					})
				},
				fail:(fail)=>{
					
				}
		      })
		    }
		  }
		})
	}
})