|
|
@@ -52,10 +52,10 @@
|
|
|
import { ref, onMounted } from 'vue'
|
|
|
import { useRouter } from 'vue-router'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
-import { logoutLogic } from '@/utils/loginUtils.js'
|
|
|
+import {logoutLogic} from '@/utils/loginUtils.js'
|
|
|
import { homeRoutes } from "@/router/index.js"
|
|
|
// 用户信息接口
|
|
|
-import { getUserInfo } from '@/api/user/user.js'
|
|
|
+import {activateInviteCode, getUserInfo} from '@/api/user/user.js'
|
|
|
// 图标
|
|
|
import { ArrowUpBold, ArrowDownBold } from '@element-plus/icons-vue'
|
|
|
|
|
|
@@ -66,14 +66,22 @@ const activationCode = ref('')
|
|
|
const courses = ref([])
|
|
|
|
|
|
// 用户名响应式变量
|
|
|
-const userName = ref(import.meta.env.VITE_APP_DEFAULT_LOGIN_USERNAME)
|
|
|
+const userName = ref()
|
|
|
+const userInfo = ref({
|
|
|
+ userId: null,
|
|
|
+ userName: import.meta.env.VITE_APP_DEFAULT_LOGIN_USERNAME,
|
|
|
+ nickname: '',
|
|
|
+ courseExpireTime: '',
|
|
|
+ blocklyExpireTime: '',
|
|
|
+ aiCourseExpireTime: ''
|
|
|
+})
|
|
|
|
|
|
// 下拉框可见性状态
|
|
|
const dropdownVisible = ref(false)
|
|
|
|
|
|
// 更新用户名
|
|
|
const updateUserName = () => {
|
|
|
- userName.value = localStorage.getItem('userName') || import.meta.env.VITE_APP_DEFAULT_LOGIN_USERNAME
|
|
|
+ userInfo.value.userName = localStorage.getItem('userName') || import.meta.env.VITE_APP_DEFAULT_LOGIN_USERNAME
|
|
|
}
|
|
|
|
|
|
// 处理下拉框显示/隐藏事件
|
|
|
@@ -105,7 +113,7 @@ const fetchUserInfo = async () => {
|
|
|
// 将课程权限信息存储在localStorage中,以便其他组件使用
|
|
|
const coursePermissions = {
|
|
|
'课程权限': res.data.courseExpireTime || '无权限',
|
|
|
- 'AI编程课': res.data.blocklyExpireTime || '无权限',
|
|
|
+ '编程课': res.data.blocklyExpireTime || '无权限',
|
|
|
'AI实验课': res.data.aiCourseExpireTime || '无权限'
|
|
|
};
|
|
|
localStorage.setItem('coursePermissions', JSON.stringify(coursePermissions));
|
|
|
@@ -115,6 +123,21 @@ const fetchUserInfo = async () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//激活邀请码
|
|
|
+const activeInviteCode = async (inviteCode) => {
|
|
|
+ // 调用activeInviteCode API 激活邀请码
|
|
|
+ const activeRes = await activateInviteCode(inviteCode)
|
|
|
+
|
|
|
+ // 检查是否激活成功
|
|
|
+ if (activeRes && activeRes.code === 0) {
|
|
|
+ ElMessage.success('邀请码激活成功')
|
|
|
+ // 获取用户web权限角色
|
|
|
+ await fetchUserInfo();
|
|
|
+ } else {
|
|
|
+ ElMessage.error(activeRes?.message || '邀请码激活失败')
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// 获取当前路由对象
|
|
|
const router = useRouter()
|
|
|
// 退出登录
|
|
|
@@ -128,8 +151,9 @@ const handleActivation = () => {
|
|
|
ElMessage.warning('请输入激活码')
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
// 这里可以添加激活码验证逻辑
|
|
|
- ElMessage.success('激活码:' + activationCode.value + ' 提交成功')
|
|
|
+ activeInviteCode(activationCode.value)
|
|
|
activationCode.value = ''
|
|
|
}
|
|
|
|