index.tsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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: forms.subjectId,
  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: forms.subjectId,
  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: index !== -1 ? true : false
  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. } else {
  230. // 判断是否有缓存
  231. prepareStore.setSubjectId(subjectList[0].id);
  232. }
  233. // 保存
  234. localStorage.setItem(
  235. 'prepareLessonSubjectId',
  236. prepareStore.getSubjectId as any
  237. );
  238. }
  239. };
  240. onMounted(async () => {
  241. prepareStore.setClassGroupId(route.query.classGroupId as any);
  242. // 获取教材分类列表
  243. checkSubjectIds();
  244. // useResizeObserver(
  245. // document.querySelector('#coursewarePresets') as HTMLElement,
  246. // (entries: any) => {
  247. // const entry = entries[0];
  248. // const { width } = entry.contentRect;
  249. // forms.bodyWidth = width + 'px';
  250. // }
  251. // );
  252. await getCoursewareList();
  253. await getOpenCoursewareList();
  254. });
  255. // 重命名
  256. const onEditTitleSubmit = async () => {
  257. try {
  258. await api_updateCoursewareInfo({
  259. id: forms.selectItem.id,
  260. name: forms.editTitle
  261. });
  262. message.success('修改成功');
  263. getCoursewareList();
  264. forms.editTitleVisiable = false;
  265. } catch {
  266. //
  267. }
  268. };
  269. // 删除
  270. const onRemove = async () => {
  271. forms.messageLoading = true;
  272. try {
  273. await api_teacherChapterLessonCoursewareRemove({
  274. id: forms.selectItem.id
  275. });
  276. message.success('删除成功');
  277. getCoursewareList();
  278. forms.preRemoveVisiable = false;
  279. } catch {
  280. //
  281. }
  282. setTimeout(() => {
  283. forms.messageLoading = false;
  284. }, 100);
  285. };
  286. // 添加课件
  287. const onAddCourseware = async (item: any) => {
  288. if (forms.messageLoading) return;
  289. forms.messageLoading = true;
  290. try {
  291. await api_addByOpenCourseware({ id: item.id });
  292. message.success('添加成功');
  293. getCoursewareList();
  294. } catch {
  295. //
  296. }
  297. setTimeout(() => {
  298. forms.messageLoading = false;
  299. }, 100);
  300. };
  301. // 预览上课
  302. const onPreviewAttend = (id: string) => {
  303. // 判断是否在应用里面
  304. if (window.matchMedia('(display-mode: standalone)').matches) {
  305. state.application = window.matchMedia(
  306. '(display-mode: standalone)'
  307. ).matches;
  308. forms.previewModal = true;
  309. fscreen();
  310. forms.previewParams = {
  311. type: 'preview',
  312. courseId: id,
  313. subjectId: prepareStore.getSubjectId,
  314. detailId: prepareStore.getSelectKey,
  315. lessonCourseId: prepareStore.getBaseCourseware.id
  316. };
  317. } else {
  318. const { href } = router.resolve({
  319. path: '/attend-class',
  320. query: {
  321. type: 'preview',
  322. courseId: id,
  323. subjectId: prepareStore.getSubjectId,
  324. detailId: prepareStore.getSelectKey,
  325. lessonCourseId: prepareStore.getBaseCourseware.id
  326. }
  327. });
  328. window.open(href, +new Date() + '');
  329. }
  330. };
  331. const onStartClass = async (item: any, classGroupId: any) => {
  332. if (classGroupId) {
  333. // 开始上课
  334. const res = await courseScheduleStart({
  335. lessonCoursewareKnowledgeDetailId: prepareStore.selectKey,
  336. classGroupId: classGroupId,
  337. useChapterLessonCoursewareId: item.id,
  338. subjectId: prepareStore.getSubjectId
  339. });
  340. if (window.matchMedia('(display-mode: standalone)').matches) {
  341. state.application = window.matchMedia(
  342. '(display-mode: standalone)'
  343. ).matches;
  344. forms.previewModal = true;
  345. fscreen();
  346. forms.previewParams = {
  347. type: 'class',
  348. classGroupId: classGroupId,
  349. courseId: item.id,
  350. subjectId: prepareStore.getSubjectId,
  351. detailId: prepareStore.getSelectKey,
  352. classId: res.data,
  353. lessonCourseId: prepareStore.getBaseCourseware.id,
  354. preStudentNum: forms.preStudentNum
  355. };
  356. } else {
  357. const { href } = router.resolve({
  358. path: '/attend-class',
  359. query: {
  360. type: 'class',
  361. classGroupId: classGroupId,
  362. courseId: item.id,
  363. subjectId: prepareStore.getSubjectId,
  364. detailId: prepareStore.getSelectKey,
  365. classId: res.data,
  366. lessonCourseId: prepareStore.getBaseCourseware.id,
  367. preStudentNum: forms.preStudentNum
  368. }
  369. });
  370. window.open(href, +new Date() + '');
  371. }
  372. } else {
  373. forms.showAttendClass = true;
  374. forms.attendClassType = 'change';
  375. forms.attendClassItem = item;
  376. }
  377. forms.showAttendClass = false;
  378. };
  379. const carouselRef = ref();
  380. const onChangeSlide = (type: 'left' | 'right') => {
  381. if (type === 'left') {
  382. carouselRef.value?.prev();
  383. } else if (type === 'right') {
  384. carouselRef.value?.next();
  385. }
  386. };
  387. return () => (
  388. <div class={styles.coursewarePresetsContainer}>
  389. <NScrollbar class={styles.coursewarePresets}>
  390. <div class={styles.title} id="coursewarePresets">
  391. <div class={styles.titleLeft}>
  392. <i class={[styles.icon, styles.iconWork]}></i>
  393. 我的课件
  394. </div>
  395. </div>
  396. <NSpace>
  397. <NSelect
  398. placeholder="选择声部"
  399. class={styles.btnSubjectList}
  400. options={[
  401. { name: '全部声部', id: '' },
  402. ...prepareStore.getSubjectList
  403. ]}
  404. labelField="name"
  405. valueField="id"
  406. value={forms.subjectId}
  407. onUpdate:value={(val: any) => {
  408. prepareStore.setSubjectId(val);
  409. // 保存
  410. }}
  411. />
  412. <NButton
  413. class={styles.addBtn}
  414. type="primary"
  415. onClick={() => {
  416. eventGlobal.emit('teacher-slideshow', true);
  417. emit('change', { status: true });
  418. }}>
  419. <NImage
  420. class={styles.addBtnIcon}
  421. previewDisabled
  422. src={add}></NImage>
  423. 添加课件
  424. </NButton>
  425. </NSpace>
  426. <div style={{ overflow: 'hidden' }}>
  427. <NSpin show={forms.loading}>
  428. <div class={styles.list}>
  429. {forms.tableList.map((item: any) => (
  430. <div class={[styles.itemWrap, styles.itemBlock, 'row-nav']}>
  431. <div class={styles.itemWrapBox}>
  432. <CoursewareType
  433. operate
  434. isEditName
  435. item={item}
  436. onClick={() => onPreviewAttend(item.id)}
  437. onEditName={() => {
  438. forms.selectItem = item;
  439. forms.editTitle = item.name;
  440. forms.editTitleVisiable = true;
  441. }}
  442. onEdit={() => {
  443. //
  444. eventGlobal.emit('teacher-slideshow', true);
  445. emit('change', {
  446. status: true,
  447. groupItem: { id: item.id }
  448. });
  449. }}
  450. onStartClass={() =>
  451. onStartClass(item, forms.classGroupId)
  452. }
  453. onDelete={() => {
  454. forms.selectItem = item;
  455. forms.preRemoveVisiable = true;
  456. }}
  457. />
  458. </div>
  459. </div>
  460. ))}
  461. {!forms.loading && forms.tableList.length <= 0 && <TheEmpty />}
  462. </div>
  463. </NSpin>
  464. </div>
  465. {forms.openTableList.length > 0 && (
  466. <>
  467. <div class={[styles.title, styles.line]}>
  468. <div class={styles.titleLeft}>
  469. <i class={[styles.icon, styles.iconCourseware]}></i>
  470. 相关课件
  471. {forms.openTableList.length > 1 && (
  472. <span
  473. class={styles.more}
  474. onClick={() => (forms.showRelatedClass = true)}>
  475. 查看更多
  476. <NIcon>
  477. <svg
  478. xmlns="http://www.w3.org/2000/svg"
  479. viewBox="0 0 24 24">
  480. <path
  481. d="M8.59 16.59L13.17 12L8.59 7.41L10 6l6 6l-6 6l-1.41-1.41z"
  482. fill="currentColor"></path>
  483. </svg>
  484. </NIcon>
  485. </span>
  486. )}
  487. </div>
  488. {forms.openTableList.length > 1 && (
  489. <NSpace class={styles.swipeControll}>
  490. <div onClick={() => onChangeSlide('left')}>
  491. <NImage
  492. previewDisabled
  493. class={[
  494. styles.leftIcon,
  495. forms.carouselIndex === 0 && styles.disabled
  496. ]}
  497. src={iconSlideRight}
  498. />
  499. </div>
  500. <div onClick={() => onChangeSlide('right')}>
  501. <NImage
  502. class={
  503. forms.carouselIndex ==
  504. forms.openTableList.length - 4 && styles.disabled
  505. }
  506. previewDisabled
  507. src={iconSlideRight}
  508. />
  509. </div>
  510. </NSpace>
  511. )}
  512. </div>
  513. <NSpin show={forms.openLoading} class={styles.openLoading}>
  514. <NCarousel
  515. slidesPerView={1}
  516. loop={false}
  517. ref={carouselRef}
  518. // style={{ width: forms.bodyWidth }}
  519. v-model:currentIndex={forms.carouselIndex}>
  520. {forms.openTableList.map((item: any) => (
  521. <div class={[styles.list, styles.listSame]}>
  522. {item.map((child: any) => (
  523. <div
  524. class={[
  525. styles.itemWrap,
  526. styles.itemBlock,
  527. 'row-nav'
  528. ]}>
  529. <div class={styles.itemWrapBox}>
  530. <CoursewareType
  531. isShowAdd
  532. item={child}
  533. onAdd={() => onAddCourseware(child)}
  534. />
  535. </div>
  536. </div>
  537. ))}
  538. </div>
  539. ))}
  540. </NCarousel>
  541. </NSpin>
  542. </>
  543. )}
  544. </NScrollbar>
  545. <NModal
  546. v-model:show={forms.showRelatedClass}
  547. preset="card"
  548. showIcon={false}
  549. class={['modalTitle background', styles.attendClassModal1]}
  550. title={'相关课件'}
  551. blockScroll={false}>
  552. <RelatedClass
  553. tableList={forms.tableList}
  554. subjectList={prepareStore.getSubjectList}
  555. subjectId={prepareStore.getSubjectId as any}
  556. coursewareDetailKnowledgeId={prepareStore.getSelectKey}
  557. onClose={() => (forms.showRelatedClass = false)}
  558. onAdd={(item: any) => onAddCourseware(item)}
  559. />
  560. </NModal>
  561. <NModal
  562. v-model:show={forms.editTitleVisiable}
  563. preset="card"
  564. class={['modalTitle', styles.removeVisiable1]}
  565. title={'课件重命名'}>
  566. <div class={styles.studentRemove}>
  567. <NInput
  568. placeholder="请输入课件名称"
  569. v-model:value={forms.editTitle}
  570. maxlength={15}
  571. onKeyup={(e: any) => {
  572. if (e.code === 'ArrowLeft' || e.code === 'ArrowRight') {
  573. e.stopPropagation();
  574. }
  575. }}
  576. />
  577. <NSpace class={styles.btnGroupModal} justify="center">
  578. <NButton round onClick={() => (forms.editTitleVisiable = false)}>
  579. 取消
  580. </NButton>
  581. <NButton
  582. round
  583. type="primary"
  584. onClick={onEditTitleSubmit}
  585. loading={forms.editBtnLoading}>
  586. 确定
  587. </NButton>
  588. </NSpace>
  589. </div>
  590. </NModal>
  591. <NModal
  592. v-model:show={forms.preRemoveVisiable}
  593. preset="card"
  594. class={['modalTitle', styles.removeVisiable1]}
  595. title={'保存预设'}>
  596. <TheMessageDialog
  597. content={`<p style="text-align: left;">请确认是否删除【${forms.selectItem.name}】,删除后不可恢复</p>`}
  598. cancelButtonText="取消"
  599. confirmButtonText="确认"
  600. loading={forms.messageLoading}
  601. onClose={() => (forms.preRemoveVisiable = false)}
  602. onConfirm={() => onRemove()}
  603. />
  604. </NModal>
  605. {/* 应用内预览或上课 */}
  606. <PreviewWindow
  607. v-model:show={forms.previewModal}
  608. type="attend"
  609. params={forms.previewParams}
  610. />
  611. <NModal
  612. v-model:show={forms.showAttendClass}
  613. preset="card"
  614. showIcon={false}
  615. class={['modalTitle background', styles.attendClassModal]}
  616. title={'选择班级'}
  617. blockScroll={false}>
  618. <AttendClass
  619. onClose={() => (forms.showAttendClass = false)}
  620. type={forms.attendClassType}
  621. onPreview={(item: any) => {
  622. if (window.matchMedia('(display-mode: standalone)').matches) {
  623. state.application = window.matchMedia(
  624. '(display-mode: standalone)'
  625. ).matches;
  626. forms.previewModal = true;
  627. forms.previewParams = {
  628. ...item
  629. };
  630. } else {
  631. const { href } = router.resolve({
  632. path: '/attend-class',
  633. query: {
  634. ...item
  635. }
  636. });
  637. window.open(href, +new Date() + '');
  638. }
  639. }}
  640. onConfirm={async (item: any) => {
  641. onStartClass(forms.attendClassItem, item.classGroupId);
  642. }}
  643. />
  644. </NModal>
  645. </div>
  646. );
  647. }
  648. });