123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- import MHeader from '@/components/m-header';
- import MSticky from '@/components/m-sticky';
- import { defineComponent, onMounted, reactive } from 'vue';
- import styles from './index.module.less';
- import { useRoute, useRouter } from 'vue-router';
- import { Button, Collapse, CollapseItem, Image, showToast } from 'vant';
- import request from '@/helpers/request';
- import library1 from './images/library-1.png';
- import library2 from './images/library-2.png';
- import library3 from './images/library-3.png';
- import { useEventListener, useWindowScroll } from '@vueuse/core';
- export default defineComponent({
- name: 'knowledge-ligrary',
- setup() {
- const router = useRouter();
- const route = useRoute();
- const forms = reactive({
- cid: route.query.cid,
- list: [] as any,
- activeNames: null,
- background: 'transparent',
- color: '#fff'
- });
- const getList = async () => {
- try {
- const { data } = await request.post(
- '/edu-app/lessonCourseware/queryStudentLessonDetail',
- {
- requestType: 'form',
- data: {
- lessonCoursewareId: forms.cid
- }
- }
- );
- forms.list = data;
- if (data && data.length > 0) {
- forms.activeNames = data[0].lessonCoursewareDetailId;
- }
- } catch {
- //
- }
- };
- const getBg = (index: number) => {
- if (index % 3 === 1) {
- return library1;
- } else if (index % 3 === 2) {
- return library2;
- } else if (index % 3 === 0) {
- return library3;
- }
- };
- // 练习模式
- const onGotoModel = async (type: string) => {
- try {
- const { data } = await request.get(
- '/edu-app/studentUnitExamination/checkKnowledgePointIds',
- {
- params: {
- lessonCoursewareId: forms.cid
- }
- }
- );
- if (!data) {
- setTimeout(() => {
- showToast('暂无题目');
- }, 100);
- return;
- }
- if (type === 'TEST') {
- // 模拟测试
- router.push({
- path: '/examination-mode',
- query: { lessonCoursewareId: forms.cid }
- });
- } else {
- router.push({
- path: '/practice-mode',
- query: { lessonCoursewareId: forms.cid }
- });
- }
- } catch {
- //
- }
- };
- onMounted(() => {
- useEventListener(document, 'scroll', () => {
- const { y } = useWindowScroll();
- if (y.value > 52) {
- forms.background = '#fff';
- forms.color = '#323333';
- } else {
- forms.background = 'transparent';
- forms.color = '#fff';
- }
- });
- getList();
- });
- return () => (
- <div class={styles.knowledgeLibrary}>
- <MSticky position="top">
- <MHeader
- border={false}
- background={forms.background}
- color={forms.color}>
- {{
- right: () => (
- <div
- class={[styles.wroingBtn]}
- onClick={() => router.push('/wroing-book')}>
- <i class={styles.iconWroing}></i>错题本
- </div>
- )
- }}
- </MHeader>
- </MSticky>
- <div class={styles.btnGroup}>
- <Button
- class={styles.btnPractice}
- round
- onClick={() => onGotoModel('PRACTICE')}></Button>
- <Button
- class={styles.btnTest}
- round
- onClick={() => onGotoModel('TEST')}></Button>
- </div>
- <div class={[styles.containerSection, styles.librarySection]}>
- <Collapse v-model={forms.activeNames} accordion border={false}>
- {forms.list.map((item: any) => (
- <CollapseItem
- title={item.lessonCoursewareDetailName}
- name={item.lessonCoursewareDetailId}
- value={forms.activeNames === 1 ? '收起' : '展开'}
- border={false}>
- {item.knowledgeDetails &&
- item.knowledgeDetails.map((detail: any, index: number) => (
- <div
- class={styles.unitItem}
- onClick={() =>
- router.push({
- path: '/unit-detail',
- query: {
- detailId: detail.lessonCoursewareKnowledgeDetailId
- }
- })
- }>
- <Image
- class={styles.unitImg}
- lazyLoad
- src={getBg(index)}
- />
- <p class={styles.name}>
- <span>{detail.name}</span>
- </p>
- </div>
- ))}
- </CollapseItem>
- ))}
- </Collapse>
- </div>
- </div>
- );
- }
- });
|