|
@@ -2,13 +2,23 @@
|
|
import {
|
|
import {
|
|
getOpenidSessionKey
|
|
getOpenidSessionKey
|
|
} from '../../utils/httpUtil';
|
|
} from '../../utils/httpUtil';
|
|
|
|
+import url from '../../utils/const';
|
|
|
|
+import request from '../../utils/WXHttpRequest';
|
|
|
|
+
|
|
|
|
+const HOST = url.baseApi;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+function getAPIUrl(action) {
|
|
|
|
+ return HOST + action;
|
|
|
|
+}
|
|
Page({
|
|
Page({
|
|
|
|
|
|
/**
|
|
/**
|
|
* 页面的初始数据
|
|
* 页面的初始数据
|
|
*/
|
|
*/
|
|
data: {
|
|
data: {
|
|
- index: undefined
|
|
|
|
|
|
+ index: 0,
|
|
|
|
+ canIUseGetUserProfile: false
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -16,11 +26,113 @@ Page({
|
|
*/
|
|
*/
|
|
|
|
|
|
onLoad: function (options) {
|
|
onLoad: function (options) {
|
|
- if(options.index){
|
|
|
|
|
|
+ if (options.index) {
|
|
this.setData({
|
|
this.setData({
|
|
index: options.index
|
|
index: options.index
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+ if (wx.getUserProfile) {
|
|
|
|
+ this.setData({
|
|
|
|
+ canIUseGetUserProfile: true
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ userLoginRecord: function (uid) {
|
|
|
|
+ if (wx.getStorageSync('uid')) {
|
|
|
|
+ console.log('调用方法')
|
|
|
|
+ let url = getAPIUrl('wx/loginLog');
|
|
|
|
+ return request.getInstance().header({
|
|
|
|
+ uid: wx.getStorageSync('uid')
|
|
|
|
+ }).method('POST').url(url).send().success(() => {}).fail(() => {});
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ getUserProfile: function (e) {
|
|
|
|
+ wx.getUserProfile({
|
|
|
|
+ desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
|
|
|
|
+ success: (userProfile) => {
|
|
|
|
+ console.log('getUserProfile', userProfile);
|
|
|
|
+ const userInfo = userProfile.userInfo;
|
|
|
|
+ this.getOpenId((openidData) => {
|
|
|
|
+ console.log('openid', openidData)
|
|
|
|
+ let url = getAPIUrl('wx/user');
|
|
|
|
+ const userData = {
|
|
|
|
+ openId: openidData.data.data.openid,
|
|
|
|
+ unionId: openidData.data.data.unionid,
|
|
|
|
+ wechatName: userInfo.nickName,
|
|
|
|
+ gender: userInfo.gender,
|
|
|
|
+ avatar: userInfo.avatarUrl
|
|
|
|
+ }
|
|
|
|
+ request.getInstance().url(url).header({}).data(userData).method('POST').send().success(res => {
|
|
|
|
+ console.log('登陆成功', res)
|
|
|
|
+ wx.hideToast()
|
|
|
|
+ wx.showToast({
|
|
|
|
+ title: '登录成功',
|
|
|
|
+ icon: 'success',
|
|
|
|
+ duration: 1500,
|
|
|
|
+ mask: true
|
|
|
|
+ })
|
|
|
|
+ wx.setStorageSync('uid', res.data.data.data.uid)
|
|
|
|
+ wx.setStorageSync('user', res.data.data.data)
|
|
|
|
+ this.userLoginRecord();
|
|
|
|
+ const pages = getCurrentPages();
|
|
|
|
+ const prevPage = pages[pages.length - 2];
|
|
|
|
+ console.log(222222, prevPage)
|
|
|
|
+ prevPage.setData({
|
|
|
|
+ fromLoginIndex: this.data.index, // 有id就塞到第一位
|
|
|
|
+ }, () => {
|
|
|
|
+ wx.navigateBack({
|
|
|
|
+ delta: 1
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+ // getOpenidSessionKey((res) => {
|
|
|
|
+ // console.log('getUserProfilegetUserProfile', res)
|
|
|
|
+ // wx.showToast({
|
|
|
|
+ // title: '登录成功',
|
|
|
|
+ // icon: 'fail',
|
|
|
|
+ // duration: 1000,
|
|
|
|
+ // success: () => {
|
|
|
|
+ // const pages = getCurrentPages();
|
|
|
|
+ // const prevPage = pages[pages.length - 2];
|
|
|
|
+ // prevPage.setData({
|
|
|
|
+ // fromLoginIndex: this.data.index, // 有id就塞到第一位
|
|
|
|
+ // }, () => {
|
|
|
|
+ // wx.navigateBack({
|
|
|
|
+ // delta: 1
|
|
|
|
+ // })
|
|
|
|
+ // })
|
|
|
|
+ // }
|
|
|
|
+ // })
|
|
|
|
+ // }, (error) => {
|
|
|
|
+ // wx.showToast({
|
|
|
|
+ // title: '登录失败',
|
|
|
|
+ // icon: 'fail',
|
|
|
|
+ // duration: 1000,
|
|
|
|
+ // success: () => {
|
|
|
|
+ // wx.navigateBack()
|
|
|
|
+ // }
|
|
|
|
+ // })
|
|
|
|
+ // });
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ getOpenId: function (successcallback, failcallback) {
|
|
|
|
+ wx.login({
|
|
|
|
+ success: function (res) {
|
|
|
|
+ if (res.code) {
|
|
|
|
+ // 获取openid
|
|
|
|
+ console.log('openId', res.code)
|
|
|
|
+ let url = getAPIUrl('wx/user/openId')
|
|
|
|
+ let data = {
|
|
|
|
+ code: res.code
|
|
|
|
+ }
|
|
|
|
+ return request.getInstance().url(url).data(data).send().success(successcallback).fail(failcallback);
|
|
|
|
+ } else {
|
|
|
|
+ console.log('获取用户登录态失败!' + res.errMsg)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
},
|
|
},
|
|
impower: function (e) {
|
|
impower: function (e) {
|
|
console.log(e)
|
|
console.log(e)
|
|
@@ -36,11 +148,11 @@ Page({
|
|
const pages = getCurrentPages();
|
|
const pages = getCurrentPages();
|
|
const prevPage = pages[pages.length - 2];
|
|
const prevPage = pages[pages.length - 2];
|
|
prevPage.setData({
|
|
prevPage.setData({
|
|
- fromLoginIndex: this.data.index, // 有id就塞到第一位
|
|
|
|
|
|
+ fromLoginIndex: this.data.index, // 有id就塞到第一位
|
|
}, () => {
|
|
}, () => {
|
|
- wx.navigateBack({
|
|
|
|
- delta: 1
|
|
|
|
- })
|
|
|
|
|
|
+ wx.navigateBack({
|
|
|
|
+ delta: 1
|
|
|
|
+ })
|
|
})
|
|
})
|
|
}
|
|
}
|
|
})
|
|
})
|