382 lines
7.2 KiB
Vue
382 lines
7.2 KiB
Vue
|
|
<template>
|
||
|
|
<view class="bind-phone-container">
|
||
|
|
<view class="bind-content">
|
||
|
|
<!-- 标题 -->
|
||
|
|
<view class="page-header">
|
||
|
|
<text class="header-title">绑定手机号</text>
|
||
|
|
<text class="header-subtitle">绑定手机号后可用于登录和找回密码</text>
|
||
|
|
</view>
|
||
|
|
|
||
|
|
<!-- 表单 -->
|
||
|
|
<view class="form-section">
|
||
|
|
<!-- 手机号 -->
|
||
|
|
<view class="form-item">
|
||
|
|
<view class="item-label">
|
||
|
|
<text class="label-icon">📱</text>
|
||
|
|
<text class="label-text">手机号码</text>
|
||
|
|
</view>
|
||
|
|
<input
|
||
|
|
class="item-input"
|
||
|
|
type="number"
|
||
|
|
v-model="phone"
|
||
|
|
placeholder="请输入手机号"
|
||
|
|
placeholder-class="input-placeholder"
|
||
|
|
maxlength="11"
|
||
|
|
/>
|
||
|
|
</view>
|
||
|
|
|
||
|
|
<!-- 验证码 -->
|
||
|
|
<view class="form-item">
|
||
|
|
<view class="item-label">
|
||
|
|
<text class="label-icon">🔢</text>
|
||
|
|
<text class="label-text">验证码</text>
|
||
|
|
</view>
|
||
|
|
<view class="code-input-wrapper">
|
||
|
|
<input
|
||
|
|
class="code-input"
|
||
|
|
type="number"
|
||
|
|
v-model="code"
|
||
|
|
placeholder="请输入验证码"
|
||
|
|
placeholder-class="input-placeholder"
|
||
|
|
maxlength="6"
|
||
|
|
/>
|
||
|
|
<button
|
||
|
|
class="send-code-btn"
|
||
|
|
@click="sendCode"
|
||
|
|
:disabled="counting"
|
||
|
|
>
|
||
|
|
{{ counting ? `${countdown}秒后重发` : '发送验证码' }}
|
||
|
|
</button>
|
||
|
|
</view>
|
||
|
|
</view>
|
||
|
|
</view>
|
||
|
|
|
||
|
|
<!-- 提示信息 -->
|
||
|
|
<view class="tips-section">
|
||
|
|
<view class="tips-item">• 验证码将发送至您的手机</view>
|
||
|
|
<view class="tips-item">• 请确保手机号码正确无误</view>
|
||
|
|
<view class="tips-item">• 一个手机号只能绑定一个账号</view>
|
||
|
|
</view>
|
||
|
|
|
||
|
|
<!-- 提交按钮 -->
|
||
|
|
<view class="button-section">
|
||
|
|
<button class="submit-btn" @click="handleSubmit" :disabled="submitting">
|
||
|
|
{{ submitting ? '提交中...' : '确认绑定' }}
|
||
|
|
</button>
|
||
|
|
</view>
|
||
|
|
</view>
|
||
|
|
</view>
|
||
|
|
</template>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
export default {
|
||
|
|
data() {
|
||
|
|
return {
|
||
|
|
phone: '',
|
||
|
|
code: '',
|
||
|
|
counting: false,
|
||
|
|
countdown: 60,
|
||
|
|
submitting: false,
|
||
|
|
timer: null
|
||
|
|
};
|
||
|
|
},
|
||
|
|
onUnload() {
|
||
|
|
if (this.timer) {
|
||
|
|
clearInterval(this.timer);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
methods: {
|
||
|
|
validatePhone() {
|
||
|
|
const phoneReg = /^1[3-9]\d{9}$/;
|
||
|
|
if (!this.phone) {
|
||
|
|
uni.showToast({
|
||
|
|
title: '请输入手机号',
|
||
|
|
icon: 'none'
|
||
|
|
});
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (!phoneReg.test(this.phone)) {
|
||
|
|
uni.showToast({
|
||
|
|
title: '请输入正确的手机号',
|
||
|
|
icon: 'none'
|
||
|
|
});
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
},
|
||
|
|
|
||
|
|
async sendCode() {
|
||
|
|
if (!this.validatePhone()) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
try {
|
||
|
|
// TODO: 调用后端API发送验证码
|
||
|
|
// await this.$http.post('/api/sms/send', { phone: this.phone });
|
||
|
|
|
||
|
|
// 模拟发送
|
||
|
|
await new Promise(resolve => setTimeout(resolve, 500));
|
||
|
|
|
||
|
|
uni.showToast({
|
||
|
|
title: '验证码已发送',
|
||
|
|
icon: 'success'
|
||
|
|
});
|
||
|
|
|
||
|
|
// 开始倒计时
|
||
|
|
this.counting = true;
|
||
|
|
this.countdown = 60;
|
||
|
|
this.timer = setInterval(() => {
|
||
|
|
this.countdown--;
|
||
|
|
if (this.countdown <= 0) {
|
||
|
|
clearInterval(this.timer);
|
||
|
|
this.counting = false;
|
||
|
|
this.countdown = 60;
|
||
|
|
}
|
||
|
|
}, 1000);
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
uni.showToast({
|
||
|
|
title: error.message || '发送失败,请重试',
|
||
|
|
icon: 'none'
|
||
|
|
});
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
validateForm() {
|
||
|
|
if (!this.validatePhone()) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!this.code) {
|
||
|
|
uni.showToast({
|
||
|
|
title: '请输入验证码',
|
||
|
|
icon: 'none'
|
||
|
|
});
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (this.code.length !== 6) {
|
||
|
|
uni.showToast({
|
||
|
|
title: '请输入6位验证码',
|
||
|
|
icon: 'none'
|
||
|
|
});
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
return true;
|
||
|
|
},
|
||
|
|
|
||
|
|
async handleSubmit() {
|
||
|
|
if (!this.validateForm()) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.submitting = true;
|
||
|
|
|
||
|
|
try {
|
||
|
|
// TODO: 调用后端API绑定手机
|
||
|
|
// const res = await this.$http.post('/api/user/bind-phone', {
|
||
|
|
// phone: this.phone,
|
||
|
|
// code: this.code
|
||
|
|
// });
|
||
|
|
|
||
|
|
// 模拟API请求
|
||
|
|
await new Promise(resolve => setTimeout(resolve, 1500));
|
||
|
|
|
||
|
|
// 更新本地用户信息
|
||
|
|
const userInfo = uni.getStorageSync('userInfo') || {};
|
||
|
|
userInfo.phone = this.phone;
|
||
|
|
uni.setStorageSync('userInfo', userInfo);
|
||
|
|
|
||
|
|
uni.showToast({
|
||
|
|
title: '绑定成功',
|
||
|
|
icon: 'success',
|
||
|
|
duration: 2000
|
||
|
|
});
|
||
|
|
|
||
|
|
setTimeout(() => {
|
||
|
|
uni.navigateBack();
|
||
|
|
}, 2000);
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
uni.showToast({
|
||
|
|
title: error.message || '绑定失败,请重试',
|
||
|
|
icon: 'none'
|
||
|
|
});
|
||
|
|
} finally {
|
||
|
|
this.submitting = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
};
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<style lang="scss" scoped>
|
||
|
|
.bind-phone-container {
|
||
|
|
min-height: 100vh;
|
||
|
|
background: linear-gradient(135deg, #FDF8F2 0%, #F5EDE0 100%);
|
||
|
|
}
|
||
|
|
|
||
|
|
.bind-content {
|
||
|
|
padding: 40upx 30upx;
|
||
|
|
}
|
||
|
|
|
||
|
|
/* 页面标题 */
|
||
|
|
.page-header {
|
||
|
|
text-align: center;
|
||
|
|
margin-bottom: 60upx;
|
||
|
|
|
||
|
|
.header-title {
|
||
|
|
display: block;
|
||
|
|
font-size: 48upx;
|
||
|
|
font-weight: 700;
|
||
|
|
color: #333;
|
||
|
|
margin-bottom: 20upx;
|
||
|
|
}
|
||
|
|
|
||
|
|
.header-subtitle {
|
||
|
|
display: block;
|
||
|
|
font-size: 26upx;
|
||
|
|
color: #999;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/* 表单区域 */
|
||
|
|
.form-section {
|
||
|
|
background: white;
|
||
|
|
border-radius: 30upx;
|
||
|
|
padding: 40upx 30upx;
|
||
|
|
margin-bottom: 40upx;
|
||
|
|
box-shadow: 0 8upx 40upx rgba(0, 0, 0, 0.08);
|
||
|
|
}
|
||
|
|
|
||
|
|
.form-item {
|
||
|
|
margin-bottom: 40upx;
|
||
|
|
|
||
|
|
&:last-child {
|
||
|
|
margin-bottom: 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
.item-label {
|
||
|
|
display: flex;
|
||
|
|
align-items: center;
|
||
|
|
margin-bottom: 20upx;
|
||
|
|
|
||
|
|
.label-icon {
|
||
|
|
font-size: 32upx;
|
||
|
|
margin-right: 10upx;
|
||
|
|
}
|
||
|
|
|
||
|
|
.label-text {
|
||
|
|
font-size: 28upx;
|
||
|
|
font-weight: 600;
|
||
|
|
color: #333;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
.item-input {
|
||
|
|
width: 100%;
|
||
|
|
max-width: 520upx; /* 限制宽度,避免输入框过长 */
|
||
|
|
margin: 0 auto;
|
||
|
|
padding: 24upx 30upx;
|
||
|
|
background: #F8F8F8;
|
||
|
|
border-radius: 20upx;
|
||
|
|
font-size: 28upx;
|
||
|
|
color: #333;
|
||
|
|
border: 2upx solid transparent;
|
||
|
|
transition: all 0.3s;
|
||
|
|
|
||
|
|
&:focus {
|
||
|
|
background: white;
|
||
|
|
border-color: #8B7355;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
.input-placeholder {
|
||
|
|
color: #ccc;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/* 验证码输入 */
|
||
|
|
.code-input-wrapper {
|
||
|
|
display: flex;
|
||
|
|
align-items: center;
|
||
|
|
gap: 20upx;
|
||
|
|
justify-content: center;
|
||
|
|
|
||
|
|
.code-input {
|
||
|
|
flex: 0 0 auto;
|
||
|
|
width: 100%;
|
||
|
|
max-width: 320upx; /* 限制验证码输入框长度 */
|
||
|
|
padding: 24upx 30upx;
|
||
|
|
background: #F8F8F8;
|
||
|
|
border-radius: 20upx;
|
||
|
|
font-size: 28upx;
|
||
|
|
color: #333;
|
||
|
|
border: 2upx solid transparent;
|
||
|
|
|
||
|
|
&:focus {
|
||
|
|
background: white;
|
||
|
|
border-color: #8B7355;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
.send-code-btn {
|
||
|
|
padding: 24upx 30upx;
|
||
|
|
background: linear-gradient(135deg, #8B7355 0%, #6D8B8B 100%);
|
||
|
|
border-radius: 20upx;
|
||
|
|
color: white;
|
||
|
|
font-size: 24upx;
|
||
|
|
white-space: nowrap;
|
||
|
|
border: none;
|
||
|
|
|
||
|
|
&[disabled] {
|
||
|
|
opacity: 0.6;
|
||
|
|
background: #ccc;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/* 提示信息 */
|
||
|
|
.tips-section {
|
||
|
|
background: linear-gradient(135deg, #E8F5FF 0%, #D6EDFF 100%);
|
||
|
|
border-radius: 20upx;
|
||
|
|
padding: 30upx;
|
||
|
|
margin-bottom: 40upx;
|
||
|
|
border-left: 6upx solid #4A90E2;
|
||
|
|
|
||
|
|
.tips-item {
|
||
|
|
font-size: 24upx;
|
||
|
|
color: #666;
|
||
|
|
line-height: 2;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/* 按钮区域 */
|
||
|
|
.button-section {
|
||
|
|
padding: 20upx 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
.submit-btn {
|
||
|
|
width: 100%;
|
||
|
|
padding: 32upx;
|
||
|
|
background: linear-gradient(135deg, #8B7355 0%, #6D8B8B 100%);
|
||
|
|
border-radius: 50upx;
|
||
|
|
color: white;
|
||
|
|
font-size: 32upx;
|
||
|
|
font-weight: 600;
|
||
|
|
box-shadow: 0 10upx 40upx rgba(139, 115, 85, 0.3);
|
||
|
|
border: none;
|
||
|
|
|
||
|
|
&:active {
|
||
|
|
opacity: 0.8;
|
||
|
|
transform: scale(0.98);
|
||
|
|
}
|
||
|
|
|
||
|
|
&[disabled] {
|
||
|
|
opacity: 0.6;
|
||
|
|
background: #ccc;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
</style>
|