index.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 styles from './index.module.less'
  16. import iconQuestionNums from '../images/icon-question-nums.png'
  17. import iconCountDown from '../images/icon-count-down.png'
  18. import iconButtonList from '../images/icon-button-list.png'
  19. import OSticky from '@/components/o-sticky'
  20. import ChoiceQuestion from '../model/choice-question'
  21. import AnswerList from '../model/answer-list'
  22. import ODialog from '@/components/o-dialog'
  23. import DragQuestion from '../model/drag-question'
  24. import KeepLookQuestion from '../model/keep-look-question'
  25. import PlayQuestion from '../model/play-question'
  26. import ErrorMode from '../model/error-mode'
  27. import ResultFinish from '../model/result-finish'
  28. export default defineComponent({
  29. name: 'unit-detail',
  30. setup() {
  31. const route = useRoute()
  32. const router = useRouter()
  33. const countDownRef = ref()
  34. const swipeRef = ref()
  35. const state = reactive({
  36. visiableError: false,
  37. visiableAnswer: false,
  38. visiableResult: false,
  39. currentIndex: 0,
  40. questionList: [1, 2, 3, 4, 5],
  41. answerList: {},
  42. time: 30 * 60 * 1000,
  43. visiableSure: false,
  44. childs: [
  45. { name: 'John', id: 0 },
  46. { name: 'Joao', id: 1 },
  47. { name: 'Jean', id: 2 }
  48. ]
  49. })
  50. return () => (
  51. <div class={styles.unitDetail}>
  52. <Cell center class={styles.unitSection}>
  53. {{
  54. title: () => <div class={styles.unitTitle}>长笛level1上册测验一</div>,
  55. label: () => (
  56. <div class={styles.unitCount}>
  57. <div class={styles.qNums}>
  58. <Icon class={styles.icon} name={iconQuestionNums} />
  59. 题目数量 <span class={styles.num}>1</span>/4
  60. </div>
  61. <div class={styles.qNums}>
  62. <Icon class={styles.icon} name={iconCountDown} />
  63. 剩余时长:
  64. <CountDown
  65. ref={countDownRef}
  66. time={state.time}
  67. format={'mm:ss'}
  68. autoStart={false}
  69. />
  70. </div>
  71. </div>
  72. )
  73. }}
  74. </Cell>
  75. <Swipe
  76. loop={false}
  77. showIndicators={false}
  78. ref={swipeRef}
  79. duration={300}
  80. touchable={false}
  81. lazyRender
  82. // initialSwipe={state.currentIndex}
  83. onChange={(index: number) => {
  84. state.currentIndex = index
  85. }}
  86. >
  87. <SwipeItem>
  88. <ChoiceQuestion v-model:value={state.answerList[0]} type="checkbox" />
  89. </SwipeItem>
  90. <SwipeItem>
  91. <ChoiceQuestion v-model:value={state.answerList[1]} type="radio" />
  92. </SwipeItem>
  93. <SwipeItem>
  94. <DragQuestion />
  95. </SwipeItem>
  96. <SwipeItem>
  97. <KeepLookQuestion />
  98. </SwipeItem>
  99. <SwipeItem>
  100. <PlayQuestion />
  101. </SwipeItem>
  102. </Swipe>
  103. <OSticky position="bottom" background="white">
  104. <div class={['btnGroup btnMore']}>
  105. {state.currentIndex > 0 && (
  106. <Button
  107. round
  108. block
  109. type="primary"
  110. plain
  111. onClick={() => {
  112. swipeRef.value?.prev()
  113. }}
  114. >
  115. 上一题
  116. </Button>
  117. )}
  118. <Button
  119. block
  120. round
  121. type="primary"
  122. onClick={() => {
  123. if (state.questionList.length - 1 === state.currentIndex) {
  124. state.visiableSure = true
  125. } else {
  126. // swipeRef.value?.next()
  127. state.visiableError = true
  128. }
  129. }}
  130. >
  131. {state.questionList.length - 1 === state.currentIndex ? '测验完成' : '下一题'}
  132. </Button>
  133. <Image
  134. src={iconButtonList}
  135. class={[styles.wapList, 'van-haptics-feedback']}
  136. onClick={() => (state.visiableAnswer = true)}
  137. />
  138. </div>
  139. </OSticky>
  140. {/* 题目集合 */}
  141. <ActionSheet v-model:show={state.visiableAnswer} title="题目列表" safeAreaInsetBottom>
  142. <AnswerList
  143. value={[1, 3, 4]}
  144. statusList={[
  145. {
  146. text: '答对',
  147. color: '#71B0FF'
  148. },
  149. {
  150. text: '答错',
  151. color: '#FF8486'
  152. }
  153. ]}
  154. onSelect={(item: any) => {
  155. // 跳转,并且跳过动画
  156. swipeRef.value?.swipeTo(item, {
  157. immediate: true
  158. })
  159. state.visiableAnswer = false
  160. }}
  161. />
  162. </ActionSheet>
  163. <Popup
  164. v-model:show={state.visiableError}
  165. style={{ width: '90%' }}
  166. round
  167. closeOnClickOverlay={false}
  168. >
  169. <ErrorMode
  170. onClose={() => (state.visiableError = false)}
  171. onConform={() => {
  172. swipeRef.value?.next()
  173. }}
  174. />
  175. </Popup>
  176. <Popup
  177. v-model:show={state.visiableResult}
  178. closeOnClickOverlay={false}
  179. style={{ background: 'transparent', width: '96%' }}
  180. >
  181. <ResultFinish
  182. // status="FAIL"
  183. confirmButtonText="继续练习本考点"
  184. cancelButtonText="下一个考点"
  185. onClose={() => (state.visiableResult = false)}
  186. onConform={() => {
  187. console.log('Success')
  188. state.visiableResult = false
  189. }}
  190. />
  191. </Popup>
  192. <ODialog
  193. v-model:show={state.visiableSure}
  194. title="测验完成"
  195. message="确认本次测验的题目都完成了吗?\n提交后不可修改哦"
  196. messageAlign="left"
  197. showCancelButton
  198. cancelButtonText="再等等"
  199. confirmButtonText="确认完成"
  200. onConfirm={() => {
  201. state.visiableResult = true
  202. }}
  203. />
  204. </div>
  205. )
  206. }
  207. })