index.tsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. import OEmpty from '@/components/o-empty'
  2. import OHeader from '@/components/o-header'
  3. import OSearch from '@/components/o-search'
  4. import OSticky from '@/components/o-sticky'
  5. import { ActionSheet, Button, Cell, CellGroup, Icon, Image, List, Popup } from 'vant'
  6. import { defineComponent, onMounted, reactive } from 'vue'
  7. import styles from './index.module.less'
  8. import iconEdit from './images/icon-edit.png'
  9. import { useRouter } from 'vue-router'
  10. import request from '@/helpers/request'
  11. import { unitTestStatus } from '@/constant'
  12. import dayjs from 'dayjs'
  13. import NoticeStart from './model/notice-start'
  14. import OFullRefresh from '@/components/o-full-refresh'
  15. export default defineComponent({
  16. name: 'unit-test',
  17. setup() {
  18. const router = useRouter()
  19. const form = reactive({
  20. oPopover: false,
  21. searchList: [] as any,
  22. list: [] as any,
  23. listState: {
  24. dataShow: true, // 判断是否有数据
  25. loading: false,
  26. finished: false,
  27. refreshing: false,
  28. height: 0 // 页面头部高度,为了处理下拉刷新用的
  29. },
  30. statusText: '全部测验',
  31. params: {
  32. keyword: null,
  33. status: null,
  34. page: 1,
  35. rows: 20
  36. },
  37. isClick: false,
  38. visiableNotice: false,
  39. unitExam: {} as any, // 测验详情
  40. selectUnitExam: {} as any
  41. })
  42. const getList = async () => {
  43. try {
  44. if (form.isClick) return
  45. form.isClick = true
  46. const res = await request.post('/api-student/studentUnitExamination/queryPageByStudent', {
  47. data: {
  48. ...form.params
  49. }
  50. })
  51. form.listState.loading = false
  52. form.listState.refreshing = false
  53. const result = res.data || {}
  54. // 处理重复请求数据
  55. if (form.list.length > 0 && result.current === 1) {
  56. return
  57. }
  58. form.list = form.list.concat(result.rows || [])
  59. form.listState.finished = result.current >= result.pages
  60. form.params.page = result.current + 1
  61. form.listState.dataShow = form.list.length > 0
  62. form.isClick = false
  63. } catch {
  64. form.listState.dataShow = false
  65. form.listState.finished = true
  66. form.listState.refreshing = false
  67. form.isClick = false
  68. }
  69. }
  70. const onSearch = () => {
  71. form.params.page = 1
  72. form.list = []
  73. form.listState.dataShow = true // 判断是否有数据
  74. form.listState.loading = false
  75. form.listState.finished = false
  76. getList()
  77. }
  78. // 开始测验
  79. const onUnitTestStart = async (item: any) => {
  80. try {
  81. // 判断是否是继续测验
  82. form.selectUnitExam = item || {}
  83. if (item.status === 'C_ING') {
  84. onExamStart()
  85. }
  86. // 是不是未开始
  87. if (item.status === 'D_NO_SUBMIT') {
  88. const { data } = await request.get('/api-student/unitExamination/detail', {
  89. params: {
  90. unitExaminationId: item.unitExaminationId
  91. }
  92. })
  93. form.unitExam = data || {}
  94. form.visiableNotice = true
  95. }
  96. } catch {
  97. //
  98. }
  99. }
  100. const onExamStart = async () => {
  101. try {
  102. await request.post('/api-student/studentUnitExamination/startExamination', {
  103. requestType: 'form',
  104. data: {
  105. studentUnitExaminationId: form.selectUnitExam.id
  106. }
  107. })
  108. router.push({
  109. path: '/examination-mode',
  110. query: {
  111. id: form.selectUnitExam.id
  112. }
  113. })
  114. } catch {
  115. //
  116. }
  117. }
  118. onMounted(() => {
  119. getList()
  120. const temp: any = [{ name: '全部测验', id: 'ALL' }]
  121. for (const i in unitTestStatus) {
  122. temp.push({
  123. name: unitTestStatus[i],
  124. id: i
  125. })
  126. }
  127. form.searchList = temp
  128. })
  129. return () => (
  130. <div class={styles.unitTest}>
  131. <OSticky
  132. position="top"
  133. onGetHeight={(height: any) => {
  134. form.listState.height = height
  135. }}
  136. >
  137. <OSearch
  138. placeholder="请输入测验名称"
  139. inputBackground="white"
  140. background="#f6f8f9"
  141. onSearch={(val: any) => {
  142. form.params.keyword = val
  143. onSearch()
  144. }}
  145. v-slots={{
  146. left: () => (
  147. <div
  148. class={styles.searchBand}
  149. style={{ marginRight: '13px' }}
  150. onClick={() => (form.oPopover = true)}
  151. >
  152. {form.statusText} <Icon name={form.oPopover ? 'arrow-up' : 'arrow-down'} />
  153. </div>
  154. )
  155. }}
  156. />
  157. </OSticky>
  158. {form.listState.dataShow ? (
  159. <OFullRefresh
  160. v-model:modelValue={form.listState.refreshing}
  161. onRefresh={onSearch}
  162. style={{
  163. minHeight: `calc(100vh - ${form.listState.height}px)`
  164. }}
  165. >
  166. <List
  167. v-model:loading={form.listState.loading}
  168. finished={form.listState.finished}
  169. finishedText=" "
  170. class={[styles.liveList]}
  171. onLoad={getList}
  172. immediateCheck={false}
  173. >
  174. {/* <audio controls>
  175. <source src="horse.mp3" type="audio/mpeg" />
  176. <source src="horse.ogg" type="audio/ogg" />
  177. 您的浏览器不支持该音频格式。
  178. </audio> */}
  179. {form.list.map((item: any) => (
  180. <CellGroup inset class={styles.cellGroup} border={false}>
  181. <Cell center isLink clickable={false}>
  182. {{
  183. icon: () => <Image src={iconEdit} class={styles.img} />,
  184. title: () => (
  185. <span class={[styles.unitTitle, 'van-ellipsis']}>{item.name}</span>
  186. ),
  187. value: () => (
  188. <span
  189. class={[
  190. styles['no-start'],
  191. item.status === 'A_PASS' && styles.pass,
  192. item.status === 'B_NO_PASS' && styles['no-pass']
  193. ]}
  194. >
  195. {unitTestStatus[item.status]}
  196. </span>
  197. )
  198. }}
  199. </Cell>
  200. <Cell center class={styles.unitSection}>
  201. {{
  202. title: () => (
  203. <div class={styles.unitInformation}>
  204. <div class={styles.name}>{item.orchestraName}</div>
  205. <div class={styles.endTime}>
  206. 截止时间:
  207. {dayjs(item.expiryDate || new Date()).format('YYYY-MM-DD HH:mm')}
  208. </div>
  209. <div class={styles.unitBtnGroup}>
  210. <Button
  211. color="#FFF0E6"
  212. round
  213. block
  214. style={{ color: '#F67146' }}
  215. onClick={() => {
  216. router.push('/test-exercise')
  217. }}
  218. >
  219. 练习模式
  220. </Button>
  221. <Button
  222. type="primary"
  223. round
  224. block
  225. disabled={item.status === 'A_PASS' || item.status === 'B_NO_PASS'}
  226. onClick={() => onUnitTestStart(item)}
  227. >
  228. {item.status === 'C_ING' ? '继续测验' : '开始测验'}
  229. </Button>
  230. </div>
  231. </div>
  232. )
  233. }}
  234. </Cell>
  235. </CellGroup>
  236. ))}
  237. </List>
  238. </OFullRefresh>
  239. ) : (
  240. <OEmpty tips="暂无单元测验" />
  241. )}
  242. <ActionSheet
  243. v-model:show={form.oPopover}
  244. cancelText="取消"
  245. actions={form.searchList}
  246. onSelect={(val: any) => {
  247. form.statusText = val.name
  248. form.params.status = val.id === 'ALL' ? null : val.id
  249. form.oPopover = false
  250. onSearch()
  251. }}
  252. />
  253. {/* 测验须知 */}
  254. <Popup
  255. v-model:show={form.visiableNotice}
  256. round
  257. style={{ width: '90%' }}
  258. closeOnClickOverlay={false}
  259. >
  260. <NoticeStart
  261. data={form.unitExam}
  262. onClose={() => {
  263. form.visiableNotice = false
  264. }}
  265. onConfirm={onExamStart}
  266. />
  267. </Popup>
  268. </div>
  269. )
  270. }
  271. })