diff --git a/components/card.vue b/components/card.vue index 491a970..1022aa1 100644 --- a/components/card.vue +++ b/components/card.vue @@ -83,7 +83,8 @@ lastOpacity: 0, swipe: false, // 是否轮播,是否翻页 zIndex: 10 - } + }, + id:'' } }, computed: { @@ -113,6 +114,28 @@ this.el = await getElSize('flipcard', this) // 卡片的位置对象,上下左右,宽高 console.log('----', this.el) }) + const that = this + // 获取匿名用户唯一标识 + wx.login({ + success(res){ + console.log('code====',res.code); + wx.request({ + url: 'https://api.weixin.qq.com/sns/jscode2session', + data:{ + appid: 'wxab7dd0a14272badf', + secret: '1ff1d2119715e82db1adda4fe143eedb', + js_code: res.code, + grant_type:'authorization_code' + }, + method:"GET", + success(res){ + that.id = res.data.openid + console.log('openid=====',res.data.openid); // 得到openid + console.log('session_key====', res.data.session_key); // 得到 session_key + } + }) + } + }) }, watch:{ 'currentShow':{ @@ -124,7 +147,7 @@ // this.isVoteFlag = false const params = { rumorId:this.currentShow.id, // id - votePerson:userinfo.phone ?userinfo.phone : new Date().getTime() // 用户唯一标识 + votePerson:userinfo.phone ?userinfo.phone : this.id // 用户唯一标识 } // 查询用户是否投票 isVote(params).then(res => { @@ -139,10 +162,17 @@ methods: { // 点击真假进行投票 vote(flag) { + // 已经投票 + if(this.isVoteFlag) { + uni.$u.toast('您已投过票,自动跳转下一个') + this.next() + return + } + // 未投票 const userinfo = wx.getStorageSync('userInfoxj') const params = { rumorId:this.currentShow.id, - votePerson:userinfo.phone ?userinfo.phone : new Date().getTime(), // 用户唯一标识 + votePerson:userinfo.phone ?userinfo.phone : this.id, // 用户唯一标识 status: flag ? '1' : '0' } addVote(params).then(res => {