|
|
@@ -20,7 +20,7 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
- <view class="form-group">
|
|
|
+<!-- <view class="form-group">
|
|
|
<view class="input-group">
|
|
|
<text class="input-icon">验</text>
|
|
|
<input
|
|
|
@@ -38,7 +38,7 @@
|
|
|
{{ codeBtnText }}
|
|
|
</text>
|
|
|
</view>
|
|
|
- </view>
|
|
|
+ </view> -->
|
|
|
|
|
|
<view class="form-group">
|
|
|
<view class="input-group">
|
|
|
@@ -82,7 +82,7 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
- <button class="register-btn" @click="handleRegister">立即注册</button>
|
|
|
+ <button class="register-btn" @click="handleRegister" :loading="isSubmitting">立即注册</button>
|
|
|
|
|
|
<view class="login-link">
|
|
|
<text>已有账号?</text>
|
|
|
@@ -99,11 +99,22 @@
|
|
|
<text class="link" @click="navigateToPrivacy">隐私政策</text>
|
|
|
</text>
|
|
|
</view>
|
|
|
+
|
|
|
+ <!-- #ifdef MP-WEIXIN -->
|
|
|
+ <view class="wechat-register-tip">
|
|
|
+ <text>推荐使用微信一键登录</text>
|
|
|
+ <button class="wechat-register-btn" @click="navigateToLogin">
|
|
|
+ <text class="wechat-icon">微</text>
|
|
|
+ <text>一键登录</text>
|
|
|
+ </button>
|
|
|
+ </view>
|
|
|
+ <!-- #endif -->
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { register, sendVerificationCode } from '@/api/services/auth.js';
|
|
|
+import storage from "@/utils/storage.js";
|
|
|
+import { register } from '@/api/services/connect.js';
|
|
|
|
|
|
export default {
|
|
|
data() {
|
|
|
@@ -120,7 +131,8 @@ export default {
|
|
|
agreed: true,
|
|
|
codeBtnText: '获取验证码',
|
|
|
codeBtnDisabled: false,
|
|
|
- countdown: 60
|
|
|
+ countdown: 60,
|
|
|
+ isSubmitting: false
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
@@ -149,50 +161,62 @@ export default {
|
|
|
url: '/pages/privacy/index'
|
|
|
})
|
|
|
},
|
|
|
- getVerificationCode() {
|
|
|
- if (this.codeBtnDisabled) return
|
|
|
+ // getVerificationCode() {
|
|
|
+ // if (this.codeBtnDisabled) return
|
|
|
|
|
|
- if (!this.formData.phone) {
|
|
|
- uni.showToast({
|
|
|
- title: '请输入手机号',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
+ // if (!this.formData.phone) {
|
|
|
+ // uni.showToast({
|
|
|
+ // title: '请输入手机号',
|
|
|
+ // icon: 'none'
|
|
|
+ // })
|
|
|
+ // return
|
|
|
+ // }
|
|
|
|
|
|
- if (!/^1\d{10}$/.test(this.formData.phone)) {
|
|
|
- uni.showToast({
|
|
|
- title: '请输入正确的手机号',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
+ // if (!/^1\d{10}$/.test(this.formData.phone)) {
|
|
|
+ // uni.showToast({
|
|
|
+ // title: '请输入正确的手机号',
|
|
|
+ // icon: 'none'
|
|
|
+ // })
|
|
|
+ // return
|
|
|
+ // }
|
|
|
|
|
|
- // 发送验证码请求
|
|
|
- uni.showLoading({ title: '发送中...' })
|
|
|
+ // // 发送验证码请求
|
|
|
+ // uni.showLoading({ title: '发送中...' })
|
|
|
|
|
|
- // 使用授权服务发送验证码
|
|
|
- sendVerificationCode({
|
|
|
- phone: this.formData.phone,
|
|
|
- type: 'register'
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- uni.showToast({
|
|
|
- title: '验证码已发送',
|
|
|
- icon: 'success'
|
|
|
- });
|
|
|
- this.startCountdown();
|
|
|
- })
|
|
|
- .catch(error => {
|
|
|
- uni.showToast({
|
|
|
- title: error,
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- })
|
|
|
- .finally(() => {
|
|
|
- uni.hideLoading();
|
|
|
- });
|
|
|
- },
|
|
|
+ // // 调用发送验证码接口
|
|
|
+ // uni.request({
|
|
|
+ // url: 'API_URL/user/sendCode', // 替换为实际接口地址
|
|
|
+ // method: 'POST',
|
|
|
+ // data: {
|
|
|
+ // phone: this.formData.phone,
|
|
|
+ // type: 'register'
|
|
|
+ // },
|
|
|
+ // success: (res) => {
|
|
|
+ // if (res.data.code === 200) {
|
|
|
+ // uni.showToast({
|
|
|
+ // title: '验证码已发送',
|
|
|
+ // icon: 'success'
|
|
|
+ // });
|
|
|
+ // this.startCountdown();
|
|
|
+ // } else {
|
|
|
+ // uni.showToast({
|
|
|
+ // title: res.data.msg || '发送失败,请稍后重试',
|
|
|
+ // icon: 'none'
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // fail: (err) => {
|
|
|
+ // uni.showToast({
|
|
|
+ // title: '网络异常,请稍后重试',
|
|
|
+ // icon: 'none'
|
|
|
+ // });
|
|
|
+ // console.error(err);
|
|
|
+ // },
|
|
|
+ // complete: () => {
|
|
|
+ // uni.hideLoading();
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
startCountdown() {
|
|
|
this.codeBtnDisabled = true
|
|
|
this.codeBtnText = `${this.countdown}秒`
|
|
|
@@ -226,13 +250,13 @@ export default {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- if (!this.formData.code) {
|
|
|
- uni.showToast({
|
|
|
- title: '请输入验证码',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- return false
|
|
|
- }
|
|
|
+ // if (!this.formData.code) {
|
|
|
+ // uni.showToast({
|
|
|
+ // title: '请输入验证码',
|
|
|
+ // icon: 'none'
|
|
|
+ // })
|
|
|
+ // return false
|
|
|
+ // }
|
|
|
|
|
|
if (!this.formData.password) {
|
|
|
uni.showToast({
|
|
|
@@ -271,36 +295,58 @@ export default {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ this.isSubmitting = true;
|
|
|
+
|
|
|
// 调用注册接口
|
|
|
uni.showLoading({ title: '注册中...' })
|
|
|
-
|
|
|
- // 使用授权服务注册
|
|
|
- register({
|
|
|
- phone: this.formData.phone,
|
|
|
- code: this.formData.code,
|
|
|
- password: this.formData.password,
|
|
|
- nickname: this.formData.nickname || `用户${this.formData.phone.substr(-4)}`
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- uni.showToast({
|
|
|
- title: '注册成功',
|
|
|
- icon: 'success'
|
|
|
- });
|
|
|
-
|
|
|
- // 延迟跳转到登录页
|
|
|
- setTimeout(() => {
|
|
|
- uni.navigateBack();
|
|
|
- }, 1500);
|
|
|
- })
|
|
|
- .catch(error => {
|
|
|
- uni.showToast({
|
|
|
- title: error,
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- })
|
|
|
- .finally(() => {
|
|
|
- uni.hideLoading();
|
|
|
- });
|
|
|
+
|
|
|
+ const data = {
|
|
|
+ phoneNumber: this.formData.phone,
|
|
|
+ password: this.formData.password,
|
|
|
+ username: this.formData.nickname || `用户${this.formData.phone.substr(-4)}`
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调用注册接口
|
|
|
+ register(data)
|
|
|
+ .then(res => {
|
|
|
+ console.log("res注册",res);
|
|
|
+ if (res.data.code === 200) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '注册成功',
|
|
|
+ icon: 'success'
|
|
|
+ });
|
|
|
+ storage.setUserInfo(data);
|
|
|
+ // 自动登录
|
|
|
+ // if (res.data.data && res.data.data.token) {
|
|
|
+ // storage.setAccessToken(res.data.data.token);
|
|
|
+ // storage.setUserInfo(data);
|
|
|
+ // storage.setHasLogin(true);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // 延迟跳转到登录页或首页
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.navigateBack({
|
|
|
+ delta: 1,
|
|
|
+ });
|
|
|
+ }, 1500);
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: res.data.msg || '注册失败,请稍后重试',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ uni.showToast({
|
|
|
+ title: '网络异常,请稍后重试',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ console.error(err);
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ uni.hideLoading();
|
|
|
+ this.isSubmitting = false;
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -419,7 +465,6 @@ export default {
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
justify-content: center;
|
|
|
- margin-top: auto;
|
|
|
padding: 40rpx 0;
|
|
|
}
|
|
|
|
|
|
@@ -428,4 +473,56 @@ export default {
|
|
|
color: #666;
|
|
|
margin-left: 10rpx;
|
|
|
}
|
|
|
+
|
|
|
+/* 微信注册提示 */
|
|
|
+.wechat-register-tip {
|
|
|
+ margin-top: 40rpx;
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ align-items: center;
|
|
|
+}
|
|
|
+
|
|
|
+.wechat-register-tip text {
|
|
|
+ font-size: 28rpx;
|
|
|
+ color: #666;
|
|
|
+ margin-bottom: 20rpx;
|
|
|
+}
|
|
|
+
|
|
|
+.wechat-register-btn {
|
|
|
+ width: 80%;
|
|
|
+ height: 90rpx;
|
|
|
+ background-color: #07C160;
|
|
|
+ color: #fff;
|
|
|
+ border-radius: 45rpx;
|
|
|
+ font-size: 32rpx;
|
|
|
+ font-weight: bold;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ border: none;
|
|
|
+ padding: 0;
|
|
|
+}
|
|
|
+
|
|
|
+.wechat-icon {
|
|
|
+ width: 40rpx;
|
|
|
+ height: 40rpx;
|
|
|
+ background-color: rgba(255, 255, 255, 0.2);
|
|
|
+ color: #fff;
|
|
|
+ border-radius: 20rpx;
|
|
|
+ font-size: 20rpx;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ margin-right: 10rpx;
|
|
|
+}
|
|
|
+
|
|
|
+/* #ifdef H5 */
|
|
|
+/* H5特殊样式调整 */
|
|
|
+@media screen and (min-width: 768px) {
|
|
|
+ .register-form {
|
|
|
+ max-width: 600rpx;
|
|
|
+ margin: 0 auto;
|
|
|
+ }
|
|
|
+}
|
|
|
+/* #endif */
|
|
|
</style>
|