fix:修复课程删除报错,修复课程编辑字段保存回显问题
This commit is contained in:
parent
568d8fdf47
commit
bff716f6b6
@ -193,9 +193,7 @@ export class TeachCourseApi {
|
|||||||
try {
|
try {
|
||||||
console.log('🚀 发送删除课程请求:', { url: '/aiol/aiolCourse/delete', id })
|
console.log('🚀 发送删除课程请求:', { url: '/aiol/aiolCourse/delete', id })
|
||||||
|
|
||||||
const response = await ApiRequest.delete<any>('/aiol/aiolCourse/delete', {
|
const response = await ApiRequest.delete<any>(`/aiol/aiolCourse/delete?id=${id}`, )
|
||||||
params: { id }
|
|
||||||
})
|
|
||||||
|
|
||||||
console.log('🗑️ 删除课程响应:', response)
|
console.log('🗑️ 删除课程响应:', response)
|
||||||
return response
|
return response
|
||||||
|
@ -27,11 +27,7 @@
|
|||||||
|
|
||||||
<!-- 错误状态 -->
|
<!-- 错误状态 -->
|
||||||
<div v-else-if="error" class="error-container">
|
<div v-else-if="error" class="error-container">
|
||||||
<n-result
|
<n-result status="error" title="加载失败" :description="error">
|
||||||
status="error"
|
|
||||||
title="加载失败"
|
|
||||||
:description="error"
|
|
||||||
>
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<n-space justify="center">
|
<n-space justify="center">
|
||||||
<n-button type="primary" @click="getCourseList(true)">
|
<n-button type="primary" @click="getCourseList(true)">
|
||||||
@ -49,10 +45,7 @@
|
|||||||
|
|
||||||
<!-- 空状态 -->
|
<!-- 空状态 -->
|
||||||
<div v-else-if="courseList.length === 0" class="empty-container">
|
<div v-else-if="courseList.length === 0" class="empty-container">
|
||||||
<n-empty
|
<n-empty description="暂无课程数据" size="large">
|
||||||
description="暂无课程数据"
|
|
||||||
size="large"
|
|
||||||
>
|
|
||||||
<template #extra>
|
<template #extra>
|
||||||
<n-button type="primary" @click="navigateToCreateCourse">
|
<n-button type="primary" @click="navigateToCreateCourse">
|
||||||
创建课程
|
创建课程
|
||||||
@ -67,13 +60,8 @@
|
|||||||
<div class="course-image-container">
|
<div class="course-image-container">
|
||||||
<div class="section-title" :class="{ 'offline': course.status === 0 }">{{ course.statusText }}
|
<div class="section-title" :class="{ 'offline': course.status === 0 }">{{ course.statusText }}
|
||||||
</div>
|
</div>
|
||||||
<n-popselect
|
<n-popselect :options="getOptionsForCourse(course)" trigger="hover" placement="bottom-end"
|
||||||
:options="getOptionsForCourse(course)"
|
:render-label="renderOptionLabel" @update:value="(value: string) => handleOptionSelect(value, course)">
|
||||||
trigger="hover"
|
|
||||||
placement="bottom-end"
|
|
||||||
:render-label="renderOptionLabel"
|
|
||||||
@update:value="(value: string) => handleOptionSelect(value, course)"
|
|
||||||
>
|
|
||||||
<div class="more-options">
|
<div class="more-options">
|
||||||
<span class="more-icon">
|
<span class="more-icon">
|
||||||
<n-icon size="20">
|
<n-icon size="20">
|
||||||
@ -117,8 +105,17 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, h, onMounted, watch } from 'vue';
|
import { ref, h, onMounted, watch } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { EllipsisVerticalSharp, Refresh } from '@vicons/ionicons5';
|
import {
|
||||||
import { useMessage, useDialog } from 'naive-ui';
|
EllipsisVerticalSharp,
|
||||||
|
Refresh,
|
||||||
|
CloudOfflineOutline, // 下架
|
||||||
|
CreateOutline, // 编辑
|
||||||
|
CopyOutline, // 复制
|
||||||
|
TrashOutline, // 删除
|
||||||
|
CloudUploadOutline, // 发布
|
||||||
|
AddOutline // 加号/添加
|
||||||
|
} from '@vicons/ionicons5';
|
||||||
|
import { useMessage, useDialog, NIcon } from 'naive-ui';
|
||||||
import TeachCourseApi, { type TeachCourse } from '@/api/modules/teachCourse';
|
import TeachCourseApi, { type TeachCourse } from '@/api/modules/teachCourse';
|
||||||
import { useCourseStore } from '@/stores/course';
|
import { useCourseStore } from '@/stores/course';
|
||||||
|
|
||||||
@ -265,21 +262,24 @@ const handleSearch = async () => {
|
|||||||
const getOptionsForCourse = (course: CourseDisplayItem) => {
|
const getOptionsForCourse = (course: CourseDisplayItem) => {
|
||||||
if (course.status === 1) { // 进行中
|
if (course.status === 1) { // 进行中
|
||||||
return [
|
return [
|
||||||
{ label: '下架', value: 'offline', icon: '/images/teacher/下架.png' },
|
{ label: '下架', value: 'offline', icon: CloudOfflineOutline },
|
||||||
{ label: '编辑', value: 'edit', icon: '/images/teacher/小编辑.png' },
|
{ label: '编辑', value: 'edit', icon: CreateOutline },
|
||||||
{ label: '删除', value: 'delete', icon: '/images/teacher/删除.png' }
|
{ label: '复制', value: 'copy', icon: CopyOutline },
|
||||||
|
{ label: '删除', value: 'delete', icon: TrashOutline }
|
||||||
];
|
];
|
||||||
} else if (course.status === 0) { // 未开始/草稿
|
} else if (course.status === 0) { // 未开始/草稿
|
||||||
return [
|
return [
|
||||||
{ label: '发布', value: 'publish', icon: '/images/teacher/加号.png' },
|
{ label: '发布', value: 'publish', icon: CloudUploadOutline },
|
||||||
{ label: '编辑', value: 'edit', icon: '/images/teacher/小编辑.png' },
|
{ label: '编辑', value: 'edit', icon: CreateOutline },
|
||||||
{ label: '删除', value: 'delete', icon: '/images/teacher/删除.png' }
|
{ label: '复制', value: 'copy', icon: CopyOutline },
|
||||||
|
{ label: '删除', value: 'delete', icon: TrashOutline }
|
||||||
];
|
];
|
||||||
} else if (course.status === 2) { // 已结束
|
} else if (course.status === 2) { // 已结束
|
||||||
return [
|
return [
|
||||||
{ label: '发布', value: 'publish', icon: '/images/teacher/加号.png' },
|
{ label: '发布', value: 'publish', icon: CloudUploadOutline },
|
||||||
{ label: '编辑', value: 'edit', icon: '/images/teacher/小编辑.png' },
|
{ label: '编辑', value: 'edit', icon: CreateOutline },
|
||||||
{ label: '删除', value: 'delete', icon: '/images/teacher/删除.png' }
|
{ label: '复制', value: 'copy', icon: CopyOutline },
|
||||||
|
{ label: '删除', value: 'delete', icon: TrashOutline }
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
@ -294,13 +294,9 @@ const renderOptionLabel = (option: any) => {
|
|||||||
gap: '6px'
|
gap: '6px'
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
h('img', {
|
h(NIcon, {
|
||||||
src: option.icon,
|
size: 16,
|
||||||
alt: '',
|
component: option.icon
|
||||||
style: {
|
|
||||||
width: '13px',
|
|
||||||
height: '13px'
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
option.label
|
option.label
|
||||||
]);
|
]);
|
||||||
@ -312,12 +308,8 @@ const handleOptionSelect = (value: string, course: any) => {
|
|||||||
// 根据不同的 value 执行对应的操作
|
// 根据不同的 value 执行对应的操作
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case 'edit':
|
case 'edit':
|
||||||
// 编辑逻辑 - 将课程数据保存到store并跳转到编辑页面
|
|
||||||
console.log('✏️ 编辑课程,准备数据:', course);
|
|
||||||
|
|
||||||
// 保存到store
|
// 保存到store
|
||||||
courseStore.setCourseEditData(course);
|
courseStore.setCourseEditData(course);
|
||||||
|
|
||||||
// 跳转到课程编辑页面,只传递课程ID
|
// 跳转到课程编辑页面,只传递课程ID
|
||||||
router.push(`/teacher/course-create/${course.id}`);
|
router.push(`/teacher/course-create/${course.id}`);
|
||||||
break;
|
break;
|
||||||
@ -333,6 +325,12 @@ const handleOptionSelect = (value: string, course: any) => {
|
|||||||
// 发布逻辑
|
// 发布逻辑
|
||||||
handlePublishCourse(course);
|
handlePublishCourse(course);
|
||||||
break;
|
break;
|
||||||
|
case 'copy':
|
||||||
|
// 复制逻辑
|
||||||
|
courseStore.setCourseEditData(course);
|
||||||
|
// 跳转到课程编辑页面,只传递课程ID
|
||||||
|
router.push(`/teacher/course-create/${course.id}?type=copy`);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -476,9 +474,9 @@ onMounted(async () => {
|
|||||||
/* 防止水平滚动 */
|
/* 防止水平滚动 */
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.top {
|
.top {
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
/* 进一步减少左右padding */
|
/* 进一步减少左右padding */
|
||||||
@ -489,58 +487,58 @@ onMounted(async () => {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
/* 确保宽度充满父容器 */
|
/* 确保宽度充满父容器 */
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-links {
|
.nav-links {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.actions {
|
.actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
gap: 12px;
|
gap: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.search-container {
|
.search-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.course-container {
|
.course-container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.loading-container {
|
.loading-container {
|
||||||
display: contents;
|
display: contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
.error-container {
|
.error-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
min-height: 400px;
|
min-height: 400px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 40px 20px;
|
padding: 40px 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.empty-container {
|
.empty-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
min-height: 400px;
|
min-height: 400px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 40px 20px;
|
padding: 40px 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.course-grid {
|
.course-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(4, 1fr);
|
grid-template-columns: repeat(4, 1fr);
|
||||||
/* 默认4列,确保100%缩放下不被截断 */
|
/* 默认4列,确保100%缩放下不被截断 */
|
||||||
@ -552,9 +550,9 @@ onMounted(async () => {
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding: 0 3px;
|
padding: 0 3px;
|
||||||
/* 减少内边距 */
|
/* 减少内边距 */
|
||||||
}
|
}
|
||||||
|
|
||||||
.course-card {
|
.course-card {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: auto;
|
height: auto;
|
||||||
/* aspect-ratio: 190 / 201; */
|
/* aspect-ratio: 190 / 201; */
|
||||||
@ -564,14 +562,14 @@ onMounted(async () => {
|
|||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.course-card:hover {
|
.course-card:hover {
|
||||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||||
/* transform: translateY(-5px); */
|
/* transform: translateY(-5px); */
|
||||||
}
|
}
|
||||||
|
|
||||||
.course-image-container {
|
.course-image-container {
|
||||||
position: relative;
|
position: relative;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@ -580,9 +578,9 @@ onMounted(async () => {
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
}
|
}
|
||||||
|
|
||||||
.section-title {
|
.section-title {
|
||||||
width: 50px;
|
width: 50px;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
background: #0288D1;
|
background: #0288D1;
|
||||||
@ -593,19 +591,19 @@ onMounted(async () => {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.section-title.offline {
|
.section-title.offline {
|
||||||
background: #FF6C17;
|
background: #FF6C17;
|
||||||
}
|
}
|
||||||
|
|
||||||
.more-options {
|
.more-options {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.more-icon {
|
.more-icon {
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: #333;
|
color: #333;
|
||||||
@ -615,14 +613,14 @@ onMounted(async () => {
|
|||||||
height: 32px;
|
height: 32px;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.course-image-container img {
|
.course-image-container img {
|
||||||
width: 13px;
|
width: 13px;
|
||||||
height: 13px;
|
height: 13px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.course-info {
|
.course-info {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@ -630,9 +628,9 @@ onMounted(async () => {
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.course-info img {
|
.course-info img {
|
||||||
width: 80%;
|
width: 80%;
|
||||||
height: auto;
|
height: auto;
|
||||||
aspect-ratio: 150 / 105;
|
aspect-ratio: 150 / 105;
|
||||||
@ -643,9 +641,9 @@ onMounted(async () => {
|
|||||||
top: -5px;
|
top: -5px;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
object-position: center;
|
object-position: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.course-name {
|
.course-name {
|
||||||
width: 80%;
|
width: 80%;
|
||||||
font-family: AppleSystemUIFont;
|
font-family: AppleSystemUIFont;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
@ -664,10 +662,10 @@ onMounted(async () => {
|
|||||||
/* 文字往上移动:添加负上边距 */
|
/* 文字往上移动:添加负上边距 */
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
/* 减小底部边距从15px到10px */
|
/* 减小底部边距从15px到10px */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 分页样式 */
|
/* 分页样式 */
|
||||||
.pagination {
|
.pagination {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
position: relative;
|
position: relative;
|
||||||
@ -749,7 +747,7 @@ onMounted(async () => {
|
|||||||
border-color: #1890ff;
|
border-color: #1890ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
:deep(.n-tabs.n-tabs--top .n-tab-pane){
|
:deep(.n-tabs.n-tabs--top .n-tab-pane) {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@
|
|||||||
<div class="form-item" v-show="formData.studentType === 'partial'">
|
<div class="form-item" v-show="formData.studentType === 'partial'">
|
||||||
<label class="form-label required">选择班级:</label>
|
<label class="form-label required">选择班级:</label>
|
||||||
<n-select v-model:value="formData.selectedClasses" multiple :options="classOptions"
|
<n-select v-model:value="formData.selectedClasses" multiple :options="classOptions"
|
||||||
placeholder="选择班级(可多选)" class="form-input" />
|
placeholder="选择班级(可多选)" class="form-input" :disabled="isEditMode && !isCopyMode" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -200,9 +200,19 @@ const courseStore = useCourseStore()
|
|||||||
// 判断是否为编辑模式
|
// 判断是否为编辑模式
|
||||||
const isEditMode = computed(() => !!route.params.id)
|
const isEditMode = computed(() => !!route.params.id)
|
||||||
const courseId = computed(() => route.params.id as string)
|
const courseId = computed(() => route.params.id as string)
|
||||||
|
// 判断是否为复制模式,数据回显,但是是新增模式
|
||||||
|
const isCopyMode = computed(() => route.query.type === 'copy')
|
||||||
|
|
||||||
// 页面标题
|
// 页面标题
|
||||||
const pageTitle = computed(() => isEditMode.value ? '编辑课程' : '创建课程')
|
const pageTitle = computed(() => {
|
||||||
|
if (isCopyMode.value) {
|
||||||
|
return '复制课程'
|
||||||
|
} else if (isEditMode.value && !isCopyMode.value) {
|
||||||
|
return '编辑课程'
|
||||||
|
} else {
|
||||||
|
return '新建课程'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// 编辑器实例,必须用 shallowRef
|
// 编辑器实例,必须用 shallowRef
|
||||||
const editorRef = shallowRef()
|
const editorRef = shallowRef()
|
||||||
@ -214,6 +224,9 @@ const previewUrl = ref('')
|
|||||||
// 待设置的课程描述内容(用于富文本编辑器初始化后设置)
|
// 待设置的课程描述内容(用于富文本编辑器初始化后设置)
|
||||||
const pendingCourseDescription = ref('')
|
const pendingCourseDescription = ref('')
|
||||||
|
|
||||||
|
// 待回显的班级数据(用于班级选项加载完成后回显)
|
||||||
|
const pendingSelectedClasses = ref<string[]>([])
|
||||||
|
|
||||||
const toolbarConfig = {}
|
const toolbarConfig = {}
|
||||||
const editorConfig = { placeholder: '请输入内容...' }
|
const editorConfig = { placeholder: '请输入内容...' }
|
||||||
const mode = 'default'
|
const mode = 'default'
|
||||||
@ -326,7 +339,19 @@ const loadCourseData = async () => {
|
|||||||
formData.startTime = storeCourseData.start_time || storeCourseData.startTime || null;
|
formData.startTime = storeCourseData.start_time || storeCourseData.startTime || null;
|
||||||
formData.endTime = storeCourseData.end_time || storeCourseData.endTime || null;
|
formData.endTime = storeCourseData.end_time || storeCourseData.endTime || null;
|
||||||
formData.studentType = (storeCourseData.type === 1 || storeCourseData.studentType === 'partial') ? 'partial' : 'all';
|
formData.studentType = (storeCourseData.type === 1 || storeCourseData.studentType === 'partial') ? 'partial' : 'all';
|
||||||
formData.selectedClasses = storeCourseData.target ? storeCourseData.target.split(',') : (storeCourseData.selectedClasses || []);
|
console.log('huixian:',storeCourseData);
|
||||||
|
|
||||||
|
// 处理班级数据:如果班级选项还没加载完成,先保存到待回显变量
|
||||||
|
const classData = storeCourseData.classId ? storeCourseData.classId.split(',') : (storeCourseData.selectedClasses || []);
|
||||||
|
if (classOptions.value.length > 0) {
|
||||||
|
// 班级选项已加载,直接设置
|
||||||
|
formData.selectedClasses = classData;
|
||||||
|
console.log('直接设置班级数据:', classData);
|
||||||
|
} else {
|
||||||
|
// 班级选项未加载,保存到待回显变量
|
||||||
|
pendingSelectedClasses.value = classData;
|
||||||
|
console.log('保存班级数据到待回显变量:', classData);
|
||||||
|
}
|
||||||
|
|
||||||
const tempCourseDescription = storeCourseData.description || storeCourseData.courseDescription || '';
|
const tempCourseDescription = storeCourseData.description || storeCourseData.courseDescription || '';
|
||||||
if (tempCourseDescription) {
|
if (tempCourseDescription) {
|
||||||
@ -389,7 +414,18 @@ const loadCourseData = async () => {
|
|||||||
formData.startTime = courseData.start_time || courseData.startTime || null;
|
formData.startTime = courseData.start_time || courseData.startTime || null;
|
||||||
formData.endTime = courseData.end_time || courseData.endTime || null;
|
formData.endTime = courseData.end_time || courseData.endTime || null;
|
||||||
formData.studentType = (courseData.type === 1 || courseData.studentType === 'partial') ? 'partial' : 'all';
|
formData.studentType = (courseData.type === 1 || courseData.studentType === 'partial') ? 'partial' : 'all';
|
||||||
formData.selectedClasses = courseData.target ? courseData.target.split(',') : (courseData.selectedClasses || []);
|
|
||||||
|
// 处理班级数据:如果班级选项还没加载完成,先保存到待回显变量
|
||||||
|
const classData = courseData.target ? courseData.target.split(',') : (courseData.selectedClasses || []);
|
||||||
|
if (classOptions.value.length > 0) {
|
||||||
|
// 班级选项已加载,直接设置
|
||||||
|
formData.selectedClasses = classData;
|
||||||
|
console.log('直接设置班级数据:', classData);
|
||||||
|
} else {
|
||||||
|
// 班级选项未加载,保存到待回显变量
|
||||||
|
pendingSelectedClasses.value = classData;
|
||||||
|
console.log('保存班级数据到待回显变量:', classData);
|
||||||
|
}
|
||||||
|
|
||||||
// 处理富文本编辑器内容
|
// 处理富文本编辑器内容
|
||||||
const tempCourseDescription = courseData.description || courseData.courseDescription || '';
|
const tempCourseDescription = courseData.description || courseData.courseDescription || '';
|
||||||
@ -676,7 +712,7 @@ const handleSubmit = async () => {
|
|||||||
question: null
|
question: null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEditMode.value) {
|
if (isEditMode.value && !isCopyMode.value) {
|
||||||
// 编辑模式
|
// 编辑模式
|
||||||
const editData = {
|
const editData = {
|
||||||
id: courseId.value,
|
id: courseId.value,
|
||||||
@ -702,7 +738,7 @@ const handleSubmit = async () => {
|
|||||||
|
|
||||||
if (response.data.code === 200) {
|
if (response.data.code === 200) {
|
||||||
// 课程创建成功后,获取新创建的课程ID并绑定老师
|
// 课程创建成功后,获取新创建的课程ID并绑定老师
|
||||||
const newCourseId = response.data.data?.id || response.data.id;
|
const newCourseId = response.data.result;
|
||||||
if (newCourseId && formData.instructors.length > 0) {
|
if (newCourseId && formData.instructors.length > 0) {
|
||||||
await handleTeacherChanges(newCourseId.toString(), true);
|
await handleTeacherChanges(newCourseId.toString(), true);
|
||||||
}
|
}
|
||||||
@ -730,8 +766,9 @@ const goBack = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取课程分类
|
// 获取课程分类
|
||||||
const getCourseList = () => {
|
const getCourseList = async () => {
|
||||||
CourseApi.getCategories().then(response => {
|
try {
|
||||||
|
const response = await CourseApi.getCategories()
|
||||||
categoryOptions.value = response.data.map((category: any) => ({
|
categoryOptions.value = response.data.map((category: any) => ({
|
||||||
label: category.name,
|
label: category.name,
|
||||||
value: category.id
|
value: category.id
|
||||||
@ -740,50 +777,71 @@ const getCourseList = () => {
|
|||||||
if (formData.courseCategory.length === 0 && categoryOptions.value.length > 0) {
|
if (formData.courseCategory.length === 0 && categoryOptions.value.length > 0) {
|
||||||
formData.courseCategory = [];
|
formData.courseCategory = [];
|
||||||
}
|
}
|
||||||
}).catch(error => {
|
console.log('课程分类选项加载完成:', categoryOptions.value);
|
||||||
|
} catch (error) {
|
||||||
console.error('获取课程列表失败:', error)
|
console.error('获取课程列表失败:', error)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取老师
|
// 获取老师
|
||||||
const getTeacherList = () => {
|
const getTeacherList = async () => {
|
||||||
TeachCourseApi.getTeacherList().then(response => {
|
try {
|
||||||
|
const response = await TeachCourseApi.getTeacherList()
|
||||||
instructorOptions.value = response.data.result.map((teacher: any) => ({
|
instructorOptions.value = response.data.result.map((teacher: any) => ({
|
||||||
label: teacher.realname,
|
label: teacher.realname,
|
||||||
value: teacher.id
|
value: teacher.id
|
||||||
}))
|
}))
|
||||||
}).catch(error => {
|
console.log('老师选项加载完成:', instructorOptions.value);
|
||||||
|
} catch (error) {
|
||||||
console.error('获取老师列表失败:', error)
|
console.error('获取老师列表失败:', error)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取班级
|
// 获取班级
|
||||||
const getClassList = () => {
|
const getClassList = async () => {
|
||||||
ClassApi.queryClassList({course_id:null}).then(response => {
|
try {
|
||||||
|
const response = await ClassApi.queryClassList({ course_id: null })
|
||||||
console.log('班级列表:', response.data.result);
|
console.log('班级列表:', response.data.result);
|
||||||
|
|
||||||
|
// 清空现有的班级选项
|
||||||
|
classOptions.value = []
|
||||||
|
|
||||||
response.data.result.forEach((cls: any) => {
|
response.data.result.forEach((cls: any) => {
|
||||||
classOptions.value.push({
|
classOptions.value.push({
|
||||||
label: cls.name,
|
label: cls.name,
|
||||||
value: cls.id
|
value: cls.id
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}).catch(error => {
|
|
||||||
|
console.log('班级选项加载完成:', classOptions.value);
|
||||||
|
|
||||||
|
// 班级数据加载完成后,如果有待回显的班级数据,进行回显
|
||||||
|
if (pendingSelectedClasses.value.length > 0) {
|
||||||
|
console.log('开始回显班级数据:', pendingSelectedClasses.value);
|
||||||
|
formData.selectedClasses = [...pendingSelectedClasses.value];
|
||||||
|
pendingSelectedClasses.value = []; // 清空待回显数据
|
||||||
|
console.log('班级回显完成:', formData.selectedClasses);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
console.error('获取班级列表失败:', error)
|
console.error('获取班级列表失败:', error)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
// 如果是编辑模式(有courseId)、有通过路由传递的课程数据,或者store中有数据
|
// 先加载基础数据(课程分类、老师、班级)
|
||||||
|
await Promise.all([
|
||||||
|
getCourseList(),
|
||||||
|
getTeacherList(),
|
||||||
|
getClassList() // 确保班级数据先加载完成
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 基础数据加载完成后,再加载课程数据进行回显
|
||||||
if (isEditMode.value && courseId.value) {
|
if (isEditMode.value && courseId.value) {
|
||||||
loadCourseData()
|
await loadCourseData()
|
||||||
} else if (route.query.courseData || courseStore.courseEditData) {
|
} else if (route.query.courseData || courseStore.courseEditData) {
|
||||||
// 即使没有ID,也尝试从路由数据或store加载(用于从列表页面直接编辑的情况)
|
// 即使没有ID,也尝试从路由数据或store加载(用于从列表页面直接编辑的情况)
|
||||||
loadCourseData()
|
await loadCourseData()
|
||||||
}
|
}
|
||||||
getCourseList()
|
|
||||||
getTeacherList()
|
|
||||||
getClassList()
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -151,6 +151,14 @@ const activeSubNavItem = ref(''); // 子菜单激活状态
|
|||||||
const examMenuExpanded = ref(false); // 考试管理菜单展开状态
|
const examMenuExpanded = ref(false); // 考试管理菜单展开状态
|
||||||
const studentMenuExpanded = ref(false); // 学员中心菜单展开状态
|
const studentMenuExpanded = ref(false); // 学员中心菜单展开状态
|
||||||
const showTopImage = ref(true); // 控制顶部图片显示/隐藏
|
const showTopImage = ref(true); // 控制顶部图片显示/隐藏
|
||||||
|
|
||||||
|
// 需要隐藏顶部图片的路由路径数组
|
||||||
|
const hideTopImageRoutes = [
|
||||||
|
'teacher/chapter-editor-teacher',
|
||||||
|
'teacher/course-editor'
|
||||||
|
// 可以在这里添加更多需要隐藏顶部图片的路由
|
||||||
|
];
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const isAiHovered = ref(false);
|
const isAiHovered = ref(false);
|
||||||
@ -654,13 +662,29 @@ onMounted(() => {
|
|||||||
} else {
|
} else {
|
||||||
document.documentElement.style.setProperty('--top-height', '0px');
|
document.documentElement.style.setProperty('--top-height', '0px');
|
||||||
}
|
}
|
||||||
|
updateTopImageVisibility();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 使用watch监听路由变化
|
// 使用watch监听路由变化
|
||||||
watch(route, () => {
|
watch(route, () => {
|
||||||
updateActiveNavItem();
|
updateActiveNavItem();
|
||||||
|
updateTopImageVisibility();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 更新顶部图片显示状态
|
||||||
|
const updateTopImageVisibility = () => {
|
||||||
|
const currentPath = route.path;
|
||||||
|
console.log('检查路径是否需要隐藏顶部图片:', currentPath);
|
||||||
|
|
||||||
|
// 检查当前路径是否包含需要隐藏顶部图片的路由
|
||||||
|
const shouldHideTopImage = hideTopImageRoutes.some(routePath =>
|
||||||
|
currentPath.includes(routePath)
|
||||||
|
);
|
||||||
|
|
||||||
|
showTopImage.value = !shouldHideTopImage;
|
||||||
|
console.log('顶部图片显示状态:', showTopImage.value);
|
||||||
|
};
|
||||||
|
|
||||||
// 更新激活的导航项
|
// 更新激活的导航项
|
||||||
const updateActiveNavItem = () => {
|
const updateActiveNavItem = () => {
|
||||||
const path = route.path;
|
const path = route.path;
|
||||||
@ -704,7 +728,7 @@ const updateActiveNavItem = () => {
|
|||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.admin-dashboard {
|
.admin-dashboard {
|
||||||
min-height: 100vh;
|
/* min-height: 100vh; */
|
||||||
}
|
}
|
||||||
|
|
||||||
.top-image-container {
|
.top-image-container {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user