index.tsx 5.2 KB

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