<script setup lang="ts">
let pageTitle: any = ref("HOTKING-个人中心-设置");
useHead(() => ({
  title: pageTitle.value,
}));
import { showConfirmDialog } from "vant";
import { useAll } from "~/api/pubAll/service";
const { userLogout } = useAll();
const user = useUserStore();
const route = useRoute();
const router = useRouter();
let loading = ref(false);
user.value.adminTitle = "设置";
onMounted(() => {});
function logoutConfirm() {
  showConfirmDialog({
    title: "提示",
    message: "确定退出登录吗？",
    beforeClose: async (action: string) => {
      if (action === "confirm") {
        await logout();
      }
      return true; // 告诉 Dialog：可以关闭
    },
  }).catch(() => {});
}

const tokenKey: any = useCookie("tokenKey");
async function logout() {
  const res: any = await userLogout();
  if (res.httpCode == 200) {
    ElMessage.success("退出成功");
    user.value.isLogin = false;
    tokenKey.value = "";
    setTimeout(() => {
      navigateTo("/");
    }, 0);
  }
}
</script>
<template>
  <div class="admin-boxs-bg">
    <div class="admin-wrap">
      <van-cell-group>
        <van-cell title="账户信息" value="修改" is-link to="/home/user/info" />
        <van-cell title="登录密码" value="修改" is-link to="/home/user/edit-ps" />
      </van-cell-group>
      <div class="userLogout" @click="logoutConfirm">
        退出
      </div>
    </div>
  </div>
</template>
<style scoped lang="scss">
.admin-wrap {
  padding: 12px 0px 72px;
  background: #f7f7f7;
  color: #333;
  .userLogout {
    width: 100%;
    margin: 12px auto;
    background: #fff;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #323233;
    font-size: 14px;
  }
}
</style> 
