SettingsPage.vue 6.34 KB
<!--
 * @Date: 2025-03-24 13:04:21
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2025-12-04 10:32:03
 * @FilePath: /mlaj/src/views/profile/SettingsPage.vue
 * @Description: 用户设置页面
-->
<template>
  <AppLayout>
    <div class="bg-gradient-to-br from-green-50 via-green-100/30 to-blue-50/30 min-h-screen">
      <div class="px-4 py-6">
        <FrostedGlass class="rounded-xl overflow-hidden">
          <!-- 设置列表 -->
          <div class="divide-y divide-gray-100">
            <!-- 头像设置 -->
            <div class="p-4" @click="router.push('/profile/settings/avatar')">
              <div class="flex items-center justify-between">
                <div class="flex items-center">
                  <!-- <div class="relative">
                    <img
                      :src="userAvatar || '/src/assets/images/avatar1.jpg'"
                      alt="用户头像"
                      class="w-16 h-16 rounded-full object-cover"
                    />
                  </div> -->
                  <div class="ml-4">
                    <h3 class="text-base font-medium text-gray-900">修改头像</h3>
                    <p class="text-sm text-gray-500">支持 jpg、png 格式,大小不超过 2MB</p>
                  </div>
                </div>
                <ChevronRightIcon class="w-5 h-5 text-gray-400" />
              </div>
            </div>

            <!-- 用户名设置 -->
            <div class="p-4" @click="router.push('/profile/settings/username')">
              <div class="flex items-center justify-between">
                <div>
                  <h3 class="text-base font-medium text-gray-900">修改用户名</h3>
                  <p class="text-sm text-gray-500">{{ username }}</p>
                </div>
                <ChevronRightIcon class="w-5 h-5 text-gray-400" />
              </div>
            </div>

            <!-- 密码设置 -->
            <!-- <div class="p-4" @click="router.push('/profile/settings/password')">
              <div class="flex items-center justify-between">
                <div>
                  <h3 class="text-base font-medium text-gray-900">修改密码</h3>
                  <p class="text-sm text-gray-500">定期修改密码更安全</p>
                </div>
                <ChevronRightIcon class="w-5 h-5 text-gray-400" />
              </div>
            </div> -->

            <!-- 视频上传 -->
            <!-- <div class="p-4" @click="router.push('/upload_video')">
              <div class="flex items-center justify-between">
                <div>
                  <h3 class="text-base font-medium text-gray-900">视频上传</h3>
                  <p class="text-sm text-gray-500">视频上传</p>
                </div>
                <ChevronRightIcon class="w-5 h-5 text-gray-400" />
              </div>
            </div> -->

            <!-- 音频播放 -->
            <!-- <div class="p-4" @click="router.push('/profile/settings/audio')">
              <div class="flex items-center justify-between">
                <div>
                  <h3 class="text-base font-medium text-gray-900">音频播放</h3>
                  <p class="text-sm text-gray-500">播放音频文件</p>
                </div>
                <ChevronRightIcon class="w-5 h-5 text-gray-400" />
              </div>
            </div> -->

            <!-- 课程学习 -->
            <!-- <div class="p-4" @click="router.push('/study')">
              <div class="flex items-center justify-between">
                <div>
                  <h3 class="text-base font-medium text-gray-900">课程学习</h3>
                  <p class="text-sm text-gray-500">课程学习</p>
                </div>
                <ChevronRightIcon class="w-5 h-5 text-gray-400" />
              </div>
            </div> -->

            <!-- 修改手机号 -->
            <div class="p-4" @click="router.push('/profile/settings/phone')">
              <div class="flex items-center justify-between">
                <div>
                  <h3 class="text-base font-medium text-gray-900">修改手机号</h3>
                  <p class="text-sm text-gray-500">{{ phone }}</p>
                </div>
                <ChevronRightIcon class="w-5 h-5 text-gray-400" />
              </div>
            </div>

            <!-- 退出登录 -->
            <div class="p-4" @click="handleLogout">
              <div class="flex items-center justify-between">
                <div>
                  <h3 class="text-base font-medium text-red-500">退出登录</h3>
                  <p class="text-sm text-gray-500">退出当前账号</p>
                </div>
                <ChevronRightIcon class="w-5 h-5 text-gray-400" />
              </div>
            </div>
          </div>
        </FrostedGlass>
      </div>
    </div>
  </AppLayout>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import AppLayout from '@/components/layout/AppLayout.vue';
import FrostedGlass from '@/components/ui/FrostedGlass.vue';
import { ChevronRightIcon } from '@heroicons/vue/24/outline';
import { useTitle } from '@vueuse/core';
import { getUserInfoAPI } from '@/api/users';
import { showConfirmDialog, showToast } from 'vant';
import { useAuth } from '@/contexts/auth';

const $route = useRoute();
const router = useRouter();
const { logout } = useAuth();
useTitle($route.meta.title);

// 用户头像
const userAvatar = ref('');

// 用户名
const username = ref('');

// 手机号
const phone = ref('');

// 退出登录
const handleLogout = () => {
  showConfirmDialog({
    title: '提示',
    message: '确定要退出登录吗?',
  })
    .then(() => {
      // 确认退出
      document.cookie = 'PHPSESSID=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
      document.cookie = 'currentUser=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
      logout(); // Clear any other auth state if present
      showToast('已退出登录');
      router.replace('/');
    })
    .catch(() => {
      // 取消退出
    });
};

// 获取用户信息
onMounted(async () => {
  try {
    const response = await getUserInfoAPI();
    if (response.data) {
      userAvatar.value = response.data.user.avatar;
      username.value = response.data.user.name;
      phone.value = response.data.user.mobile;
    }
  } catch (error) {
    console.error('获取用户信息失败:', error);
  }
});
</script>