index.vue 12 KB

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