index.tsx 9.8 KB

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