diff --git a/app.js b/app.js index c270d1a..caaef00 100644 --- a/app.js +++ b/app.js @@ -23,9 +23,43 @@ App({ // // 发送 res.code 到后台换取 openId, sessionKey, unionId // } // }) + this.loginGettoken() }, globalData: { userInfo: null, - token: '1212121212' - } + token: '2222' + }, + //登录-获取token + loginGettoken(){ + let that = this + wx.login({ + success (res) { + if (res.code) { + //发起网络请求 + wx.request({ + url:'https://cktest.2weisou.com/meta/auth/mobile/token/social?grant_type=mobil&mobile=MINI_C@'+res.code+'@'+'', + method: "POST", + data: { + }, + header: { + Authorization: "Basic YXBwbGV0OmFwcGxldA==", + }, + success(res1) { + if (res1.statusCode == 200) { + let userInfo = res1.data.user_info + that.globalData.token = res1.data.access_token + that.globalData.userInfo = res1.data.user_info + // console.log(that.globalData.token) + // console.log(that.globalData.userInfo) + wx.setStorageSync('token', res1.data.access_token) + wx.setStorageSync('userInfo', res1.data.user_info) + } + } + }) + } else { + console.log('登录失败!' + res.errMsg) + } + } + }) + }, }) diff --git a/pages/index/index.js b/pages/index/index.js index 7b2174d..6d2a37d 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -8,10 +8,12 @@ Page({ }, onLoad() { }, - tabindex(e) { - let index= e.currentTarget.dataset.index + + tabindex() { + let userInfo = getApp().globalData.userInfo + console.log(userInfo) wx.navigateTo({ - url: '../out/index?index=' +index, + url: '/pages/out/index?index=1&userid=' + userInfo.id + '&gameid=1'+ '&type=' + 1 }) }, tabsaoma() { diff --git a/pages/login/index.js b/pages/login/index.js index 90800c1..9bb0cee 100644 --- a/pages/login/index.js +++ b/pages/login/index.js @@ -1,7 +1,9 @@ // index.js // 获取应用实例 const app = getApp() - +let userInfo = getApp().globalData.userInfo +let token = getApp().globalData.token +console.log(userInfo) Page({ data: { avatarModal: false, @@ -16,7 +18,37 @@ Page({ token: '' }, onLoad() { - this.loginGettoken() + if (userInfo) { + this.setData({ + token: token, + userid: userInfo.id, + userInfo: userInfo + }) + if(!!userInfo.userWxName&&!!userInfo.phone){ + this.leave() + return; + } + if(!userInfo.userWxName||!userInfo.phone){ + this.setData({ + showBg: true + }) + }else{ + this.setData({ + showBg: false + }) + } + this.setData({ + avatarModal: !!userInfo.userWxName?false:true, + phoneModal1: !!userInfo.phone?false:true, + step: 1 + }) + if(!this.data.avatarModal){ + this.setData({ + step: 2, + phoneModal: this.data.phoneModal1 + }) + } + } }, backhome(){ wx.navigateTo({ diff --git a/pages/middle/index.js b/pages/middle/index.js index 505291f..26cbdb5 100644 --- a/pages/middle/index.js +++ b/pages/middle/index.js @@ -1,4 +1,4 @@ -// pages/out/index.js + Page({ /** @@ -10,17 +10,11 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad: function (options) { - // wx.navigateTo({ - // url: '/pages/login/index' - // }) + wx.showModal({ title: '温馨提示', content: '确定进入该小程序吗', showCancel: false,//是否显示取消按钮 - // cancelText: "取消",//默认是“取消” - // cancelColor: '#000000',//取消文字的颜色 - // confirmText: "确定",//默认是“确定” - // confirmColor: '#3cc51f',//确定文字的颜色 success: function (res) { if (res.cancel) { //点击取消,wx.navigateBack diff --git a/pages/share/index.js b/pages/share/index.js index 1f4a295..a1b6a71 100644 --- a/pages/share/index.js +++ b/pages/share/index.js @@ -12,13 +12,13 @@ Page({ onLoad: function (options) { }, - backGame(){ + closeShare(){ // wx.navigateBack({ // delta: 1 // }) let userInfo = wx.getStorageSync('userInfo') wx.navigateTo({ - url: `/pages/login/index?index=1&userid=${userInfo.id}&gameid=1&type=2`, + url: `/pages/out/index?index=1&userid=${userInfo.id}&gameid=1&type=2`, }) }, /** @@ -70,7 +70,7 @@ Page({ console.log(e) this.shareFun() return { - title: '5.5元购新房万份好礼免费兑', + title: '万套特惠房源5折起iPhone13 Pro Max免费赢', imageUrl: 'https://static.quhouse.com/468340e3a1374decb4fa51a172aa4f52.png', path: '/pages/index/index' } diff --git a/pages/share/index.wxml b/pages/share/index.wxml index bb62200..7cb5136 100644 --- a/pages/share/index.wxml +++ b/pages/share/index.wxml @@ -10,6 +10,6 @@ - + \ No newline at end of file