Browse Source

h5登录方式修改为手机号登录

zyh
Aaron 4 years ago
parent
commit
c42fc330d7
  1. 3
      pages.json
  2. 23
      pages/user/ChangePassword/index.vue
  3. 129
      pages/user/Login/index.vue
  4. 6
      pages/user/PersonalData/index.vue
  5. 1
      utils/index.js

3
pages.json

@ -25,7 +25,8 @@
} }
}, },
{ {
"path": "pages/user/RetrievePassword/index", // "path": "pages/user/RetrievePassword/index",
"path": "pages/user/ChangePassword/index",
"style": { "style": {
"navigationBarTitleText": "重置密码" "navigationBarTitleText": "重置密码"
} }

23
pages/user/ChangePassword/index.vue

@ -1,8 +1,11 @@
<template> <template>
<view class="ChangePassword"> <view class="ChangePassword">
<view class="phone"> <!-- <view class="phone">
当前手机号: 当前手机号:
<input type="text" v-model="phone" disabled /> <input type="text" v-model="phone" disabled />
</view> -->
<view class="title">
通过手机号来修改密码
</view> </view>
<view class="list"> <view class="list">
<view class="item"> <view class="item">
@ -19,12 +22,7 @@
<view class="confirmBnt bg-color-red" @click="confirm">确认修改</view> <view class="confirmBnt bg-color-red" @click="confirm">确认修改</view>
</view> </view>
</template> </template>
<style scoped lang="less">
.ChangePassword .phone input {
width: 2 * 100rpx;
text-align: center;
}
</style>
<script> <script>
// import { mapGetters } from "vuex"; // import { mapGetters } from "vuex";
import sendVerifyCode from '@/mixins/SendVerifyCode' import sendVerifyCode from '@/mixins/SendVerifyCode'
@ -133,3 +131,14 @@ export default {
}, },
} }
</script> </script>
<style scoped lang="less">
.ChangePassword {
.list{
width: 100%;
padding: 0 10%;
background-color: #FFFFFF;
.code{}
}
}
</style>

129
pages/user/Login/index.vue

