hookehuyr

feat(CreateFamily): 添加表单验证并禁用无效提交按钮

当表单未填写完整时禁用提交按钮并显示灰色样式,移除手动验证逻辑
1 <!-- 1 <!--
2 * @Date: 2025-08-27 17:44:53 2 * @Date: 2025-08-27 17:44:53
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-08-28 12:55:42 4 + * @LastEditTime: 2025-08-28 21:35:16
5 * @FilePath: /lls_program/src/pages/CreateFamily/index.vue 5 * @FilePath: /lls_program/src/pages/CreateFamily/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
115 /> 115 />
116 <view 116 <view
117 @click="deleteAvatar" 117 @click="deleteAvatar"
118 - class="absolute -top-2 -right-2 w-5 h-5 bg-red-500 rounded-full flex items-center justify-center" 118 + class="absolute -top-2 -right-2 w-4 h-4 bg-red-500 rounded-full flex items-center justify-center"
119 > 119 >
120 <view class="text-white text-xs">×</view> 120 <view class="text-white text-xs">×</view>
121 </view> 121 </view>
...@@ -140,8 +140,11 @@ ...@@ -140,8 +140,11 @@
140 </view> 140 </view>
141 <!-- Submit Button --> 141 <!-- Submit Button -->
142 <view 142 <view
143 - @click="handleCreateFamily" 143 + @tap="isFormValid ? handleCreateFamily : null"
144 - class="w-full py-3 bg-blue-500 text-white text-lg font-medium rounded-lg flex items-center justify-center" 144 + :class="[
145 + 'w-full py-3 text-white text-lg font-medium rounded-lg flex items-center justify-center',
146 + isFormValid ? 'bg-blue-500' : 'bg-gray-400'
147 + ]"
145 > 148 >
146 创建家庭 149 创建家庭
147 </view> 150 </view>
...@@ -160,7 +163,7 @@ ...@@ -160,7 +163,7 @@
160 </template> 163 </template>
161 164
162 <script setup> 165 <script setup>
163 -import { ref, nextTick } from 'vue'; 166 +import { ref, nextTick, computed } from 'vue';
164 import Taro from '@tarojs/taro'; 167 import Taro from '@tarojs/taro';
165 import { Edit, Tips, Photograph } from '@nutui/icons-vue-taro'; 168 import { Edit, Tips, Photograph } from '@nutui/icons-vue-taro';
166 // import AppHeader from '../../components/AppHeader.vue'; 169 // import AppHeader from '../../components/AppHeader.vue';
...@@ -176,6 +179,14 @@ const familyAvatar = ref(''); ...@@ -176,6 +179,14 @@ const familyAvatar = ref('');
176 const focusedIndex = ref(-1); 179 const focusedIndex = ref(-1);
177 const inputRefs = ref([]); 180 const inputRefs = ref([]);
178 181
182 +const isFormValid = computed(() => {
183 + return (
184 + familyName.value.trim() !== '' &&
185 + familyIntro.value.trim() !== '' &&
186 + familyMotto.value.every(char => char.trim() !== '')
187 + );
188 +});
189 +
179 // 图片预览相关 190 // 图片预览相关
180 const previewVisible = ref(false); 191 const previewVisible = ref(false);
181 const previewImages = ref([]); 192 const previewImages = ref([]);
...@@ -364,10 +375,6 @@ const validateForm = () => { ...@@ -364,10 +375,6 @@ const validateForm = () => {
364 * 创建家庭 375 * 创建家庭
365 */ 376 */
366 const handleCreateFamily = () => { 377 const handleCreateFamily = () => {
367 - if (!validateForm()) {
368 - return;
369 - }
370 -
371 // 在实际应用中,这里会调用API创建家庭 378 // 在实际应用中,这里会调用API创建家庭
372 // 目前仅作为演示跳转到仪表盘页面 379 // 目前仅作为演示跳转到仪表盘页面
373 showToast('家庭创建成功', 'success'); 380 showToast('家庭创建成功', 'success');
......