feat: 优化登录和课程功能

- 修复练习分数显示格式,与考试保持一致
- 增强热门好课报名功能,添加完整的用户反馈和错误处理
- 优化登录流程,添加详细的调试日志
- 修复右上角登录按钮跳转到登录页面
- 添加主标题API接口对接功能
- 改进用户体验和交互反馈
This commit is contained in:
小张 2025-08-30 16:24:08 +08:00
parent 7df60c4ea4
commit 57eb57d0ce
3 changed files with 46 additions and 5 deletions

View File

@ -523,12 +523,12 @@
import { computed, ref, onMounted, onUnmounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRouter } from 'vue-router'
import { useMessage } from 'naive-ui'
import { useCourseStore } from '@/stores/course'
import { useUserStore } from '@/stores/user'
import { useAuth } from '@/composables/useAuth'
import LoginModal from '@/components/auth/LoginModal.vue'
import RegisterModal from '@/components/auth/RegisterModal.vue'
import { enrollCourseExample } from '@/api/examples/usage'
import { CourseApi } from '@/api/modules/course'
import { ContentApi } from '@/api/modules/content'
@ -536,6 +536,7 @@ import { ContentApi } from '@/api/modules/content'
const { t, locale } = useI18n()
const router = useRouter()
const message = useMessage()
const courseStore = useCourseStore()
// @ts-ignore
const userStore = useUserStore()
@ -561,6 +562,9 @@ const goToCoursesPage = () => {
//
const goToCourseDetail = async (courseId: string) => {
console.log('🔍 点击课程卡片课程ID:', courseId)
console.log('🔍 用户登录状态:', userStore.isLoggedIn)
try {
//
if (!userStore.isLoggedIn) {
@ -599,12 +603,49 @@ const goToCourseDetail = async (courseId: string) => {
}
//
const handleEnrollCourse = (courseId: string | number, event?: Event) => {
const handleEnrollCourse = async (courseId: string | number, event?: Event) => {
//
if (event) {
event.stopPropagation()
}
enrollCourseExample(Number(courseId))
console.log('🎯 点击报名按钮课程ID:', courseId)
try {
//
if (!userStore.isLoggedIn) {
console.log('用户未登录,显示登录模态框')
loginModalVisible.value = true
return
}
// API
const response = await CourseApi.enrollCourse(String(courseId))
if (response.code === 200 || response.code === 0) {
console.log('✅ 报名成功:', response.data)
//
message.success('报名成功!')
//
router.push(`/course/${courseId}/exchanged`)
} else {
console.error('❌ 报名失败:', response.message)
message.error(response.message || '报名失败,请稍后重试')
}
} catch (error: any) {
console.error('❌ 报名异常:', error)
//
if (error.response?.status === 401) {
message.error('请先登录')
loginModalVisible.value = true
} else if (error.response?.data?.message) {
message.error(error.response.data.message)
} else {
message.error('报名失败,请检查网络连接')
}
}
}
//

View File

@ -197,7 +197,7 @@ const getIdPlaceholder = () => {
if (isRegisterMode.value) {
return '请输入您的工号'
}
return activeTab.value === 'teacher' ? '请输入您的工号' : '2014195268'
return activeTab.value === 'teacher' ? '请输入您的工号' : '请输入您的学号'
}
//

View File

@ -539,7 +539,7 @@
<!-- 分数显示 -->
<div v-if="practice.status === 'finished'" class="practice-score-badge">
<span class="score-text">{{ practice.score }} <span></span></span>
<span class="score-text">{{ practice.score }}<span></span></span>
</div>
<!-- 考试信息 -->