|
@@ -1,59 +1,110 @@
|
|
|
-var util = require('../../../utils/util.js');
|
|
|
-var api = require('../../../config/api.js');
|
|
|
-var user = require('../../../services/user.js');
|
|
|
-var app = getApp();
|
|
|
+const util = require('../../../utils/util.js');
|
|
|
+const api = require('../../../config/api.js');
|
|
|
+const user = require('../../../services/user.js');
|
|
|
+const app = getApp();
|
|
|
|
|
|
Page({
|
|
|
data: {
|
|
|
- userInfo: {}
|
|
|
+ userInfo: {},
|
|
|
+ showLoginDialog: false
|
|
|
},
|
|
|
- onLoad: function (options) {
|
|
|
+ onLoad: function(options) {
|
|
|
// 页面初始化 options为页面跳转所带来的参数
|
|
|
- console.log(app.globalData)
|
|
|
},
|
|
|
- onReady: function () {
|
|
|
+ onReady: function() {
|
|
|
|
|
|
},
|
|
|
- onShow: function () {
|
|
|
-
|
|
|
- let userInfo = wx.getStorageSync('userInfo');
|
|
|
- let token = wx.getStorageSync('token');
|
|
|
-
|
|
|
- // 页面显示
|
|
|
- if (userInfo && token) {
|
|
|
- app.globalData.userInfo = userInfo;
|
|
|
- app.globalData.token = token;
|
|
|
- }
|
|
|
-
|
|
|
+ onShow: function() {
|
|
|
this.setData({
|
|
|
userInfo: app.globalData.userInfo,
|
|
|
});
|
|
|
-
|
|
|
},
|
|
|
- onHide: function () {
|
|
|
+ onHide: function() {
|
|
|
// 页面隐藏
|
|
|
|
|
|
},
|
|
|
- onUnload: function () {
|
|
|
+ onUnload: function() {
|
|
|
// 页面关闭
|
|
|
},
|
|
|
- goLogin(){
|
|
|
- user.loginByWeixin().then(res => {
|
|
|
+
|
|
|
+ onUserInfoClick: function() {
|
|
|
+ if (wx.getStorageSync('token')) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ this.showLoginDialog();
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ showLoginDialog() {
|
|
|
+ this.setData({
|
|
|
+ showLoginDialog: true
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ onCloseLoginDialog () {
|
|
|
+ this.setData({
|
|
|
+ showLoginDialog: false
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ onDialogBody () {
|
|
|
+ // 阻止冒泡
|
|
|
+ },
|
|
|
+
|
|
|
+ onWechatLogin(e) {
|
|
|
+ if (e.detail.errMsg !== 'getUserInfo:ok') {
|
|
|
+ if (e.detail.errMsg === 'getUserInfo:fail auth deny') {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ wx.showToast({
|
|
|
+ title: '微信登录失败',
|
|
|
+ })
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ util.login().then((res) => {
|
|
|
+ return util.request(api.AuthLoginByWeixin, {
|
|
|
+ code: res,
|
|
|
+ userInfo: e.detail
|
|
|
+ }, 'POST');
|
|
|
+ }).then((res) => {
|
|
|
+ console.log(res)
|
|
|
+ if (res.errno !== 0) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '微信登录失败',
|
|
|
+ })
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 设置用户信息
|
|
|
this.setData({
|
|
|
- userInfo: res.data.userInfo
|
|
|
+ userInfo: res.data.userInfo,
|
|
|
+ showLoginDialog: false
|
|
|
});
|
|
|
app.globalData.userInfo = res.data.userInfo;
|
|
|
app.globalData.token = res.data.token;
|
|
|
+ wx.setStorageSync('userInfo', JSON.stringify(res.data.userInfo));
|
|
|
+ wx.setStorageSync('token', res.data.token);
|
|
|
}).catch((err) => {
|
|
|
console.log(err)
|
|
|
- });
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ onOrderInfoClick: function(event) {
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '/pages/ucenter/order/order',
|
|
|
+ })
|
|
|
},
|
|
|
- exitLogin: function () {
|
|
|
+
|
|
|
+ onSectionItemClick: function(event) {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ // TODO 移到个人信息页面
|
|
|
+ exitLogin: function() {
|
|
|
wx.showModal({
|
|
|
title: '',
|
|
|
confirmColor: '#b4282d',
|
|
|
content: '退出登录?',
|
|
|
- success: function (res) {
|
|
|
+ success: function(res) {
|
|
|
if (res.confirm) {
|
|
|
wx.removeStorageSync('token');
|
|
|
wx.removeStorageSync('userInfo');
|