index.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import MHeader from '@/components/m-header';
  2. import MSticky from '@/components/m-sticky';
  3. import { defineComponent, onMounted, reactive, ref } from 'vue';
  4. import styles from './index.module.less';
  5. import { useRouter } from 'vue-router';
  6. import {
  7. Button,
  8. Cell,
  9. CellGroup,
  10. Checkbox,
  11. CheckboxGroup,
  12. Image,
  13. showToast
  14. } from 'vant';
  15. import iconBook from './images/icon-book.png';
  16. import request from '@/helpers/request';
  17. import MEmpty from '@/components/m-empty';
  18. export default defineComponent({
  19. name: 'wroing-book',
  20. setup() {
  21. const router = useRouter();
  22. const checkboxRefs = ref([] as any);
  23. const forms = reactive({
  24. list: [] as any,
  25. checked: [] as any
  26. });
  27. const getList = async () => {
  28. try {
  29. const { data } = await request.post(
  30. '/edu-app/knowledgePoint/studentPage'
  31. );
  32. forms.list = data || [];
  33. } catch {
  34. //
  35. }
  36. };
  37. const checkboxToggle = (index: number) => {
  38. checkboxRefs.value[index].toggle();
  39. };
  40. const onSubmit = () => {
  41. try {
  42. console.log(forms.checked);
  43. if (forms.checked.length <= 0) {
  44. showToast('请选择练习知识点');
  45. return;
  46. }
  47. router.push({
  48. path: '/examination-mode',
  49. query: {
  50. type: 'ai',
  51. knowledgePointIds: forms.checked.join(',')
  52. }
  53. });
  54. } catch {
  55. //
  56. }
  57. };
  58. onMounted(() => {
  59. getList();
  60. });
  61. return () => (
  62. <div class={styles.woringBook}>
  63. <MSticky position="top">
  64. <MHeader border={false} background="transparent">
  65. {{
  66. content: () => (
  67. <div class={styles.woringHeader}>
  68. <i
  69. onClick={() => router.back()}
  70. class={[
  71. 'van-badge__wrapper van-icon van-icon-arrow-left van-nav-bar__arrow',
  72. styles.leftArrow
  73. ]}></i>
  74. <span class={styles.title}>
  75. <i></i>
  76. </span>
  77. </div>
  78. )
  79. }}
  80. </MHeader>
  81. </MSticky>
  82. <div class={styles.woringSecgtion}>
  83. <div class={styles.title}>请选择练习知识点</div>
  84. <CellGroup border={false}>
  85. <CheckboxGroup v-model={forms.checked}>
  86. {forms.list.map((item: any, index: number) => (
  87. <Cell
  88. center
  89. onClick={() => checkboxToggle(index)}
  90. class={styles.cell}>
  91. {{
  92. icon: () => <Image src={iconBook} class={styles.iconImg} />,
  93. title: () => (
  94. <div class={styles.cellTitle}>{item.name}</div>
  95. ),
  96. label: () => (
  97. <p class={styles.cellContent}>
  98. <span>{item.questionNum}</span>道错题
  99. </p>
  100. ),
  101. 'right-icon': () => (
  102. <Checkbox
  103. name={item.pointId}
  104. ref={el => (checkboxRefs.value[index] = el)}
  105. onClick={(e: MouseEvent) => e.stopPropagation()}
  106. />
  107. )
  108. }}
  109. </Cell>
  110. ))}
  111. </CheckboxGroup>
  112. {forms.list.length <= 0 && (
  113. <div class={styles.emptyContainer}>
  114. <MEmpty />
  115. </div>
  116. )}
  117. </CellGroup>
  118. </div>
  119. <MSticky position="bottom" varName="--bottom-height">
  120. <div class={'btnGroup'}>
  121. <Button round block type="primary" onClick={onSubmit}>
  122. 确认
  123. </Button>
  124. </div>
  125. </MSticky>
  126. </div>
  127. );
  128. }
  129. });