296 lines
6.2 KiB
Vue
296 lines
6.2 KiB
Vue
<template>
|
|
<view class="page">
|
|
<view class="status-bar"></view>
|
|
<view class="content">
|
|
<view class="logo" v-if="false">
|
|
<image :lazy-load="true" src="../../static/images/logo.png"></image>
|
|
</view>
|
|
<view class="list">
|
|
<view class="item">
|
|
<iconfont type="mobile"></iconfont>
|
|
<input class="input" v-model="mobile" type="number" maxlength="11" placeholder="请输入手机号" />
|
|
</view>
|
|
<view class="item verify-item">
|
|
<view class="verfiy-code-icon">
|
|
<iconfont type="verify-code"></iconfont>
|
|
</view>
|
|
<input class="input" v-model="verify_code" type="text" placeholder="请输入验证码" />
|
|
<view class="verify-btn" @tap="getVerifyCode">{{verify_text}}</view>
|
|
</view>
|
|
</view>
|
|
<view class="button" hover-class="button-hover" @tap="bindLogin"><text>登录</text></view>
|
|
<view class="other">
|
|
<navigator url="register" open-type="navigate">注册账户</navigator>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import {
|
|
mapState,
|
|
mapMutations
|
|
} from 'vuex';
|
|
import iconfont from '@/components/iconfont/iconfont.vue';
|
|
import validator from '@/common/validator';
|
|
import md5 from "@/common/md5";
|
|
var that, js;
|
|
export default {
|
|
components: {
|
|
iconfont
|
|
},
|
|
|
|
data() {
|
|
return {
|
|
mobile: '',
|
|
password: '',
|
|
originUrl: '',
|
|
hasLogin: false,
|
|
verify_code: '',
|
|
second: 0
|
|
};
|
|
},
|
|
|
|
onUnload() {
|
|
clearInterval(js)
|
|
this.second = 0;
|
|
if (this.originUrl.search('/pages/user/login') != '-1') {
|
|
uni.reLaunch({
|
|
url: '../news/index'
|
|
});
|
|
}
|
|
},
|
|
onShow() {},
|
|
onLoad(e) {
|
|
let loginOriginUrl = uni.getStorageSync('loginOriginUrl');
|
|
if (loginOriginUrl) {
|
|
this.originUrl = loginOriginUrl;
|
|
setTimeout(() => {
|
|
uni.removeStorageSync('loginOriginUrl');
|
|
}, 1000);
|
|
console.log(this.originUrl);
|
|
}
|
|
},
|
|
computed: {
|
|
verify_text() {
|
|
if (this.second == 0) {
|
|
return '获取验证码';
|
|
} else {
|
|
if (this.second < 10) {
|
|
return '0' + this.second + '秒后重新获取';
|
|
} else {
|
|
return this.second + '秒后重新获取';
|
|
}
|
|
}
|
|
}
|
|
},
|
|
methods: {
|
|
...mapMutations(['login']),
|
|
getUserInfo() {
|
|
this.$app.request({
|
|
url: this.$api.user.getUserInfo,
|
|
method: 'GET',
|
|
header: {
|
|
token: getApp().globalData.token
|
|
},
|
|
success: res => {
|
|
if (res) {
|
|
getApp().globalData.userInfo = res;
|
|
uni.setStorageSync("userInfo", res);
|
|
}
|
|
},
|
|
complete: res => {
|
|
|
|
}
|
|
})
|
|
},
|
|
bindLogin() {
|
|
if (!validator.checkMobile(this.mobile)) {
|
|
return;
|
|
} else if (this.verify_code == '') {
|
|
this.$alert('请输入验证码');
|
|
return;
|
|
}
|
|
uni.showLoading({
|
|
title: '登录中…'
|
|
});
|
|
this.$app.request({
|
|
url: this.$api.user.doLogin,
|
|
data: {
|
|
username: this.mobile,
|
|
verificationCode: this.verify_code,
|
|
},
|
|
method: 'POST',
|
|
success: res => {
|
|
uni.hideLoading();
|
|
console.log(res.msg != undefined)
|
|
if (res != undefined && res.msg == undefined) {
|
|
/*更新登录状态,保存用户数据*/
|
|
this.hasLogin = true;
|
|
this.login(res.data);
|
|
uni.setStorage({
|
|
key: "token",
|
|
data: res.data
|
|
})
|
|
uni.setStorageSync('source', 'login');
|
|
getApp().globalData.token = res.data
|
|
/*登录后跳转*/
|
|
console.log(this.originUrl);
|
|
if (this.originUrl) {
|
|
uni.navigateBack();
|
|
} else {
|
|
// #ifndef H5
|
|
uni.switchTab({
|
|
url: '/pages/news/index'
|
|
});
|
|
// #endif
|
|
|
|
// #ifdef H5
|
|
uni.navigateTo({
|
|
url: '/pages/news/index'
|
|
});
|
|
// #endif
|
|
}
|
|
} else {
|
|
this.$alert(res.msg);
|
|
}
|
|
},
|
|
fail(e) {
|
|
uni.hideLoading()
|
|
if (e.data) {
|
|
this.$alert(res.data.msg)
|
|
} else {
|
|
this.$alert('系统错误')
|
|
}
|
|
}
|
|
});
|
|
},
|
|
/*获取验证码*/
|
|
getVerifyCode() {
|
|
if (this.second > 0) {
|
|
return;
|
|
}
|
|
if (!validator.checkMobile(this.mobile)) {
|
|
return;
|
|
}
|
|
var _self = this;
|
|
|
|
this.$app.request({
|
|
url: this.$api.user.getVerifyCode + this.mobile,
|
|
method: 'GET',
|
|
dataType: 'json',
|
|
success: (res) => {
|
|
console.log(res)
|
|
if (res.statusCode != 200) {
|
|
_self.second = 120;
|
|
_self.$alert('获取成功');
|
|
js = setInterval(function() {
|
|
that.second--;
|
|
if (that.second == 0) {
|
|
clearInterval(js)
|
|
}
|
|
}, 1000)
|
|
}
|
|
},
|
|
fail(e) {
|
|
_self.$alert(e.data.msg);
|
|
}
|
|
});
|
|
},
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
.content {
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
|
|
.logo {
|
|
margin-top: 143rpx;
|
|
margin-left: auto;
|
|
margin-right: auto;
|
|
|
|
image {
|
|
height: 65rpx;
|
|
width: 360rpx;
|
|
}
|
|
}
|
|
|
|
.list {
|
|
display: flex;
|
|
flex-direction: column;
|
|
padding-top: 40rpx;
|
|
padding-left: 100rpx;
|
|
padding-right: 100rpx;
|
|
|
|
.item {
|
|
display: flex;
|
|
flex-direction: row;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
height: 100rpx;
|
|
border-bottom: 1upx solid rgba(230, 230, 230, 1);
|
|
|
|
.icon {
|
|
color: #ababab;
|
|
margin-right: 5rpx;
|
|
font-size: 40rpx;
|
|
}
|
|
|
|
.verfiy-code-icon {
|
|
.icon {
|
|
font-size: 52rpx;
|
|
margin-right: -6rpx;
|
|
margin-left: -4rpx;
|
|
}
|
|
}
|
|
|
|
.input {
|
|
flex: 1;
|
|
text-align: left;
|
|
font-size: 30rpx;
|
|
margin-left: 16rpx;
|
|
}
|
|
}
|
|
|
|
.verify-item {
|
|
position: relative;
|
|
|
|
.verify-btn {
|
|
position: absolute;
|
|
top: 22rpx;
|
|
right: 10rpx;
|
|
color: #8CC7B5;
|
|
font-size: 30rpx;
|
|
z-index: 9999;
|
|
}
|
|
}
|
|
}
|
|
|
|
.button {
|
|
margin-top: 100rpx;
|
|
}
|
|
|
|
.other {
|
|
display: flex;
|
|
flex-direction: row;
|
|
justify-content: center;
|
|
align-items: center;
|
|
font-size: 30rpx;
|
|
margin-top: 60rpx;
|
|
color: #8cc7b5;
|
|
text-align: center;
|
|
height: 40rpx;
|
|
line-height: 40rpx;
|
|
|
|
text {
|
|
font-size: 24rpx;
|
|
margin-left: 15rpx;
|
|
margin-right: 15rpx;
|
|
}
|
|
}
|
|
}
|
|
</style>
|