index.tsx 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. // 查看测验
  101. const onUnitTestLook = (item: any) => {
  102. //
  103. router.push({
  104. path: '/unit-detail',
  105. query: {
  106. id: item.id
  107. }
  108. })
  109. }
  110. const onExamStart = async () => {
  111. try {
  112. await request.post('/api-student/studentUnitExamination/startExamination', {
  113. requestType: 'form',
  114. data: {
  115. studentUnitExaminationId: form.selectUnitExam.id
  116. }
  117. })
  118. router.push({
  119. path: '/examination-mode',
  120. query: {
  121. id: form.selectUnitExam.id
  122. }
  123. })
  124. } catch {
  125. //
  126. }
  127. }
  128. onMounted(() => {
  129. getList()
  130. const temp: any = [{ name: '全部测验', id: 'ALL' }]
  131. for (const i in unitTestStatus) {
  132. temp.push({
  133. name: unitTestStatus[i],
  134. id: i
  135. })
  136. }
  137. form.searchList = temp
  138. })
  139. return () => (
  140. <div class={styles.unitTest}>
  141. <OSticky
  142. position="top"
  143. onGetHeight={(height: any) => {
  144. form.listState.height = height
  145. }}
  146. >
  147. <OSearch
  148. placeholder="请输入测验名称"
  149. inputBackground="white"
  150. background="#f6f8f9"
  151. onSearch={(val: any) => {
  152. form.params.keyword = val
  153. onSearch()
  154. }}
  155. v-slots={{
  156. left: () => (
  157. <div
  158. class={styles.searchBand}
  159. style={{ marginRight: '13px' }}
  160. onClick={() => (form.oPopover = true)}
  161. >
  162. {form.statusText} <Icon name={form.oPopover ? 'arrow-up' : 'arrow-down'} />
  163. </div>
  164. )
  165. }}
  166. />
  167. </OSticky>
  168. {form.listState.dataShow ? (
  169. <OFullRefresh
  170. v-model:modelValue={form.listState.refreshing}
  171. onRefresh={onSearch}
  172. style={{
  173. minHeight: `calc(100vh - ${form.listState.height}px)`
  174. }}
  175. >
  176. <List
  177. v-model:loading={form.listState.loading}
  178. finished={form.listState.finished}
  179. finishedText=" "
  180. class={[styles.liveList]}
  181. onLoad={getList}
  182. immediateCheck={false}
  183. >
  184. {/* <audio controls>
  185. <source src="horse.mp3" type="audio/mpeg" />
  186. <source src="horse.ogg" type="audio/ogg" />
  187. 您的浏览器不支持该音频格式。
  188. </audio> */}
  189. {form.list.map((item: any) => (
  190. <CellGroup inset class={styles.cellGroup} border={false}>
  191. <Cell center isLink clickable={false}>
  192. {{
  193. icon: () => <Image src={iconEdit} class={styles.img} />,
  194. title: () => (
  195. <span class={[styles.unitTitle, 'van-ellipsis']}>{item.name}</span>
  196. ),
  197. value: () => (
  198. <span
  199. class={[
  200. styles['no-start'],
  201. item.status === 'A_PASS' && styles.pass,
  202. item.status === 'B_NO_PASS' && styles['no-pass']
  203. ]}
  204. >
  205. {unitTestStatus[item.status]}
  206. </span>
  207. )
  208. }}
  209. </Cell>
  210. <Cell center class={styles.unitSection}>
  211. {{
  212. title: () => (
  213. <div class={styles.unitInformation}>
  214. <div>
  215. <div class={styles.name}>{item.orchestraName}</div>
  216. <div class={styles.endTime}>
  217. 截止时间:
  218. {dayjs(item.expiryDate || new Date()).format('YYYY-MM-DD HH:mm')}
  219. </div>
  220. </div>
  221. {item.status === 'A_PASS' || item.status === 'B_NO_PASS' ? (
  222. <span>
  223. {item.score || 0}
  224. <i>分</i>
  225. </span>
  226. ) : (
  227. ''
  228. )}
  229. </div>
  230. ),
  231. label: () => (
  232. <div class={styles.unitBtnGroup}>
  233. <Button
  234. color="#FFF0E6"
  235. round
  236. block
  237. style={{ color: '#F67146' }}
  238. onClick={() => {
  239. router.push({
  240. path: '/test-exercise',
  241. query: {
  242. id: item.unitExaminationId
  243. }
  244. })
  245. }}
  246. >
  247. 练习模式
  248. </Button>
  249. {item.status === 'A_PASS' || item.status === 'B_NO_PASS' ? (
  250. <Button type="primary" round block onClick={() => onUnitTestLook(item)}>
  251. 查看测验
  252. </Button>
  253. ) : (
  254. <Button
  255. type="primary"
  256. round
  257. block
  258. disabled={dayjs().isAfter(dayjs(item.expiryDate))}
  259. onClick={() => onUnitTestStart(item)}
  260. >
  261. {item.status === 'C_ING' ? '继续测验' : '开始测验'}
  262. </Button>
  263. )}
  264. </div>
  265. )
  266. }}
  267. </Cell>
  268. </CellGroup>
  269. ))}
  270. </List>
  271. </OFullRefresh>
  272. ) : (
  273. <OEmpty tips="暂无单元测验" />
  274. )}
  275. <ActionSheet
  276. v-model:show={form.oPopover}
  277. cancelText="取消"
  278. actions={form.searchList}
  279. onSelect={(val: any) => {
  280. form.statusText = val.name
  281. form.params.status = val.id === 'ALL' ? null : val.id
  282. form.oPopover = false
  283. onSearch()
  284. }}
  285. />
  286. {/* 测验须知 */}
  287. <Popup
  288. v-model:show={form.visiableNotice}
  289. round
  290. style={{ width: '90%' }}
  291. closeOnClickOverlay={false}
  292. >
  293. <NoticeStart
  294. data={form.unitExam}
  295. onClose={() => {
  296. form.visiableNotice = false
  297. }}
  298. onConfirm={onExamStart}
  299. />
  300. </Popup>
  301. </div>
  302. )
  303. }
  304. })