index.vue 12 KB

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