index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. import { Button, Cell, Empty, Image, Tab, Tabs } from 'vant'
  2. import {
  3. computed,
  4. defineComponent,
  5. nextTick,
  6. onMounted,
  7. reactive,
  8. ref
  9. } from 'vue'
  10. import styles from './index.module.less'
  11. import IconTrophy from './image/icon-trophy.png'
  12. import IconLevel from '../share-active/track-review-activity/images/icon_level.png'
  13. import IconLevel2 from '../share-active/track-review-activity/images/icon_level2.png'
  14. import IconLevel3 from '../share-active/track-review-activity/images/icon_level3.png'
  15. import IconEmtry from './image/icon-emtry.png'
  16. import IconAvator from '@/common/images/icon_teacher.png'
  17. import request from '@/helpers/request'
  18. import { useRoute, useRouter } from 'vue-router'
  19. import { state as userInfo } from '@/state'
  20. import { useRect } from '@vant/use'
  21. interface IMusicItem {
  22. loaded: boolean
  23. musicSheetName: string
  24. musicSubject: string
  25. musicSheetId: number
  26. evaluationId: number
  27. rankingList: any
  28. [_: string]: any
  29. }
  30. export default defineComponent({
  31. name: 'leaderboard',
  32. setup() {
  33. const route = useRoute()
  34. const router = useRouter()
  35. const state = reactive({
  36. tabIndex: 0,
  37. musicList: [] as IMusicItem[],
  38. isSignup: false, // 是否报名
  39. isChallenge: false, // 是否挑战过
  40. rankingMethod: '',
  41. score: 0
  42. })
  43. const getMusicList = async () => {
  44. try {
  45. const { data } = await request.post(
  46. `/api-student/open/activity/info/${route.query.id}`
  47. )
  48. state.rankingMethod = data.rankingMethod
  49. const activityList =
  50. data.rankingMethod === 'TOTAL_SCORE'
  51. ? data.subjectInfos
  52. : data.activityMusicVoList
  53. if (Array.isArray(activityList)) {
  54. state.musicList = activityList.map(n => {
  55. n.rankingList = []
  56. return n
  57. })
  58. state.isChallenge = activityList.filter(n => n.join).length
  59. ? true
  60. : false
  61. }
  62. img.value = data.subjectUrl
  63. state.isSignup = data.join ? true : false
  64. } catch (error) {}
  65. }
  66. const getData = async () => {
  67. try {
  68. const { data } = await request.get(
  69. '/api-student/open/activityEvaluationRecord/queryRankingList',
  70. {
  71. params: {
  72. activityPlanId: route.query.id,
  73. activityEvaluationId:
  74. state.musicList[state.tabIndex].evaluationId,
  75. limit: 10
  76. }
  77. }
  78. )
  79. if (Array.isArray(data.rankingList)) {
  80. state.musicList[state.tabIndex].rankingList = data.rankingList
  81. }
  82. if (data.userActivityRankingVo) {
  83. state.score = data.userActivityRankingVo.score
  84. }
  85. } catch (error) {}
  86. }
  87. const img = ref()
  88. const imgShow = ref(false)
  89. const imgHeight = ref(100)
  90. const openActive = () => {
  91. router.back()
  92. // router.replace({
  93. // path: '/track-review-activity',
  94. // query: {
  95. // id: route.query.id
  96. // }
  97. // })
  98. }
  99. onMounted(async () => {
  100. await getMusicList()
  101. await getData()
  102. })
  103. const user = computed(() => {
  104. if (!state.musicList[state.tabIndex]) return {} as any
  105. const userdata = userInfo.user.data
  106. if (!userdata.userId) return {} as any
  107. const rank = state.musicList[state.tabIndex]
  108. const item = rank?.rankingList?.find(n => n.userId == userdata.userId)
  109. let step = rank?.rankingList?.findIndex(n => n.userId == userdata.userId)
  110. step = step > -1 ? step + 1 : 0
  111. return {
  112. join: rank.join,
  113. score: item?.score || 0,
  114. isTop: item ? true : false,
  115. heardUrl: userdata.heardUrl,
  116. username: userdata.username,
  117. userId: userdata.userId,
  118. step
  119. }
  120. })
  121. const imgRef = ref()
  122. const userRef = ref()
  123. return () => (
  124. <div class={styles.leaderboard}>
  125. <div class={styles.container}>
  126. <div class={styles.headImg} ref={imgRef}>
  127. <Image
  128. width="100%"
  129. fit="cover"
  130. src={img.value}
  131. onLoad={img => {
  132. nextTick(() => {
  133. const { height } = useRect(imgRef)
  134. imgShow.value = true
  135. imgHeight.value = height || 100
  136. })
  137. }}
  138. onError={err => {
  139. console.log(err)
  140. }}
  141. />
  142. </div>
  143. {imgShow.value && (
  144. <Tabs
  145. v-model:active={state.tabIndex}
  146. class={styles.tabs}
  147. animated
  148. swipeable
  149. titleInactiveColor="rgba(153,152,155,1)"
  150. titleActiveColor="#fff"
  151. onChange={index => getData()}
  152. >
  153. {state.musicList.map((item: IMusicItem) => {
  154. return (
  155. <Tab
  156. title={
  157. state.rankingMethod === 'TOTAL_SCORE'
  158. ? item.subjectName
  159. : item.musicSheetName
  160. }
  161. >
  162. <div
  163. class={[
  164. styles.tabContent,
  165. user.value.userId &&
  166. (!state.isSignup ||
  167. !state.isChallenge ||
  168. user.value.join)
  169. ? styles.hasUser
  170. : null
  171. ]}
  172. style={{ height: `calc(100vh - ${imgHeight.value}px)` }}
  173. >
  174. <div class={styles.itemContent}>
  175. <div class={styles.item}>
  176. <div class={styles.left}>排名</div>
  177. <div class={styles.center}>昵称</div>
  178. <div class={styles.right}>评分</div>
  179. </div>
  180. {item.rankingList.map((n: any, index: number) => {
  181. const t = (index + 1).toString().padStart(2, '0')
  182. return (
  183. <div class={styles.item}>
  184. <div class={styles.left}>
  185. {index == 0 && <Image src={IconLevel} />}
  186. {index == 1 && <Image src={IconLevel2} />}
  187. {index == 2 && <Image src={IconLevel3} />}
  188. {index != 0 && index != 1 && index != 2 && t}
  189. </div>
  190. <div class={styles.center}>
  191. <Image
  192. width="38px"
  193. height="38px"
  194. fit="cover"
  195. round
  196. src={n.userAvatar || IconAvator}
  197. />
  198. <div class={styles.user}>
  199. <div class={styles.userContent}>
  200. <span class={styles.name}>
  201. {n.username}
  202. </span>
  203. <span class={styles.tag}>
  204. {n.userSubject}
  205. </span>
  206. </div>
  207. <div class={styles.times}>{n.joinDate}</div>
  208. </div>
  209. </div>
  210. <div class={styles.right}>
  211. <div class={styles.fraction}>{n.score}分</div>
  212. <div class={styles.time}>
  213. 第 {n.times} 次评测
  214. </div>
  215. </div>
  216. </div>
  217. )
  218. })}
  219. {!item.rankingList.length && (
  220. <Empty
  221. image={IconEmtry}
  222. description="该曲目暂无排名喔~"
  223. />
  224. )}
  225. </div>
  226. <div class="van-safe-area-bottom"></div>
  227. </div>
  228. </Tab>
  229. )
  230. })}
  231. </Tabs>
  232. )}
  233. {user.value.userId &&
  234. (!state.isSignup ? (
  235. <div
  236. ref={userRef}
  237. class={[styles.activeUser, 'van-safe-area-bottom']}
  238. >
  239. <Cell
  240. center
  241. title={user.value.username}
  242. label="您尚未报名参赛"
  243. v-slots={{
  244. icon: () => (
  245. <Image
  246. class={styles.avator}
  247. fit="cover"
  248. round
  249. src={user.value.heardUrl || IconAvator}
  250. />
  251. )
  252. }}
  253. />
  254. </div>
  255. ) : !state.isChallenge ? (
  256. <div
  257. ref={userRef}
  258. class={[styles.activeUser, 'van-safe-area-bottom']}
  259. >
  260. <Cell
  261. center
  262. title={user.value.username}
  263. label="您尚未评测哦!"
  264. v-slots={{
  265. icon: () => (
  266. <Image
  267. class={styles.avator}
  268. fit="cover"
  269. round
  270. src={user.value.heardUrl || IconAvator}
  271. />
  272. )
  273. }}
  274. />
  275. </div>
  276. ) : user.value.join ? (
  277. <div
  278. ref={userRef}
  279. class={[styles.activeUser, 'van-safe-area-bottom']}
  280. >
  281. <Cell
  282. center
  283. title={user.value.username}
  284. v-slots={{
  285. icon: () => (
  286. <Image
  287. class={styles.avator}
  288. fit="cover"
  289. round
  290. src={user.value.heardUrl || IconAvator}
  291. />
  292. ),
  293. label: () => {
  294. if (user.value.isTop) {
  295. return (
  296. <div>
  297. 您的评测已上榜! 当前排名
  298. <span style={{ color: '#FA6400' }}>
  299. {' '}
  300. {user.value.step}
  301. </span>
  302. </div>
  303. )
  304. } else {
  305. return <div>您的评测暂未上榜,快去挑战吧!</div>
  306. }
  307. },
  308. value: () => {
  309. if (!user.value.score && !state.score) {
  310. return
  311. }
  312. return (
  313. <span class={styles.num}>
  314. {user.value.score || state.score}分
  315. </span>
  316. )
  317. }
  318. }}
  319. />
  320. </div>
  321. ) : null)}
  322. </div>
  323. </div>
  324. )
  325. }
  326. })