@ -5,40 +5,50 @@
<view class="item" :class="current === index ? 'on' : ''" v-for="(item, index) in navList" <view class="item" :class="current === index ? 'on' : ''" v-for="(item, index) in navList"
@click="navTap(index)" :key="index">{{ item }}</view> @click="navTap(index)" :key="index">{{ item }}</view>
</view> </view>
<!-- 手机号登录 -->
<view class="list" :hidden="current !== 0"> <view class="list" :hidden="current !== 0">
<form @submit.prevent="submit"> <form @submit.prevent="submit">
<view class="item"> <view class="item getPhoneCode">
<view class="acea-row row-between-wrapper"> <view class="acea-row row-between-wrapper">
<input type="text" placeholder="输入手机号码" <input type="text" placeholder="输入手机号码"
v-model="account" required v-model="account" required/>
@input="checkPhone"/> </view>
<view class="phoneCode" @click="sendCode">
{{ clockText }}
</view> </view>
</view> </view>
<view class="item" v-if="account.length === 11"> <view class="item">
<view class="acea-row row-between-wrapper"> <view class="acea-row row-between-wrapper">
<input type="password" placeholder="填写登录密码" v-model="password" required /> <input type="text" placeholder="请输入验证码" v-model="captcha" required />
<!-- <input type="password" placeholder="填写登录密码" v-model="password" required /> -->
</view> </view>
</view> </view>
</form> </form>
</view> </view>
<!-- <view class="list" :hidden="current !== 1"> <!-- 账号密码登录 -->
<view class="list" :hidden="current !== 1">
<view class="item"> <view class="item">
<view class="acea-row row-between-wrapper"> <view class="acea-row row-between-wrapper">
<input type="text" placeholder="输入手机号码" v-model="account" /> <input type="text" placeholder="输入手机号码" v-model="account" />
</view> </view>
</view> </view>
<view class="item"> <view class="item">
<view class="acea-row row-between-wrapper">
<input type="text" placeholder="输入密码" v-model="password" />
</view>
</view>
<!-- <view class="item">
<view class="align-left"> <view class="align-left">
<input type="text" placeholder="填写验证码" class="codeIput" v-model="captcha" /> <input type="text" placeholder="填写验证码" class="codeIput" v-model="captcha" />
<button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''" <button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''"
@click="code">{{ text }}</button> @click="code">{{ text }}</button>
</view> </view>
</view>
</view> --> </view> -->
<view class="logon" @click="loginMobile" :hidden="current !== 1">登录</view> </view>
<view class="logon" @click="submit" :hidden="current === 1">登录</view> <view class="logon" @click="loginMobile" :hidden="current === 1">手机号登录</view>
<view class="logon" @click="submit" :hidden="current !== 1">登录</view>
<view class="tip"> <view class="tip">
没有账号? 第一次使用?
<text @click="formItem = 2" class="font-color-red">立即注册</text> <text @click="formItem = 2" class="font-color-red">立即注册</text>
</view> </view>
</view> </view>
@ -124,22 +134,21 @@
mixins: [sendVerifyCode], mixins: [sendVerifyCode],
data: function () { data: function () {
return { return {
navList: ["手机号登录"], // navList: ["", ""],
navList: ["手机号登录",],
current: 0, current: 0,
account: "", account: "",
password: "", password: "",
captcha: "", captcha: "",
inviteCode: "", inviteCode: "",
formItem: 1, formItem: 1,
type: "login" type: "login",
timer: null,
clock: 60,
clockText: '获取验证码'
}; };
}, },
methods: { methods: {
checkPhone(e) {
if (e.target.value.length === 11) {
console.log('手机号')
}
},
async loginMobile() { async loginMobile() {
var that = this; var that = this;
const { const {
@ -166,16 +175,18 @@
return validatorDefaultCatch(e); return validatorDefaultCatch(e);
} }
loginMobile({ loginMobile({
phone: that.account, account: that.account,
captcha: that.captcha, captcha: that.captcha,
spread: cookie.get("spread") spread: cookie.get("spread")
}) })
.then(res => { .then(res => {
var data = res.data; var data = res.data;
that.$store.commit("login", data.token, dayjs(data.expires_time)); that.$store.commit("login", data.token, dayjs(data.expires_time));
that.$store.dispatch('userInfo', true)
handleGetUserInfo(); handleGetUserInfo();
}) })
.catch(err => { .catch(err => {
console.log(err)
uni.showToast({ uni.showToast({
title: err.msg || err.response.data.msg || err.response.data.message, title: err.msg || err.response.data.msg || err.response.data.message,
icon: "none", icon: "none",
@ -240,12 +251,33 @@
}, },
// //
async code() { async code() {
var that = this;
const { const {
account account
} = that; } = this;
try { try {
await that await this
.$validator({
account: [
required(required.message("手机号码")),
chs_phone(chs_phone.message())
]
})
.validate({
account
});
} catch (e) {
return validatorDefaultCatch(e);
}
if (this.formItem == 2) this.type = "register";
this.showCode()
},
//
async sendCode () {
const {
account
} = this;
try {
await this
.$validator({ .$validator({
account: [ account: [
required(required.message("手机号码")), required(required.message("手机号码")),
@ -258,10 +290,30 @@
} catch (e) { } catch (e) {
return validatorDefaultCatch(e); return validatorDefaultCatch(e);
} }
if (that.formItem == 2) that.type = "register"; //
await registerVerify({ if (this.clock !== 60) {
phone: that.account, return
type: that.type }
this.clock--
this.clockText = `${this.clock}`
this.timer = setInterval(() => {
if (parseInt(this.clock) === 1) {
clearTimeout(this.timer)
this.clock = 60
this.clockText = '获取验证码'
return
}
this.clock--
if (this.clock < 10) this.clock = `0${this.clock}`
this.clockText = `${this.clock}`
}, 1000)
this.showCode()
},
//
showCode() {
return registerVerify({
phone: this.account,
type: this.type
}) })
.then(res => { .then(res => {
uni.showToast({ uni.showToast({
@ -269,7 +321,7 @@
icon: "success", icon: "success",
duration: 2000 duration: 2000
}); });
that.sendCode(); this.sendCode();
}) })
.catch(err => { .catch(err => {
uni.showToast({ uni.showToast({
@ -279,9 +331,7 @@
}); });
}); });
}, },
navTap: function (index) { navTap(index) { this.current = index; },
this.current = index;
},
async submit() { async submit() {
const { const {
account, account,
@ -306,7 +356,7 @@
} catch (e) { } catch (e) {
return validatorDefaultCatch(e); return validatorDefaultCatch(e);
} }
//
login({ login({
username: account, username: account,
password, password,
@ -337,3 +387,22 @@
} }
}; };
</script> </script>
<style lang="scss">
.register .whiteBg .title .item{
border-bottom: 2px solid;
}
.register .whiteBg .title .item.on{
border-bottom-color: #f35749;
}
.getPhoneCode{
display: flex;
justify-content: space-between;
.phoneCode{
color: #FFFFFF;
background-color: #f35749;
padding: 12rpx;
border-radius: 30rpx;
}
}
</style>

6
pages/user/PersonalData/index.vue

@ -44,15 +44,13 @@
<input type="text" v-else value="未绑定" disabled class="id" /> <input type="text" v-else value="未绑定" disabled class="id" />
</view> </view>
</view> </view>
<!-- <!-- <view class="item acea-row row-between-wrapper" @click="goChangePassword()">
<view class="item acea-row row-between-wrapper" @click="goChangePassword()">
<view>密码</view> <view>密码</view>
<view class="input acea-row row-between-wrapper"> <view class="input acea-row row-between-wrapper">
<text>点击修改密码</text> <text>点击修改密码</text>
<text class="iconfont icon-suozi"></text> <text class="iconfont icon-suozi"></text>
</view> </view>
</view> </view> -->
-->
</view> </view>
<view class="modifyBnt bg-color-red" @click="submit">保存修改</view> <view class="modifyBnt bg-color-red" @click="submit">保存修改</view>
<!-- #ifndef MP-WEIXIN --> <!-- #ifndef MP-WEIXIN -->

1
utils/index.js

@ -354,7 +354,6 @@ export const handleGetUserInfo = () => {
console.log('获取用户信息') console.log('获取用户信息')
store.dispatch('setUserInfo', res.data) store.dispatch('setUserInfo', res.data)
console.log('获取用户信息后跳转回显的页面') console.log('获取用户信息后跳转回显的页面')
let redirect = cookie.get('redirect').replace(/\ /g, '') let redirect = cookie.get('redirect').replace(/\ /g, '')
if (redirect) { if (redirect) {
reLaunch({ reLaunch({

Loading…
Cancel
Save