index.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. import { defineComponent, onMounted, reactive, watch, ref } from 'vue';
  2. import styles from './index.module.less';
  3. import {
  4. NButton,
  5. NModal,
  6. NScrollbar,
  7. NSelect,
  8. NSpace,
  9. NSpin,
  10. useDialog,
  11. useMessage
  12. } from 'naive-ui';
  13. import { usePrepareStore } from '/src/store/modules/prepareLessons';
  14. import { useCatchStore } from '/src/store/modules/catchData';
  15. import TrainType from '/src/views/attend-class/model/train-type';
  16. import TheEmpty from '/src/components/TheEmpty';
  17. import Draggable from 'vuedraggable';
  18. import {
  19. lessonPreTrainingBatchSave,
  20. lessonPreTrainingPage,
  21. lessonPreTrainingDelete
  22. } from '../../../api';
  23. import { evaluateDifficult } from '/src/utils/contants';
  24. import TrainUpdate from '/src/views/attend-class/model/train-update';
  25. import AssignHomework from './assign-homework';
  26. import Trainguide from '@/custom-plugins/guide-page/train-guide';
  27. export default defineComponent({
  28. name: 'courseware-modal',
  29. setup() {
  30. const catchStore = useCatchStore();
  31. const prepareStore = usePrepareStore();
  32. const dialog = useDialog();
  33. const message = useMessage();
  34. const forms = reactive({
  35. showAttendClass: false,
  36. list: [] as any,
  37. drag: false,
  38. loadingStatus: false,
  39. trainList: [] as any,
  40. assignHomeworkStatus: false,
  41. editStatus: false,
  42. editItem: {} as any,
  43. removeIds: [] as any, // 临时删除的编号
  44. removeVisiable: false,
  45. removeVisiable1: false
  46. });
  47. const showGuide = ref(false);
  48. // 完成编辑
  49. const onOverEdit = async () => {
  50. // dialog.warning({
  51. // title: '提示',
  52. // content: `是否完成编辑?`,
  53. // positiveText: '确定',
  54. // negativeText: '取消',
  55. // onPositiveClick: async () => {
  56. try {
  57. // 保存课件
  58. await lessonPreTrainingBatchSave({
  59. coursewareKnowledgeDetailId: prepareStore.getSelectKey,
  60. subjectId: prepareStore.getSubjectId,
  61. lessonPreTrainingDetails: forms.trainList
  62. });
  63. forms.drag = false;
  64. message.success('编辑成功');
  65. forms.removeVisiable = false;
  66. prepareStore.setCoursewareList(forms.trainList);
  67. prepareStore.setIsEditTrain(false);
  68. // 重置临时删除编号
  69. forms.removeIds = [];
  70. } catch {
  71. //
  72. }
  73. // }
  74. // });
  75. };
  76. // 获取列表
  77. const getList = async () => {
  78. forms.loadingStatus = true;
  79. try {
  80. // 判断是否有选择对应的课件
  81. if (!prepareStore.getSelectKey) return;
  82. const { data } = await lessonPreTrainingPage({
  83. coursewareKnowledgeDetailId: prepareStore.getSelectKey,
  84. subjectId: prepareStore.getSubjectId,
  85. page: 1,
  86. rows: 99
  87. });
  88. const tempRows = data.rows || [];
  89. const temp: any = [];
  90. tempRows.forEach((row: any) => {
  91. let tList: string[] = [];
  92. const configJson = row.trainingConfigJson;
  93. if (row.trainingType === 'EVALUATION') {
  94. tList = [
  95. `${evaluateDifficult[configJson.evaluateDifficult]}`,
  96. '全部小节',
  97. // `速度${configJson.evaluateSpeed}`,
  98. `${configJson.trainingTimes}分合格`
  99. ];
  100. } else {
  101. tList = [
  102. `${configJson.practiceChapterBegin}-${configJson.practiceChapterEnd}小节`,
  103. `速度${configJson.practiceSpeed}`,
  104. `${configJson.trainingTimes}分钟`
  105. ];
  106. }
  107. temp.push({
  108. typeList: tList || [],
  109. ...row
  110. });
  111. });
  112. prepareStore.setTrainList(temp || []);
  113. const tempCourse: any = [];
  114. temp.forEach((item: any) => {
  115. if (!forms.removeIds.includes(item.id)) {
  116. tempCourse.push(item);
  117. }
  118. });
  119. forms.trainList = tempCourse || [];
  120. setTimeout(() => {
  121. showGuide.value = true;
  122. }, 500);
  123. } catch {
  124. //
  125. }
  126. forms.loadingStatus = false;
  127. };
  128. // 声部变化时
  129. watch(
  130. () => prepareStore.getSubjectId,
  131. () => {
  132. getList();
  133. }
  134. );
  135. // 监听选择的key 左侧选择了其它的课
  136. watch(
  137. () => prepareStore.getSelectKey,
  138. () => {
  139. forms.trainList = [];
  140. getList();
  141. }
  142. );
  143. watch(
  144. () => prepareStore.getIsAddTrain,
  145. (val: boolean) => {
  146. if (val) {
  147. forms.trainList = [];
  148. getList();
  149. prepareStore.setIsAddTrain(false);
  150. }
  151. }
  152. );
  153. // 删除
  154. const onDelete = (item: any) => {
  155. //
  156. forms.removeIds.push(item.id);
  157. const index = forms.trainList.findIndex((c: any) => c.id === item.id);
  158. forms.trainList.splice(index, 1);
  159. // prepareStore.setCoursewareList(forms.trainList);
  160. };
  161. // 单个删除
  162. const onRemove = async (item: any) => {
  163. try {
  164. dialog.warning({
  165. title: '提示',
  166. content: '该训练已下架,是否删除?',
  167. positiveText: '确定',
  168. negativeText: '取消',
  169. onPositiveClick: async () => {
  170. forms.removeIds.push(item.id);
  171. await lessonPreTrainingDelete({ ids: item.id });
  172. message.success('删除成功');
  173. getList();
  174. }
  175. });
  176. } catch {
  177. //
  178. }
  179. };
  180. // const checkSubjectIds = () => {
  181. // const subjectList = prepareStore.getSubjectList;
  182. // // 并且没有声部时才会更新
  183. // if (subjectList.length > 0) {
  184. // // 判断浏览器上面是否有
  185. // const index = subjectList.findIndex(
  186. // (subject: any) => subject.id == forms.subjectId
  187. // );
  188. // // 并且声部在列表中
  189. // if (forms.subjectId && index >= 0) {
  190. // prepareStore.setSubjectId(forms.subjectId);
  191. // } else {
  192. // // 判断是否有缓存
  193. // prepareStore.setSubjectId(subjectList[0].id);
  194. // }
  195. // }
  196. // };
  197. onMounted(async () => {
  198. // 获取教材分类列表
  199. // await catchStore.getSubjects();
  200. // const subjectList = catchStore.getSubjectList;
  201. // if (subjectList.length > 0 && !prepareStore.getSubjectId) {
  202. // prepareStore.setSubjectId(subjectList[0].id);
  203. // }
  204. // 获取教材分类列表
  205. // checkSubjectIds();
  206. await getList();
  207. });
  208. return () => (
  209. <div class={styles.coursewareModal}>
  210. <div class={styles.btnGroup}>
  211. {forms.drag ? (
  212. <NSpace>
  213. <NButton
  214. type="default"
  215. onClick={() => {
  216. forms.removeVisiable = true;
  217. }}>
  218. 完成编辑
  219. </NButton>
  220. <NButton
  221. type="error"
  222. onClick={() => {
  223. forms.drag = false;
  224. prepareStore.setIsEditTrain(false);
  225. forms.removeIds = [];
  226. getList();
  227. }}>
  228. 取消编辑
  229. </NButton>
  230. <NButton
  231. type="error"
  232. onClick={() => {
  233. // forms.trainList = [];
  234. // prepareStore.setTrainList([]);
  235. forms.removeVisiable1 = true;
  236. }}>
  237. 清空资源
  238. </NButton>
  239. <span class={styles.tips}>拖动可将资源进行排序</span>
  240. </NSpace>
  241. ) : (
  242. <NSpace>
  243. {/* <NSelect
  244. placeholder="选择声部"
  245. options={catchStore.getSubjectList}
  246. labelField="name"
  247. valueField="id"
  248. value={prepareStore.getSubjectId}
  249. onUpdate:value={(val: any) => {
  250. prepareStore.setSubjectId(val);
  251. }}
  252. /> */}
  253. <div class={styles.btnItem}>
  254. <span class={styles.btnTitle}>声部:</span>
  255. <NSelect
  256. placeholder="选择声部"
  257. class={styles.btnSubjectList}
  258. options={prepareStore.getSubjectList}
  259. labelField="name"
  260. valueField="id"
  261. value={prepareStore.getSubjectId}
  262. onUpdate:value={(val: any) => {
  263. prepareStore.setSubjectId(val);
  264. localStorage.setItem('prepareLessonSubjectId', val);
  265. }}
  266. />
  267. </div>
  268. <NButton
  269. type="default"
  270. onClick={() => {
  271. forms.drag = true;
  272. prepareStore.setIsEditTrain(true);
  273. }}>
  274. 编辑
  275. </NButton>
  276. </NSpace>
  277. )}
  278. <NSpace>
  279. <NButton
  280. type="primary"
  281. {...{ id: 'train-0' }}
  282. disabled={forms.drag}
  283. onClick={() => {
  284. let count = 0;
  285. forms.trainList.forEach((item: any) => {
  286. if (!item.removeFlag) {
  287. count++;
  288. }
  289. });
  290. if (count <= 0) {
  291. message.error('作业内容不能为空');
  292. return;
  293. }
  294. forms.assignHomeworkStatus = true;
  295. }}>
  296. 布置作业
  297. </NButton>
  298. </NSpace>
  299. </div>
  300. <NScrollbar class={styles.listContainer}>
  301. <NSpin show={forms.loadingStatus}>
  302. <div
  303. class={[
  304. styles.listSection,
  305. !forms.loadingStatus && prepareStore.getTrainList.length <= 0
  306. ? styles.emptySection
  307. : ''
  308. ]}>
  309. {forms.trainList.length > 0 && (
  310. <>
  311. {forms.drag ? (
  312. <Draggable
  313. v-model:modelValue={forms.trainList}
  314. itemKey="id"
  315. // tag="transition-group"
  316. componentData={{
  317. itemKey: 'id',
  318. tag: 'div',
  319. animation: 200,
  320. group: 'description',
  321. disabled: false
  322. }}
  323. class={styles.list}>
  324. {{
  325. item: (element: any) => {
  326. const item = element.element;
  327. return (
  328. <div data-id={item.id} class={styles.itemBlock}>
  329. <TrainType
  330. item={item}
  331. isDelete
  332. type="prepare"
  333. onDelete={(child: any) => onDelete(child)}
  334. offShelf={item.removeFlag ? true : false}
  335. onOffShelf={() => onRemove(item)}
  336. />
  337. </div>
  338. );
  339. }
  340. }}
  341. </Draggable>
  342. ) : (
  343. <div class={styles.list}>
  344. {forms.trainList.map((item: any) => (
  345. <TrainType
  346. item={item}
  347. type="prepare"
  348. offShelf={item.removeFlag ? true : false}
  349. onOffShelf={() => onRemove(item)}
  350. onEdit={(child: any) => {
  351. console.log('edit', child);
  352. const { trainingConfigJson, id, musicId, ...res } =
  353. child;
  354. forms.editItem = {
  355. ...res,
  356. id: musicId,
  357. trainId: id,
  358. ...trainingConfigJson
  359. };
  360. forms.editStatus = true;
  361. }}
  362. />
  363. ))}
  364. </div>
  365. )}
  366. </>
  367. )}
  368. {!forms.loadingStatus &&
  369. prepareStore.getTrainList.length <= 0 && (
  370. <TheEmpty description="暂无作业" />
  371. )}
  372. </div>
  373. </NSpin>
  374. </NScrollbar>
  375. {/* 编辑 */}
  376. <NModal
  377. v-model:show={forms.editStatus}
  378. class={['modalTitle background', styles.trainEditModal]}
  379. preset="card"
  380. title="作业设置">
  381. <TrainUpdate
  382. item={forms.editItem}
  383. onClose={() => (forms.editStatus = false)}
  384. onConfirm={() => {
  385. forms.editItem = {};
  386. prepareStore.setIsAddTrain(true);
  387. }}
  388. />
  389. </NModal>
  390. {/* 添加自定义教材 */}
  391. <NModal
  392. v-model:show={forms.assignHomeworkStatus}
  393. preset="card"
  394. showIcon={false}
  395. class={['modalTitle background', styles.assignHomework]}
  396. title={'布置作业'}
  397. blockScroll={false}>
  398. <AssignHomework
  399. trainList={forms.trainList}
  400. onClose={() => (forms.assignHomeworkStatus = false)}
  401. />
  402. </NModal>
  403. {showGuide.value ? <Trainguide></Trainguide> : null}
  404. <NModal
  405. v-model:show={forms.removeVisiable}
  406. preset="card"
  407. class={['modalTitle', styles.removeVisiable]}
  408. title={'提示'}>
  409. <div class={styles.studentRemove}>
  410. <p>是否完成编辑?</p>
  411. <NSpace class={styles.btnGroupModal} justify="center">
  412. <NButton round type="primary" onClick={onOverEdit}>
  413. 确定
  414. </NButton>
  415. <NButton round onClick={() => (forms.removeVisiable = false)}>
  416. 取消
  417. </NButton>
  418. </NSpace>
  419. </div>
  420. </NModal>
  421. <NModal
  422. v-model:show={forms.removeVisiable1}
  423. preset="card"
  424. class={['modalTitle', styles.removeVisiable1]}
  425. title={'清空资源'}>
  426. <div class={styles.studentRemove}>
  427. <p>
  428. 请确认是否要清空作业?
  429. <span>点击确认后所有的作业内容 将被清空掉。</span>
  430. </p>
  431. <NSpace class={styles.btnGroupModal} justify="center">
  432. <NButton
  433. round
  434. type="primary"
  435. onClick={() => {
  436. forms.trainList.forEach((item: any) => {
  437. forms.removeIds.push(item.id);
  438. });
  439. forms.trainList = [];
  440. forms.removeVisiable1 = false;
  441. // prepareStore.setCoursewareList([]);
  442. console.log(prepareStore.getTrainList, 'getCourseware1');
  443. }}>
  444. 确定
  445. </NButton>
  446. <NButton round onClick={() => (forms.removeVisiable1 = false)}>
  447. 取消
  448. </NButton>
  449. </NSpace>
  450. </div>
  451. </NModal>
  452. </div>
  453. );
  454. }
  455. });