| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516 |
- <template>
- <view class="container">
- <!-- #ifdef MP-WEIXIN -->
- <image class="bg" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/bg_login.png" mode="widthFix">
- </image>
- <view class="force-login-wrap">
- <view :style="{ height: menuButtonInfo.height, marginTop: menuButtonInfo.top }" class="backImg">
- <image @tap="goBack()" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/back_white.png">
- </image>
- </view>
- <view class="top-title">
- <view class="title-text">欢迎注册<text class="blue">文依学术</text></view>
- <view class="login-notice">填写信息完成注册</view>
- </view>
- <view class="force-login__content">
- <view class="input-form">
- <view class="input-item">
- <input class="input-field" type="text" v-model="formData.userName" placeholder="请输入用户账号(登录名)" />
- </view>
- <view class="input-item">
- <input class="input-field" type="text" v-model="formData.nickName" placeholder="请输入用户名称" />
- </view>
- <view class="input-item">
- <input class="input-field" type="number" v-model="formData.phonenumber" placeholder="请输入手机号" maxlength="11" />
- </view>
- <view class="input-item code-input-item">
- <input class="input-field code-input" type="number" v-model="verifyCode" placeholder="请输入验证码" maxlength="6" />
- <view class="get-code-btn" @click="getVerifyCode">
- {{ codeText }}
- </view>
- </view>
- <view class="input-item">
- <view class="mima">
- <input class="input-field" type="text" :password="showPassword" v-model="formData.password" placeholder="请输入密码" />
- <view class="pwd-toggle" @click="closePwd">
- <image
- :src="showPassword ? 'https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/icon_invisible.png' : 'https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/icon_visible.png'"
- mode="aspectFill"></image>
- </view>
- </view>
- </view>
- <view class="input-item">
- <view class="mima">
- <input class="input-field" type="text" :password="showConfirmPassword" v-model="formData.confirmPassword" placeholder="请再次输入密码" />
- <view class="pwd-toggle" @click="closeConfirmPwd">
- <image
- :src="showConfirmPassword ? 'https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/icon_invisible.png' : 'https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/icon_visible.png'"
- mode="aspectFill"></image>
- </view>
- </view>
- </view>
- </view>
- <view class="tips-group">
- <view class="tips-item" @click="toLogin">已有账号?立即登录</view>
- </view>
- <view class="login-btn-wrap">
- <button class="login-btn" @click="handleRegister">注册</button>
- </view>
- <view class="tips">
- <checkbox :checked="isAgreement" @click="handleAgreement()" />
- <view class="tips-text" @click="handleAgreement()">已阅读并接受</view>
- <view class="btn" @click.stop="navTo('/pages_user/userAgreement')">《用户注册协议》</view>
- <view class="btn" @click.stop="navTo('/pages_user/privacyPolicy')">《隐私保护政策》</view>
- </view>
- </view>
- </view>
- <!-- #endif -->
- </view>
- </template>
- <script>
- import { sendSmsCode, smsRegister } from '@/api/user'
- export default {
- data() {
- return {
- formData: {
- userName: '',
- nickName: '',
- phonenumber: '',
- password: '',
- confirmPassword: ''
- },
- verifyCode: '',
- isAgreement: false,
- menuButtonInfo: {},
- codeText: '获取验证码',
- countdown: 0,
- countdownTimer: null,
- showPassword: true,
- showConfirmPassword: true
- }
- },
- onLoad(option) {
- this.getMenuButtonInfo()
- },
- onUnload() {
- // 清除倒计时
- if (this.countdownTimer) {
- clearInterval(this.countdownTimer);
- this.countdownTimer = null;
- }
- },
- methods: {
- navTo(path) {
- uni.navigateTo({
- url: path
- })
- },
- closePwd() {
- this.showPassword = !this.showPassword
- },
- closeConfirmPwd() {
- this.showConfirmPassword = !this.showConfirmPassword
- },
- // 获取胶囊按钮布局参数
- getMenuButtonInfo() {
- const menuBtn = uni.getMenuButtonBoundingClientRect();
- if (menuBtn) {
- this.menuButtonInfo = {
- top: menuBtn.top + 'px',
- height: menuBtn.height + 'px',
- centerY: (menuBtn.top + menuBtn.height / 2) + 'px',
- right: menuBtn.right + 'px'
- };
- }
- },
- // 返回
- goBack() {
- uni.navigateBack({
- delta: 1
- })
- },
- // 跳转到登录页
- toLogin() {
- uni.navigateTo({
- url: '/pages/auth/login'
- })
- },
- // 获取验证码
- getVerifyCode() {
- if (this.countdown > 0) {
- return;
- }
- if (!this.formData.phonenumber) {
- uni.showToast({
- icon: 'none',
- title: "请输入手机号",
- });
- return;
- }
- if (!/^1[3-9]\d{9}$/.test(this.formData.phonenumber)) {
- uni.showToast({
- icon: 'none',
- title: "请输入正确的手机号",
- });
- return;
- }
- // 调用发送验证码API
- uni.showLoading({
- title: "发送中..."
- });
- let params = {
- phone: this.formData.phonenumber,
- type: '2',
- }
- sendSmsCode(params)
- .then(res => {
- uni.hideLoading();
- if (res.code == 200) {
- uni.showToast({
- icon: 'success',
- title: "验证码已发送",
- });
- // 开始倒计时
- this.countdown = 60;
- this.countdownTimer = setInterval(() => {
- this.countdown--;
- this.codeText = this.countdown + '秒重新获取';
- if (this.countdown <= 0) {
- clearInterval(this.countdownTimer);
- this.countdownTimer = null;
- this.codeText = '获取验证码';
- }
- }, 1000);
- } else {
- uni.showToast({
- icon: 'none',
- title: res.msg || "发送验证码失败",
- });
- }
- })
- .catch(err => {
- uni.hideLoading();
- });
- },
- // 注册
- handleRegister() {
- if (!this.isAgreement) {
- uni.showToast({
- icon: 'none',
- title: "请先同意协议后再注册",
- });
- return;
- }
- if (!this.formData.userName) {
- uni.showToast({
- icon: 'none',
- title: "请输入用户账号",
- });
- return;
- }
- if (!this.formData.nickName) {
- uni.showToast({
- icon: 'none',
- title: "请输入用户名称",
- });
- return;
- }
- if (!this.formData.phonenumber) {
- uni.showToast({
- icon: 'none',
- title: "请输入手机号",
- });
- return;
- }
- if (!/^1[3-9]\d{9}$/.test(this.formData.phonenumber)) {
- uni.showToast({
- icon: 'none',
- title: "请输入正确的手机号",
- });
- return;
- }
- if (!this.verifyCode) {
- uni.showToast({
- icon: 'none',
- title: "请输入验证码",
- });
- return;
- }
- if (!this.formData.password) {
- uni.showToast({
- icon: 'none',
- title: "请输入密码",
- });
- return;
- }
- if (this.formData.password !== this.formData.confirmPassword) {
- uni.showToast({
- icon: 'none',
- title: "两次输入的密码不一致",
- });
- return;
- }
- this.register();
- },
- // 注册
- register() {
- uni.showLoading({
- title: "注册中..."
- });
- // 调用注册接口
- const data = {
- userId: '', // 新用户userId为空
- userName: this.formData.userName,
- code: this.verifyCode,
- nickName: this.formData.nickName,
- phonenumber: this.formData.phonenumber,
- password: this.formData.password,
- confirmPassword: this.formData.confirmPassword
- };
- smsRegister(data)
- .then(res => {
- uni.hideLoading();
- if (res.code == 200) {
- uni.showToast({
- icon: 'success',
- title: "注册成功",
- });
- uni.setStorageSync('AppToken', res.data.token);
- uni.setStorageSync('userInfo', res.data.user);
-
- if (!res.data.user.roles) {
- console.log("跳转注册")
- uni.navigateTo({
- url: '/pages/auth/register'
- })
- } else {
- console.log("没跳转注册")
- uni.$emit('refreshLogin');
- uni.navigateBack({
- delta: 1
- });
- }
- } else {
- uni.showToast({
- icon: 'none',
- title: res.msg,
- });
- }
- })
- .catch(err => {
- uni.hideLoading();
- uni.showToast({
- icon: 'none',
- title: "网络错误,请稍后重试",
- });
- });
- },
- handleAgreement() {
- this.isAgreement = !this.isAgreement;
- }
- }
- }
- </script>
- <style lang="scss">
- .container {
- flex: 1;
- padding: 0 24rpx;
- display: flex;
- flex-direction: column;
- justify-content: flex-start;
- position: relative;
- .bg {
- width: 100%;
- position: absolute;
- top: 0;
- left: 0;
- }
- .backImg {
- display: flex;
- align-items: center;
- image {
- width: 40rpx;
- height: 40rpx;
- }
- margin-left: 32rpx;
- }
- }
- .force-login-wrap {
- width: 100%;
- height: 100vh;
- position: relative;
- .top-title {
- padding: 0 32rpx;
- text-align: left;
- margin-top: 20rpx;
- .title-text {
- font-weight: 600;
- font-size: 48rpx;
- color: #333333;
- margin-bottom: 20rpx;
- .blue {
- color: #157CF8;
- }
- }
- .login-notice {
- font-weight: 400;
- font-size: 32rpx;
- color: #666666;
- line-height: 40rpx;
- }
- }
- .force-login__content {
- margin-top: 54rpx;
- padding: 0 32rpx;
- position: relative;
- .input-form {
- margin-bottom: 60rpx;
- .input-item {
- background: #FFFFFF;
- border-radius: 16rpx;
- padding: 30rpx 40rpx;
- margin-bottom: 48rpx;
- box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
- &::last-child {
- margin-bottom: 0
- }
- .input-field {
- width: 100%;
- font-size: 30rpx;
- font-family: PingFang SC;
- color: #333333;
- &::placeholder {
- color: #CCCCCC;
- }
- }
- .mima {
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: space-between;
- .pwd-toggle {
- width: 88rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- image {
- width: 32rpx;
- height: 32rpx;
- }
- }
- &.code-input-item {
- display: flex;
- align-items: center;
- .code-input {
- flex: 1;
- }
- .get-code-btn {
- font-size: 28rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #157CF8;
- padding-left: 20rpx;
- white-space: nowrap;
- }
- }
- }
- }
- .tips-group {
- display: flex;
- align-items: center;
- justify-content: flex-end;
- font-weight: 400;
- font-size: 24rpx;
- color: #388BFF;
- line-height: 40rpx;
- margin: -40rpx 0 24rpx;
- }
- .login-btn-wrap {
- margin-bottom: 40rpx;
- margin-top: 140rpx;
- .login-btn {
- width: 100%;
- height: 88rpx;
- background: rgba(56, 139, 255, 1);
- border-radius: 44rpx;
- font-size: 32rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #FFFFFF;
- border: none;
- display: flex;
- align-items: center;
- justify-content: center;
- &::after {
- border: none;
- }
- }
- }
- }
- }
- .tips {
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 24rpx;
- color: #666666;
- flex-wrap: nowrap;
- padding: 0 60rpx;
- checkbox {
- margin-right: 10rpx;
- flex-shrink: 0;
- transform: scale(0.8);
- }
- .tips-text {
- margin-right: 4rpx;
- white-space: nowrap;
- }
- .btn {
- color: #157CF8;
- margin: 0 2rpx;
- white-space: nowrap;
- }
- }
- </style>
|