index.tsx 8.5 KB

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