<template>
<div class="container">
<h2 style="text-align: left">用户注册</h2>
<form @submit.prevent="submitForm">
<!-- 账号密码部分 -->
<div class="form-group">
<label>用户账号:</label>
<input type="text" v-model.trim="formData.username" required>
</div>
<div class="form-group">
<label>输入密码:</label>
<input type="password" v-model.trim="formData.password" required>
</div>
<div class="form-group">
<label>确认密码:</label>
<div class="input-group">
<input type="password" v-model.trim="formData.confirmPassword" required>
<span v-if="!isPasswordMatch" class="error">密码不一致</span>
</div>
</div>
<!-- 性别单选横向排列 -->
<div class="form-group horizontal">
<label>性别:</label>
<div class="option-group">
<label><input type="radio" v-model="formData.gender" value="男"> 男</label>
<label><input type="radio" v-model="formData.gender" value="女"> 女</label>
</div>
</div>
<!-- 运动多选横向排列 -->
<div class="form-group horizontal">
<label>喜爱的运动:</label>
<div class="option-group">
<label v-for="sport in sports" :key="sport" class="sport-option">
<input type="checkbox" v-model="formData.selectedSports" :value="sport"> {{ sport }}
</label>
</div>
</div>
<!-- 地址选择 -->
<div class="form-group horizontal">
<label>地址:</label>
<select v-model="formData.address">
<option>南昌</option>
</select>
</div>
<!-- 协议同意 -->
<div class="form-group">
<label class="agree-label">
<input type="checkbox" v-model="formData.agree"> 是否同意本站协议
</label>
</div>
<button type="submit" :disabled="!isFormValid">提交</button>
<div v-if="errorMsg" class="error">{{ errorMsg }}</div>
</form>
</div>
</template>
<script>
// 保持与之前相同的脚本部分
</script>
<style>
.container {
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
text-align: left;
}
.form-group {
margin: 15px 0;
}
.form-group.horizontal {
display: flex;
align-items: center;
gap: 15px;
}
.option-group {
display: flex;
gap: 20px;
flex-wrap: wrap;
}
.sport-option {
white-space: nowrap;
}
label {
display: block;
margin: 5px 0;
}
input[type="radio"],
input[type="checkbox"] {
margin-right: 5px;
}
.error {
color: red;
font-size: 0.9em;
margin-top: 5px;
display: block;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
}
button:disabled {
background-color: #cccccc;
cursor: not-allowed;
}
.input-group {
display: flex;
flex-direction: column;
gap: 5px;
}
.agree-label {
display: flex !important;
align-items: center;
gap: 5px;
}
</style>