|
@@ -8,10 +8,10 @@ const {
|
|
} = require('../../utils/util.js');
|
|
} = require('../../utils/util.js');
|
|
var app = getApp();
|
|
var app = getApp();
|
|
import {
|
|
import {
|
|
- getWxUserInfo
|
|
|
|
|
|
+ getWxUserInfo,
|
|
|
|
+ wxUserLogin
|
|
} from '../../utils/request'
|
|
} from '../../utils/request'
|
|
Page({
|
|
Page({
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 页面的初始数据
|
|
* 页面的初始数据
|
|
*/
|
|
*/
|
|
@@ -71,7 +71,8 @@ Page({
|
|
*/
|
|
*/
|
|
onLoad: function (options) {
|
|
onLoad: function (options) {
|
|
// this.isLongPolling()
|
|
// this.isLongPolling()
|
|
- // this.newLogin();
|
|
|
|
|
|
+ this.newLogin();
|
|
|
|
+
|
|
},
|
|
},
|
|
|
|
|
|
isLongPolling: function () {
|
|
isLongPolling: function () {
|
|
@@ -115,56 +116,39 @@ Page({
|
|
let {
|
|
let {
|
|
idx
|
|
idx
|
|
} = e.currentTarget.dataset;
|
|
} = e.currentTarget.dataset;
|
|
-
|
|
|
|
- this._isLogin();
|
|
|
|
-
|
|
|
|
- if (this.data.isLogin) {
|
|
|
|
- switch (idx) {
|
|
|
|
- case 0:
|
|
|
|
- wx.navigateTo({
|
|
|
|
- url: './my_follow/index',
|
|
|
|
- success: function (res) {},
|
|
|
|
- fail: function (res) {},
|
|
|
|
- complete: function (res) {},
|
|
|
|
- })
|
|
|
|
- break;
|
|
|
|
- case 1:
|
|
|
|
- let tabList = this.data.tabList;
|
|
|
|
- tabList[1].img = "../../imgs/icon/comment.png";
|
|
|
|
- this.setData({
|
|
|
|
- tabList
|
|
|
|
- })
|
|
|
|
- wx.navigateTo({
|
|
|
|
- url: './my_comment/index',
|
|
|
|
- success: function (res) {},
|
|
|
|
- fail: function (res) {},
|
|
|
|
- complete: function (res) {},
|
|
|
|
- })
|
|
|
|
- break;
|
|
|
|
- case 2:
|
|
|
|
- wx.navigateTo({
|
|
|
|
- url: './my_saw/index',
|
|
|
|
- success: function (res) {},
|
|
|
|
- fail: function (res) {},
|
|
|
|
- complete: function (res) {},
|
|
|
|
- })
|
|
|
|
- break;
|
|
|
|
- case 3:
|
|
|
|
- console.log('userId', this.data.userInfo.id)
|
|
|
|
- wx.navigateTo({
|
|
|
|
- url: `/pages/user/my_course/my_course?userId=${this.data.userInfo.id}`
|
|
|
|
- })
|
|
|
|
- break;
|
|
|
|
- case 4:
|
|
|
|
- wx.navigateTo({
|
|
|
|
- url: `/pages/user/my_host_course/index?userId=${this.data.userInfo.id}`
|
|
|
|
- })
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- Toast.showToast('tip', '请登录后查看', () => {
|
|
|
|
-
|
|
|
|
- });
|
|
|
|
|
|
+ // this._isLogin();
|
|
|
|
+ switch (idx) {
|
|
|
|
+ case 0:
|
|
|
|
+ wx.navigateTo({
|
|
|
|
+ url: './my_follow/index'
|
|
|
|
+ })
|
|
|
|
+ break;
|
|
|
|
+ case 1:
|
|
|
|
+ let tabList = this.data.tabList;
|
|
|
|
+ tabList[1].img = "../../imgs/icon/comment.png";
|
|
|
|
+ this.setData({
|
|
|
|
+ tabList
|
|
|
|
+ })
|
|
|
|
+ wx.navigateTo({
|
|
|
|
+ url: './my_comment/index',
|
|
|
|
+ })
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ wx.navigateTo({
|
|
|
|
+ url: './my_saw/index'
|
|
|
|
+ })
|
|
|
|
+ break;
|
|
|
|
+ case 3:
|
|
|
|
+ console.log('userId', this.data.userInfo.id)
|
|
|
|
+ wx.navigateTo({
|
|
|
|
+ url: `/pages/user/my_course/my_course?userId=${this.data.userInfo.id}`
|
|
|
|
+ })
|
|
|
|
+ break;
|
|
|
|
+ case 4:
|
|
|
|
+ wx.navigateTo({
|
|
|
|
+ url: `/pages/user/my_host_course/index?userId=${this.data.userInfo.id}`
|
|
|
|
+ })
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -179,10 +163,7 @@ Page({
|
|
|
|
|
|
if (this.data.isLogin) {
|
|
if (this.data.isLogin) {
|
|
wx.navigateTo({
|
|
wx.navigateTo({
|
|
- url: './my_follow/index',
|
|
|
|
- success: function (res) {},
|
|
|
|
- fail: function (res) {},
|
|
|
|
- complete: function (res) {},
|
|
|
|
|
|
+ url: './my_follow/index'
|
|
})
|
|
})
|
|
} else {
|
|
} else {
|
|
Toast.showToast('tip', '请登录后查看', () => {
|
|
Toast.showToast('tip', '请登录后查看', () => {
|
|
@@ -196,10 +177,7 @@ Page({
|
|
|
|
|
|
if (this.data.isLogin) {
|
|
if (this.data.isLogin) {
|
|
wx.navigateTo({
|
|
wx.navigateTo({
|
|
- url: './my_order/index',
|
|
|
|
- success: function (res) {},
|
|
|
|
- fail: function (res) {},
|
|
|
|
- complete: function (res) {},
|
|
|
|
|
|
+ url: './my_order/index'
|
|
})
|
|
})
|
|
} else {
|
|
} else {
|
|
Toast.showToast('tip', '请登录后查看', () => {
|
|
Toast.showToast('tip', '请登录后查看', () => {
|
|
@@ -281,12 +259,10 @@ Page({
|
|
isLogin: false
|
|
isLogin: false
|
|
})
|
|
})
|
|
app.globalData.isLogin = false;
|
|
app.globalData.isLogin = false;
|
|
-
|
|
|
|
}
|
|
}
|
|
- // console.log("isLogin",this.data.isLogin);
|
|
|
|
|
|
|
|
},
|
|
},
|
|
-
|
|
|
|
|
|
+ // @deprecated
|
|
getUserProfile: function (e) {
|
|
getUserProfile: function (e) {
|
|
Toast.showToast2('loading');
|
|
Toast.showToast2('loading');
|
|
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
|
|
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
|
|
@@ -427,7 +403,7 @@ Page({
|
|
status,
|
|
status,
|
|
id
|
|
id
|
|
} = e.currentTarget.dataset;
|
|
} = e.currentTarget.dataset;
|
|
- this._isLogin();
|
|
|
|
|
|
+ // this._isLogin();
|
|
if (this.data.isLogin) {
|
|
if (this.data.isLogin) {
|
|
wx.navigateTo({
|
|
wx.navigateTo({
|
|
url: `./my_order/index?status=${status}&&id=${id}`
|
|
url: `./my_order/index?status=${status}&&id=${id}`
|
|
@@ -452,51 +428,34 @@ Page({
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
|
|
- // newLogin() {
|
|
|
|
- // wx.login({
|
|
|
|
- // success: res => {
|
|
|
|
- // let {
|
|
|
|
- // code
|
|
|
|
- // } = res;
|
|
|
|
-
|
|
|
|
- // console.log(789, res);
|
|
|
|
-
|
|
|
|
- // if (code) {
|
|
|
|
- // wx.request({
|
|
|
|
- // url: serverName + '/wx/api/user/getLoginSessionKey',
|
|
|
|
- // data: {
|
|
|
|
- // code,
|
|
|
|
- // },
|
|
|
|
- // header: {
|
|
|
|
- // 'content-type': 'application/x-www-form-urlencoded'
|
|
|
|
- // },
|
|
|
|
- // method: 'post',
|
|
|
|
- // // dataType: 'json',
|
|
|
|
- // // responseType: 'text',
|
|
|
|
- // success: res => {
|
|
|
|
- // if (res.data.code > -1) {
|
|
|
|
- // let {
|
|
|
|
- // loginSessionKey
|
|
|
|
- // } = res.data.data;
|
|
|
|
- // wx.setStorageSync('token', loginSessionKey)
|
|
|
|
- // } else {
|
|
|
|
- // Toast.showToast('warn', '登录失败,请重试');
|
|
|
|
- // }
|
|
|
|
- // },
|
|
|
|
- // fail: res => {
|
|
|
|
- // Toast.showToast('warn', '登录失败,请重试');
|
|
|
|
-
|
|
|
|
- // },
|
|
|
|
- // complete: res => {
|
|
|
|
- // this._isLogin();
|
|
|
|
- // Toast.hideLoading();
|
|
|
|
- // },
|
|
|
|
- // })
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- // })
|
|
|
|
-
|
|
|
|
- // },
|
|
|
|
|
|
+ newLogin() {
|
|
|
|
+ wx.login({
|
|
|
|
+ success: async res => {
|
|
|
|
+ let {
|
|
|
|
+ code
|
|
|
|
+ } = res;
|
|
|
|
+
|
|
|
|
+ if (code) {
|
|
|
|
+ const result = await wxUserLogin(code)
|
|
|
|
+ console.log('result', result)
|
|
|
|
+ if (result.code === 0) {
|
|
|
|
+ const {
|
|
|
|
+ loginSessionKey,
|
|
|
|
+ sessionKey
|
|
|
|
+ } = result.data
|
|
|
|
+ wx.setStorageSync('token', loginSessionKey)
|
|
|
|
+ wx.setStorageSync('sessionKey', sessionKey)
|
|
|
|
+ this.setData({
|
|
|
|
+ isLogin: true
|
|
|
|
+ })
|
|
|
|
+ this.updateUserinfo();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ },
|
|
/**
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
*/
|
|
@@ -508,36 +467,14 @@ Page({
|
|
* 生命周期函数--监听页面显示
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
*/
|
|
onShow: async function () {
|
|
onShow: async function () {
|
|
- let {
|
|
|
|
- avatar = ""
|
|
|
|
- } = this.data;
|
|
|
|
-
|
|
|
|
- const userInfo = wx.getStorageSync('userInfo')
|
|
|
|
- const sessionKey = wx.getStorageSync('sessionKey')
|
|
|
|
- let avatarUrl = userInfo ? userInfo.avatarUrl : "";
|
|
|
|
- let avatarName = userInfo ? userInfo.nickName : "";
|
|
|
|
- console.log('sessionKey', sessionKey)
|
|
|
|
- if (sessionKey) {
|
|
|
|
- this.updateUserinfo();
|
|
|
|
|
|
+ if (!this.data.isLogin) {
|
|
|
|
+ this.newLogin();
|
|
}
|
|
}
|
|
-
|
|
|
|
- this.setData({
|
|
|
|
- avatarUrl: avatarUrl || avatar,
|
|
|
|
- avatarName: avatarName || '已登录'
|
|
|
|
- })
|
|
|
|
- this._isLogin()
|
|
|
|
-
|
|
|
|
- if (userInfo) {
|
|
|
|
- this.setData({
|
|
|
|
- userInfo: userInfo,
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
},
|
|
},
|
|
|
|
|
|
async updateUserinfo() {
|
|
async updateUserinfo() {
|
|
const sessionKey = wx.getStorageSync('sessionKey')
|
|
const sessionKey = wx.getStorageSync('sessionKey')
|
|
- console.log('sessionKey', sessionKey)
|
|
|
|
|
|
+ // console.log('sessionKey', sessionKey)
|
|
if (sessionKey) {
|
|
if (sessionKey) {
|
|
const res = await getWxUserInfo(sessionKey)
|
|
const res = await getWxUserInfo(sessionKey)
|
|
const userInfo = wx.getStorageInfoSync('userInfo')
|
|
const userInfo = wx.getStorageInfoSync('userInfo')
|
|
@@ -548,8 +485,10 @@ Page({
|
|
}
|
|
}
|
|
console.log('userInfo-mergeObj', mergeObj)
|
|
console.log('userInfo-mergeObj', mergeObj)
|
|
wx.setStorageSync('userInfo', mergeObj)
|
|
wx.setStorageSync('userInfo', mergeObj)
|
|
|
|
+ this.setData({
|
|
|
|
+ userInfo: mergeObj
|
|
|
|
+ })
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|