import { defineComponent, nextTick, onMounted, reactive, ref, watch } from 'vue'; import styles from './index.module.less'; import { NButton, NTooltip, NCarousel, NIcon, NImage, NInput, NModal, NScrollbar, NSelect, NSpace, NSpin, NTabPane, NTabs, useMessage } from 'naive-ui'; import { usePrepareStore } from '/src/store/modules/prepareLessons'; import add from '@/views/studentList/images/add.png'; import iconSlideRight from '../../../images/icon-slide-right.png'; import CoursewareType from '../../../model/courseware-type'; import TheEmpty from '/src/components/TheEmpty'; import RelatedClass from '../../../model/related-class'; import { state } from '/src/state'; import { useResizeObserver } from '@vueuse/core'; import AttendClass from '/src/views/prepare-lessons/model/attend-class'; import { api_addByOpenCourseware, api_teacherChapterLessonCoursewareRemove, api_queryOpenCoursewareByPage, api_updateCoursewareInfo, teacherChapterLessonCoursewareList, courseScheduleStart } from '../../../api'; import { useRoute, useRouter } from 'vue-router'; import TheMessageDialog from '/src/components/TheMessageDialog'; import { eventGlobal, fscreen } from '/src/utils'; import PreviewWindow from '/src/views/preview-window'; import Related from './related'; import Train from '../train'; import ResourceMain from '../../resource-main'; export default defineComponent({ name: 'courseware-presets', props: { addParam: { type: Object, default: () => ({}) } }, emits: ['change'], setup(props, { emit }) { const prepareStore = usePrepareStore(); const message = useMessage(); const route = useRoute(); const router = useRouter(); const localStorageSubjectId = localStorage.getItem( 'prepareLessonSubjectId' ); const forms = reactive({ // 选取参数带的,后取缓存 leftWidth: '100%', rightWidth: '0', messageLoading: false, subjectId: route.query.subjectId ? Number(route.query.subjectId) : localStorageSubjectId ? Number(localStorageSubjectId) : '', courseScheduleSubjectId: route.query.courseScheduleSubjectId, classGroupId: route.query.classGroupId, preStudentNum: route.query.preStudentNum, bodyWidth: '100%', loading: false, openLoading: false, showRelatedClass: false, tableList: [] as any, openTableShow: true, // 是否显示 openTableList: [] as any, selectItem: {} as any, editTitleVisiable: false, editTitle: null, editBtnLoading: false, preRemoveVisiable: false, addVisiable: false, // 是否有添加的课件 carouselIndex: 0, showAttendClass: false, attendClassType: 'change', // attendClassItem: {} as any, previewModal: false, previewParams: { type: '', courseId: '', subjectId: '', detailId: '' } as any, workVisiable: false }); const getCoursewareList = async () => { forms.loading = true; try { // 判断是否有选择对应的课件 或声部 if (!prepareStore.getSelectKey) return (forms.loading = false); const { data } = await teacherChapterLessonCoursewareList({ subjectId: prepareStore.getSubjectId, coursewareDetailKnowledgeId: prepareStore.getSelectKey }); if (!Array.isArray(data)) { return; } const tempList: any = []; data.forEach((item: any) => { const firstItem: any = item.chapterKnowledgeList[0]?.chapterKnowledgeMaterialList[0]; tempList.push({ id: item.id, lessonPreTrainingId: item.lessonPreTrainingId, openFlag: item.openFlag, openFlagEnable: item.openFlagEnable, subjectNames: item.subjectNames, fromChapterLessonCoursewareId: item.fromChapterLessonCoursewareId, name: item.name, coverImg: firstItem?.bizInfo.coverImg, type: firstItem?.bizInfo.type, isNotWork: item.lessonPreTrainingNum <= 0 ? true : false // 是否布置作业 }); }); forms.tableList = tempList; } catch { // } forms.loading = false; }; // 监听选择的key 左侧选择了其它的课 watch( () => [prepareStore.getSelectKey, prepareStore.getSubjectId], async () => { await getCoursewareList(); // await getOpenCoursewareList(); eventGlobal.emit('openCoursewareChanged'); subjectRef.value?.syncBarPosition(); } ); watch( () => prepareStore.getSubjectList, () => { checkSubjectIds(); } ); const checkSubjectIds = () => { const subjectList = prepareStore.getSubjectList; // 并且没有声部时才会更新 if (subjectList.length > 0) { const prepareLessonCourseWareSubjectIsNull = sessionStorage.getItem( 'prepareLessonCourseWareSubjectIsNull' ); if (prepareLessonCourseWareSubjectIsNull === 'true') { prepareStore.setSubjectId(''); return; } // 并且声部在列表中 const localStorageSubjectId = localStorage.getItem( 'prepareLessonSubjectId' ); // // 先取 上次上课声部,在取班级声部 最后取缓存 let subjectId = null; let index = -1; if (forms.courseScheduleSubjectId) { // 判断浏览器上面是否有 index = subjectList.findIndex( (subject: any) => subject.id == forms.courseScheduleSubjectId ); if (index >= 0) { subjectId = Number(forms.courseScheduleSubjectId); } } // 判断班级上面声部 & 还没有声部 if (forms.subjectId && !subjectId) { // 判断浏览器上面是否有 index = subjectList.findIndex( (subject: any) => subject.id == forms.subjectId ); if (index >= 0) { subjectId = Number(forms.subjectId); } } // 缓存声部 & 还没有声部 if (localStorageSubjectId && !subjectId) { // 判断浏览器上面是否有 index = subjectList.findIndex( (subject: any) => subject.id == localStorageSubjectId ); if (index >= 0) { subjectId = Number(localStorageSubjectId); } } // 判断是否选择为空 if (subjectId && index >= 0) { prepareStore.setSubjectId(subjectId); // forms.subjectId = subjectId; } else { // 判断是否有缓存 // prepareStore.setSubjectId(subjectList[0].id); // forms.subjectId = subjectList[0].id; } // 保存 localStorage.setItem( 'prepareLessonSubjectId', prepareStore.getSubjectId as any ); subjectRef.value?.syncBarPosition(); } }; const subjectRef = ref(); onMounted(async () => { useResizeObserver( document.querySelector('#presetsLeftRef') as HTMLElement, (entries: any) => { const entry = entries[0]; const { width } = entry.contentRect; forms.leftWidth = width + 'px'; } ); useResizeObserver( document.querySelector('#presetsRightRef') as HTMLElement, (entries: any) => { const entry = entries[0]; const { width } = entry.contentRect; forms.rightWidth = width + 'px'; } ); prepareStore.setClassGroupId(route.query.classGroupId as any); if (!prepareStore.getSubjectId) { // 获取教材分类列表 checkSubjectIds(); } await getCoursewareList(); console.log(props.addParam, 'addCourseware'); if (props.addParam.isAdd) { forms.addVisiable = true; } }); const getModalHeight = () => { const dom: any = document.querySelector('#model-homework-height'); if (dom) { useResizeObserver(dom as HTMLElement, (entries: any) => { const entry = entries[0]; const { height } = entry.contentRect; dom.style.setProperty('--window-page-lesson-height', height + 'px'); }); } }; // 重命名 // const onEditTitleSubmit = async () => { // try { // await api_updateCoursewareInfo({ // id: forms.selectItem.id, // name: forms.editTitle // }); // message.success('修改成功'); // getCoursewareList(); // // getOpenCoursewareList() // forms.editTitleVisiable = false; // } catch { // // // } // }; // 删除 const onRemove = async () => { forms.messageLoading = true; try { await api_teacherChapterLessonCoursewareRemove({ id: forms.selectItem.id }); message.success('删除成功'); getCoursewareList(); // getOpenCoursewareList(); eventGlobal.emit('openCoursewareChanged'); forms.preRemoveVisiable = false; } catch { // } setTimeout(() => { forms.messageLoading = false; }, 100); }; // 添加课件 const onAddCourseware = async (item: any) => { if (forms.messageLoading) return; forms.messageLoading = true; try { await api_addByOpenCourseware({ id: item.id }); message.success('添加成功'); getCoursewareList(); // getOpenCoursewareList(); eventGlobal.emit('openCoursewareChanged'); } catch { // } setTimeout(() => { forms.messageLoading = false; }, 100); }; // 预览上课 const onPreviewAttend = (id: string) => { // 判断是否在应用里面 if (window.matchMedia('(display-mode: standalone)').matches) { state.application = window.matchMedia( '(display-mode: standalone)' ).matches; forms.previewModal = true; fscreen(); forms.previewParams = { type: 'preview', courseId: id, subjectId: prepareStore.getSubjectId, detailId: prepareStore.getSelectKey, lessonCourseId: prepareStore.getBaseCourseware.id }; } else { const { href } = router.resolve({ path: '/attend-class', query: { type: 'preview', courseId: id, subjectId: prepareStore.getSubjectId, detailId: prepareStore.getSelectKey, lessonCourseId: prepareStore.getBaseCourseware.id } }); window.open(href, +new Date() + ''); } }; const onStartClass = async (item: any, classGroupId: any) => { if (classGroupId) { // 开始上课 const res = await courseScheduleStart({ lessonCoursewareKnowledgeDetailId: prepareStore.selectKey, classGroupId: classGroupId, useChapterLessonCoursewareId: item.id, subjectId: prepareStore.getSubjectId }); if (window.matchMedia('(display-mode: standalone)').matches) { state.application = window.matchMedia( '(display-mode: standalone)' ).matches; forms.previewModal = true; fscreen(); forms.previewParams = { type: 'class', classGroupId: classGroupId, courseId: item.id, subjectId: prepareStore.getSubjectId, detailId: prepareStore.getSelectKey, classId: res.data, lessonCourseId: prepareStore.getBaseCourseware.id, preStudentNum: forms.preStudentNum }; } else { const { href } = router.resolve({ path: '/attend-class', query: { type: 'class', classGroupId: classGroupId, courseId: item.id, subjectId: prepareStore.getSubjectId, detailId: prepareStore.getSelectKey, classId: res.data, lessonCourseId: prepareStore.getBaseCourseware.id, preStudentNum: forms.preStudentNum } }); window.open(href, +new Date() + ''); } } else { forms.showAttendClass = true; forms.attendClassType = 'change'; forms.attendClassItem = item; } }; // const carouselRef = ref(); // const onChangeSlide = (type: 'left' | 'right') => { // if (type === 'left') { // carouselRef.value?.prev(); // } else if (type === 'right') { // carouselRef.value?.next(); // } // }; return () => (