From 5aadec396395c86cae6a059b3f2d8d893f16c6d2 Mon Sep 17 00:00:00 2001 From: chen <2659004835@qq.com> Date: Thu, 9 Dec 2021 16:54:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=A7=E5=93=81=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E3=80=81=E6=8E=88=E6=9D=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/canvasposter/canvasposter.js | 197 +++++++++++++++-------------- pages/index/index.js | 43 ++++--- pages/index/index.wxml | 2 +- pages/works/works.js | 67 +++++----- 4 files changed, 159 insertions(+), 150 deletions(-) diff --git a/pages/canvasposter/canvasposter.js b/pages/canvasposter/canvasposter.js index 6f112bf..94e5171 100644 --- a/pages/canvasposter/canvasposter.js +++ b/pages/canvasposter/canvasposter.js @@ -119,6 +119,24 @@ Page({ url: '../../img/background/1.png' }); this.getBottleCategories(); + // 换取token + wx.login({ + success: res => { + wx.request({ + url: urlPath.getopenid, + method: 'post', + data: {code: res.code}, + success(res) { + console.log(res); + if (res.data.code == 0) { + wx.setStorageSync('token', res.data.data.token); + wx.setStorageSync('username', res.data.data.user.wx_name); + console.log(wx.getStorageSync('username')); + } + } + }); + } + }) }, // 上传图片 uploadImg() { @@ -372,11 +390,17 @@ Page({ }, // 打开遮罩层 openMask() { - this.synthesis(); - this.setData({ - showCanvas: true, - showTitle:true - }) + if (wx.getStorageSync('username')!='' && wx.getStorageSync('username')!=undefined ) { + this.synthesis(); + this.setData({ + showCanvas: true, + showTitle:true + }) + } else { + this.setData({ + isLogin: true + }) + } }, downLoadImg(netUrl, storageKeyUrl) { wx.getImageInfo({ @@ -428,44 +452,38 @@ Page({ }, // 保存图片到系统相册 saveImg: function() { - if (wx.getStorageSync('token')) { - wx.saveImageToPhotosAlbum({ - filePath: this.data.canvasTemImg, - success: res => { - wx.showToast({ - title: '保存成功', - icon: "success" - }) - this.saveImgEv(this.data.canvasTemImg); - }, - fail: res => { - wx.showModal({ - title: '提示', - content: '保存失败,请确保相册权限已打开', - success: (e) => { - if (e.confirm) { - wx.openSetting({ - success: settingdata => { - if (settingdata.authSetting['scope.writePhotosAlbum']) { - console.log('获取权限成功,给出再次点击图片保存到相册的提示。') - } else { - console.log('获取权限失败,给出不给权限就无法正常使用的提示') - } - }, - fail: error => { - console.log(error) + wx.saveImageToPhotosAlbum({ + filePath: this.data.canvasTemImg, + success: res => { + wx.showToast({ + title: '保存成功', + icon: "success" + }) + this.saveImgEv(this.data.canvasTemImg); + }, + fail: res => { + wx.showModal({ + title: '提示', + content: '保存失败,请确保相册权限已打开', + success: (e) => { + if (e.confirm) { + wx.openSetting({ + success: settingdata => { + if (settingdata.authSetting['scope.writePhotosAlbum']) { + console.log('获取权限成功,给出再次点击图片保存到相册的提示。') + } else { + console.log('获取权限失败,给出不给权限就无法正常使用的提示') } - }) - } + }, + fail: error => { + console.log(error) + } + }) } - }) - } - }) - } else { - this.setData({ - isLogin: true - }) - } + } + }) + } + }) }, // 保存图片接口 saveImgEv(imgSrc) { @@ -498,51 +516,45 @@ Page({ }, // 分享图片 shareImg() { - if (wx.getStorageSync('token')) { - if(this.data.times==0){ - wx.showToast({ - title:'正在调起分享', - duration:5000 - }) - this.setData({ - times:this.data.times++ - }) - wx.uploadFile({ - url: urlPath.composeBottle, - filePath: this.data.canvasTemImg, - name: 'image', - formData: { - 'name': this.data.titleVal - }, - header: { - "Content-Type": "multipart/form-data", - 'Content-Type': 'application/json', - 'token': wx.getStorageSync('token') - }, - success: (res)=> { - let newRes = JSON.parse(res.data); - if(newRes.code==0){ - wx.downloadFile({ - url: 'https://fenggu.scdxtc.cn' + newRes.data.src, - success: (res) => { - wx.showShareImageMenu({ - path: res.tempFilePath, - success:(res)=>{ - this.shareEv(newRes.data.id); - } - }) - } - }) - } - }, - fail: function(data) { - console.log(data); - } - }) - } - } else { + if(this.data.times==0){ + wx.showToast({ + title:'正在调起分享', + duration:5000 + }) this.setData({ - isLogin: true + times:this.data.times++ + }) + wx.uploadFile({ + url: urlPath.composeBottle, + filePath: this.data.canvasTemImg, + name: 'image', + formData: { + 'name': this.data.titleVal + }, + header: { + "Content-Type": "multipart/form-data", + 'Content-Type': 'application/json', + 'token': wx.getStorageSync('token') + }, + success: (res)=> { + let newRes = JSON.parse(res.data); + if(newRes.code==0){ + wx.downloadFile({ + url: 'https://fenggu.scdxtc.cn' + newRes.data.src, + success: (res) => { + wx.showShareImageMenu({ + path: res.tempFilePath, + success:(res)=>{ + this.shareEv(newRes.data.id); + } + }) + } + }) + } + }, + fail: function(data) { + console.log(data); + } }) } }, @@ -599,15 +611,14 @@ Page({ wx_name: this.data.userInfo.nickName, avater: this.data.userInfo.avatarUrl, }, - success(res) { - console.log(res, 1234); + success:(res)=> { + console.log(this.data.userInfo.nickName,); + console.log(res); if (res.data.code == 0) { - wx.setStorageSync('token', res.data.data - .token); - wx.setStorageSync('openid', res.data.data - .openid); - wx.setStorageSync('user', res.data.data - .user); + wx.setStorageSync('token', res.data.data.token); + wx.setStorageSync('openid', res.data.data.openid); + wx.setStorageSync('username', res.data.data.user.wx_name); + console.log(wx.getStorageSync('username')); } } }); diff --git a/pages/index/index.js b/pages/index/index.js index 9985826..e5f7137 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -16,6 +16,7 @@ Page({ vote(e){ var that = this; var id = e.currentTarget.dataset.id; + let newIndex = e.currentTarget.dataset.index; if(id > 0){ wx.request({ url: urlPath.vote, @@ -30,7 +31,11 @@ Page({ wx.showToast({ title: '投票成功' }); - that.onLoad(); + that.data.works_list[newIndex].number++; + that.setData({ + works_list:that.data.works_list + }) + // that.onLoad(); }else{ wx.showToast({ title:res.data.msg, @@ -94,14 +99,11 @@ Page({ rule_text:['1、本次活动不收任何费用,不退稿。2、参赛作品需附有作品介绍,字数限100字以内。3、每位参赛者仅限提交不超过5幅3、每位参赛者仅限提交不超过5幅'],//活动规则 //列表 works_list: [], - page : 1, pageSize : 20, }); //登录状态 wx.checkSession({ success: function (res) { - console.log("DDDDDDD"); - that.getVoteList(); that.getSlideList(); that.saveVisit(); that.getBaseInfo(); @@ -110,14 +112,12 @@ Page({ fail: function(){ wx.login({ success: res => { - console.log(res); wx.request({ url: urlPath.getopenid, data: { code: res.code }, success(res) { - console.log(res); if(res.data.code == 0){ wx.setStorageSync('token', res.data.data.token); wx.setStorageSync('openid', res.data.data.openid); @@ -208,9 +208,15 @@ Page({ }, getVoteList:function(){ var that = this; - if(!that.data.forMore){ - return; - } + if(that.data.page==1) { + that.setData({ + works_list:[] + }) + } else { + if(!that.data.forMore){ + return; + } + } var vote_list = []; wx.request({ url: urlPath.getVoteList, @@ -222,6 +228,7 @@ Page({ page_size:that.data.pageSize }, success(res){ + console.log(res,9000); if(res.data.code == 0){ if(res.data.data.length > 0){ res.data.data.forEach(function(item){ @@ -237,9 +244,6 @@ Page({ that.setData({ works_list:that.data.works_list.concat(vote_list) }); - that.setData({ - page : that.data.page + 1 - }) }else{ that.setData({ forMore:false @@ -256,6 +260,7 @@ Page({ if(that.data.for_search){ that.search(); }else{ + that.data.page++ that.getVoteList(); } }, @@ -273,18 +278,14 @@ Page({ onReady: function () { }, - /** - * 生命周期函数--监听页面显示 - */ - onShow: function () { - - }, - /** * 生命周期函数--监听页面隐藏 */ onHide: function () { - + this.setData({ + page:1 + }) + this.getVoteList(); }, /** @@ -321,6 +322,8 @@ Page({ selected: 1 }) } + this.setData({page:1}) + this.getVoteList(); }, getBaseInfo:function(){ var that = this; diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 7868b13..78b4d37 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -63,7 +63,7 @@ {{item.name}} {{item.number}} - diff --git a/pages/works/works.js b/pages/works/works.js index 5c12a9a..b72e527 100644 --- a/pages/works/works.js +++ b/pages/works/works.js @@ -8,29 +8,10 @@ Page({ data: { workTitleArr: ['保存的作品', '分享的作品'], workIndex: 0, - imgArr: [{ - imgSrc: '../../img/background/1.png', - workName: '饺子吃肉肉饺子吃肉肉饺子吃肉肉饺子吃' - }, - { - imgSrc: '../../img/background/1.png', - workName: '饺子吃肉肉' - }, - { - imgSrc: '../../img/background/1.png', - workName: '饺子吃肉肉' - }, - { - imgSrc: '../../img/background/1.png', - workName: '饺子吃肉肉' - }, - { - imgSrc: '../../img/background/1.png', - workName: '饺子吃肉肉' - }, - ], + imgArr: [], page: 1, - size: 200 + size: 200, + times:0 }, /** @@ -77,25 +58,39 @@ Page({ this.setData({ imgArr: newArr }) + } else { + wx.showToast({ + title:'暂无作品数据', + icon:'none' + }) } } }); }, shareEv(e) { - wx.downloadFile({ - url: this.data.imgArr[e.currentTarget.dataset.index].imgSrc, - success: (res) => { - wx.showShareImageMenu({ - path: res.tempFilePath, - success:(res)=>{ - this.shareImg(e.currentTarget.dataset.id,e.currentTarget.dataset.index); - }, - fail:(err)=>{ - console.log(err); - } - }) - } - }) + if(this.data.times==0){ + wx.showToast({ + title:'正在调起分享', + duration:5000 + }) + this.setData({ + times:this.data.times++ + }) + wx.downloadFile({ + url: this.data.imgArr[e.currentTarget.dataset.index].imgSrc, + success: (res) => { + wx.showShareImageMenu({ + path: res.tempFilePath, + success:(res)=>{ + this.shareImg(e.currentTarget.dataset.id,e.currentTarget.dataset.index); + }, + fail:(err)=>{ + console.log(err); + } + }) + } + }) + } }, shareImg(id,index){ wx.request({