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 IconLevel from '../share-active/track-review-activity/images/icon_level.png' import IconLevel2 from '../share-active/track-review-activity/images/icon_level2.png' import IconLevel3 from '../share-active/track-review-activity/images/icon_level3.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, // 是否挑战过 rankingMethod: '', score: 0 }) const getMusicList = async () => { try { const { data } = await request.post( `/api-student/open/activity/info/${route.query.id}` ) state.rankingMethod = data.rankingMethod const activityList = data.rankingMethod === 'TOTAL_SCORE' ? data.subjectInfos : data.activityMusicVoList if (Array.isArray(activityList)) { state.musicList = activityList.map(n => { n.rankingList = [] return n }) state.isChallenge = activityList.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.rankingMethod === 'TOTAL_SCORE' ? state.musicList[state.tabIndex].subjectId : state.musicList[state.tabIndex].evaluationId, limit: 10 } } ) if (Array.isArray(data.rankingList)) { state.musicList[state.tabIndex].rankingList = data.rankingList } if (data.userActivityRankingVo) { state.score = data.userActivityRankingVo.score } } 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: item?.score || 0, 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 && } {index == 1 && } {index == 2 && } {index != 0 && index != 1 && index != 2 && t}
{n.username} {n.userSubject}
{n.joinDate}
{n.score}分
{state.rankingMethod !== 'TOTAL_SCORE' && (
第 {n.times} 次评测
)}
) })} {!item.rankingList.length && ( )}
) })}
)} {user.value.userId && (!state.isSignup ? (
( ) }} />
) : !state.isChallenge ? (
( ) }} />
) : user.value.join ? (
( ), label: () => { if (user.value.isTop) { return (
您的评测已上榜! 当前排名 {' '} {user.value.step}
) } else { return
您的评测暂未上榜,快去挑战吧!
} }, value: () => { if (!user.value.score && !state.score) { return } return ( {user.value.score || state.score}分 ) } }} />
) : null)}
) } })