|
@@ -63,7 +63,7 @@ Page({
|
|
|
],
|
|
|
|
|
|
active: false,
|
|
|
- isLogin: ''
|
|
|
+ isLogin: false
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -150,13 +150,14 @@ Page({
|
|
|
})
|
|
|
break;
|
|
|
case 3:
|
|
|
+ console.log('userId', this.data.userInfo.id)
|
|
|
wx.navigateTo({
|
|
|
- url: "/pages/user/my_course/my_course"
|
|
|
+ url: `/pages/user/my_course/my_course?userId=${this.data.userInfo.id}`
|
|
|
})
|
|
|
break;
|
|
|
case 4:
|
|
|
wx.navigateTo({
|
|
|
- url: "/pages/user/my_host_course/index"
|
|
|
+ url: `/pages/user/my_host_course/index?userId=${this.data.userInfo.id}`
|
|
|
})
|
|
|
break;
|
|
|
}
|
|
@@ -293,7 +294,7 @@ Page({
|
|
|
wx.getUserProfile({
|
|
|
desc: '获取您的身份信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
|
|
|
success: (res) => {
|
|
|
- console.log(123456, res);
|
|
|
+ console.log("getUserProfile", res);
|
|
|
let {
|
|
|
encryptedData,
|
|
|
iv,
|
|
@@ -329,9 +330,12 @@ Page({
|
|
|
success: res => {
|
|
|
if (res.data.code > -1) {
|
|
|
let {
|
|
|
- loginSessionKey
|
|
|
+ loginSessionKey,
|
|
|
+ sessionKey
|
|
|
} = res.data.data;
|
|
|
wx.setStorageSync('token', loginSessionKey)
|
|
|
+ wx.setStorageSync('sessionKey', sessionKey)
|
|
|
+ this.updateUserinfo();
|
|
|
} else {
|
|
|
Toast.showToast('warn', '登录失败,请重试');
|
|
|
}
|
|
@@ -399,10 +403,12 @@ Page({
|
|
|
if (res.data.code > -1) {
|
|
|
wx.setStorageSync('userInfo', null);
|
|
|
wx.setStorageSync('token', null);
|
|
|
+ wx.setStorageSync('sessionKey', null);
|
|
|
console.log(wx.getStorageSync('token'))
|
|
|
this.setData({
|
|
|
isLogin: false,
|
|
|
- avatarUrl: ""
|
|
|
+ avatarUrl: "",
|
|
|
+
|
|
|
})
|
|
|
app.globalData.isLogin = false;
|
|
|
}
|
|
@@ -424,10 +430,7 @@ Page({
|
|
|
this._isLogin();
|
|
|
if (this.data.isLogin) {
|
|
|
wx.navigateTo({
|
|
|
- url: `./my_order/index?status=${status}&&id=${id}`,
|
|
|
- success: function (res) {},
|
|
|
- fail: function (res) {},
|
|
|
- complete: function (res) {},
|
|
|
+ url: `./my_order/index?status=${status}&&id=${id}`
|
|
|
})
|
|
|
} else {
|
|
|
Toast.showToast('tip', '请登录后查看', () => {
|
|
@@ -449,51 +452,51 @@ 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: 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();
|
|
|
+ // },
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+
|
|
|
+ // },
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
@@ -504,13 +507,19 @@ Page({
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
- onShow: function () {
|
|
|
+ onShow: async function () {
|
|
|
let {
|
|
|
avatar = ""
|
|
|
} = this.data;
|
|
|
- console.log(wx.getStorageSync('userInfo'))
|
|
|
- let avatarUrl = wx.getStorageSync('userInfo') ? wx.getStorageSync('userInfo').avatarUrl : "";
|
|
|
- let avatarName = wx.getStorageSync('userInfo') ? wx.getStorageSync('userInfo').nickName : "";
|
|
|
+
|
|
|
+ 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();
|
|
|
+ }
|
|
|
|
|
|
this.setData({
|
|
|
avatarUrl: avatarUrl || avatar,
|
|
@@ -518,8 +527,30 @@ Page({
|
|
|
})
|
|
|
this._isLogin()
|
|
|
|
|
|
- getWxUserInfo('9fbbd7dfca6e49d9b20b77eb0f94e73a')
|
|
|
- // debugger
|
|
|
+ if (userInfo) {
|
|
|
+ this.setData({
|
|
|
+ userInfo: userInfo,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ async updateUserinfo() {
|
|
|
+ const sessionKey = wx.getStorageSync('sessionKey')
|
|
|
+ console.log('sessionKey', sessionKey)
|
|
|
+ if (sessionKey) {
|
|
|
+ const res = await getWxUserInfo(sessionKey)
|
|
|
+ const userInfo = wx.getStorageInfoSync('userInfo')
|
|
|
+ if (res.data) {
|
|
|
+ const mergeObj = {
|
|
|
+ ...userInfo,
|
|
|
+ ...res.data
|
|
|
+ }
|
|
|
+ console.log('userInfo-mergeObj', mergeObj)
|
|
|
+ wx.setStorageSync('userInfo', mergeObj)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
/**
|