index.tsx 5.0 KB

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