import { Button, Cell, Empty, Image, Tab, Tabs } from 'vant' import { computed, defineComponent, nextTick, 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' import { useRect } from '@vant/use' 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[], isSignup: false, // 是否报名 isChallenge: false // 是否挑战过 }) const getMusicList = async () => { try { const { data } = await request.post( `/api-student/open/activity/info/${route.query.id}` ) if (Array.isArray(data.activityMusicVoList)) { state.musicList = data.activityMusicVoList.map(n => { n.rankingList = [] return n }) state.isChallenge = data.activityMusicVoList.filter(n => n.join) .length ? true : false } img.value = data.subjectUrl state.isSignup = data.join ? true : false } catch (error) {} } const getData = async () => { 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 } } catch (error) {} } const img = ref() const imgShow = ref(false) const imgHeight = ref(100) 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 } }) const imgRef = ref() const userRef = ref() return () => (
{ nextTick(() => { const { height } = useRect(imgRef) imgShow.value = true imgHeight.value = height || 100 }) }} onError={err => { console.log(err) }} />
{imgShow.value && ( getData()} > {state.musicList.map((item: IMusicItem) => { return (
排名
昵称
评分
{item.rankingList.map((n: any, index: number) => { const t = (index + 1).toString().padStart(2, '0') return (
{index == 0 ? : t}
{n.username} {n.userSubject}
{n.joinDate}
{n.score}分
第 {n.times} 次评测
) })} {!item.rankingList.length && ( )}
) })}
)} {!state.isSignup ? (
( ) }} />
) : !state.isChallenge ? (
( ) }} />
) : user.value.join ? (
( ), label: () => { if (user.value.isTop) { return (
您的评测已上榜! 当前排名 {' '} {user.value.step}
) } else { return
您的评测暂未上榜,快去挑战吧!
} }, value: () => ( {user.value.score}分 ) }} />
) : null}
) } })