index.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import MHeader from '@/components/m-header';
  2. import MSticky from '@/components/m-sticky';
  3. import { defineComponent, onMounted, reactive } from 'vue';
  4. import styles from './index.module.less';
  5. import { useRoute, useRouter } from 'vue-router';
  6. import { Button, Collapse, CollapseItem, Image, showToast } from 'vant';
  7. import request from '@/helpers/request';
  8. import library1 from './images/library-1.png';
  9. import library2 from './images/library-2.png';
  10. import library3 from './images/library-3.png';
  11. import { useEventListener, useWindowScroll } from '@vueuse/core';
  12. export default defineComponent({
  13. name: 'knowledge-ligrary',
  14. setup() {
  15. const router = useRouter();
  16. const route = useRoute();
  17. const forms = reactive({
  18. cid: route.query.cid,
  19. list: [] as any,
  20. activeNames: null,
  21. background: 'transparent',
  22. color: '#fff'
  23. });
  24. const getList = async () => {
  25. try {
  26. const { data } = await request.post(
  27. '/edu-app/lessonCourseware/queryStudentLessonDetail',
  28. {
  29. requestType: 'form',
  30. data: {
  31. lessonCoursewareId: forms.cid
  32. }
  33. }
  34. );
  35. forms.list = data;
  36. if (data && data.length > 0) {
  37. forms.activeNames = data[0].lessonCoursewareDetailId;
  38. }
  39. } catch {
  40. //
  41. }
  42. };
  43. const getBg = (index: number) => {
  44. if (index % 3 === 1) {
  45. return library1;
  46. } else if (index % 3 === 2) {
  47. return library2;
  48. } else if (index % 3 === 0) {
  49. return library3;
  50. }
  51. };
  52. // 练习模式
  53. const onGotoModel = async (type: string) => {
  54. try {
  55. const { data } = await request.get(
  56. '/edu-app/studentUnitExamination/checkKnowledgePointIds',
  57. {
  58. params: {
  59. lessonCoursewareId: forms.cid
  60. }
  61. }
  62. );
  63. if (!data) {
  64. setTimeout(() => {
  65. showToast('暂无题目');
  66. }, 100);
  67. return;
  68. }
  69. if (type === 'TEST') {
  70. // 模拟测试
  71. router.push({
  72. path: '/examination-mode',
  73. query: { lessonCoursewareId: forms.cid }
  74. });
  75. } else {
  76. router.push({
  77. path: '/practice-mode',
  78. query: { lessonCoursewareId: forms.cid }
  79. });
  80. }
  81. } catch {
  82. //
  83. }
  84. };
  85. onMounted(() => {
  86. useEventListener(document, 'scroll', () => {
  87. const { y } = useWindowScroll();
  88. if (y.value > 52) {
  89. forms.background = '#fff';
  90. forms.color = '#323333';
  91. } else {
  92. forms.background = 'transparent';
  93. forms.color = '#fff';
  94. }
  95. });
  96. getList();
  97. });
  98. return () => (
  99. <div class={styles.knowledgeLibrary}>
  100. <MSticky position="top">
  101. <MHeader
  102. border={false}
  103. background={forms.background}
  104. color={forms.color}>
  105. {{
  106. right: () => (
  107. <div
  108. class={[styles.wroingBtn]}
  109. onClick={() => router.push('/wroing-book')}>
  110. <i class={styles.iconWroing}></i>错题本
  111. </div>
  112. )
  113. }}
  114. </MHeader>
  115. </MSticky>
  116. <div class={styles.btnGroup}>
  117. <Button
  118. class={styles.btnPractice}
  119. round
  120. onClick={() => onGotoModel('PRACTICE')}></Button>
  121. <Button
  122. class={styles.btnTest}
  123. round
  124. onClick={() => onGotoModel('TEST')}></Button>
  125. </div>
  126. <div class={[styles.containerSection, styles.librarySection]}>
  127. <Collapse v-model={forms.activeNames} accordion border={false}>
  128. {forms.list.map((item: any) => (
  129. <CollapseItem
  130. title={item.lessonCoursewareDetailName}
  131. name={item.lessonCoursewareDetailId}
  132. value={forms.activeNames === 1 ? '收起' : '展开'}
  133. border={false}>
  134. {item.knowledgeDetails &&
  135. item.knowledgeDetails.map((detail: any, index: number) => (
  136. <div
  137. class={styles.unitItem}
  138. onClick={() =>
  139. router.push({
  140. path: '/unit-detail',
  141. query: {
  142. detailId: detail.lessonCoursewareKnowledgeDetailId
  143. }
  144. })
  145. }>
  146. <Image
  147. class={styles.unitImg}
  148. lazyLoad
  149. src={getBg(index)}
  150. />
  151. <p class={styles.name}>
  152. <span>{detail.name}</span>
  153. </p>
  154. </div>
  155. ))}
  156. </CollapseItem>
  157. ))}
  158. </Collapse>
  159. </div>
  160. </div>
  161. );
  162. }
  163. });