From 9b05f390a79125c108ffd7de2f05b6a29061f3b1 Mon Sep 17 00:00:00 2001 From: wuxw <928255095@qq.com> Date: Sun, 23 Feb 2020 01:05:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=A1=B5=E9=9D=A2=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- factory/LoginFactory.js | 28 +++------- pages/login/login.vue | 112 ++++++++++++++++++++++------------------ 2 files changed, 70 insertions(+), 70 deletions(-) diff --git a/factory/LoginFactory.js b/factory/LoginFactory.js index 56868e8..77b402c 100644 --- a/factory/LoginFactory.js +++ b/factory/LoginFactory.js @@ -60,6 +60,11 @@ class LoginFactory { } let _userInfo = JSON.parse(util.des.desDecrypt(userInfo)); + + let _tmpUserInfo = { + userName:_userInfo.userName, + password:_userInfo.password + } uni.request({ url: constant.url.loginUrl, @@ -67,32 +72,15 @@ class LoginFactory { header: { APP_ID: constant.app.appId }, - data: _userInfo, + data: _tmpUserInfo, success: function (res) { console.log('login success...:'); res = res.data; if (res.result == 0) { //that.globalData.userInfo = res.userInfo; - wx.setStorageSync(constant.mapping.USER_INFO, JSON.stringify(userInfo)); - let date = new Date(); - let year = date.getFullYear(); //获取当前年份 - - let mon = date.getMonth(); //获取当前月份 - - let da = date.getDate(); //获取当前日 - - let h = date.getHours() + 1; //获取小时 - - let m = date.getMinutes(); //获取分钟 - - let s = date.getSeconds(); //获取秒 - - console.log("获取过去时间", year, mon, da, h, m, s); //将时间格式转化为时间戳 - - let afterOneHourDate = new Date(year, mon, da, h, m, s); //30s之后的时间 - - console.log("afterOneHourDate", afterOneHourDate); + //wx.setStorageSync(constant.mapping.USER_INFO, JSON.stringify(userInfo)); + let afterOneHourDate = util.date.addHour(new Date(),1); wx.setStorageSync(constant.mapping.LOGIN_FLAG, { sessionKey: userInfo.userName, expireTime: afterOneHourDate.getTime() diff --git a/pages/login/login.vue b/pages/login/login.vue index 3143130..81a92b4 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -40,62 +40,72 @@ uni.hideTabBar({ animation: false }); - - + + }, methods: { - - doLogin:function(){ - if(this.username == ''){ + + doLogin: function() { + let _that = this; + if (this.username == '') { uni.showToast({ - icon:none, - title:"用户名不能为空" + icon: none, + title: "用户名不能为空" }); - return ; + return; } - - if(this.password == ''){ + + if (this.password == '') { uni.showToast({ - icon:none, - title:"密码不能为空" + icon: none, + title: "密码不能为空" }); - return ; + return; } - + let userInfo = { - username:this.username, - password:this.password + username: this.username, + password: this.password } - + uni.request({ - url: this.java110Constant.url.loginUrl, - header: this.java110Context.getHeaders(), - data: userInfo, - success: function (res) { - console.log('login success'); - res = res.data; - - if(res.statusCode != 200){ - uni.showToast({ - title: res.data - }); - return; - } - let _userInfo = this.java110Util.dec.desEncrypt(JSON.stringify(userInfo)); - uni.setStorageSync(constant.mapping.USER_INFO,_userInfo); - uni.redirectTo({ - url:"/page/index/index" - }); - }, - fail: function (error) { - // 调用服务端登录接口失败 - uni.showToast({ - title: '调用接口失败' - }); - console.log(error); - } - }); - + url: this.java110Constant.url.loginUrl, + header: this.java110Context.getHeaders(), + method: "POST", + data: userInfo, + success: function(res) { + console.log('login success',res); + if (res.statusCode != 200) { + uni.showToast({ + title: res.data + }); + return; + } + let data = res.data; + + let _tmpUserInfo = data.userInfo; + _tmpUserInfo['password'] = _that.password; + let _userInfo = _that.java110Util.des.desEncrypt(JSON.stringify(_tmpUserInfo)); + uni.setStorageSync(_that.java110Constant.mapping.USER_INFO, _userInfo); + uni.setStorageSync(_that.java110Constant.mapping.TOKEN, data.token); + let afterOneHourDate = _that.java110Util.date.addHour(new Date(),1); + wx.setStorageSync(_that.java110Constant.mapping.LOGIN_FLAG, { + sessionKey: _tmpUserInfo.userName, + expireTime: afterOneHourDate.getTime() + }); + uni.switchTab({ + url: "/pages/index/index" + }); + }, + fail: function(error) { + // 调用服务端登录接口失败 + uni.showToast({ + title: '调用接口失败' + }); + console.log(error); + } + }); + } } @@ -103,21 +113,23 @@