<template>
  <view class="mine-page">
    <view class="card">

      <uv-button type="error" :plain="true" @click="onLogout" :loading="loading">
        退出登录
      </uv-button>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'
import { useUserStore } from '@/store/user'
import { logout } from '@/api/user'

const loading = ref(false)
const userStore = useUserStore()

const onLogout = async () => {
  if (loading.value) return
  loading.value = true
  try {
    await logout()
  } catch (e) {
    // 忽略错误
  } finally {
    userStore.logout()
    uni.$uv.toast('已退出登录')
    setTimeout(() => {
      uni.reLaunch({ url: '/pages/login/index' })
    }, 200)
    loading.value = false
  }
}
</script>

<style lang="scss" scoped>
.mine-page {

  background-color: #f6f7fb;

  box-sizing: border-box;
}

.card {
  background: #ffffff;
  border-radius: 16rpx;
  padding: 32rpx;
  box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.04);
}

.title {
  font-size: 30rpx;
  font-weight: 600;
  margin-bottom: 24rpx;
  color: #111827;
}
</style>



