|
|
@@ -36,6 +36,8 @@
|
|
|
hover-class="submit-btn-hover"
|
|
|
:hover-start-time="0"
|
|
|
:hover-stay-time="120"
|
|
|
+ :disabled="submitting"
|
|
|
+ :loading="submitting"
|
|
|
@click="submitChangePassword"
|
|
|
>
|
|
|
确认修改
|
|
|
@@ -48,11 +50,13 @@
|
|
|
<script setup lang="ts">
|
|
|
import { ref } from 'vue'
|
|
|
import TopBar from '@/components/common/TopBar.vue'
|
|
|
+import { changePassword } from '@/api/user'
|
|
|
import { showToast } from '@/utils'
|
|
|
|
|
|
const currentPassword = ref('')
|
|
|
const newPassword = ref('')
|
|
|
const confirmNewPassword = ref('')
|
|
|
+const submitting = ref(false)
|
|
|
|
|
|
function validateForm(): boolean {
|
|
|
if (!currentPassword.value.trim()) {
|
|
|
@@ -82,12 +86,24 @@ function validateForm(): boolean {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
-function submitChangePassword() {
|
|
|
- if (!validateForm()) return
|
|
|
- showToast({ title: '密码修改成功', icon: 'success' })
|
|
|
- setTimeout(() => {
|
|
|
- uni.navigateBack()
|
|
|
- }, 1500)
|
|
|
+async function submitChangePassword() {
|
|
|
+ if (!validateForm() || submitting.value) return
|
|
|
+
|
|
|
+ submitting.value = true
|
|
|
+ try {
|
|
|
+ await changePassword({
|
|
|
+ oldPassword: currentPassword.value,
|
|
|
+ newPassword: newPassword.value,
|
|
|
+ })
|
|
|
+ showToast({ title: '密码修改成功', icon: 'success' })
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.navigateBack()
|
|
|
+ }, 1500)
|
|
|
+ } catch (error) {
|
|
|
+ // 错误已在 request 中统一提示
|
|
|
+ } finally {
|
|
|
+ submitting.value = false
|
|
|
+ }
|
|
|
}
|
|
|
</script>
|
|
|
|