浏览代码

bug修复

master
suizhijia 5 年前
父节点
当前提交
4b1118784e
共有 1 个文件被更改,包括 8 次插入8 次删除
  1. +8
    -8
      496_dongfengqichen/pages/poster/poster.js

+ 8
- 8
496_dongfengqichen/pages/poster/poster.js 查看文件

onLoad: function (options) { onLoad: function (options) {
app.globalData.nowPage = 2; app.globalData.nowPage = 2;
}, },

/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
onReady: function () { onReady: function () {
_totalDownloadTask = 6;
_currentSuccessDownloadTask = 0;
_saveImg = false;
if(app.globalData.userInfoData && app.globalData.userInfoData.avatarUrl){ if(app.globalData.userInfoData && app.globalData.userInfoData.avatarUrl){
this.data.userHead = app.globalData.userInfoData.avatarUrl; this.data.userHead = app.globalData.userInfoData.avatarUrl;
this.setData({ this.setData({
} }
}, },
cacheFun:function(){ cacheFun:function(){
// _saveImg = true;
wx.getSystemInfo({ wx.getSystemInfo({
success: option => { success: option => {
this.data.windowScale = option.windowWidth / 750; this.data.windowScale = option.windowWidth / 750;
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function () { onShow: function () {
_totalDownloadTask = 6;
_currentSuccessDownloadTask = 0;
_saveImg = false;

}, },


/** /**
} }
}, },
saveImg: function () {//保存到手机 saveImg: function () {//保存到手机
console.log(this.data.posterUrl);
if (!this.data.posterUrl[this.data.swiperCurrent]){ if (!this.data.posterUrl[this.data.swiperCurrent]){
wx.showLoading({ wx.showLoading({
title: '海报合成中', title: '海报合成中',
mask:true mask:true
}) })
console.log("swiperCurrent = " + this.data.swiperCurrent)
_saveImg = true; _saveImg = true;
// console.log("值1:"+_currentSuccessDownloadTask);
this.posterDrawing(this.data.swiperCurrent + 1); this.posterDrawing(this.data.swiperCurrent + 1);
}else{ }else{
this.savePic(); this.savePic();
} }
}, },
savePic: function () { savePic: function () {
wx.hideLoading();
wx.saveImageToPhotosAlbum({ wx.saveImageToPhotosAlbum({
filePath: this.data.posterUrl[this.data.swiperCurrent], filePath: this.data.posterUrl[this.data.swiperCurrent],
success(res) { success(res) {
// console.log("_totalDownloadTask = " + _totalDownloadTask) // console.log("_totalDownloadTask = " + _totalDownloadTask)
// console.log("_currentSuccessDownloadTask = " + _currentSuccessDownloadTask) // console.log("_currentSuccessDownloadTask = " + _currentSuccessDownloadTask)
//图片尚未下载完成,禁止绘制 //图片尚未下载完成,禁止绘制
// console.log("值2:"+_currentSuccessDownloadTask);
if(_currentSuccessDownloadTask < _totalDownloadTask || !_saveImg){ if(_currentSuccessDownloadTask < _totalDownloadTask || !_saveImg){
return; return;
} }
//先画个圆 前两个参数确定了圆心 (x,y) 坐标 第三个参数是圆的半径 四参数是绘图方向 默认是false,即顺时针 //先画个圆 前两个参数确定了圆心 (x,y) 坐标 第三个参数是圆的半径 四参数是绘图方向 默认是false,即顺时针
ctx.arc(scale * 50 / 2 + scale * 121, scale * 50 / 2 + scale * 62, scale * 50 / 2, 0, Math.PI * 2, false); ctx.arc(scale * 50 / 2 + scale * 121, scale * 50 / 2 + scale * 62, scale * 50 / 2, 0, Math.PI * 2, false);
ctx.clip(); //剪切 ctx.clip(); //剪切
console.log(this.data.userHead)
ctx.drawImage(this.data.userHead, scale * 121, scale * 62, scale * 50, scale * 50); //头像 ctx.drawImage(this.data.userHead, scale * 121, scale * 62, scale * 50, scale * 50); //头像
ctx.restore(); //恢复之前保存的绘图上下文 ctx.restore(); //恢复之前保存的绘图上下文
//名称 //名称
canvasId: 'myCanvas', canvasId: 'myCanvas',
success: res => { success: res => {
this.data.posterUrl[this.data.swiperCurrent] = res.tempFilePath; this.data.posterUrl[this.data.swiperCurrent] = res.tempFilePath;
wx.hideLoading();
this.savePic(); this.savePic();
} }
}) })

正在加载...
取消
保存