import { computed, defineComponent, onMounted, reactive, ref, watch } from 'vue'; import styles from './index.module.less'; import { NButton, NTooltip, NIcon, NImage, NModal, NScrollbar, NSpin, NTabPane, NTabs, useMessage, NPopselect } 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, 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, instrumentId: route.query.instrumentId ? Number(route.query.instrumentId) : 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: '', instrumentId: '', detailId: '' } as any, workVisiable: false, wikiCategoryIdChild: null }); const getCoursewareList = async () => { forms.loading = true; try { // 判断是否有选择对应的课件 或声部 if (!prepareStore.getSelectKey) return (forms.loading = false); const { data } = await teacherChapterLessonCoursewareList({ instrumentId: prepareStore.getInstrumentId, 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, instrumentNames: item.instrumentNames, 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.getInstrumentId], async () => { eventGlobal.emit('openCoursewareChanged'); await getCoursewareList(); // await getOpenCoursewareList(); subjectRef.value?.syncBarPosition(); } ); watch( () => prepareStore.getInstrumentList, () => { checkInstrumentIds(); } ); const checkInstrumentIds = () => { const instrumentsList = prepareStore.getSingleInstrumentList; // 并且没有声部时才会更新 if (instrumentsList.length > 0) { const prepareLessonCourseWareSubjectIsNull = sessionStorage.getItem( 'prepareLessonCourseWareSubjectIsNull' ); if (prepareLessonCourseWareSubjectIsNull === 'true') { prepareStore.setInstrumentId(''); return; } // 并且声部在列表中 const localStorageSubjectId = localStorage.getItem( 'prepareLessonSubjectId' ); // // 先取 上次上课声部,在取班级声部 最后取缓存 let instrumentId = null; let index = -1; if (forms.courseScheduleSubjectId) { // 判断浏览器上面是否有 index = instrumentsList.findIndex( (subject: any) => subject.id == forms.courseScheduleSubjectId ); if (index >= 0) { instrumentId = Number(forms.courseScheduleSubjectId); } } // 判断班级上面声部 & 还没有声部 if (forms.instrumentId && !instrumentId) { // 判断浏览器上面是否有 index = instrumentsList.findIndex( (subject: any) => subject.id == forms.instrumentId ); if (index >= 0) { instrumentId = Number(forms.instrumentId); } } // 缓存声部 & 还没有声部 if (localStorageSubjectId && !instrumentId) { // 判断浏览器上面是否有 index = instrumentsList.findIndex( (subject: any) => subject.id == localStorageSubjectId ); if (index >= 0) { instrumentId = Number(localStorageSubjectId); } } // 判断是否选择为空 if (instrumentId && index >= 0) { prepareStore.setSubjectId(instrumentId); // forms.instrumentId = instrumentId; } else { // 判断是否有缓存 // prepareStore.setSubjectId(instrumentsList[0].id); // forms.instrumentId = instrumentsList[0].id; } // 保存 localStorage.setItem( 'prepareLessonSubjectId', prepareStore.getInstrumentId as any ); subjectRef.value?.syncBarPosition(); } }; const getInitInstrumentId = () => { let instrumentId: any = ''; prepareStore.getInstrumentList.forEach((item: any) => { if (Array.isArray(item.instruments)) { item.instruments.forEach((child: any) => { if (child.id === prepareStore.getInstrumentId) { instrumentId = child.id; } }); } }); if (instrumentId) { forms.wikiCategoryIdChild = instrumentId; } }; 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.getInstrumentId) { // 获取教材分类列表 checkInstrumentIds(); } else { getInitInstrumentId(); } await getCoursewareList(); if (props.addParam.isAdd) { forms.addVisiable = true; } }); // 删除 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, instrumentId: prepareStore.getInstrumentId, detailId: prepareStore.getSelectKey, lessonCourseId: prepareStore.getBaseCourseware.id }; } else { const { href } = router.resolve({ path: '/attend-class', query: { type: 'preview', courseId: id, instrumentId: prepareStore.getInstrumentId, detailId: prepareStore.getSelectKey, lessonCourseId: prepareStore.getBaseCourseware.id } }); window.open(href, +new Date() + ''); } }; const onStartClass = async ( item: any, classGroupId: any, instrumentId?: any ) => { if (classGroupId) { // 开始上课 const res = await courseScheduleStart({ lessonCoursewareKnowledgeDetailId: prepareStore.selectKey, classGroupId: classGroupId, useChapterLessonCoursewareId: item.id // instrumentId: prepareStore.getInstrumentId }); 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, instrumentId: instrumentId || route.query.instrumentId, 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, // instrumentId: prepareStore.getInstrumentId, instrumentId: instrumentId || route.query.instrumentId, 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 selectChildObj = (item: any, index: number) => { const obj: any = {}; item?.forEach((child: any) => { if (child.id === forms.wikiCategoryIdChild) { obj.selected = true; obj.name = child.name; } }); return obj; }; const tabInstrumentValue = computed(() => { let instrumentId: any = prepareStore.getInstrumentId ? prepareStore.getInstrumentId : ''; prepareStore.getFormatInstrumentList.forEach((item: any) => { if (Array.isArray(item.instruments)) { item.instruments.forEach((child: any) => { if (child.id === prepareStore.getInstrumentId) { instrumentId = item.id + ''; } }); } }); return instrumentId; }); return () => (