index.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import {
  2. ActionSheet,
  3. Button,
  4. Cell,
  5. CountDown,
  6. Icon,
  7. Image,
  8. Popup,
  9. Swipe,
  10. SwipeItem,
  11. Tag
  12. } from 'vant'
  13. import { defineComponent, onMounted, reactive, ref } from 'vue'
  14. import { useRoute, useRouter } from 'vue-router'
  15. import NoticeStart from '../model/notice-start'
  16. import styles from './index.module.less'
  17. import iconQuestionNums from '../images/icon-question-nums.png'
  18. import iconCountDown from '../images/icon-count-down.png'
  19. import iconButtonList from '../images/icon-button-list.png'
  20. import OSticky from '@/components/o-sticky'
  21. import ChoiceQuestion from '../model/choice-question'
  22. import AnswerList from '../model/answer-list'
  23. import ODialog from '@/components/o-dialog'
  24. import DragQuestion from '../model/drag-question'
  25. import KeepLookQuestion from '../model/keep-look-question'
  26. import PlayQuestion from '../model/play-question'
  27. export default defineComponent({
  28. name: 'unit-detail',
  29. setup() {
  30. const route = useRoute()
  31. const router = useRouter()
  32. const countDownRef = ref()
  33. const swipeRef = ref()
  34. const state = reactive({
  35. visiableAnswer: false,
  36. currentIndex: 0,
  37. questionList: [5],
  38. answerList: {},
  39. time: 30 * 60 * 1000,
  40. visiableSure: false,
  41. childs: [
  42. { name: 'John', id: 0 },
  43. { name: 'Joao', id: 1 },
  44. { name: 'Jean', id: 2 }
  45. ]
  46. })
  47. return () => (
  48. <div class={styles.unitDetail}>
  49. <Cell center class={styles.unitSection}>
  50. {{
  51. title: () => <div class={styles.unitTitle}>长笛level1上册测验一</div>,
  52. label: () => (
  53. <div class={styles.unitCount}>
  54. <div class={styles.qNums}>
  55. <Icon class={styles.icon} name={iconQuestionNums} />
  56. 题目数量 <span class={styles.num}>1</span>/4
  57. </div>
  58. <div class={styles.qNums}>
  59. <Icon class={styles.icon} name={iconCountDown} />
  60. 剩余时长:
  61. <CountDown
  62. ref={countDownRef}
  63. time={state.time}
  64. format={'mm:ss'}
  65. autoStart={false}
  66. />
  67. </div>
  68. </div>
  69. )
  70. }}
  71. </Cell>
  72. <Swipe
  73. loop={false}
  74. showIndicators={false}
  75. ref={swipeRef}
  76. duration={300}
  77. touchable={false}
  78. lazyRender
  79. // initialSwipe={state.currentIndex}
  80. onChange={(index: number) => {
  81. state.currentIndex = index
  82. }}
  83. >
  84. <SwipeItem>
  85. <ChoiceQuestion v-model:value={state.answerList[0]} type="checkbox" />
  86. </SwipeItem>
  87. <SwipeItem>
  88. <ChoiceQuestion v-model:value={state.answerList[1]} type="radio" />
  89. </SwipeItem>
  90. <SwipeItem>
  91. <DragQuestion />
  92. </SwipeItem>
  93. <SwipeItem>
  94. <KeepLookQuestion />
  95. </SwipeItem>
  96. <SwipeItem>
  97. <PlayQuestion />
  98. </SwipeItem>
  99. </Swipe>
  100. <OSticky position="bottom" background="white">
  101. <div class={['btnGroup btnMore']}>
  102. {state.currentIndex > 0 && (
  103. <Button
  104. round
  105. block
  106. type="primary"
  107. plain
  108. onClick={() => {
  109. swipeRef.value?.prev()
  110. }}
  111. >
  112. 上一题
  113. </Button>
  114. )}
  115. <Button
  116. block
  117. round
  118. type="primary"
  119. onClick={() => {
  120. // if (state.questionList.length - 1 === state.currentIndex) {
  121. // state.visiableSure = true
  122. // } else {
  123. swipeRef.value?.next()
  124. // }
  125. }}
  126. >
  127. 下一题
  128. {/* {state.questionList.length === state.currentIndex + 1 ? '测试完成' : '下一题'} */}
  129. </Button>
  130. <Image
  131. src={iconButtonList}
  132. class={[styles.wapList, 'van-haptics-feedback']}
  133. onClick={() => (state.visiableAnswer = true)}
  134. />
  135. </div>
  136. </OSticky>
  137. {/* 题目集合 */}
  138. <ActionSheet v-model:show={state.visiableAnswer} title="题目列表" safeAreaInsetBottom>
  139. <AnswerList
  140. value={[1, 3, 4]}
  141. onSelect={(item: any) => {
  142. // 跳转,并且跳过动画
  143. swipeRef.value?.swipeTo(item, {
  144. immediate: true
  145. })
  146. state.visiableAnswer = false
  147. }}
  148. />
  149. </ActionSheet>
  150. <ODialog
  151. v-model:show={state.visiableSure}
  152. title="测验完成"
  153. message="确认本次测验的题目都完成了吗?\n提交后不可修改哦"
  154. messageAlign="left"
  155. showCancelButton
  156. cancelButtonText="再等等"
  157. confirmButtonText="确认完成"
  158. />
  159. </div>
  160. )
  161. }
  162. })