unit-detail.tsx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. import MHeader from '@/components/m-header';
  2. import MSticky from '@/components/m-sticky';
  3. import {
  4. computed,
  5. defineComponent,
  6. onMounted,
  7. reactive,
  8. ref,
  9. watch
  10. } from 'vue';
  11. import styles from './index.module.less';
  12. import { useRoute } from 'vue-router';
  13. import request from '@/helpers/request';
  14. import { useEventListener, useWindowScroll } from '@vueuse/core';
  15. import MEmpty from '@/components/m-empty';
  16. import { Button } from 'vant';
  17. import { browser } from '@/helpers/utils';
  18. export default defineComponent({
  19. name: 'unit-detail',
  20. setup() {
  21. const route = useRoute();
  22. const forms = reactive({
  23. detailId: route.query.detailId,
  24. loading: false,
  25. background: 'transparent',
  26. color: '#fff',
  27. dataInfo: {} as any,
  28. title: ' ',
  29. listKnowledge: [] as any,
  30. prevDetailId: '',
  31. nextDetailId: ''
  32. });
  33. const getList = async () => {
  34. forms.loading = true;
  35. try {
  36. const { data } = await request.get(
  37. '/edu-app/lessonCoursewareKnowledgeDetail/detail/' + forms.detailId
  38. );
  39. forms.dataInfo = data;
  40. forms.title = data.name;
  41. } catch {
  42. //
  43. }
  44. forms.loading = false;
  45. };
  46. const getPointList = async () => {
  47. try {
  48. const params: any = {
  49. lessonCoursewareId: route.query.lessonCoursewareId
  50. };
  51. if (browser().ios) {
  52. params.platform = 'iOS-STUDENT';
  53. params.verson = route.query.verson || '1.0.8';
  54. }
  55. const { data } = await request.post(
  56. '/edu-app/lessonCoursewareDetail/listKnowledge',
  57. {
  58. data: params
  59. }
  60. );
  61. forms.listKnowledge = data || [];
  62. } catch {
  63. //
  64. }
  65. };
  66. const upDisabled = computed(() => {
  67. const listKnowledge = forms.listKnowledge || [];
  68. let parentIndex = listKnowledge.findIndex(
  69. (item: any) => item.id === forms.dataInfo?.lessonCoursewareDetailId
  70. );
  71. const parentItem = listKnowledge.find(
  72. (item: any) => item.id === forms.dataInfo?.lessonCoursewareDetailId
  73. );
  74. if (!parentItem) {
  75. return true;
  76. }
  77. let detailIndex =
  78. parentItem?.lessonCoursewareDetailKnowledgeDetailList?.findIndex(
  79. (item: any) => item.id == forms.detailId
  80. );
  81. let lessonStatus = false; // 当前章节上面是否有内容
  82. let lessonCoursewareDetailId = '';
  83. while (detailIndex >= 0) {
  84. detailIndex--;
  85. if (detailIndex >= 0) {
  86. const tempItem =
  87. parentItem?.lessonCoursewareDetailKnowledgeDetailList?.[
  88. detailIndex
  89. ];
  90. if (tempItem.id) {
  91. lessonStatus = true;
  92. lessonCoursewareDetailId = tempItem.id;
  93. }
  94. }
  95. if (lessonStatus) {
  96. break;
  97. }
  98. }
  99. // 判断当前章节上面课程是否有内容,否则往上一个章节走
  100. if (lessonStatus) {
  101. forms.prevDetailId = lessonCoursewareDetailId;
  102. return false;
  103. }
  104. let prevLessonStatus = false;
  105. while (parentIndex >= 0) {
  106. parentIndex--;
  107. const tempDetail =
  108. listKnowledge[parentIndex]
  109. ?.lessonCoursewareDetailKnowledgeDetailList || [];
  110. let tempLessonLength = tempDetail.length;
  111. while (tempLessonLength > 0) {
  112. if (tempDetail[tempLessonLength - 1]) {
  113. prevLessonStatus = true;
  114. lessonCoursewareDetailId = tempDetail[tempLessonLength - 1].id;
  115. }
  116. tempLessonLength--;
  117. if (prevLessonStatus) {
  118. break;
  119. }
  120. }
  121. if (prevLessonStatus) {
  122. break;
  123. }
  124. }
  125. if (prevLessonStatus) {
  126. forms.prevDetailId = lessonCoursewareDetailId;
  127. }
  128. return !prevLessonStatus;
  129. });
  130. const downDisabled = computed(() => {
  131. const listKnowledge = forms.listKnowledge || [];
  132. let parentIndex = listKnowledge.findIndex(
  133. (item: any) => item.id === forms.dataInfo?.lessonCoursewareDetailId
  134. );
  135. const parentItem = listKnowledge.find(
  136. (item: any) => item.id === forms.dataInfo?.lessonCoursewareDetailId
  137. );
  138. if (!parentItem) {
  139. return true;
  140. }
  141. let detailIndex =
  142. parentItem?.lessonCoursewareDetailKnowledgeDetailList?.findIndex(
  143. (item: any) => item.id == forms.detailId
  144. );
  145. let lessonStatus = false; // 当前章节上面是否有内容
  146. let lessonCoursewareDetailId = '';
  147. while (
  148. detailIndex <
  149. parentItem?.lessonCoursewareDetailKnowledgeDetailList.length - 1
  150. ) {
  151. detailIndex++;
  152. if (detailIndex >= 0) {
  153. const tempItem =
  154. parentItem?.lessonCoursewareDetailKnowledgeDetailList?.[
  155. detailIndex
  156. ];
  157. if (tempItem.id) {
  158. lessonStatus = true;
  159. lessonCoursewareDetailId = tempItem.id;
  160. }
  161. }
  162. if (lessonStatus) {
  163. break;
  164. }
  165. }
  166. // 判断当前章节上面课程是否有内容,否则往上一个章节走
  167. if (lessonStatus) {
  168. forms.nextDetailId = lessonCoursewareDetailId;
  169. return false;
  170. }
  171. let nextLessonStatus = false;
  172. while (parentIndex <= listKnowledge.length - 1) {
  173. parentIndex++;
  174. const tempDetail =
  175. listKnowledge[parentIndex]
  176. ?.lessonCoursewareDetailKnowledgeDetailList || [];
  177. let tempLessonLength = 0;
  178. while (tempLessonLength <= tempDetail.length - 1) {
  179. if (tempDetail[tempLessonLength]) {
  180. nextLessonStatus = true;
  181. lessonCoursewareDetailId = tempDetail[tempLessonLength].id;
  182. }
  183. tempLessonLength++;
  184. if (nextLessonStatus) {
  185. break;
  186. }
  187. }
  188. if (nextLessonStatus) {
  189. break;
  190. }
  191. }
  192. if (nextLessonStatus) {
  193. forms.nextDetailId = lessonCoursewareDetailId;
  194. }
  195. return !nextLessonStatus;
  196. });
  197. // 切换
  198. const handleChanage = async (type: string) => {
  199. if (type === 'up') {
  200. forms.detailId = forms.prevDetailId;
  201. await getList();
  202. } else if (type === 'down') {
  203. forms.detailId = forms.nextDetailId;
  204. await getList();
  205. }
  206. };
  207. onMounted(async () => {
  208. useEventListener(document, 'scroll', () => {
  209. const { y } = useWindowScroll();
  210. if (y.value > 52) {
  211. forms.background = '#fff';
  212. forms.color = '#323333';
  213. } else {
  214. forms.background = 'transparent';
  215. forms.color = '#fff';
  216. }
  217. });
  218. // __initMove();
  219. await getList();
  220. await getPointList();
  221. });
  222. return () => (
  223. <div class={styles.knowledgeLibrary}>
  224. <MSticky position="top">
  225. <MHeader
  226. border={false}
  227. background={forms.background}
  228. color={forms.color}
  229. title={forms.title}></MHeader>
  230. </MSticky>
  231. <div class={[styles.containerSection, styles.woringSection]}>
  232. {forms.dataInfo?.desc && (
  233. <div
  234. class={styles.woringContent}
  235. v-html={forms.dataInfo.desc}></div>
  236. )}
  237. {!forms.dataInfo?.desc && !forms.loading && (
  238. <div class={styles.woringContent}>
  239. <MEmpty description="暂无内容" style={{ paddingTop: '40px' }} />
  240. </div>
  241. )}
  242. </div>
  243. <MSticky position="bottom">
  244. <div class={[styles.stickBtnGroup]}>
  245. <Button
  246. round
  247. class={styles.prevBtn}
  248. disabled={upDisabled.value}
  249. onClick={() => handleChanage('up')}></Button>
  250. <Button
  251. round
  252. disabled={downDisabled.value}
  253. class={styles.nextBtn}
  254. onClick={() => handleChanage('down')}></Button>
  255. </div>
  256. </MSticky>
  257. </div>
  258. );
  259. }
  260. });