教师端功能

This commit is contained in:
Admin 2025-08-20 22:50:28 +08:00
parent fea00e8c1a
commit 9889b6c57d

View File

@ -90,7 +90,7 @@
<div class="course-meta"> <div class="course-meta">
<span class="course-students">{{ course.studentsCount }}{{ t('home.popularCourses.studentsEnrolled') <span class="course-students">{{ course.studentsCount }}{{ t('home.popularCourses.studentsEnrolled')
}}</span> }}</span>
<button class="enroll-btn" @click="handleEnrollCourse(course.id)">{{ t('home.popularCourses.enroll') <button class="enroll-btn" @click.stop="handleEnrollCourse(course.id, $event)">{{ t('home.popularCourses.enroll')
}}</button> }}</button>
</div> </div>
</div> </div>
@ -520,23 +520,90 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, computed, ref } from 'vue' import { computed, ref, onMounted } from 'vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { useCourseStore } from '@/stores/course' import { useCourseStore } from '@/stores/course'
import { useUserStore } from '@/stores/user' import { useUserStore } from '@/stores/user'
import { useAuth } from '@/composables/useAuth' import { useAuth } from '@/composables/useAuth'
import { CourseApi } from '@/api'
import LoginModal from '@/components/auth/LoginModal.vue' import LoginModal from '@/components/auth/LoginModal.vue'
import RegisterModal from '@/components/auth/RegisterModal.vue' import RegisterModal from '@/components/auth/RegisterModal.vue'
import { enrollCourseExample } from '@/api/examples/usage'
import { CourseApi } from '@/api/modules/course'
// import { getPopularCourses } from '@/data/mockCourses' // import { getPopularCourses } from '@/data/mockCourses'
const { t, locale } = useI18n() const { t, locale } = useI18n()
const router = useRouter() const router = useRouter()
const courseStore = useCourseStore() const courseStore = useCourseStore()
// @ts-ignore
const userStore = useUserStore() const userStore = useUserStore()
const { loginModalVisible, registerModalVisible, handleAuthSuccess } = useAuth() const { loginModalVisible, registerModalVisible, handleAuthSuccess } = useAuth()
//
const goToCourseDetail = async (courseId: string) => {
try {
//
if (!userStore.isLoggedIn) {
console.log('用户未登录,跳转到课程详情页')
router.push(`/course/${courseId}`)
return
}
console.log('检查课程报名状态课程ID:', courseId)
//
const response = await CourseApi.checkEnrollmentStatus(String(courseId))
if ((response.code === 0 || response.code === 200) && response.data) {
const isEnrolled = response.data.result
if (isEnrolled) {
//
console.log('用户已报名,跳转到已报名页面')
router.push(`/course/${courseId}/enrolled`)
} else {
//
console.log('用户未报名,跳转到课程详情页')
router.push(`/course/${courseId}`)
}
} else {
//
console.warn('查询报名状态失败,跳转到课程详情页')
router.push(`/course/${courseId}`)
}
} catch (error) {
console.error('检查报名状态时发生错误:', error)
//
router.push(`/course/${courseId}`)
}
}
//
const handleEnrollCourse = (courseId: string | number, event?: Event) => {
//
if (event) {
event.stopPropagation()
}
enrollCourseExample(Number(courseId))
}
//
const showIssueModal = () => {
//
router.push('/help-center').then(() => {
window.location.reload();
})
}
//
const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
})
}
// 广 // 广
const showAdvertisement = ref(true) const showAdvertisement = ref(true)
@ -655,7 +722,8 @@ const aiCards = computed(() => [
]) ])
// //
const partners = computed(() => [ // 使
/* const partners = computed(() => [
{ {
id: 1, id: 1,
name: '云南师范大学', name: '云南师范大学',
@ -686,7 +754,7 @@ const partners = computed(() => [
name: '德宏师范学院', name: '德宏师范学院',
logo: '/logo/德宏师范.jpg' logo: '/logo/德宏师范.jpg'
} }
]) ]) */
// //
// const featuredReviews = computed(() => [ // const featuredReviews = computed(() => [
@ -720,65 +788,7 @@ const partners = computed(() => [
// } // }
// ]) // ])
// //
const goToCourseDetail = async (courseId: string) => {
try {
//
if (!userStore.isLoggedIn) {
console.log('用户未登录,跳转到课程详情页')
router.push(`/course/${courseId}`)
return
}
console.log('检查课程报名状态课程ID:', courseId)
//
const response = await CourseApi.checkEnrollmentStatus(String(courseId))
if ((response.code === 0 || response.code === 200) && response.data) {
const isEnrolled = response.data.result
if (isEnrolled) {
//
console.log('用户已报名,跳转到已报名页面')
router.push(`/course/${courseId}/enrolled`)
} else {
//
console.log('用户未报名,跳转到课程详情页')
router.push(`/course/${courseId}`)
}
} else {
//
console.warn('查询报名状态失败,跳转到课程详情页')
router.push(`/course/${courseId}`)
}
} catch (error) {
console.error('检查报名状态时发生错误:', error)
//
router.push(`/course/${courseId}`)
}
}
// -
const handleEnrollCourse = (courseId: string) => {
//
router.push(`/course/${courseId}`)
}
//
const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
})
}
const showIssueModal = () => {
//
router.push('/help-center').then(() => {
window.location.reload();
})
}
onMounted(async () => { onMounted(async () => {
await courseStore.fetchCourses() await courseStore.fetchCourses()