import { Button, Cell, Empty, Image, Tab, Tabs } from 'vant' import { computed, defineComponent, onMounted, reactive, ref } from 'vue' import styles from './index.module.less' import IconTrophy from './image/icon-trophy.png' import IconEmtry from './image/icon-emtry.png' import IconAvator from '@/common/images/icon_teacher.png' import request from '@/helpers/request' import { useRoute, useRouter } from 'vue-router' import { state as userInfo } from '@/state' interface IMusicItem { loaded: boolean musicSheetName: string musicSubject: string musicSheetId: number evaluationId: number rankingList: any [_: string]: any } export default defineComponent({ name: 'leaderboard', setup() { const route = useRoute() const router = useRouter() const state = reactive({ tabIndex: 0, musicList: [] as IMusicItem[] }) const getMusicList = async () => { try { const { data: { activityMusicVoList, shareUrl } } = await request.post( `/api-student/open/activity/info/${route.query.id}` ) if (Array.isArray(activityMusicVoList)) { state.musicList = activityMusicVoList.map(n => { n.rankingList = [] n.loaded = false return n }) } img.value = shareUrl } catch (error) {} } const getData = async () => { if (state.musicList[state.tabIndex].loaded) return try { const { data } = await request.get( '/api-student/open/activityEvaluationRecord/queryRankingList', { params: { activityPlanId: route.query.id, activityEvaluationId: state.musicList[state.tabIndex].evaluationId, limit: 10 } } ) if (Array.isArray(data.rankingList)) { state.musicList[state.tabIndex].rankingList = data.rankingList state.musicList[state.tabIndex].loaded = true } } catch (error) {} } const img = ref() const imgShow = ref(false) const imgHeight = ref(42) const openActive = () => { router.back() // router.replace({ // path: '/track-review-activity', // query: { // id: route.query.id // } // }) } onMounted(async () => { await getMusicList() await getData() }) const user = computed(() => { if (!state.musicList[state.tabIndex]) return {} as any const userdata = userInfo.user.data if (!userdata.userId) return {} as any const rank = state.musicList[state.tabIndex] const item = rank?.rankingList?.find(n => n.userId == userdata.userId) let step = rank?.rankingList?.findIndex(n => n.userId == userdata.userId) step = step > -1 ? step + 1 : 0 return { join: rank.join, score: rank.score, isTop: item ? true : false, heardUrl: userdata.heardUrl, username: userdata.username, userId: userdata.userId, step } }) return () => (
{ imgHeight.value = img.target.height imgShow.value = true }} />
{imgShow.value && ( getData()} > {state.musicList.map((item: IMusicItem) => { return (
排名
昵称
评分
{item.rankingList.map((n: any, index: number) => { const t = (index + 1).toString().padStart(2, '0') const time = (n.joinDate + '').split(' ')[0] return (
{index == 0 ? : t}
{n.username}
{n.userSubject}
{n.score}分
{time}
) })} {!item.rankingList.length && ( )}
) })}
)} {user.value.userId && (
( ), label: () => { if (user.value.join) { if (user.value.isTop) { return (
您的评测已上榜! 当前排名 {' '} {user.value.step}
) } else { return (
您的评测暂未上榜,快去 openActive()}>挑战 吧!
) } } else { return
您尚未报名参赛
} }, value: () => { if (user.value.join) { return ( {user.value.score}分 ) } else { // return ( // // ) } } }} />
)}
) } })