index.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. }}
  265. />
  266. </div>
  267. <NButton
  268. type="default"
  269. onClick={() => {
  270. forms.drag = true;
  271. prepareStore.setIsEditTrain(true);
  272. }}>
  273. 编辑
  274. </NButton>
  275. </NSpace>
  276. )}
  277. <NSpace>
  278. <NButton
  279. type="primary"
  280. {...{ id: 'train-0' }}
  281. disabled={forms.drag}
  282. onClick={() => {
  283. let count = 0;
  284. forms.trainList.forEach((item: any) => {
  285. if (!item.removeFlag) {
  286. count++;
  287. }
  288. });
  289. if (count <= 0) {
  290. message.error('作业内容不能为空');
  291. return;
  292. }
  293. forms.assignHomeworkStatus = true;
  294. }}>
  295. 布置作业
  296. </NButton>
  297. </NSpace>
  298. </div>
  299. <NScrollbar class={styles.listContainer}>
  300. <NSpin show={forms.loadingStatus}>
  301. <div
  302. class={[
  303. styles.listSection,
  304. !forms.loadingStatus && prepareStore.getTrainList.length <= 0
  305. ? styles.emptySection
  306. : ''
  307. ]}>
  308. {forms.trainList.length > 0 && (
  309. <>
  310. {forms.drag ? (
  311. <Draggable
  312. v-model:modelValue={forms.trainList}
  313. itemKey="id"
  314. // tag="transition-group"
  315. componentData={{
  316. itemKey: 'id',
  317. tag: 'div',
  318. animation: 200,
  319. group: 'description',
  320. disabled: false
  321. }}
  322. class={styles.list}>
  323. {{
  324. item: (element: any) => {
  325. const item = element.element;
  326. return (
  327. <div data-id={item.id} class={styles.itemBlock}>
  328. <TrainType
  329. item={item}
  330. isDelete
  331. type="prepare"
  332. onDelete={(child: any) => onDelete(child)}
  333. offShelf={item.removeFlag ? true : false}
  334. onOffShelf={() => onRemove(item)}
  335. />
  336. </div>
  337. );
  338. }
  339. }}
  340. </Draggable>
  341. ) : (
  342. <div class={styles.list}>
  343. {forms.trainList.map((item: any) => (
  344. <TrainType
  345. item={item}
  346. type="prepare"
  347. offShelf={item.removeFlag ? true : false}
  348. onOffShelf={() => onRemove(item)}
  349. onEdit={(child: any) => {
  350. console.log('edit', child);
  351. const { trainingConfigJson, id, musicId, ...res } =
  352. child;
  353. forms.editItem = {
  354. ...res,
  355. id: musicId,
  356. trainId: id,
  357. ...trainingConfigJson
  358. };
  359. forms.editStatus = true;
  360. }}
  361. />
  362. ))}
  363. </div>
  364. )}
  365. </>
  366. )}
  367. {!forms.loadingStatus &&
  368. prepareStore.getTrainList.length <= 0 && (
  369. <TheEmpty description="暂无作业" />
  370. )}
  371. </div>
  372. </NSpin>
  373. </NScrollbar>
  374. {/* 编辑 */}
  375. <NModal
  376. v-model:show={forms.editStatus}
  377. class={['modalTitle background', styles.trainEditModal]}
  378. preset="card"
  379. title="作业设置">
  380. <TrainUpdate
  381. item={forms.editItem}
  382. onClose={() => (forms.editStatus = false)}
  383. onConfirm={() => {
  384. forms.editItem = {};
  385. prepareStore.setIsAddTrain(true);
  386. }}
  387. />
  388. </NModal>
  389. {/* 添加自定义教材 */}
  390. <NModal
  391. v-model:show={forms.assignHomeworkStatus}
  392. preset="card"
  393. showIcon={false}
  394. class={['modalTitle background', styles.assignHomework]}
  395. title={'布置作业'}
  396. blockScroll={false}>
  397. <AssignHomework
  398. trainList={forms.trainList}
  399. onClose={() => (forms.assignHomeworkStatus = false)}
  400. />
  401. </NModal>
  402. {showGuide.value ? <Trainguide></Trainguide> : null}
  403. <NModal
  404. v-model:show={forms.removeVisiable}
  405. preset="card"
  406. class={['modalTitle', styles.removeVisiable]}
  407. title={'提示'}>
  408. <div class={styles.studentRemove}>
  409. <p>是否完成编辑?</p>
  410. <NSpace class={styles.btnGroupModal} justify="center">
  411. <NButton round type="primary" onClick={onOverEdit}>
  412. 确定
  413. </NButton>
  414. <NButton round onClick={() => (forms.removeVisiable = false)}>
  415. 取消
  416. </NButton>
  417. </NSpace>
  418. </div>
  419. </NModal>
  420. <NModal
  421. v-model:show={forms.removeVisiable1}
  422. preset="card"
  423. class={['modalTitle', styles.removeVisiable1]}
  424. title={'清空资源'}>
  425. <div class={styles.studentRemove}>
  426. <p>
  427. 请确认是否要清空作业?
  428. <span>点击确认后所有的作业内容 将被清空掉。</span>
  429. </p>
  430. <NSpace class={styles.btnGroupModal} justify="center">
  431. <NButton
  432. round
  433. type="primary"
  434. onClick={() => {
  435. forms.trainList.forEach((item: any) => {
  436. forms.removeIds.push(item.id);
  437. });
  438. forms.trainList = [];
  439. forms.removeVisiable1 = false;
  440. // prepareStore.setCoursewareList([]);
  441. console.log(prepareStore.getTrainList, 'getCourseware1');
  442. }}>
  443. 确定
  444. </NButton>
  445. <NButton round onClick={() => (forms.removeVisiable1 = false)}>
  446. 取消
  447. </NButton>
  448. </NSpace>
  449. </div>
  450. </NModal>
  451. </div>
  452. );
  453. }
  454. });