game-ranking.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <template>
  2. <view>
  3. <uni-nav-bar id="nav-bar" status-bar="true" @clickLeft="onBack" :title="pageTitle" backgroundColor="rgba(151, 151, 255, 1)"
  4. color="#FFFFFF" fixed="true" :border="false">
  5. <view slot="left">
  6. <view class=" flex align-center margin-left">
  7. <image class="w-left-arrow" src="../../../static/m-icon/leftBack.png"></image>
  8. </view>
  9. </view>
  10. </uni-nav-bar>
  11. <view class="make-bg-bPurple rankingTop">
  12. <view style="position:absolute;left:0; right:0; top:-100px; bottom:0;margin:auto;" class="flex justify-center align-center">
  13. <image style="width: 337px;height: 337px;" src="/static/ranking-light.png"></image>
  14. </view>
  15. <!-- 底部领奖台 -->
  16. <view class="flex justify-center rankingImageContainer">
  17. <image style="height: 94px; width: 100%; margin: 0 37rpx;" src="/static/ranking-plat.png"></image>
  18. </view>
  19. <view class="rankingImageContainer">
  20. <view class="text-white text-bold text-15px text-center" style="margin-top: 66px;width: 160rpx;">{{rankInfo?rankInfo.rankScoreList[1]:''}}</view>
  21. <view class="text-white text-bold text-15px text-center" style="margin: 38px 75rpx 0; width: 160rpx;">{{rankInfo?rankInfo.rankScoreList[0]:''}}</view>
  22. <view class="text-white text-bold text-15px text-center" style="margin-top: 66px;width: 160rpx;">{{rankInfo?rankInfo.rankScoreList[2]:''}}</view>
  23. </view>
  24. <!-- 头像部分 -->
  25. <view class="rankingHeadContainer">
  26. <view class="flex justify-around margin-left margin-right" style="margin-top: 40px; width: 100%;">
  27. <!-- 排名2 -->
  28. <view class="text-white flex justify-center flex-direction align-center" style="margin-top: 25px;width: 160rpx;height: 100%;">
  29. <view v-if="rankUserInfo[1].bShow" class="rankHeadMin" style="border: 3px solid #dee2e5; ">
  30. <image class="rankHead" mode="aspectFill" :src="rankUserInfo[1].avatarUrl"></image>
  31. <view class="flex justify-center rankingNum">
  32. <view style="background-color: #dee2e5;" class="flex justify-center align-center rankingNumChild">
  33. 2
  34. </view>
  35. </view>
  36. </view>
  37. {{rankUserInfo[1].username}}
  38. </view>
  39. <!-- 排名1 -->
  40. <view class="text-white flex justify-center flex-direction align-center" style="height: 100%;width: 160rpx;">
  41. <view v-if="rankUserInfo[0].bShow" class="rankHeadBig">
  42. <image class="rankHead" mode="aspectFill" :src="rankUserInfo[0].avatarUrl"></image>
  43. <view style="position: absolute;top:-14px;left: 0; width: 100%;height: 16px; " class="flex justify-center">
  44. <image style=" width: 22px;height: 16px;" src="../../../static/ranking-crown.png"></image>
  45. </view>
  46. <view class="flex justify-center rankingNumOne">
  47. <view style=" background-color: #fed642;" class="flex justify-center align-center rankingNumOneChild">
  48. 1
  49. </view>
  50. </view>
  51. </view>
  52. {{rankUserInfo[0].username}}
  53. </view>
  54. <!-- 排名3 -->
  55. <view class="text-white flex justify-center flex-direction align-center" style="margin-top: 25px;width: 160rpx;height: 100%;">
  56. <view v-if="rankUserInfo[2].bShow" class="rankHeadMin" style="border: 3px solid #fdaf41;">
  57. <image class="rankHead" mode="aspectFill" :src="rankUserInfo[2].avatarUrl"></image>
  58. <view class="flex justify-center rankingNum">
  59. <view style=" background-color: #fdaf41;" class="flex justify-center align-center rankingNumChild">
  60. 3
  61. </view>
  62. </view>
  63. </view>
  64. {{rankUserInfo[2].username}}
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. <!-- 切换游戏信息和分类部分 -->
  70. <view style="background-color: #FFFFFF; box-shadow: 0px 0px 3px 2px rgba(113, 113, 219, 0.23);">
  71. <view class="flex justify-between padding">
  72. <view class="flex justify-center align-center ">
  73. <image style="width:50px;height: 50px; background-color: #eeeeee; border-radius: 8px;" :src="rankSelectedGame?rankSelectedGame.gameIcon:''"></image>
  74. <view style="margin-left: 22rpx;">{{rankSelectedGame?rankSelectedGame.gameName:''}}</view>
  75. </view>
  76. <view class="button-fav" @tap="showModal" data-target="bottomModal">切换</view>
  77. </view>
  78. <view class="nav flex justify-around align-center ">
  79. <view style="width: 200rpx; margin: 0 40rpx;" class="cu-item text-bold text-18px text-center" :class="0==TabCur?'make-text-bPurple cur':''"
  80. data-id="0" @tap="tabSelect">
  81. 全国
  82. </view>
  83. <view style="height: 30px; border-right: 1rpx solid #AAAAAA;"></view>
  84. <view style="width: 200rpx; margin: 0 40rpx;" class="cu-item text-bold text-18px text-center text-cut" :class="1==TabCur?'make-text-bPurple cur':''"
  85. data-id="1" @tap="tabSelect">
  86. {{cityName}}
  87. </view>
  88. </view>
  89. </view>
  90. <!-- 滚动部分 style="height: 300px; margin-bottom: 87px;"-->
  91. <view >
  92. <scroll-view style="max-height:300px; width: 100%; padding: 22rpx; box-sizing: border-box;" scroll-y="true">
  93. <view class="flex justify-between align-center bg-white" style="height: 73px; width: 100%; border-radius: 8px; margin-bottom:14rpx ; "
  94. v-for="(item,index) in otherUserInfoList" v-bind:key="index">
  95. <view class="flex justify-center align-center " style="margin-left: 68rpx;">
  96. <view class="text-13px margin-right flex justify-center align-center text-bold" style="background-color: #f6f3f7; width: 27px;height: 27px; border-radius: 45px;">{{index+1}}</view>
  97. <image class="head-image-50" :src="item.avatarUrl"></image>
  98. <view class="text-16px text-bold margin-left">{{item.username}}</view>
  99. </view>
  100. <view class="text-bold text-16px" style="margin-right: 68rpx;">{{otherScoreList[index]}}</view>
  101. </view>
  102. <view v-if="otherUserInfoList.length == 0 " class="text-center text-gray">没有其他排名数据~</view>
  103. <view style="height: 73px; "></view>
  104. </scroll-view>
  105. </view>
  106. <view class="flex justify-between align-center bg-white" style="position: fixed;bottom: 0;height: 73px; width: 100%;">
  107. <view class="flex justify-center align-center " style="margin-left: 68rpx;">
  108. <view class="text-13px margin-right text-gray">{{rankInfo&&rankInfo.userRank>3?'名落孙山':'金榜题名'}}</view>
  109. <image class="head-image-50" :src="rankInfo?rankInfo.userInfo.avatarUrl:''"></image>
  110. <view class="text-16px text-bold margin-left">{{rankInfo?rankInfo.userInfo.username:''}}</view>
  111. </view>
  112. <view class="text-bold text-16px" style="margin-right: 68rpx;">{{rankInfo&&rankInfo.userScore?rankInfo.userScore:0}}</view>
  113. </view>
  114. <view class="cu-modal bottom-modal" :class="modalName=='bottomModal'?'show':''" @tap="hideModal">
  115. <view class="cu-dialog bg-white" style=" border-radius: 15px;" @tap.stop="">
  116. <view class="flex justify-center align-center" style="width: 100%; height: 60rpx;" @tap="hideModal">
  117. <view class="text-blue" style="width: 80rpx; height: 2px; background-color: #AAAAAA;"></view>
  118. </view>
  119. <view class="article" style="position: relative; ">
  120. <view class="title">
  121. 最近在玩
  122. </view>
  123. <view class="cu-item">
  124. <view class="cu-form-group margin-top">
  125. <view v-if="playRankingGames.length!=0" class="grid col-4 homepage-grid-square flex-sub ">
  126. <view v-for="(item,index) in playRankingGames" :key="index" v-if="index<4" @tap="onChangeGame(item)">
  127. <image class="item-img" :src="item.gameIcon" mode="aspectFill"></image>
  128. <view class="border text-center text-cut">{{item.gameName}}</view>
  129. </view>
  130. </view>
  131. <view v-else class="text-center text-gray" :style="{width:'100%'}">去玩游戏吧~</view>
  132. </view>
  133. </view>
  134. </view>
  135. <view class="article" style="position: relative; ">
  136. <view class="title">
  137. 总榜
  138. </view>
  139. <scroll-view scroll-y="true" class="cu-item">
  140. <view class="cu-form-group ">
  141. <view class="grid col-4 homepage-grid-square flex-sub ">
  142. <view v-if="calorieGame" @tap="onChangeGame(calorieGame)">
  143. <image class="item-img" :src="calorieGame.gameIcon" mode="aspectFill"></image>
  144. <view class="border text-center margin-bottom text-cut">{{calorieGame.gameName}}</view>
  145. </view>
  146. </view>
  147. </view>
  148. </scroll-view>
  149. </view>
  150. <view class="article" style="height: 270px; position: relative; bottom: 10px;">
  151. <view class="title">
  152. 全部游戏
  153. </view>
  154. <scroll-view scroll-y="true" style="height: 250px;" class="cu-item">
  155. <view class="cu-form-group ">
  156. <view v-if="allGames.length!=0" class="grid col-4 homepage-grid-square flex-sub ">
  157. <view v-for="(item,index) in allGames" :key="index" @tap="onChangeGame(item)">
  158. <image class="item-img" :src="item.gameIcon" mode="aspectFill"></image>
  159. <view class="border text-center margin-bottom text-cut">{{item.gameName}}</view>
  160. </view>
  161. </view>
  162. <view v-else class="text-center text-gray" :style="{width:'100%'}">去玩游戏吧~</view>
  163. </view>
  164. </scroll-view>
  165. </view>
  166. </view>
  167. </view>
  168. </view>
  169. </template>
  170. <script>
  171. import config from '../../../common/config.js';
  172. import reqUtil from "@/util/util-js/requstUtil.js";
  173. import {
  174. mapState,
  175. mapMutations
  176. } from 'vuex'
  177. export default {
  178. computed: mapState(['rankSelectedGame', 'rankInfo', 'cityName', 'city', 'playRankingGames', 'playGames', 'hasLogin', 'allGames']),
  179. data() {
  180. return {
  181. pageTitle: '排行榜',
  182. TabCur: 0,
  183. rankUserInfo: [{
  184. bShow: false,
  185. avatarUrl: '',
  186. username: '',
  187. },
  188. {
  189. bShow: false,
  190. avatarUrl: '',
  191. username: '',
  192. },
  193. {
  194. bShow: false,
  195. avatarUrl: '',
  196. username: '',
  197. }
  198. ],
  199. //除去前三名的数据
  200. otherUserInfoList: [],
  201. otherScoreList: [],
  202. modalName: null,
  203. scrollviewHight: 0,
  204. //卡路里游戏
  205. calorieGame: null,
  206. }
  207. },
  208. onLoad() {
  209. let that = this;
  210. //获得全部游戏列表
  211. that.getAllGame(() => {
  212. reqUtil.requestData(config.URL.GETRANKGAME).then(res => {
  213. console.warn('GETRANKGAME =====', res);
  214. // 如果玩家有记录显示的游戏,
  215. if (res.data !== null) {
  216. that.$store.state.rankSelectedGame = res.data;
  217. that.onGetRank();
  218. reqUtil.requestData(config.URL.GAMEDETAIL, {
  219. gameId: '1'
  220. }).then(res => {
  221. that.calorieGame = res.data.gameInfo;
  222. },
  223. e => {
  224. console.log(e)
  225. });
  226. } else {
  227. // //如果没有记录到用户的选择数据,给一个游戏显示
  228. // if (that.allGames.length == 0) {
  229. // console.warn("allGames 没有任何游戏!");
  230. // return;
  231. // }
  232. // //设置第一个游戏给显示
  233. // that.$store.state.rankSelectedGame = that.allGames[0];
  234. // console.log("this.getAllGame rankSelectedGame", that.rankSelectedGame);
  235. // that.onGetRank();
  236. reqUtil.requestData(config.URL.GAMEDETAIL, {
  237. gameId: '1'
  238. }).then(res => {
  239. console.log("*************", res);
  240. that.calorieGame = res.data.gameInfo;
  241. that.$store.state.rankSelectedGame = that.calorieGame;
  242. that.onGetRank();
  243. },
  244. e => {
  245. console.log(e)
  246. });
  247. }
  248. },
  249. e => {
  250. console.log(e)
  251. });
  252. });
  253. //获取最近玩的游戏列表
  254. reqUtil.requestData(config.URL.RECENTLYPLAYINGGET).then(res => {
  255. console.log('RECENTLYPLAYINGGET =====', res);
  256. if (res.code == 0 && res.data.gameList) {
  257. // that.$store.state.playRankingGames = res.data.gameList;
  258. let _arry = [];
  259. for(let i=0;i<res.data.gameList.length;i++){
  260. if(res.data.gameList[i].gameRankingShow){
  261. _arry.push(res.data.gameList[i]);
  262. }
  263. }
  264. that.$store.state.playRankingGames = _arry;
  265. that.onGetRank();
  266. }
  267. },
  268. e => {
  269. console.log(e)
  270. });
  271. },
  272. onReady() {
  273. let that = this;
  274. uni.getSystemInfo({
  275. success(res) {
  276. // 计算组件的高度
  277. let view = uni.createSelectorQuery().select('#nav-bar');
  278. view.boundingClientRect(data => {
  279. let navHeight = data.height;
  280. let scrollXHight = uni.upx2px(90);
  281. that.scrollviewHight = res.windowHeight - navHeight - 265-125-73;
  282. }).exec();
  283. }
  284. });
  285. },
  286. methods: {
  287. ...mapMutations(['getRankGame', 'getAllGame']),
  288. tabSelect(e) {
  289. this.TabCur = e.currentTarget.dataset.id;
  290. if (this.TabCur == 1 && this.city.cityCode == "") {
  291. console.warn("选择城市时候,cityCode 不能为空");
  292. return;
  293. }
  294. this.onGetRank();
  295. },
  296. onBack() {
  297. uni.navigateBack({
  298. delta: 1
  299. })
  300. },
  301. showModal(e) {
  302. this.modalName = e.currentTarget.dataset.target
  303. },
  304. hideModal(e) {
  305. this.modalName = null
  306. },
  307. onChangeGame(item) {
  308. uni.showToast({
  309. title: '',
  310. icon: "loading",
  311. duration: 10000
  312. })
  313. // console.log(item);
  314. //这里切换游戏
  315. let that = this;
  316. //切换游戏,修改一次用户记录的数据
  317. reqUtil.requestData(config.URL.MOTIFYRANKGAME, {
  318. gameId: item.gameId,
  319. score: 111
  320. }, "POST").then(res => {
  321. console.log('MOTIFYRANKGAME =====', res, item);
  322. //设置当前显示的游戏数据
  323. that.$store.state.rankSelectedGame = item;
  324. that.hideModal();
  325. that.onGetRank();
  326. },
  327. e => {
  328. console.log(e)
  329. });
  330. },
  331. onGetRank() {
  332. uni.showToast({
  333. title: '',
  334. icon: "loading",
  335. duration: 10000
  336. })
  337. // console.log( this.rankSelectedGame);
  338. if(!this.rankSelectedGame)return;
  339. this.getRankGame({
  340. param: {
  341. type: this.TabCur == 0 ? "china" : "city",
  342. cityCode: this.city.cityCode,
  343. gameId: this.rankSelectedGame.gameId
  344. },
  345. callback: (res) => {
  346. uni.hideToast();
  347. if (res.data == null) return;
  348. for (let i = 0; i < 3; i++) {
  349. if (this.rankInfo.rankingList[i]) {
  350. this.rankUserInfo[i] = Object.assign({
  351. bShow: true
  352. }, this.rankInfo.rankingList[i])
  353. // console.log("=====", this.rankUserInfo[i]);
  354. } else {
  355. this.rankUserInfo[i] = Object.assign({
  356. bShow: false,
  357. avatarUrl: '',
  358. username: '',
  359. })
  360. }
  361. }
  362. //.slice(3)
  363. this.otherUserInfoList = this.rankInfo.rankingList;
  364. this.otherScoreList = this.rankInfo.rankScoreList;
  365. }
  366. });
  367. }
  368. }
  369. }
  370. </script>
  371. <style>
  372. .rankingTop {
  373. position: relative;
  374. width: 100%;
  375. height: 265px;
  376. }
  377. .rankingImageContainer {
  378. position: absolute;
  379. left: 0;
  380. bottom: 0;
  381. height: 94px;
  382. width: 100%;
  383. display: flex;
  384. justify-content: center;
  385. }
  386. .rankingNum {
  387. position: absolute;
  388. bottom: -10px;
  389. left: 0;
  390. width: 100%;
  391. height: 20px;
  392. }
  393. .rankingNumChild {
  394. width: 20px;
  395. height: 20px;
  396. border-radius: 45px;
  397. }
  398. .rankingNumOne {
  399. position: absolute;
  400. bottom: -12px;
  401. left: 0;
  402. width: 100%;
  403. height: 24px;
  404. }
  405. .rankingNumOneChild {
  406. width: 24px;
  407. height: 24px;
  408. border-radius: 45px;
  409. }
  410. .rankingHeadContainer {
  411. position: absolute;
  412. top: 0;
  413. left: 0;
  414. height: 172px;
  415. width: 100%;
  416. display: flex;
  417. justify-content: center;
  418. /* border: 1rpx solid #000000; */
  419. }
  420. .button-fav {
  421. background-color: rgba(153, 150, 252, 255);
  422. color: #FFFFFF;
  423. border-radius: 10px;
  424. width: 184rpx;
  425. height: 90rpx;
  426. display: flex;
  427. justify-content: center;
  428. text-align: center;
  429. align-items: center;
  430. }
  431. .head-image-50 {
  432. width: 50px;
  433. height: 50px;
  434. background-color: #eeeeee;
  435. border-radius: 45px;
  436. }
  437. .title {
  438. text-align: justify;
  439. /* padding: 40rpx 30rpx; */
  440. font-size: 15px;
  441. position: relative;
  442. height: 30px;
  443. line-height: 60upx;
  444. margin: 20rpx 40rpx;
  445. font-weight: 400;
  446. color: rgba(26, 26, 26, 1);
  447. }
  448. .homepage-grid-square {
  449. width: 250rpx;
  450. /* height: 250rpx; */
  451. align-items: start;
  452. }
  453. .homepage-grid-square image {
  454. width: 144rpx;
  455. height: 144rpx;
  456. }
  457. .item-img {
  458. border-radius: 20rpx;
  459. box-shadow: 0px 1px 2px 0px rgba(113, 113, 219, 0.23);
  460. }
  461. .rankHead {
  462. width: 100%;
  463. height: 100%;
  464. border-radius: 45px;
  465. flex-shrink: 0;
  466. }
  467. .rankHeadMin {
  468. display: flex;
  469. position: relative;
  470. width: 55px;
  471. height: 55px;
  472. border-radius: 45px;
  473. box-sizing: border-box;
  474. margin-bottom: 21px;
  475. }
  476. .rankHeadBig {
  477. display: flex;
  478. position: relative;
  479. width: 73px;
  480. height: 73px;
  481. border: 3px solid #fed642;
  482. border-radius: 45px;
  483. box-sizing: border-box;
  484. margin-bottom: 21px;
  485. }
  486. </style>