index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <template>
  2. <div class="rank-wrap">
  3. <div class="type-list">
  4. <div
  5. v-for="(item, index) in rankTypeList"
  6. :key="index"
  7. :class="{ item: 1, active: item.type === currRankType }"
  8. @click="changeCurrRankType(item.type)"
  9. >
  10. {{ t(item.label) }}
  11. </div>
  12. </div>
  13. <div
  14. v-if="rankList.length"
  15. class="rank-list"
  16. >
  17. <div class="top">
  18. <div
  19. v-for="(item, index) in [rankList[1], rankList[0], rankList[2]]"
  20. :key="currRankType + '-' + index"
  21. :class="{ item: 1, [`rank-${item.rank}`]: 1 }"
  22. >
  23. <div
  24. class="avatar"
  25. @click="
  26. currRankType !== RankTypeEnum.blog &&
  27. router.push({
  28. name: routerName.profile,
  29. params: { userId: item.users[0]?.id },
  30. })
  31. "
  32. >
  33. <Avatar
  34. :size="100"
  35. :avatar="item.users[0]?.avatar"
  36. :living="!!item.live?.live"
  37. ></Avatar>
  38. </div>
  39. <div class="username">{{ item.users[0]?.username }}</div>
  40. <div class="rank">
  41. <i>0{{ item.rank }}</i>
  42. <div
  43. v-if="item.live?.live && currRankType === RankTypeEnum.liveRoom"
  44. class="living"
  45. @click="handleJoin(item.live)"
  46. >
  47. {{ t('common.living') }}
  48. </div>
  49. </div>
  50. <div
  51. class="wallet"
  52. v-if="currRankType === RankTypeEnum.wallet"
  53. >
  54. <span>{{ t('common.wallet') }}: </span>
  55. <span>{{ formatMoney(item.balance) }}¥</span>
  56. </div>
  57. <div
  58. class="signin"
  59. v-if="currRankType === RankTypeEnum.signin"
  60. >
  61. <span>
  62. {{ t('rank.accumulatedSignin', { nums: item.signin_nums }) }}
  63. </span>
  64. </div>
  65. </div>
  66. </div>
  67. <div class="top50-list">
  68. <div
  69. v-for="(item, index) in rankList.filter((item, index) => index >= 3)"
  70. :key="index"
  71. class="top50-item"
  72. >
  73. <div class="rank">
  74. <i>{{ item.rank >= 10 ? item.rank : '0' + item.rank }}</i>
  75. </div>
  76. <div
  77. class="left"
  78. @click="
  79. currRankType !== RankTypeEnum.blog &&
  80. router.push({
  81. name: routerName.profile,
  82. params: { userId: item.users[0]?.id },
  83. })
  84. "
  85. >
  86. <img
  87. :src="item.users[0]?.avatar"
  88. class="avatar"
  89. alt=""
  90. />
  91. <div class="username">{{ item.users[0]?.username }}</div>
  92. <div
  93. class="wallet"
  94. v-if="currRankType === RankTypeEnum.wallet"
  95. >
  96. <span>{{ t('common.wallet') }}: </span>
  97. <span>{{ formatMoney(item.balance) }}¥</span>
  98. </div>
  99. <div
  100. class="signin"
  101. v-if="currRankType === RankTypeEnum.signin"
  102. >
  103. <span>
  104. ({{
  105. t('rank.accumulatedSignin', { nums: item.signin_nums })
  106. }})
  107. </span>
  108. </div>
  109. <div
  110. v-if="item.live?.live && currRankType === RankTypeEnum.liveRoom"
  111. class="living-tag"
  112. @click.stop="handleJoin(item.live)"
  113. >
  114. {{ t('common.living') }}
  115. </div>
  116. </div>
  117. <div class="right"></div>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. </template>
  123. <script lang="ts" setup>
  124. import { onMounted, ref } from 'vue';
  125. import { useI18n } from 'vue-i18n';
  126. import { fetchLiveRoomList } from '@/api/liveRoom';
  127. import { fetchSigninList } from '@/api/signin';
  128. import { fetchUserList } from '@/api/user';
  129. import { fetchWalletList } from '@/api/wallet';
  130. import { fullLoading } from '@/components/FullLoading';
  131. import { RankTypeEnum } from '@/interface';
  132. import router, { routerName } from '@/router';
  133. import { ILiveRoom, LiveRoomIsShowEnum } from '@/types/ILiveRoom';
  134. import { formatMoney } from '@/utils';
  135. export interface IRankType {
  136. type: RankTypeEnum;
  137. label: string;
  138. }
  139. const rankTypeList = ref<IRankType[]>([
  140. {
  141. type: RankTypeEnum.liveRoom,
  142. label: 'rank.liveRank',
  143. },
  144. {
  145. type: RankTypeEnum.user,
  146. label: 'rank.userRank',
  147. },
  148. {
  149. type: RankTypeEnum.wallet,
  150. label: 'rank.richRank',
  151. },
  152. {
  153. type: RankTypeEnum.signin,
  154. label: 'rank.signinRank',
  155. },
  156. // {
  157. // type: RankTypeEnum.blog,
  158. // label: '博客用户',
  159. // },
  160. ]);
  161. const mockDataNums = 4;
  162. const currRankType = ref(RankTypeEnum.liveRoom);
  163. const { t } = useI18n();
  164. const mockRank: {
  165. users: { id; username; avatar }[];
  166. rank: number;
  167. level: number;
  168. score: number;
  169. balance: number;
  170. signin_nums: number;
  171. live?: ILiveRoom;
  172. }[] = [
  173. {
  174. users: [
  175. {
  176. id: -1,
  177. username: '待上榜',
  178. avatar: '',
  179. },
  180. ],
  181. rank: 1,
  182. level: 0,
  183. score: 0,
  184. balance: 0,
  185. signin_nums: 0,
  186. live: undefined,
  187. },
  188. {
  189. users: [
  190. {
  191. id: -1,
  192. username: '待上榜',
  193. avatar: '',
  194. },
  195. ],
  196. rank: 2,
  197. level: 0,
  198. score: 0,
  199. balance: 0,
  200. signin_nums: 0,
  201. live: undefined,
  202. },
  203. {
  204. users: [
  205. {
  206. id: -1,
  207. username: '待上榜',
  208. avatar: '',
  209. },
  210. ],
  211. rank: 3,
  212. level: 0,
  213. score: 0,
  214. balance: 0,
  215. signin_nums: 0,
  216. live: undefined,
  217. },
  218. {
  219. users: [
  220. {
  221. id: -1,
  222. username: '待上榜',
  223. avatar: '',
  224. },
  225. ],
  226. rank: 4,
  227. level: 0,
  228. score: 0,
  229. balance: 0,
  230. signin_nums: 0,
  231. live: undefined,
  232. },
  233. ];
  234. const rankList = ref(mockRank);
  235. function handleJoin(item) {
  236. router.push({
  237. name: routerName.pull,
  238. params: { roomId: item.live.live_room_id },
  239. });
  240. }
  241. async function getWalletList() {
  242. try {
  243. fullLoading({ loading: true });
  244. const res = await fetchWalletList({});
  245. if (res.code === 200) {
  246. const length = res.data.rows.length;
  247. rankList.value = res.data.rows.map((item, index) => {
  248. return {
  249. users: [
  250. {
  251. id: item.user?.id,
  252. username: item.user?.username,
  253. avatar: item.user?.avatar,
  254. },
  255. ],
  256. rank: index + 1,
  257. level: 0,
  258. score: 0,
  259. balance: item.balance || 0,
  260. signin_nums: 0,
  261. };
  262. });
  263. if (length < mockDataNums) {
  264. rankList.value.push(...mockRank.slice(length));
  265. }
  266. }
  267. } catch (error) {
  268. console.log(error);
  269. } finally {
  270. fullLoading({ loading: false });
  271. }
  272. }
  273. async function getLiveRoomList() {
  274. try {
  275. fullLoading({ loading: true });
  276. const res = await fetchLiveRoomList({
  277. hidden_cover_img: true,
  278. is_show: LiveRoomIsShowEnum.yes,
  279. orderName: 'updated_at',
  280. orderBy: 'desc',
  281. });
  282. if (res.code === 200) {
  283. const length = res.data.rows.length;
  284. rankList.value = res.data.rows.map((item, index) => {
  285. return {
  286. users: [
  287. {
  288. id: item.users?.[0].id,
  289. username: item.users?.[0].username,
  290. avatar: item.users?.[0].avatar,
  291. },
  292. ],
  293. live: item,
  294. rank: index + 1,
  295. level: 0,
  296. score: 0,
  297. balance: 0,
  298. signin_nums: 0,
  299. };
  300. });
  301. if (length < mockDataNums) {
  302. rankList.value.push(...mockRank.slice(length));
  303. }
  304. }
  305. } catch (error) {
  306. console.log(error);
  307. } finally {
  308. fullLoading({ loading: false });
  309. }
  310. }
  311. async function getUserList() {
  312. try {
  313. fullLoading({ loading: true });
  314. const res = await fetchUserList({
  315. orderName: 'updated_at',
  316. orderBy: 'desc',
  317. });
  318. if (res.code === 200) {
  319. const length = res.data.rows.length;
  320. rankList.value = res.data.rows.map((item, index) => {
  321. return {
  322. users: [
  323. {
  324. id: item.id,
  325. username: item.username,
  326. avatar: item.avatar,
  327. },
  328. ],
  329. rank: index + 1,
  330. level: 0,
  331. score: 0,
  332. balance: 0,
  333. signin_nums: 0,
  334. };
  335. });
  336. if (length < mockDataNums) {
  337. rankList.value.push(...mockRank.slice(length));
  338. }
  339. }
  340. } catch (error) {
  341. console.log(error);
  342. } finally {
  343. fullLoading({ loading: false });
  344. }
  345. }
  346. async function getSigninList() {
  347. try {
  348. fullLoading({ loading: true });
  349. const res = await fetchSigninList({
  350. orderName: 'sum_nums',
  351. orderBy: 'desc',
  352. });
  353. if (res.code === 200) {
  354. const length = res.data.rows.length;
  355. rankList.value = res.data.rows.map((item, index) => {
  356. return {
  357. users: [
  358. {
  359. id: item.user?.id,
  360. username: item.user?.username,
  361. avatar: item.user?.avatar,
  362. },
  363. ],
  364. rank: index + 1,
  365. level: 0,
  366. score: 0,
  367. balance: 0,
  368. signin_nums: item.sum_nums || 0,
  369. };
  370. });
  371. if (length < mockDataNums) {
  372. rankList.value.push(...mockRank.slice(length));
  373. }
  374. }
  375. } catch (error) {
  376. console.log(error);
  377. } finally {
  378. fullLoading({ loading: false });
  379. }
  380. }
  381. function changeCurrRankType(type: RankTypeEnum) {
  382. currRankType.value = type;
  383. switch (type) {
  384. case RankTypeEnum.liveRoom:
  385. getLiveRoomList();
  386. break;
  387. case RankTypeEnum.user:
  388. getUserList();
  389. break;
  390. case RankTypeEnum.signin:
  391. getSigninList();
  392. break;
  393. case RankTypeEnum.wallet:
  394. getWalletList();
  395. break;
  396. default:
  397. break;
  398. }
  399. }
  400. onMounted(() => {
  401. changeCurrRankType(currRankType.value);
  402. });
  403. </script>
  404. <style lang="scss" scoped>
  405. .rank-wrap {
  406. box-sizing: border-box;
  407. padding-top: 10px;
  408. height: calc(100vh - $header-height);
  409. background-color: #f4f4f4;
  410. .type-list {
  411. display: flex;
  412. align-items: center;
  413. margin: 20px 0;
  414. width: 100%;
  415. .item {
  416. flex: 1;
  417. margin: 0 10px;
  418. height: 40px;
  419. border-radius: 10px;
  420. background-color: $theme-color-gold;
  421. color: white;
  422. text-align: center;
  423. font-weight: bold;
  424. font-size: 20px;
  425. line-height: 40px;
  426. filter: grayscale(1);
  427. cursor: pointer;
  428. &.active {
  429. filter: grayscale(0);
  430. }
  431. }
  432. }
  433. .rank-list {
  434. width: 100%;
  435. .living-tag {
  436. display: inline-block;
  437. margin: 0 auto;
  438. padding: 2px 5px;
  439. width: 40px;
  440. border: 1px solid $theme-color-gold;
  441. border-radius: 10px;
  442. color: $theme-color-gold;
  443. text-align: center;
  444. font-size: 12px;
  445. line-height: 1.2;
  446. cursor: pointer;
  447. }
  448. .top {
  449. display: flex;
  450. align-items: flex-end;
  451. justify-content: center;
  452. margin-top: 100px;
  453. width: 100%;
  454. .item {
  455. position: relative;
  456. margin: 0 20px;
  457. width: 200px;
  458. height: 180px;
  459. border-radius: 15px;
  460. background-color: white;
  461. text-align: center;
  462. &.rank-1 {
  463. height: 200px;
  464. border-color: #ff6744;
  465. color: #ff6744;
  466. .rank {
  467. margin-top: 20px;
  468. }
  469. .avatar-wrap {
  470. .avatar {
  471. border: 2px solid #ff6744;
  472. }
  473. }
  474. }
  475. &.rank-2 {
  476. border-color: #44d6ff;
  477. color: #44d6ff;
  478. .avatar-wrap {
  479. .avatar {
  480. border: 2px solid #44d6ff;
  481. }
  482. }
  483. }
  484. &.rank-3 {
  485. border-color: #ffb200;
  486. color: #ffb200;
  487. .avatar-wrap {
  488. .avatar {
  489. border: 2px solid #ffb200;
  490. }
  491. }
  492. }
  493. .avatar {
  494. margin-top: -50px;
  495. display: inline-block;
  496. cursor: pointer;
  497. }
  498. .username {
  499. margin-bottom: 10px;
  500. font-size: 22px;
  501. }
  502. .rank {
  503. position: relative;
  504. display: inline-block;
  505. padding: 0px 20px;
  506. border: 1px solid;
  507. border-radius: 20px;
  508. font-size: 20px;
  509. .living {
  510. position: absolute;
  511. bottom: 0;
  512. left: 50%;
  513. transform: translate(-50%, 130%);
  514. @extend .living-tag;
  515. }
  516. }
  517. .wallet,
  518. .signin {
  519. margin-top: 10px;
  520. }
  521. }
  522. }
  523. .top50-list {
  524. margin-top: 20px;
  525. border-radius: 10px;
  526. background-color: white;
  527. .top50-item {
  528. display: flex;
  529. align-items: center;
  530. padding: 0 10px;
  531. height: 40px;
  532. color: #666;
  533. &:nth-child(2n) {
  534. background-color: #fafbfc;
  535. }
  536. .rank {
  537. box-sizing: border-box;
  538. margin-right: 20px;
  539. width: 80px;
  540. border-radius: 40px;
  541. background-color: #84f9da;
  542. color: white;
  543. text-align: center;
  544. font-size: 20px;
  545. }
  546. .left {
  547. display: flex;
  548. align-items: center;
  549. font-size: 12px;
  550. cursor: pointer;
  551. .avatar {
  552. margin-right: 10px;
  553. width: 28px;
  554. height: 28px;
  555. border-radius: 50%;
  556. }
  557. .username {
  558. width: 100px;
  559. @extend %singleEllipsis;
  560. }
  561. .wallet,
  562. .signin {
  563. margin-left: 4px;
  564. }
  565. }
  566. }
  567. }
  568. }
  569. }
  570. </style>