瀏覽代碼

feat(profile): 更新用户信息表单字段和验证逻辑

- 将昵称字段标签更正为姓名
- 移除了重复的手机号输入框(phone2)
- 增强了提交前的字段验证检查
- 为每个必填字段添加独立的空值提示
- 添加了地址字段的非空验证
- 优化了表单提交时的用户体验
mcbaiyun 2 月之前
父節點
當前提交
aa9738ad42
共有 1 個文件被更改,包括 28 次插入6 次删除
  1. 28 6
      src/pages/profile/complete-info.vue

+ 28 - 6
src/pages/profile/complete-info.vue

@@ -21,8 +21,8 @@
       </view>
 
       <view class="form-item">
-        <text class="label">昵称</text>
-        <input class="input" type="nickname" v-model="form.nickname" placeholder="请输入昵称" />
+        <text class="label">姓名</text>
+        <input class="input" type="nickname" v-model="form.nickname" placeholder="请输入姓名" />
       </view>
 
       <view class="form-item">
@@ -80,8 +80,7 @@ const form = ref({
   phone: '',
   age: '',
   sex: 0,
-  address: '',
-  phone2: ''
+  address: ''
 })
 
 const region = ref<string[]>([])
@@ -179,10 +178,33 @@ const getCurrentLocation = async () => {
 
 const onSubmit = async () => {
   if (submitting.value) return
-  if (!form.value.nickname || !form.value.avatar) {
-    uni.showToast({ title: '请填写昵称和选择头像', icon: 'none' })
+
+  // 检查所有必需字段
+  if (!form.value.avatar) {
+    uni.showToast({ title: '请选择头像', icon: 'none' })
+    return
+  }
+  if (!form.value.nickname) {
+    uni.showToast({ title: '请输入姓名', icon: 'none' })
+    return
+  }
+  if (!form.value.phone) {
+    uni.showToast({ title: '请输入手机号', icon: 'none' })
+    return
+  }
+  if (!form.value.age) {
+    uni.showToast({ title: '请输入年龄', icon: 'none' })
+    return
+  }
+  if (!form.value.sex) {
+    uni.showToast({ title: '请选择性别', icon: 'none' })
     return
   }
+  if (!form.value.address) {
+    uni.showToast({ title: '请选择或自动获取省/市', icon: 'none' })
+    return
+  }
+
   submitting.value = true
   try {
     const token = uni.getStorageSync('token')