修改产品列表、授权问题

master
chen 2021-12-09 16:54:23 +08:00
parent b05c3a3132
commit 5aadec3963
4 changed files with 159 additions and 150 deletions

View File

@ -119,6 +119,24 @@ Page({
url: '../../img/background/1.png' url: '../../img/background/1.png'
}); });
this.getBottleCategories(); 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() { uploadImg() {
@ -372,11 +390,17 @@ Page({
}, },
// 打开遮罩层 // 打开遮罩层
openMask() { openMask() {
this.synthesis(); if (wx.getStorageSync('username')!='' && wx.getStorageSync('username')!=undefined ) {
this.setData({ this.synthesis();
showCanvas: true, this.setData({
showTitle:true showCanvas: true,
}) showTitle:true
})
} else {
this.setData({
isLogin: true
})
}
}, },
downLoadImg(netUrl, storageKeyUrl) { downLoadImg(netUrl, storageKeyUrl) {
wx.getImageInfo({ wx.getImageInfo({
@ -428,44 +452,38 @@ Page({
}, },
// 保存图片到系统相册 // 保存图片到系统相册
saveImg: function() { saveImg: function() {
if (wx.getStorageSync('token')) { wx.saveImageToPhotosAlbum({
wx.saveImageToPhotosAlbum({ filePath: this.data.canvasTemImg,
filePath: this.data.canvasTemImg, success: res => {
success: res => { wx.showToast({
wx.showToast({ title: '保存成功',
title: '保存成功', icon: "success"
icon: "success" })
}) this.saveImgEv(this.data.canvasTemImg);
this.saveImgEv(this.data.canvasTemImg); },
}, fail: res => {
fail: res => { wx.showModal({
wx.showModal({ title: '提示',
title: '提示', content: '保存失败,请确保相册权限已打开',
content: '保存失败,请确保相册权限已打开', success: (e) => {
success: (e) => { if (e.confirm) {
if (e.confirm) { wx.openSetting({
wx.openSetting({ success: settingdata => {
success: settingdata => { if (settingdata.authSetting['scope.writePhotosAlbum']) {
if (settingdata.authSetting['scope.writePhotosAlbum']) { console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
console.log('获取权限成功,给出再次点击图片保存到相册的提示。') } else {
} else { console.log('获取权限失败,给出不给权限就无法正常使用的提示')
console.log('获取权限失败,给出不给权限就无法正常使用的提示')
}
},
fail: error => {
console.log(error)
} }
}) },
} fail: error => {
console.log(error)
}
})
} }
}) }
} })
}) }
} else { })
this.setData({
isLogin: true
})
}
}, },
// 保存图片接口 // 保存图片接口
saveImgEv(imgSrc) { saveImgEv(imgSrc) {
@ -498,51 +516,45 @@ Page({
}, },
// 分享图片 // 分享图片
shareImg() { shareImg() {
if (wx.getStorageSync('token')) { if(this.data.times==0){
if(this.data.times==0){ wx.showToast({
wx.showToast({ title:'正在调起分享',
title:'正在调起分享', duration:5000
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 {
this.setData({ 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, wx_name: this.data.userInfo.nickName,
avater: this.data.userInfo.avatarUrl, avater: this.data.userInfo.avatarUrl,
}, },
success(res) { success:(res)=> {
console.log(res, 1234); console.log(this.data.userInfo.nickName,);
console.log(res);
if (res.data.code == 0) { if (res.data.code == 0) {
wx.setStorageSync('token', res.data.data wx.setStorageSync('token', res.data.data.token);
.token); wx.setStorageSync('openid', res.data.data.openid);
wx.setStorageSync('openid', res.data.data wx.setStorageSync('username', res.data.data.user.wx_name);
.openid); console.log(wx.getStorageSync('username'));
wx.setStorageSync('user', res.data.data
.user);
} }
} }
}); });

View File

@ -16,6 +16,7 @@ Page({
vote(e){ vote(e){
var that = this; var that = this;
var id = e.currentTarget.dataset.id; var id = e.currentTarget.dataset.id;
let newIndex = e.currentTarget.dataset.index;
if(id > 0){ if(id > 0){
wx.request({ wx.request({
url: urlPath.vote, url: urlPath.vote,
@ -30,7 +31,11 @@ Page({
wx.showToast({ wx.showToast({
title: '投票成功' title: '投票成功'
}); });
that.onLoad(); that.data.works_list[newIndex].number++;
that.setData({
works_list:that.data.works_list
})
// that.onLoad();
}else{ }else{
wx.showToast({ wx.showToast({
title:res.data.msg, title:res.data.msg,
@ -94,14 +99,11 @@ Page({
rule_text:['1、本次活动不收任何费用不退稿。2、参赛作品需附有作品介绍字数限100字以内。3、每位参赛者仅限提交不超过5幅3、每位参赛者仅限提交不超过5幅'],//活动规则 rule_text:['1、本次活动不收任何费用不退稿。2、参赛作品需附有作品介绍字数限100字以内。3、每位参赛者仅限提交不超过5幅3、每位参赛者仅限提交不超过5幅'],//活动规则
//列表 //列表
works_list: [], works_list: [],
page : 1,
pageSize : 20, pageSize : 20,
}); });
//登录状态 //登录状态
wx.checkSession({ wx.checkSession({
success: function (res) { success: function (res) {
console.log("DDDDDDD");
that.getVoteList();
that.getSlideList(); that.getSlideList();
that.saveVisit(); that.saveVisit();
that.getBaseInfo(); that.getBaseInfo();
@ -110,14 +112,12 @@ Page({
fail: function(){ fail: function(){
wx.login({ wx.login({
success: res => { success: res => {
console.log(res);
wx.request({ wx.request({
url: urlPath.getopenid, url: urlPath.getopenid,
data: { data: {
code: res.code code: res.code
}, },
success(res) { success(res) {
console.log(res);
if(res.data.code == 0){ if(res.data.code == 0){
wx.setStorageSync('token', res.data.data.token); wx.setStorageSync('token', res.data.data.token);
wx.setStorageSync('openid', res.data.data.openid); wx.setStorageSync('openid', res.data.data.openid);
@ -208,9 +208,15 @@ Page({
}, },
getVoteList:function(){ getVoteList:function(){
var that = this; var that = this;
if(!that.data.forMore){ if(that.data.page==1) {
return; that.setData({
} works_list:[]
})
} else {
if(!that.data.forMore){
return;
}
}
var vote_list = []; var vote_list = [];
wx.request({ wx.request({
url: urlPath.getVoteList, url: urlPath.getVoteList,
@ -222,6 +228,7 @@ Page({
page_size:that.data.pageSize page_size:that.data.pageSize
}, },
success(res){ success(res){
console.log(res,9000);
if(res.data.code == 0){ if(res.data.code == 0){
if(res.data.data.length > 0){ if(res.data.data.length > 0){
res.data.data.forEach(function(item){ res.data.data.forEach(function(item){
@ -237,9 +244,6 @@ Page({
that.setData({ that.setData({
works_list:that.data.works_list.concat(vote_list) works_list:that.data.works_list.concat(vote_list)
}); });
that.setData({
page : that.data.page + 1
})
}else{ }else{
that.setData({ that.setData({
forMore:false forMore:false
@ -256,6 +260,7 @@ Page({
if(that.data.for_search){ if(that.data.for_search){
that.search(); that.search();
}else{ }else{
that.data.page++
that.getVoteList(); that.getVoteList();
} }
}, },
@ -273,18 +278,14 @@ Page({
onReady: function () { onReady: function () {
}, },
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/** /**
* 生命周期函数--监听页面隐藏 * 生命周期函数--监听页面隐藏
*/ */
onHide: function () { onHide: function () {
this.setData({
page:1
})
this.getVoteList();
}, },
/** /**
@ -321,6 +322,8 @@ Page({
selected: 1 selected: 1
}) })
} }
this.setData({page:1})
this.getVoteList();
}, },
getBaseInfo:function(){ getBaseInfo:function(){
var that = this; var that = this;

View File

@ -63,7 +63,7 @@
<view class="name" bindtap="personal" data-uid="{{item.uid}}"> <view class="name" bindtap="personal" data-uid="{{item.uid}}">
{{item.name}} <text>{{item.number}}</text> {{item.name}} <text>{{item.number}}</text>
</view> </view>
<button class="add" bindtap='vote' data-id="{{item.ids}}"> <button class="add" bindtap='vote' data-id="{{item.ids}}" data-index="{{index}}">
投票 投票
</button> </button>
</view> </view>

View File

@ -8,29 +8,10 @@ Page({
data: { data: {
workTitleArr: ['保存的作品', '分享的作品'], workTitleArr: ['保存的作品', '分享的作品'],
workIndex: 0, workIndex: 0,
imgArr: [{ 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: '饺子吃肉肉'
},
],
page: 1, page: 1,
size: 200 size: 200,
times:0
}, },
/** /**
@ -77,25 +58,39 @@ Page({
this.setData({ this.setData({
imgArr: newArr imgArr: newArr
}) })
} else {
wx.showToast({
title:'暂无作品数据',
icon:'none'
})
} }
} }
}); });
}, },
shareEv(e) { shareEv(e) {
wx.downloadFile({ if(this.data.times==0){
url: this.data.imgArr[e.currentTarget.dataset.index].imgSrc, wx.showToast({
success: (res) => { title:'正在调起分享',
wx.showShareImageMenu({ duration:5000
path: res.tempFilePath, })
success:(res)=>{ this.setData({
this.shareImg(e.currentTarget.dataset.id,e.currentTarget.dataset.index); times:this.data.times++
}, })
fail:(err)=>{ wx.downloadFile({
console.log(err); 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){ shareImg(id,index){
wx.request({ wx.request({