|
@@ -88,108 +88,10 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
// 页面生命周期 监听页面加载是否加载完成
|
|
|
- onLoad() {
|
|
|
- const time = moment().valueOf() / 1000 - uni.getStorageSync('loginSmsCodeTime'); // 从本地缓存中异步获取指定 key 对应的内容。
|
|
|
- if (time < 60) {
|
|
|
- this.codeSeconds = this.$mConstDataConfig.sendCodeTime - parseInt(time, 10);
|
|
|
- this.handleSmsCodeTime(this.codeSeconds);
|
|
|
- } else {
|
|
|
- this.codeSeconds = this.$mConstDataConfig.sendCodeTime;
|
|
|
- this.smsCodeBtnDisabled = false;
|
|
|
- uni.removeStorageSync('loginSmsCodeTime');
|
|
|
- }
|
|
|
- this.loginParams.mobile = uni.getStorageSync('loginMobile') || '';
|
|
|
- this.loginParams.password = uni.getStorageSync('loginPassword') || '';
|
|
|
- this.userInfo = uni.getStorageSync('wechatUserInfo');
|
|
|
-
|
|
|
+ onLoad() {
|
|
|
this.getCaptchaImage();
|
|
|
- // this.changeLogin();
|
|
|
},
|
|
|
- methods: {
|
|
|
- //获取用户信息
|
|
|
- changeLogin(){
|
|
|
- let that = this
|
|
|
- // 授权
|
|
|
- // 获取用户详细信息, 可以获取到说明已经授权过, 直接拿到用户信息
|
|
|
- uni.getUserInfo({
|
|
|
- provider: 'weixin',
|
|
|
- //授权成功的回调
|
|
|
- success(res) {
|
|
|
- uni.showToast({
|
|
|
- title:'授权成功',
|
|
|
- icon:'none'
|
|
|
- })
|
|
|
- // that.wechatuserinfo = res.userInfo
|
|
|
- console.log(res)
|
|
|
- uni.setStorageSync('wechatUserInfo',res.userInfo )
|
|
|
- },
|
|
|
- //第一次进入小程序
|
|
|
- fail() {
|
|
|
- uni.showToast({
|
|
|
- title: '请点击授权进行登录',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
-
|
|
|
- loginTest(mobile, password) {
|
|
|
- this.loginParams.mobile = mobile;
|
|
|
- this.loginParams.password = password;
|
|
|
- },
|
|
|
-
|
|
|
- // 发送验证码并进入倒计时
|
|
|
- async getSmsCode() {
|
|
|
- this.reqBody['mobile'] = this.loginParams['mobile'];
|
|
|
- let checkSendCode = this.$mGraceChecker.check(
|
|
|
- this.reqBody,
|
|
|
- this.$mFormRule.sendCodeRule
|
|
|
- );
|
|
|
- if (!checkSendCode) {
|
|
|
- this.$mHelper.toast(this.$mGraceChecker.error);
|
|
|
- return;
|
|
|
- }
|
|
|
- await this.$http
|
|
|
- .post(smsCode, {
|
|
|
- mobile: this.loginParams.mobile,
|
|
|
- usage: 'login',
|
|
|
- })
|
|
|
- .then((r) => {
|
|
|
- if (r.data) {
|
|
|
- this.$mHelper.toast(`验证码发送成功, 验证码是${r.data}`);
|
|
|
- } else {
|
|
|
- this.$mHelper.toast('验证码已发送.');
|
|
|
- }
|
|
|
- this.smsCodeBtnDisabled = true;
|
|
|
- uni.setStorageSync('loginSmsCodeTime', moment().valueOf() / 1000);
|
|
|
- this.handleSmsCodeTime(59);
|
|
|
- });
|
|
|
- },
|
|
|
-
|
|
|
- handleSmsCodeTime(time) {
|
|
|
- let timer = setInterval(() => {
|
|
|
- if (time === 0) {
|
|
|
- clearInterval(timer);
|
|
|
- this.smsCodeBtnDisabled = false;
|
|
|
- } else {
|
|
|
- this.codeSeconds = time;
|
|
|
- this.smsCodeBtnDisabled = true;
|
|
|
- time--;
|
|
|
- }
|
|
|
- }, 1000);
|
|
|
- },
|
|
|
- // 失去焦点的手机号
|
|
|
- blurMobileChange(e) {
|
|
|
- this.mobile = e.detail.value;
|
|
|
- },
|
|
|
- // 切换登录方式
|
|
|
- showLoginBySmsCode() {
|
|
|
- this.loginByPass = !this.loginByPass;
|
|
|
- },
|
|
|
- // // 返回上一页
|
|
|
- // navBack() {
|
|
|
- // this.$mRouter.back();
|
|
|
- // },
|
|
|
+ methods: {
|
|
|
// 统一跳转路由
|
|
|
navTo() {
|
|
|
this.$mRouter.redirectTo({ route: '/pages/public/resetpassword' });
|
|
@@ -225,19 +127,7 @@ export default {
|
|
|
if (!cheRes) {
|
|
|
this.$mHelper.toast(this.$mGraceChecker.error);
|
|
|
return;
|
|
|
- }
|
|
|
- /* #ifdef APP-PLUS */
|
|
|
- this.reqBody.group = 'tinyShopApp';
|
|
|
- /* #endif */
|
|
|
- /* #ifdef H5 */
|
|
|
- this.reqBody.group = 'tinyShopH5';
|
|
|
- /* #endif */
|
|
|
- /* #ifdef MP-WEIXIN */
|
|
|
- this.reqBody.group = 'tinyShopWechatMq';
|
|
|
- /* #endif */
|
|
|
- /* #ifdef MP-QQ */
|
|
|
- this.reqBody.group = 'tinyShopQqMq';
|
|
|
- /* #endif */
|
|
|
+ }
|
|
|
this.handleLogin(this.loginParams, loginApi);
|
|
|
},
|
|
|
// 登录
|
|
@@ -247,25 +137,8 @@ export default {
|
|
|
.post(loginApi, params)
|
|
|
.then((r) => {
|
|
|
this.$mHelper.toast('恭喜您,登录成功!');
|
|
|
- this.$mStore.commit('login', r.data);
|
|
|
- const backToPage = uni.getStorageSync('backToPage');
|
|
|
- if (backToPage) {
|
|
|
- if (
|
|
|
- backToPage.indexOf('/pages/user/user') !== -1 ||
|
|
|
- backToPage.indexOf('/pages/cart/cart') !== -1 ||
|
|
|
- backToPage.indexOf('/pages/index/index') !== -1 ||
|
|
|
- backToPage.indexOf('/pages/notify/notify') !== -1 ||
|
|
|
- backToPage.indexOf('/pages/category/category') !== -1
|
|
|
- ) {
|
|
|
- this.$mRouter.reLaunch(JSON.parse(backToPage));
|
|
|
- } else {
|
|
|
- this.$mRouter.redirectTo(JSON.parse(backToPage));
|
|
|
- }
|
|
|
- uni.removeStorageSync('backToPage');
|
|
|
- uni.removeStorageSync('wechatUserInfo');
|
|
|
- } else {
|
|
|
+ this.$mStore.commit('login', r.data);
|
|
|
this.$mRouter.reLaunch({ route: '/pages/index/index' });
|
|
|
- }
|
|
|
})
|
|
|
.catch(() => {
|
|
|
this.btnLoading = false;
|