241 lines
7.1 KiB
Vue
241 lines
7.1 KiB
Vue
<template>
|
||
<view class="app">
|
||
<view class="item">
|
||
<view class="lefttext">
|
||
姓名
|
||
</view>
|
||
<input class="righttext" type="text" placeholder="请输入" maxlength="10" v-model="patientName" />
|
||
</view>
|
||
<view class="item">
|
||
<view class="lefttext">
|
||
输入密码
|
||
</view>
|
||
<u-input class='righttext' style='left:30%' placeholder="请输入密码" maxlength="10" v-model="password"
|
||
type="password" :border="false" :password-icon="true" />
|
||
</view>
|
||
<view class="item">
|
||
<view class="lefttext">
|
||
重复密码
|
||
</view>
|
||
<u-input class='righttext' style='left:30%' placeholder="请再次输入密码" maxlength="10" v-model="newpassword"
|
||
type="password" :border="false" :password-icon="true" />
|
||
</view>
|
||
<view class="item">
|
||
<view class="lefttext">
|
||
手机号
|
||
</view>
|
||
<input class="righttext" style='left:23%' type="text" placeholder="请输入" maxlength="11" v-model="phone" />
|
||
</view>
|
||
<!-- <view class="item">
|
||
<view class="lefttext">
|
||
验证码
|
||
</view>
|
||
<input class="righttext" style='left:23%' type="text" placeholder="" maxlength="6" v-model="verification" />
|
||
<view class="obtaincode" :style="{'color':getCodeBtnColor}" @click.stop="getCode()">
|
||
{{getCodeText}}
|
||
</view>
|
||
</view> -->
|
||
<view class="radio-content" @tap="changeRadio">
|
||
<view class="radio-right">
|
||
<view class="radio" :class="radio == 2 ? 'radio-default':''">
|
||
<view :class="radio == 2 ? 'radio-active':''"></view>
|
||
</view>
|
||
</view>
|
||
<text class="agreement">我已阅读并同意</text>
|
||
<text @tap='maskshow=true;showRegectAgreeButton=false'>《用户协议》</text>
|
||
</view>
|
||
<view class="loginbtn" @tap='register'>
|
||
注册
|
||
</view>
|
||
<view class="switch" style="right:5%" @tap='gologin'>
|
||
已有账号,去登录
|
||
</view>
|
||
<u-toast ref="uToast" />
|
||
</view>
|
||
</template>
|
||
<script>
|
||
import {
|
||
appRegister
|
||
} from '../../api/register/index.js'
|
||
export default {
|
||
data() {
|
||
return {
|
||
radio: 1, //用户协议
|
||
patientName: '',
|
||
phone: '',
|
||
password: '',
|
||
newpassword: '',
|
||
verification: '',
|
||
getCodeText: '获取验证码', //获取验证码的文字
|
||
getCodeBtnColor: "#4C7BC9", //获取验证码的color
|
||
getCodeisWaiting: false, //判断是否在倒计时中
|
||
};
|
||
},
|
||
methods: {
|
||
//注册功能
|
||
register() {
|
||
if (this.password !== this.newpassword) {
|
||
this.$refs.uToast.show({
|
||
title: '密码输入不一致,请重新输入',
|
||
type: 'error',
|
||
duration: '1500'
|
||
})
|
||
} else {
|
||
appRegister(this.patientName, this.phone, this.password, this.verification).then(res => {
|
||
console.log(res)
|
||
if (res.code == 200) {
|
||
this.$refs.uToast.show({
|
||
title: '注册成功,前往登录',
|
||
type: 'success',
|
||
url: '/pages/login/login',
|
||
duration: '1500'
|
||
})
|
||
} else {
|
||
this.$refs.uToast.show({
|
||
title: res.msg,
|
||
type: 'error'
|
||
})
|
||
}
|
||
})
|
||
}
|
||
},
|
||
//跳转登录页
|
||
gologin() {
|
||
uni.navigateTo({
|
||
url: `/pages/login/login`
|
||
})
|
||
},
|
||
//点击获取验证码
|
||
getCode() {
|
||
uni.hideKeyboard() //隐藏已经显示的软键盘,如果软键盘没有显示则不做任何操作。
|
||
if (this.getCodeisWaiting) { //是否在倒计时中
|
||
return;
|
||
}
|
||
if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.phone))) { //校验手机号码是否有误
|
||
uni.showToast({
|
||
title: '请填写正确手机号码',
|
||
icon: "none"
|
||
});
|
||
return false;
|
||
}
|
||
this.getCodeText = "发送中..." //发送验证码
|
||
this.getCodeisWaiting = true;
|
||
this.getCodeBtnColor = "rgba(138,139,133,1)" //追加样式,修改颜色
|
||
//示例用定时器模拟请求效果
|
||
//setTimeout(()用于在指定的毫秒数后调用函数或计算表达式
|
||
setTimeout(() => {
|
||
uni.showToast({
|
||
title: '验证码已发送',
|
||
icon: "none"
|
||
}); //弹出提示框
|
||
// this.code = '1234'; //发送验证码,进行填入 示例默认1234,生产中请删除这一句。
|
||
this.setTimer(); //调用定时器方法
|
||
}, 1000)
|
||
},
|
||
//获取验证码的倒计时 setTimer: 需要每隔一段时间执行一件事的的时候就需要使用SetTimer函数
|
||
setTimer() {
|
||
let holdTime = 60; //定义变量并赋值
|
||
this.getCodeText = "重新获取(60)"
|
||
//setInterval()是一个实现定时调用的函数,可按照指定的周期(以毫秒计)来调用函数或计算表达式。
|
||
//setInterval方法会不停地调用函数,直到 clearInterval被调用或窗口被关闭。
|
||
this.Timer = setInterval(() => {
|
||
if (holdTime <= 0) {
|
||
this.getCodeisWaiting = false;
|
||
this.getCodeBtnColor = "#4C7BC9";
|
||
this.getCodeText = "获取验证码"
|
||
clearInterval(this.Timer); //清除该函数
|
||
return; //返回前面
|
||
}
|
||
this.getCodeText = "重新获取(" + holdTime + ")"
|
||
holdTime--;
|
||
}, 1000)
|
||
},
|
||
doReg() {
|
||
// uni.hideKeyboard() //隐藏已经显示的软键盘,如果软键盘没有显示则不做任何操作。
|
||
// //模板示例部分验证规则
|
||
// if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.phoneNumber))) { //校验手机号码
|
||
// uni.showToast({
|
||
// title: '请填写正确手机号码',
|
||
// icon: "none"
|
||
// });
|
||
// return false;
|
||
// }
|
||
// //示例验证码,实际使用中应为请求服务器比对验证码是否正确。
|
||
// if (this.code != 1234) {
|
||
// uni.showToast({
|
||
// title: '验证码不正确',
|
||
// icon: "none"
|
||
// });
|
||
// return false;
|
||
// }
|
||
// uni.showLoading({
|
||
// title: '提交中...'
|
||
// })
|
||
// //模板示例把用户注册信息储存在本地,实际使用中请替换为上传服务器。
|
||
// setTimeout(() => {
|
||
// uni.getStorage({
|
||
// key: 'UserList',
|
||
// success: (res) => {
|
||
// //增加记录,密码md5
|
||
// res.data.push({
|
||
// username: this.phoneNumber,
|
||
// passwd: md5(this.passwd)
|
||
// })
|
||
// uni.setStorage({
|
||
// key: 'UserList',
|
||
// data: res.data,
|
||
// success: function() {
|
||
// uni.hideLoading()
|
||
// uni.showToast({
|
||
// title: '注册成功',
|
||
// icon: "success"
|
||
// });
|
||
// setTimeout(function() {
|
||
// uni.navigateBack();
|
||
// }, 1000)
|
||
// }
|
||
// });
|
||
// },
|
||
// fail: (e) => {
|
||
// uni.hideLoading()
|
||
// console.log('error');
|
||
// //新建UserList
|
||
// uni.setStorage({
|
||
// key: 'UserList',
|
||
// data: [{
|
||
// username: this.phoneNumber,
|
||
// passwd: md5(this.passwd)
|
||
// }],
|
||
// success: function() {
|
||
// uni.hideLoading()
|
||
// uni.showToast({
|
||
// title: '注册成功',
|
||
// icon: "success"
|
||
// });
|
||
// setTimeout(function() {
|
||
// uni.navigateBack();
|
||
// }, 1000)
|
||
// },
|
||
// fail: function(e) {
|
||
// console.log('set error:' + JSON.stringify(e));
|
||
// }
|
||
// });
|
||
// }
|
||
// });
|
||
// }, 1000)
|
||
},
|
||
changeRadio() {
|
||
if (this.radio == 1) {
|
||
this.radio = 2;
|
||
} else {
|
||
this.radio = 1;
|
||
}
|
||
},
|
||
},
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
@import "./register.scss";
|
||
</style>
|