|
|
@@ -2,6 +2,7 @@
|
|
|
import { computed, ref } from 'vue'
|
|
|
import { showToast } from 'vant'
|
|
|
import ConfirmDialog from '~/components/common/ConfirmDialog.vue'
|
|
|
+import { userApi } from '~/api/user'
|
|
|
|
|
|
definePageMeta({
|
|
|
auth: true,
|
|
|
@@ -12,11 +13,13 @@ type CancellationReason = 'noNeed' | 'privacy' | 'experience' | 'other'
|
|
|
const router = useRouter()
|
|
|
const route = useRoute()
|
|
|
const { t } = useI18n()
|
|
|
+const { logout } = useAuth()
|
|
|
|
|
|
const reason = ref<CancellationReason>('noNeed')
|
|
|
const otherReason = ref('')
|
|
|
const acknowledged = ref(false)
|
|
|
const confirmVisible = ref(false)
|
|
|
+const destroying = ref(false)
|
|
|
|
|
|
const isOther = computed(() => reason.value === 'other')
|
|
|
const canSubmit = computed(() => {
|
|
|
@@ -43,11 +46,26 @@ const handleClickSubmit = () => {
|
|
|
}
|
|
|
|
|
|
const handleConfirm = async () => {
|
|
|
- // TODO: Integrate account cancellation API later.
|
|
|
- showToast(t('mine.cancellation.toast.placeholderSuccess'))
|
|
|
- setTimeout(() => {
|
|
|
- router.back()
|
|
|
- }, 500)
|
|
|
+ if (destroying.value)
|
|
|
+ return
|
|
|
+
|
|
|
+ try {
|
|
|
+ destroying.value = true
|
|
|
+
|
|
|
+ // NOTE: Do NOT send extra params for now (only frontend display).
|
|
|
+ await userApi.destroy()
|
|
|
+
|
|
|
+ showToast(t('mine.cancellation.toast.success'))
|
|
|
+ logout()
|
|
|
+ router.replace('/')
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ console.error('Failed to destroy account:', error)
|
|
|
+ showToast(t('mine.cancellation.toast.failed'))
|
|
|
+ }
|
|
|
+ finally {
|
|
|
+ destroying.value = false
|
|
|
+ }
|
|
|
}
|
|
|
</script>
|
|
|
|