| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- <template>
- <div class="rank-wrap">
- <div class="type-list">
- <div
- v-for="(item, index) in rankTypeList"
- :key="index"
- :class="{ item: 1, active: item.type === currRankType }"
- @click="changeCurrRankType(item.type)"
- >
- {{ item.label }}
- </div>
- </div>
- <div
- v-if="rankList.length"
- class="rank-list"
- >
- <div class="top">
- <div
- v-for="(item, index) in [rankList[1], rankList[0], rankList[2]]"
- :key="index"
- :class="{ item: 1, [`rank-${item.rank}`]: 1 }"
- >
- <div class="avatar">
- <img
- :src="item.avatar"
- alt=""
- />
- <div class="border"></div>
- </div>
- <div class="username">{{ item.username }}</div>
- <div class="rank">
- <i>0{{ item.rank }}</i>
- </div>
- <div v-if="item.balance">余额:{{ item.balance }}</div>
- </div>
- </div>
- <div class="top50-list">
- <div
- v-for="(item, index) in rankList.filter((item, index) => index >= 3)"
- :key="index"
- class="top50-item"
- >
- <div class="rank">
- <i>{{ item.rank >= 10 ? item.rank : '0' + item.rank }}</i>
- </div>
- <div class="left">
- <img
- :src="item.avatar"
- class="avatar"
- alt=""
- />
- <div class="username">{{ item.username }}</div>
- </div>
- <div class="right"></div>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script lang="ts" setup>
- import { onMounted, ref } from 'vue';
- import { fetchLiveRoomList } from '@/api/liveRoom';
- import { fetchUserList } from '@/api/user';
- import { fetchWalletList } from '@/api/wallet';
- import { RankTypeEnum } from '@/interface';
- export interface IRankType {
- type: RankTypeEnum;
- label: string;
- }
- const rankTypeList = ref<IRankType[]>([
- {
- type: RankTypeEnum.liveRoom,
- label: '主播榜',
- },
- {
- type: RankTypeEnum.user,
- label: '用户榜',
- },
- {
- type: RankTypeEnum.wallet,
- label: '土豪榜',
- },
- ]);
- const currRankType = ref(RankTypeEnum.liveRoom);
- const mockRank = [
- {
- username: '待上榜',
- avatar: '',
- rank: 1,
- level: -1,
- score: -1,
- },
- {
- username: '待上榜',
- avatar: '',
- rank: 2,
- level: -1,
- score: -1,
- },
- {
- username: '待上榜',
- avatar: '',
- rank: 3,
- level: -1,
- score: -1,
- },
- ];
- const rankList = ref(mockRank);
- async function getWalletList() {
- const res = await fetchWalletList();
- if (res.code === 200) {
- const length = res.data.rows.length;
- rankList.value = res.data.rows.map((item, index) => {
- return {
- username: item.user.username!,
- avatar: item.user.avatar!,
- rank: index + 1,
- level: 1,
- score: 1,
- balance: item.balance,
- };
- });
- if (length < 3) {
- rankList.value.push(...mockRank.slice(length));
- }
- }
- }
- async function getLiveRoomList() {
- const res = await fetchLiveRoomList({
- orderName: 'updated_at',
- orderBy: 'desc',
- });
- if (res.code === 200) {
- const length = res.data.rows.length;
- rankList.value = res.data.rows.map((item, index) => {
- return {
- username: item.user_username!,
- avatar: item.user_avatar!,
- rank: index + 1,
- level: 1,
- score: 1,
- };
- });
- if (length < 3) {
- rankList.value.push(...mockRank.slice(length));
- }
- }
- }
- function changeCurrRankType(type: RankTypeEnum) {
- currRankType.value = type;
- switch (type) {
- case RankTypeEnum.liveRoom:
- getLiveRoomList();
- break;
- case RankTypeEnum.user:
- getUserList();
- break;
- case RankTypeEnum.wallet:
- getWalletList();
- break;
- default:
- break;
- }
- }
- onMounted(() => {
- changeCurrRankType(currRankType.value);
- });
- async function getUserList() {
- try {
- const res = await fetchUserList({
- orderName: 'updated_at',
- orderBy: 'desc',
- });
- if (res.code === 200) {
- const length = res.data.rows.length;
- rankList.value = res.data.rows.map((item, index) => {
- return {
- username: item.username!,
- avatar: item.avatar!,
- rank: index + 1,
- level: 1,
- score: 1,
- };
- });
- if (length < 3) {
- rankList.value.push(...mockRank.slice(length));
- }
- }
- } catch (error) {
- console.log(error);
- }
- }
- </script>
- <style lang="scss" scoped>
- .rank-wrap {
- box-sizing: border-box;
- padding-top: 10px;
- height: calc(100vh - 64px);
- background-color: #f4f4f4;
- .type-list {
- display: flex;
- align-items: center;
- margin: 20px 0;
- width: 100%;
- .item {
- flex: 1;
- margin: 0 10px;
- height: 40px;
- border-radius: 10px;
- background-color: $theme-color-gold;
- color: white;
- text-align: center;
- font-weight: bold;
- font-size: 20px;
- line-height: 40px;
- filter: grayscale(1);
- cursor: pointer;
- &.active {
- filter: grayscale(0);
- }
- }
- }
- .rank-list {
- width: 100%;
- .top {
- display: flex;
- align-items: flex-end;
- justify-content: center;
- margin-top: 100px;
- width: 100%;
- .item {
- position: relative;
- margin: 0 20px;
- width: 200px;
- height: 180px;
- border-radius: 15px;
- background-color: white;
- text-align: center;
- &.rank-1 {
- height: 200px;
- border-color: #ff6744;
- color: #ff6744;
- .rank {
- margin-top: 20px;
- }
- }
- &.rank-2 {
- border-color: #44d6ff;
- color: #44d6ff;
- }
- &.rank-3 {
- border-color: #ffb200;
- color: #ffb200;
- }
- .avatar {
- position: relative;
- margin-top: -50px;
- img {
- display: inline-block;
- margin: 0 auto;
- width: 100px;
- height: 100px;
- border-radius: 50%;
- background-color: pink;
- }
- }
- .username {
- margin-bottom: 10px;
- font-size: 22px;
- }
- .rank {
- display: inline-block;
- padding: 0px 20px;
- border: 1px solid;
- border-radius: 20px;
- font-size: 20px;
- }
- }
- }
- .top50-list {
- margin-top: 20px;
- border-radius: 10px;
- background-color: white;
- .top50-item {
- display: flex;
- align-items: center;
- padding: 0 10px;
- height: 40px;
- color: #666;
- &:nth-child(2n) {
- background-color: #fafbfc;
- }
- .rank {
- width: 80px;
- box-sizing: border-box;
- margin-right: 20px;
- border-radius: 40px;
- text-align: center;
- background-color: #84f9da;
- color: white;
- font-size: 20px;
- }
- .left {
- display: flex;
- align-items: center;
- .avatar {
- margin-right: 10px;
- width: 28px;
- height: 28px;
- border-radius: 50%;
- background-color: pink;
- }
- .username {
- font-size: 12px;
- }
- }
- }
- }
- }
- }
- </style>
|