This commit is contained in:
周源 2022-04-26 17:17:58 +08:00
commit d4a890aaa0
2 changed files with 199 additions and 98 deletions

View File

@ -1,5 +1,6 @@
<template> <template>
<view style=""> <view style="">
<u-gap height="60" bgColor="#FFF"></u-gap>
<u--form :model="userInfo" ref="loginForm"> <u--form :model="userInfo" ref="loginForm">
<view class="content_main"> <view class="content_main">
<view class="copyright_iocn"> <view class="copyright_iocn">
@ -9,17 +10,38 @@
</image> </image>
</view> </view>
<u-form-item prop="number" ref="item1" class="data_itm"> <view class="tab_op">
<view :class="tab == 0?'choosed':'unchoosed'" @click="pwdLog()">
密码登录
</view>
<view :class="tab == 1?'choosed':'unchoosed'" @click="codeLog()">
验证码登录
</view>
</view>
<u-form-item prop="number" ref="item1" class="data_itm" v-if="tab == 0">
<u--input placeholder="请输入手机号" border="bottom" clearable v-model="userInfo.number"></u--input> <u--input placeholder="请输入手机号" border="bottom" clearable v-model="userInfo.number"></u--input>
</u-form-item> </u-form-item>
<u-form-item prop="pasw" ref="item1" class="data_itm"> <u-form-item prop="pasw" ref="item1" class="data_itm" v-if="tab == 0">
<u--input type="password" placeholder="请输入密码" border="bottom" clearable v-model="userInfo.pasw"> <u--input type="password" placeholder="请输入密码" border="bottom" clearable v-model="userInfo.pasw">
</u--input> </u--input>
</u-form-item> </u-form-item>
<u-button text="登录" size="large" throttleTime=1000 color="#99241B" style="margin-top: 84rpx;" @click="login()"> <u-form-item prop="phone" ref="item1" class="data_itm" v-if="tab == 1">
<u--input placeholder="请输入手机号" border="bottom" clearable v-model="userInfo.phone"></u--input>
</u-form-item>
<u-form-item prop="code" ref="item1" class="data_itm" v-if="tab == 1">
<u-input placeholder="请输入验证码" border="bottom" clearable v-model="userInfo.code">
<template slot="suffix">
<u-code ref="uCode" @change="codeChange" seconds="60" changeText="X秒重新获取"></u-code>
<u-button @click="getCode" :text="tips" :hairline="false" plain style="border: 0px;">
</u-button>
</template>
</u-input>
</u-form-item>
<u-button text="登录" size="large" throttleTime=1000 color="#99241B" style="margin-top: 84rpx;"
@click="login()">
</u-button> </u-button>
<view class="other_op"> <view class="other_op">
<text @click="goRegist">注册账号</text> <!-- <text @click="goRegist">注册账号</text> -->
<text @click="goRemeber">忘记密码</text> <text @click="goRemeber">忘记密码</text>
</view> </view>
</view> </view>
@ -31,32 +53,36 @@
export default { export default {
data() { data() {
return { return {
tips: '',
userInfo: { userInfo: {
number: null, number: null,
pasw: null pasw: null,
phone: null,
code: null,
}, },
rules: { rules: {
'number': [{ 'number': [{
type: 'number', type: 'number',
required: true, required: true,
message: '请填写手机号', message: '请填写账号',
trigger: ['blur'] trigger: ['blur']
}, {
validator: (rule, value, callback) => {
return uni.$u.test.mobile(value);
},
message: '请输入格式正确的手机号',
trigger: ['blur'],
}], }],
'pasw': [{ 'pasw': [{
required: true, required: true,
message: '请填写密码', message: '请填写密码',
trigger: ['blur'] trigger: ['blur']
}], }],
} },
tab: 0,
}; };
}, },
methods: { methods: {
pwdLog() {
this.tab = 0
},
codeLog() {
this.tab = 1
},
goRegist() { goRegist() {
uni.navigateTo({ uni.navigateTo({
url: '/pages/Login/Register' url: '/pages/Login/Register'
@ -67,12 +93,12 @@
url: '/pages/Login/RemeberPW' url: '/pages/Login/RemeberPW'
}) })
}, },
login(){ login() {
let data = { if(this.tab == 0){
this.http.request('/auth/loginByPwd', {
phone: this.userInfo.number, phone: this.userInfo.number,
pwd: this.userInfo.pasw pwd: this.userInfo.pasw
} }, "POST").then(res => {
this.http.request('/auth/loginByPwd', {phone: this.userInfo.number,pwd: this.userInfo.pasw}, "POST").then(res => {
if (res.code == 200) { if (res.code == 200) {
uni.navigateTo({ uni.navigateTo({
url: '/pages/pageHome/pageHome' url: '/pages/pageHome/pageHome'
@ -80,11 +106,63 @@
} }
}).catch(e => { }).catch(e => {
uni.showToast({ uni.showToast({
title:e.data.message, title: e.data.message,
icon:"none", icon: "none",
});
})
}else if(this.tab == 1){
this.http.request('/auth/loginByPhone', {
phone: this.userInfo.phone,
code: this.userInfo.code
}, "POST").then(res => {
if (res.code == 200) {
uni.navigateTo({
url: '/pages/pageHome/pageHome'
})
}
}).catch(e => {
uni.showToast({
title: e.data.message,
icon: "none",
}); });
}) })
} }
},
codeChange(text) {
this.tips = text;
},
getCode() {
uni.hideKeyboard()
if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.userInfo.phone))) { //
uni.showToast({
title: '请填写正确手机号码',
icon: "none"
});
return false;
}
if (this.$refs.uCode.canGetCode) {
//
uni.showLoading({
title: '正在获取验证码'
})
this.http.request('/auth/getCode?phone=' + this.userInfo.phone, {}, "GET").then(res => {
if (res.code == 200) {
uni.hideLoading();
uni.$u.toast('验证码已发送');
this.$refs.uCode.start();
}
}).catch(e => {
uni.showToast({
title: e.data.message,
icon: "none",
});
})
} else {
uni.$u.toast('倒计时结束后再发送');
}
},
}, },
onReady() { onReady() {
this.$refs.loginForm.setRules(this.rules); this.$refs.loginForm.setRules(this.rules);
@ -97,7 +175,7 @@
margin: 0rpx 76rpx; margin: 0rpx 76rpx;
.copyright_iocn { .copyright_iocn {
margin: 120rpx 0rpx; margin: 0rpx 0rpx 120rpx;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
@ -109,5 +187,29 @@
align-items: center; align-items: center;
padding: 24rpx 0rpx; padding: 24rpx 0rpx;
} }
.tab_op {
height: 60rpx;
width: 100%;
height: 60rpx;
overflow: hidden;
font-size: 16px;
font-weight: 600;
.choosed {
width: 200rpx;
text-align: center;
color: #99241B;
float: left;
font-size: 17px;
}
.unchoosed {
width: 200rpx;
text-align: center;
color: #32333B;
float: left;
}
}
} }
</style> </style>

View File

@ -52,7 +52,6 @@ export default {
options.complete = (response) => { options.complete = (response) => {
// console.log(response, 'response----') // console.log(response, 'response----')
let statusCode = response.statusCode let statusCode = response.statusCode
console.log(statusCode)
response.config = _config response.config = _config
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
if (statusCode === 200) { if (statusCode === 200) {