|
|
@@ -51,15 +51,14 @@ import { useRouter } from 'vue-router'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
import { logoutLogic } from '@/utils/loginUtils.js'
|
|
|
import { homeRoutes } from "@/router/index.js"
|
|
|
+// 用户信息接口
|
|
|
+import { getUserInfo } from '@/api/user/user.js'
|
|
|
|
|
|
// 激活码响应式变量
|
|
|
const activationCode = ref('')
|
|
|
|
|
|
// 课程列表响应式变量
|
|
|
-const courses = ref([
|
|
|
- { name: 'AI编程课', expireDate: '2026.02.21到期' },
|
|
|
- { name: 'AI实验课', expireDate: '2026.05.12到期' }
|
|
|
-])
|
|
|
+const courses = ref([])
|
|
|
|
|
|
// 用户名响应式变量
|
|
|
const userName = ref(import.meta.env.VITE_APP_DEFAULT_LOGIN_USERNAME)
|
|
|
@@ -69,6 +68,40 @@ const updateUserName = () => {
|
|
|
userName.value = localStorage.getItem('userName') || import.meta.env.VITE_APP_DEFAULT_LOGIN_USERNAME
|
|
|
}
|
|
|
|
|
|
+// 获取用户信息
|
|
|
+const fetchUserInfo = async () => {
|
|
|
+ try {
|
|
|
+ const userId = localStorage.getItem('userId');
|
|
|
+ // 检查userId是否存在
|
|
|
+ if (!userId) {
|
|
|
+ console.warn('用户未登录,无法获取用户信息');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const res = await getUserInfo(userId);
|
|
|
+ console.log('用户信息:', res);
|
|
|
+ if (res.code === 0 && res.data) {
|
|
|
+ // 更新用户名
|
|
|
+ userName.value = res.data.username;
|
|
|
+ localStorage.setItem('userName', res.data.username);
|
|
|
+ // 更新课程信息
|
|
|
+ courses.value = [
|
|
|
+ { name: '课程权限', expireDate: res.data.courseExpireTime || '无权限' },
|
|
|
+ { name: 'AI编程课', expireDate: res.data.blocklyExpireTime || '无权限' },
|
|
|
+ { name: 'AI实验课', expireDate: res.data.aiCourseExpireTime || '无权限' }
|
|
|
+ ];
|
|
|
+ // 将课程权限信息存储在localStorage中,以便其他组件使用
|
|
|
+ const coursePermissions = {
|
|
|
+ '课程权限': res.data.courseExpireTime || '无权限',
|
|
|
+ 'AI编程课': res.data.blocklyExpireTime || '无权限',
|
|
|
+ 'AI实验课': res.data.aiCourseExpireTime || '无权限'
|
|
|
+ };
|
|
|
+ localStorage.setItem('coursePermissions', JSON.stringify(coursePermissions));
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('获取用户信息失败:', error);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// 获取当前路由对象
|
|
|
const router = useRouter()
|
|
|
// 退出登录
|
|
|
@@ -90,6 +123,8 @@ const handleActivation = () => {
|
|
|
onMounted(() => {
|
|
|
// 初始化用户名
|
|
|
updateUserName()
|
|
|
+ // 获取用户信息
|
|
|
+ fetchUserInfo()
|
|
|
// storage事件监听器,监听其他标签页对localStorage的修改
|
|
|
window.addEventListener('storage', (e) => {
|
|
|
if (e.key === 'userName') {
|
|
|
@@ -97,6 +132,11 @@ onMounted(() => {
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="scss">
|