index.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. import { defineComponent, onMounted, reactive, ref, watch } from 'vue';
  2. import styles from './index.module.less';
  3. import {
  4. NButton,
  5. NCarousel,
  6. NIcon,
  7. NImage,
  8. NInput,
  9. NModal,
  10. NScrollbar,
  11. NSelect,
  12. NSpace,
  13. NSpin,
  14. useMessage
  15. } from 'naive-ui';
  16. import { usePrepareStore } from '/src/store/modules/prepareLessons';
  17. import add from '@/views/studentList/images/add.png';
  18. import iconSlideRight from '../../../images/icon-slide-right.png';
  19. import CoursewareType from '../../../model/courseware-type';
  20. import TheEmpty from '/src/components/TheEmpty';
  21. import RelatedClass from '../../../model/related-class';
  22. import { state } from '/src/state';
  23. import { useResizeObserver } from '@vueuse/core';
  24. import AttendClass from '/src/views/prepare-lessons/model/attend-class';
  25. import {
  26. api_addByOpenCourseware,
  27. api_teacherChapterLessonCoursewareRemove,
  28. api_queryOpenCoursewareByPage,
  29. api_updateCoursewareInfo,
  30. teacherChapterLessonCoursewareList,
  31. courseScheduleStart
  32. } from '../../../api';
  33. import { useRoute, useRouter } from 'vue-router';
  34. import TheMessageDialog from '/src/components/TheMessageDialog';
  35. import { eventGlobal, fscreen } from '/src/utils';
  36. import PreviewWindow from '/src/views/preview-window';
  37. export default defineComponent({
  38. name: 'courseware-presets',
  39. emits: ['change'],
  40. setup(props, { emit }) {
  41. const prepareStore = usePrepareStore();
  42. const message = useMessage();
  43. const route = useRoute();
  44. const router = useRouter();
  45. const localStorageSubjectId = localStorage.getItem(
  46. 'prepareLessonSubjectId'
  47. );
  48. const forms = reactive({
  49. // 选取参数带的,后取缓存
  50. messageLoading: false,
  51. subjectId: route.query.subjectId
  52. ? Number(route.query.subjectId)
  53. : localStorageSubjectId
  54. ? Number(localStorageSubjectId)
  55. : '',
  56. courseScheduleSubjectId: route.query.courseScheduleSubjectId,
  57. classGroupId: route.query.classGroupId,
  58. preStudentNum: route.query.preStudentNum,
  59. bodyWidth: '100%',
  60. loading: false,
  61. openLoading: false,
  62. showRelatedClass: false,
  63. tableList: [] as any,
  64. openTableList: [] as any,
  65. selectItem: {} as any,
  66. editTitleVisiable: false,
  67. editTitle: null,
  68. editBtnLoading: false,
  69. preRemoveVisiable: false,
  70. carouselIndex: 0,
  71. showAttendClass: false,
  72. attendClassType: 'change', //
  73. attendClassItem: {} as any,
  74. previewModal: false,
  75. previewParams: {
  76. type: '',
  77. courseId: '',
  78. subjectId: '',
  79. detailId: ''
  80. } as any
  81. });
  82. const getCoursewareList = async () => {
  83. forms.loading = true;
  84. try {
  85. // 判断是否有选择对应的课件 或声部
  86. if (!prepareStore.getSelectKey) return (forms.loading = false);
  87. const { data } = await teacherChapterLessonCoursewareList({
  88. subjectId: prepareStore.getSubjectId,
  89. coursewareDetailKnowledgeId: prepareStore.getSelectKey
  90. });
  91. if (!Array.isArray(data)) {
  92. return;
  93. }
  94. const tempList: any = [];
  95. data.forEach((item: any) => {
  96. const firstItem: any =
  97. item.chapterKnowledgeList[0]?.chapterKnowledgeMaterialList[0];
  98. tempList.push({
  99. id: item.id,
  100. openFlag: item.openFlag,
  101. openFlagEnable: item.openFlagEnable,
  102. subjectNames: item.subjectNames,
  103. fromChapterLessonCoursewareId: item.fromChapterLessonCoursewareId,
  104. name: item.name,
  105. coverImg: firstItem?.bizInfo.coverImg,
  106. type: firstItem?.bizInfo.type
  107. });
  108. });
  109. forms.tableList = tempList;
  110. } catch {
  111. //
  112. }
  113. forms.loading = false;
  114. };
  115. const getOpenCoursewareList = async () => {
  116. // 查询公开课件列表
  117. forms.openLoading = true;
  118. try {
  119. // 判断是否有选择对应的课件 或声部
  120. if (!prepareStore.getSelectKey) return (forms.openLoading = false);
  121. const { data } = await api_queryOpenCoursewareByPage({
  122. subjectId: prepareStore.getSubjectId,
  123. coursewareDetailKnowledgeId: prepareStore.getSelectKey,
  124. page: 1,
  125. rows: 20
  126. });
  127. const result = data.rows || [];
  128. const tempList: any = [];
  129. result.forEach((item: any) => {
  130. // const index = forms.tableList.findIndex(
  131. // (i: any) => i.fromChapterLessonCoursewareId === item.id
  132. // );
  133. const firstItem: any =
  134. item.chapterKnowledgeList[0]?.chapterKnowledgeMaterialList[0];
  135. tempList.push({
  136. id: item.id,
  137. openFlag: item.openFlag,
  138. openFlagEnable: item.openFlagEnable,
  139. subjectNames: item.subjectNames,
  140. fromChapterLessonCoursewareId: item.fromChapterLessonCoursewareId,
  141. name: item.name,
  142. coverImg: firstItem?.bizInfo.coverImg,
  143. type: firstItem?.bizInfo.type,
  144. isAdd: item.addFlag
  145. });
  146. });
  147. forms.openTableList = chunkArray(tempList, 4);
  148. } catch {
  149. //
  150. }
  151. forms.openLoading = false;
  152. };
  153. const chunkArray = (array: any, size: number) => {
  154. const result = [];
  155. for (let i = 0; i < array.length; i += size) {
  156. result.push(array.slice(i, i + size));
  157. }
  158. return result;
  159. };
  160. // 监听选择的key 左侧选择了其它的课
  161. watch(
  162. () => [prepareStore.getSelectKey, prepareStore.getSubjectId],
  163. async () => {
  164. await getCoursewareList();
  165. await getOpenCoursewareList();
  166. }
  167. );
  168. // 检测数据是否存在
  169. // watch(
  170. // () => forms.tableList,
  171. // () => {
  172. // // fromChapterLessonCoursewareId;
  173. // forms.openTableList.forEach((item: any) => {
  174. // const index = forms.tableList.findIndex(
  175. // (i: any) => i.fromChapterLessonCoursewareId === item.id
  176. // );
  177. // item.isAdd = index !== -1 ? true : false;
  178. // });
  179. // }
  180. // );
  181. watch(
  182. () => prepareStore.getSubjectList,
  183. () => {
  184. checkSubjectIds();
  185. }
  186. );
  187. const checkSubjectIds = () => {
  188. const subjectList = prepareStore.getSubjectList;
  189. // 并且没有声部时才会更新
  190. if (subjectList.length > 0) {
  191. // 并且声部在列表中
  192. const localStorageSubjectId = localStorage.getItem(
  193. 'prepareLessonSubjectId'
  194. );
  195. // // 先取 上次上课声部,在取班级声部 最后取缓存
  196. let subjectId = null;
  197. let index = -1;
  198. if (forms.courseScheduleSubjectId) {
  199. // 判断浏览器上面是否有
  200. index = subjectList.findIndex(
  201. (subject: any) => subject.id == forms.courseScheduleSubjectId
  202. );
  203. if (index >= 0) {
  204. subjectId = Number(forms.courseScheduleSubjectId);
  205. }
  206. }
  207. // 判断班级上面声部 & 还没有声部
  208. if (forms.subjectId && !subjectId) {
  209. // 判断浏览器上面是否有
  210. index = subjectList.findIndex(
  211. (subject: any) => subject.id == forms.subjectId
  212. );
  213. if (index >= 0) {
  214. subjectId = Number(forms.subjectId);
  215. }
  216. }
  217. // 缓存声部 & 还没有声部
  218. if (localStorageSubjectId && !subjectId) {
  219. // 判断浏览器上面是否有
  220. index = subjectList.findIndex(
  221. (subject: any) => subject.id == localStorageSubjectId
  222. );
  223. if (index >= 0) {
  224. subjectId = Number(localStorageSubjectId);
  225. }
  226. }
  227. if (subjectId && index >= 0) {
  228. prepareStore.setSubjectId(subjectId);
  229. // forms.subjectId = subjectId;
  230. } else {
  231. // 判断是否有缓存
  232. prepareStore.setSubjectId(subjectList[0].id);
  233. // forms.subjectId = subjectList[0].id;
  234. }
  235. // 保存
  236. localStorage.setItem(
  237. 'prepareLessonSubjectId',
  238. prepareStore.getSubjectId as any
  239. );
  240. }
  241. };
  242. onMounted(async () => {
  243. prepareStore.setClassGroupId(route.query.classGroupId as any);
  244. if (!prepareStore.getSubjectId) {
  245. // 获取教材分类列表
  246. checkSubjectIds();
  247. }
  248. // useResizeObserver(
  249. // document.querySelector('#coursewarePresets') as HTMLElement,
  250. // (entries: any) => {
  251. // const entry = entries[0];
  252. // const { width } = entry.contentRect;
  253. // forms.bodyWidth = width + 'px';
  254. // }
  255. // );
  256. await getCoursewareList();
  257. await getOpenCoursewareList();
  258. });
  259. // 重命名
  260. const onEditTitleSubmit = async () => {
  261. try {
  262. await api_updateCoursewareInfo({
  263. id: forms.selectItem.id,
  264. name: forms.editTitle
  265. });
  266. message.success('修改成功');
  267. getCoursewareList();
  268. // getOpenCoursewareList()
  269. forms.editTitleVisiable = false;
  270. } catch {
  271. //
  272. }
  273. };
  274. // 删除
  275. const onRemove = async () => {
  276. forms.messageLoading = true;
  277. try {
  278. await api_teacherChapterLessonCoursewareRemove({
  279. id: forms.selectItem.id
  280. });
  281. message.success('删除成功');
  282. getCoursewareList();
  283. getOpenCoursewareList();
  284. forms.preRemoveVisiable = false;
  285. } catch {
  286. //
  287. }
  288. setTimeout(() => {
  289. forms.messageLoading = false;
  290. }, 100);
  291. };
  292. // 添加课件
  293. const onAddCourseware = async (item: any) => {
  294. if (forms.messageLoading) return;
  295. forms.messageLoading = true;
  296. try {
  297. await api_addByOpenCourseware({ id: item.id });
  298. message.success('添加成功');
  299. getCoursewareList();
  300. getOpenCoursewareList();
  301. } catch {
  302. //
  303. }
  304. setTimeout(() => {
  305. forms.messageLoading = false;
  306. }, 100);
  307. };
  308. // 预览上课
  309. const onPreviewAttend = (id: string) => {
  310. // 判断是否在应用里面
  311. if (window.matchMedia('(display-mode: standalone)').matches) {
  312. state.application = window.matchMedia(
  313. '(display-mode: standalone)'
  314. ).matches;
  315. forms.previewModal = true;
  316. fscreen();
  317. forms.previewParams = {
  318. type: 'preview',
  319. courseId: id,
  320. subjectId: prepareStore.getSubjectId,
  321. detailId: prepareStore.getSelectKey,
  322. lessonCourseId: prepareStore.getBaseCourseware.id
  323. };
  324. } else {
  325. const { href } = router.resolve({
  326. path: '/attend-class',
  327. query: {
  328. type: 'preview',
  329. courseId: id,
  330. subjectId: prepareStore.getSubjectId,
  331. detailId: prepareStore.getSelectKey,
  332. lessonCourseId: prepareStore.getBaseCourseware.id
  333. }
  334. });
  335. window.open(href, +new Date() + '');
  336. }
  337. };
  338. const onStartClass = async (item: any, classGroupId: any) => {
  339. if (classGroupId) {
  340. // 开始上课
  341. const res = await courseScheduleStart({
  342. lessonCoursewareKnowledgeDetailId: prepareStore.selectKey,
  343. classGroupId: classGroupId,
  344. useChapterLessonCoursewareId: item.id,
  345. subjectId: prepareStore.getSubjectId
  346. });
  347. if (window.matchMedia('(display-mode: standalone)').matches) {
  348. state.application = window.matchMedia(
  349. '(display-mode: standalone)'
  350. ).matches;
  351. forms.previewModal = true;
  352. fscreen();
  353. forms.previewParams = {
  354. type: 'class',
  355. classGroupId: classGroupId,
  356. courseId: item.id,
  357. subjectId: prepareStore.getSubjectId,
  358. detailId: prepareStore.getSelectKey,
  359. classId: res.data,
  360. lessonCourseId: prepareStore.getBaseCourseware.id,
  361. preStudentNum: forms.preStudentNum
  362. };
  363. } else {
  364. const { href } = router.resolve({
  365. path: '/attend-class',
  366. query: {
  367. type: 'class',
  368. classGroupId: classGroupId,
  369. courseId: item.id,
  370. subjectId: prepareStore.getSubjectId,
  371. detailId: prepareStore.getSelectKey,
  372. classId: res.data,
  373. lessonCourseId: prepareStore.getBaseCourseware.id,
  374. preStudentNum: forms.preStudentNum
  375. }
  376. });
  377. window.open(href, +new Date() + '');
  378. }
  379. } else {
  380. forms.showAttendClass = true;
  381. forms.attendClassType = 'change';
  382. forms.attendClassItem = item;
  383. }
  384. };
  385. const carouselRef = ref();
  386. const onChangeSlide = (type: 'left' | 'right') => {
  387. if (type === 'left') {
  388. carouselRef.value?.prev();
  389. } else if (type === 'right') {
  390. carouselRef.value?.next();
  391. }
  392. };
  393. return () => (
  394. <div class={styles.coursewarePresetsContainer}>
  395. <NScrollbar class={styles.coursewarePresets}>
  396. <div class={styles.title} id="coursewarePresets">
  397. <div class={styles.titleLeft}>
  398. <i class={[styles.icon, styles.iconWork]}></i>
  399. 我的课件
  400. </div>
  401. </div>
  402. <NSpace>
  403. <NSelect
  404. placeholder="选择声部"
  405. class={styles.btnSubjectList}
  406. options={[
  407. { name: '全部声部', id: '' },
  408. ...prepareStore.getSubjectList
  409. ]}
  410. labelField="name"
  411. valueField="id"
  412. value={prepareStore.getSubjectId}
  413. onUpdate:value={(val: any) => {
  414. prepareStore.setSubjectId(val);
  415. // 保存
  416. forms.subjectId = val;
  417. }}
  418. />
  419. <NButton
  420. class={styles.addBtn}
  421. type="primary"
  422. onClick={() => {
  423. eventGlobal.emit('teacher-slideshow', true);
  424. emit('change', { status: true, type: 'create' });
  425. }}>
  426. <NImage
  427. class={styles.addBtnIcon}
  428. previewDisabled
  429. src={add}></NImage>
  430. 创建课件
  431. </NButton>
  432. </NSpace>
  433. <div style={{ overflow: 'hidden' }}>
  434. <NSpin show={forms.loading}>
  435. <div class={styles.list}>
  436. {forms.tableList.map((item: any) => (
  437. <div class={[styles.itemWrap, styles.itemBlock, 'row-nav']}>
  438. <div class={styles.itemWrapBox}>
  439. <CoursewareType
  440. operate
  441. isEditName
  442. item={item}
  443. onClick={() => onPreviewAttend(item.id)}
  444. onEditName={() => {
  445. forms.selectItem = item;
  446. forms.editTitle = item.name;
  447. forms.editTitleVisiable = true;
  448. }}
  449. onEdit={() => {
  450. //
  451. eventGlobal.emit('teacher-slideshow', true);
  452. emit('change', {
  453. status: true,
  454. type: 'update',
  455. groupItem: { id: item.id }
  456. });
  457. }}
  458. onStartClass={() =>
  459. onStartClass(item, forms.classGroupId)
  460. }
  461. onDelete={() => {
  462. forms.selectItem = item;
  463. forms.preRemoveVisiable = true;
  464. }}
  465. />
  466. </div>
  467. </div>
  468. ))}
  469. {!forms.loading && forms.tableList.length <= 0 && (
  470. <TheEmpty class={styles.empty1} />
  471. )}
  472. </div>
  473. </NSpin>
  474. </div>
  475. {forms.openTableList.length > 0 && (
  476. <>
  477. <div class={[styles.title, styles.line]}>
  478. <div class={styles.titleLeft}>
  479. <i class={[styles.icon, styles.iconCourseware]}></i>
  480. 相关课件
  481. {forms.openTableList.length > 1 && (
  482. <span
  483. class={styles.more}
  484. onClick={() => (forms.showRelatedClass = true)}>
  485. 查看更多
  486. {/* <NIcon size={15}>
  487. <svg
  488. xmlns="http://www.w3.org/2000/svg"
  489. viewBox="0 0 24 24">
  490. <path
  491. d="M8.59 16.59L13.17 12L8.59 7.41L10 6l6 6l-6 6l-1.41-1.41z"
  492. fill="currentColor"></path>
  493. </svg>
  494. </NIcon> */}
  495. <i class={styles.iconP}></i>
  496. </span>
  497. )}
  498. </div>
  499. {forms.openTableList.length > 1 && (
  500. <NSpace class={styles.swipeControll}>
  501. <div onClick={() => onChangeSlide('left')}>
  502. <NImage
  503. previewDisabled
  504. class={[
  505. styles.leftIcon,
  506. forms.carouselIndex === 0 && styles.disabled
  507. ]}
  508. src={iconSlideRight}
  509. />
  510. </div>
  511. <div onClick={() => onChangeSlide('right')}>
  512. <NImage
  513. class={
  514. forms.carouselIndex ==
  515. forms.openTableList.length - 1 && styles.disabled
  516. }
  517. previewDisabled
  518. src={iconSlideRight}
  519. />
  520. </div>
  521. </NSpace>
  522. )}
  523. </div>
  524. <NSpin show={forms.openLoading} class={styles.openLoading}>
  525. <NCarousel
  526. slidesPerView={1}
  527. loop={false}
  528. ref={carouselRef}
  529. // style={{ width: forms.bodyWidth }}
  530. v-model:currentIndex={forms.carouselIndex}>
  531. {forms.openTableList.map((item: any) => (
  532. <div class={[styles.list, styles.listSame]}>
  533. {item.map((child: any) => (
  534. <div
  535. class={[
  536. styles.itemWrap,
  537. styles.itemBlock,
  538. 'row-nav'
  539. ]}>
  540. <div class={styles.itemWrapBox}>
  541. <CoursewareType
  542. isShowOpenFlag={false}
  543. isShowAdd
  544. isHoverShowAdd={false}
  545. item={child}
  546. onClick={() => onPreviewAttend(child.id)}
  547. onAdd={() => onAddCourseware(child)}
  548. />
  549. </div>
  550. </div>
  551. ))}
  552. </div>
  553. ))}
  554. </NCarousel>
  555. </NSpin>
  556. </>
  557. )}
  558. </NScrollbar>
  559. <NModal
  560. v-model:show={forms.showRelatedClass}
  561. preset="card"
  562. showIcon={false}
  563. class={['modalTitle background', styles.attendClassModal1]}
  564. title={'相关课件'}
  565. blockScroll={false}>
  566. <RelatedClass
  567. tableList={forms.tableList}
  568. subjectList={prepareStore.getSubjectList}
  569. subjectId={prepareStore.getSubjectId as any}
  570. coursewareDetailKnowledgeId={prepareStore.getSelectKey}
  571. onClose={() => (forms.showRelatedClass = false)}
  572. onAdd={(item: any) => onAddCourseware(item)}
  573. onClick={(item: any) => {
  574. onPreviewAttend(item.id);
  575. forms.showRelatedClass = false;
  576. }}
  577. />
  578. </NModal>
  579. <NModal
  580. v-model:show={forms.editTitleVisiable}
  581. preset="card"
  582. class={['modalTitle', styles.removeVisiable1]}
  583. title={'课件重命名'}>
  584. <div class={styles.studentRemove}>
  585. <NInput
  586. placeholder="请输入课件名称"
  587. v-model:value={forms.editTitle}
  588. maxlength={15}
  589. onKeyup={(e: any) => {
  590. if (e.code === 'ArrowLeft' || e.code === 'ArrowRight') {
  591. e.stopPropagation();
  592. }
  593. }}
  594. />
  595. <NSpace class={styles.btnGroupModal} justify="center">
  596. <NButton round onClick={() => (forms.editTitleVisiable = false)}>
  597. 取消
  598. </NButton>
  599. <NButton
  600. round
  601. type="primary"
  602. onClick={onEditTitleSubmit}
  603. loading={forms.editBtnLoading}>
  604. 确定
  605. </NButton>
  606. </NSpace>
  607. </div>
  608. </NModal>
  609. <NModal
  610. v-model:show={forms.preRemoveVisiable}
  611. preset="card"
  612. class={['modalTitle', styles.removeVisiable1]}
  613. title={'删除课件'}>
  614. <TheMessageDialog
  615. content={`<p style="text-align: left;">请确认是否删除【${forms.selectItem.name}】,删除后不可恢复</p>`}
  616. cancelButtonText="取消"
  617. confirmButtonText="确认"
  618. loading={forms.messageLoading}
  619. onClose={() => (forms.preRemoveVisiable = false)}
  620. onConfirm={() => onRemove()}
  621. />
  622. </NModal>
  623. {/* 应用内预览或上课 */}
  624. <PreviewWindow
  625. v-model:show={forms.previewModal}
  626. type="attend"
  627. params={forms.previewParams}
  628. />
  629. <NModal
  630. v-model:show={forms.showAttendClass}
  631. preset="card"
  632. showIcon={false}
  633. class={['modalTitle background', styles.attendClassModal]}
  634. title={'选择班级'}
  635. blockScroll={false}>
  636. <AttendClass
  637. onClose={() => (forms.showAttendClass = false)}
  638. type={forms.attendClassType}
  639. onPreview={(item: any) => {
  640. if (window.matchMedia('(display-mode: standalone)').matches) {
  641. state.application = window.matchMedia(
  642. '(display-mode: standalone)'
  643. ).matches;
  644. forms.previewModal = true;
  645. forms.previewParams = {
  646. ...item
  647. };
  648. } else {
  649. const { href } = router.resolve({
  650. path: '/attend-class',
  651. query: {
  652. ...item
  653. }
  654. });
  655. window.open(href, +new Date() + '');
  656. }
  657. }}
  658. onConfirm={async (item: any) => {
  659. onStartClass(forms.attendClassItem, item.classGroupId);
  660. }}
  661. />
  662. </NModal>
  663. </div>
  664. );
  665. }
  666. });