index.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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.rankingMethod === 'TOTAL_SCORE'
  75. ? state.musicList[state.tabIndex].subjectId
  76. : state.musicList[state.tabIndex].evaluationId,
  77. limit: 10
  78. }
  79. }
  80. )
  81. if (Array.isArray(data.rankingList)) {
  82. state.musicList[state.tabIndex].rankingList = data.rankingList
  83. }
  84. if (data.userActivityRankingVo) {
  85. state.score = data.userActivityRankingVo.score
  86. }
  87. } catch (error) {}
  88. }
  89. const img = ref()
  90. const imgShow = ref(false)
  91. const imgHeight = ref(100)
  92. const openActive = () => {
  93. router.back()
  94. // router.replace({
  95. // path: '/track-review-activity',
  96. // query: {
  97. // id: route.query.id
  98. // }
  99. // })
  100. }
  101. onMounted(async () => {
  102. await getMusicList()
  103. await getData()
  104. })
  105. const user = computed(() => {
  106. if (!state.musicList[state.tabIndex]) return {} as any
  107. const userdata = userInfo.user.data
  108. if (!userdata.userId) return {} as any
  109. const rank = state.musicList[state.tabIndex]
  110. const item = rank?.rankingList?.find(n => n.userId == userdata.userId)
  111. let step = rank?.rankingList?.findIndex(n => n.userId == userdata.userId)
  112. step = step > -1 ? step + 1 : 0
  113. return {
  114. join: rank.join,
  115. score: item?.score || 0,
  116. isTop: item ? true : false,
  117. heardUrl: userdata.heardUrl,
  118. username: userdata.username,
  119. userId: userdata.userId,
  120. step
  121. }
  122. })
  123. const imgRef = ref()
  124. const userRef = ref()
  125. return () => (
  126. <div class={styles.leaderboard}>
  127. <div class={styles.container}>
  128. <div class={styles.headImg} ref={imgRef}>
  129. <Image
  130. width="100%"
  131. fit="cover"
  132. src={img.value}
  133. onLoad={img => {
  134. nextTick(() => {
  135. const { height } = useRect(imgRef)
  136. imgShow.value = true
  137. imgHeight.value = height || 100
  138. })
  139. }}
  140. onError={err => {
  141. console.log(err)
  142. }}
  143. />
  144. </div>
  145. {imgShow.value && (
  146. <Tabs
  147. v-model:active={state.tabIndex}
  148. class={styles.tabs}
  149. animated
  150. swipeable
  151. titleInactiveColor="rgba(153,152,155,1)"
  152. titleActiveColor="#fff"
  153. onChange={index => getData()}
  154. >
  155. {state.musicList.map((item: IMusicItem) => {
  156. return (
  157. <Tab
  158. title={
  159. state.rankingMethod === 'TOTAL_SCORE'
  160. ? item.subjectName
  161. : item.musicSheetName
  162. }
  163. >
  164. <div
  165. class={[
  166. styles.tabContent,
  167. user.value.userId &&
  168. (!state.isSignup ||
  169. !state.isChallenge ||
  170. user.value.join)
  171. ? styles.hasUser
  172. : null
  173. ]}
  174. style={{ height: `calc(100vh - ${imgHeight.value}px)` }}
  175. >
  176. <div class={styles.itemContent}>
  177. <div class={styles.item}>
  178. <div class={styles.left}>排名</div>
  179. <div class={styles.center}>昵称</div>
  180. <div class={styles.right}>评分</div>
  181. </div>
  182. {item.rankingList.map((n: any, index: number) => {
  183. const t = (index + 1).toString().padStart(2, '0')
  184. return (
  185. <div class={styles.item}>
  186. <div class={styles.left}>
  187. {index == 0 && <Image src={IconLevel} />}
  188. {index == 1 && <Image src={IconLevel2} />}
  189. {index == 2 && <Image src={IconLevel3} />}
  190. {index != 0 && index != 1 && index != 2 && t}
  191. </div>
  192. <div class={styles.center}>
  193. <Image
  194. width="38px"
  195. height="38px"
  196. fit="cover"
  197. round
  198. src={n.userAvatar || IconAvator}
  199. />
  200. <div class={styles.user}>
  201. <div class={styles.userContent}>
  202. <span class={styles.name}>
  203. {n.username}
  204. </span>
  205. <span class={styles.tag}>
  206. {n.userSubject}
  207. </span>
  208. </div>
  209. <div class={styles.times}>{n.joinDate}</div>
  210. </div>
  211. </div>
  212. <div class={styles.right}>
  213. <div class={styles.fraction}>{n.score}分</div>
  214. {state.rankingMethod !== 'TOTAL_SCORE' && (
  215. <div class={styles.time}>
  216. 第 {n.times} 次评测
  217. </div>
  218. )}
  219. </div>
  220. </div>
  221. )
  222. })}
  223. {!item.rankingList.length && (
  224. <Empty
  225. image={IconEmtry}
  226. description={`该${
  227. state.rankingMethod === 'TOTAL_SCORE'
  228. ? '声部'
  229. : '曲目'
  230. }暂无排名喔~`}
  231. />
  232. )}
  233. </div>
  234. <div class="van-safe-area-bottom"></div>
  235. </div>
  236. </Tab>
  237. )
  238. })}
  239. </Tabs>
  240. )}
  241. {user.value.userId &&
  242. (!state.isSignup ? (
  243. <div
  244. ref={userRef}
  245. class={[styles.activeUser, 'van-safe-area-bottom']}
  246. >
  247. <Cell
  248. center
  249. title={user.value.username}
  250. label="您尚未报名参赛"
  251. v-slots={{
  252. icon: () => (
  253. <Image
  254. class={styles.avator}
  255. fit="cover"
  256. round
  257. src={user.value.heardUrl || IconAvator}
  258. />
  259. )
  260. }}
  261. />
  262. </div>
  263. ) : !state.isChallenge ? (
  264. <div
  265. ref={userRef}
  266. class={[styles.activeUser, 'van-safe-area-bottom']}
  267. >
  268. <Cell
  269. center
  270. title={user.value.username}
  271. label="您尚未评测哦!"
  272. v-slots={{
  273. icon: () => (
  274. <Image
  275. class={styles.avator}
  276. fit="cover"
  277. round
  278. src={user.value.heardUrl || IconAvator}
  279. />
  280. )
  281. }}
  282. />
  283. </div>
  284. ) : user.value.join ? (
  285. <div
  286. ref={userRef}
  287. class={[styles.activeUser, 'van-safe-area-bottom']}
  288. >
  289. <Cell
  290. center
  291. title={user.value.username}
  292. v-slots={{
  293. icon: () => (
  294. <Image
  295. class={styles.avator}
  296. fit="cover"
  297. round
  298. src={user.value.heardUrl || IconAvator}
  299. />
  300. ),
  301. label: () => {
  302. if (user.value.isTop) {
  303. return (
  304. <div>
  305. 您的评测已上榜! 当前排名
  306. <span style={{ color: '#FA6400' }}>
  307. {' '}
  308. {user.value.step}
  309. </span>
  310. </div>
  311. )
  312. } else {
  313. return <div>您的评测暂未上榜,快去挑战吧!</div>
  314. }
  315. },
  316. value: () => {
  317. if (!user.value.score && !state.score) {
  318. return
  319. }
  320. return (
  321. <span class={styles.num}>
  322. {user.value.score || state.score}分
  323. </span>
  324. )
  325. }
  326. }}
  327. />
  328. </div>
  329. ) : null)}
  330. </div>
  331. </div>
  332. )
  333. }
  334. })