doum
2026-04-25 b7d451c91ec40bee70f23b1e2cf6a8797643faef
app/pages/change-password/change-password.vue
@@ -14,7 +14,7 @@
         <text class="change-password-page__rule">密码规则:字母、数字组合,不少于8个字符</text>
      </view>
      <button class="change-password-page__submit" hover-class="change-password-page__submit--hover">确认修改</button>
      <button class="change-password-page__submit" hover-class="change-password-page__submit--hover" @click="handleSubmit">确认修改</button>
   </view>
</template>
@@ -27,6 +27,42 @@
               confirmPassword: ''
            }
         }
      },
      methods: {
         handleSubmit() {
            if (!this.form.password) {
               uni.showToast({ title: '请输入新密码', icon: 'none' })
               return
            }
            if (!this.form.confirmPassword) {
               uni.showToast({ title: '请再次输入新密码', icon: 'none' })
               return
            }
            if (this.form.password !== this.form.confirmPassword) {
               uni.showToast({ title: '两次密码输入不一致', icon: 'none' })
               return
            }
            const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/
            if (!passwordRegex.test(this.form.password)) {
               uni.showToast({ title: '密码需字母、数字组合,不少于8个字符', icon: 'none' })
               return
            }
            uni.showLoading({ title: '修改中...' })
            this.$u.api.changePassword({ newPassword: this.form.password }).then(res => {
               uni.hideLoading()
               if (res.code === 200) {
                  uni.showToast({ title: '修改成功', icon: 'success' })
                  setTimeout(() => {
                     this.$store.commit('clearAll')
                     uni.reLaunch({
                        url: '/pages/login/login'
                     })
                  }, 1500)
               }
            }).catch(err => {
               uni.hideLoading()
            })
         }
      }
   }
</script>