list.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view>
  3. <uni-nav-bar id="nav-bar" status-bar="true" @clickLeft="onBack()" :title="title" color="#000000" fixed="true" :border="false">
  4. <view slot="left">
  5. <view class=" flex align-center margin-left">
  6. <image class="p-left-arrow" src="../../../static/p-left-arrow.png"></image>
  7. </view>
  8. </view>
  9. </uni-nav-bar>
  10. <view class="card-view game-item" v-for="(item,index) in list" :key="index">
  11. <!-- <view class="only-arrow"> -->
  12. <view v-if="platform == gamePlatform[item.platform] || item.platform == 2" class="content" @tap="onNavTo(item)">
  13. <image :src="item.gameIcon" class="png"></image>
  14. <text class="text-black text-bold ">{{item.gameName}}</text>
  15. <view class="only-arrow"></view>
  16. </view>
  17. <!-- </view> -->
  18. </view>
  19. <view v-if="bDontUpdate" class="text-16px text-gray text-center margin">- 没有更多数据 -</view>
  20. </view>
  21. </template>
  22. <script>
  23. import reqUtil from "@/util/util-js/requstUtil.js"
  24. import config from "@/common/config.js"
  25. import {
  26. mapState
  27. } from 'vuex';
  28. export default {
  29. computed: mapState(['platform', 'gamePlatform']),
  30. data() {
  31. return {
  32. list: [],
  33. title: "最近在玩",
  34. type: '',
  35. page: 1,
  36. size: 10,
  37. bDontUpdate: false,
  38. }
  39. },
  40. onLoad(option) {
  41. let that = this;
  42. if (option && option.type) {
  43. that.type = option.type;
  44. that.onGetData();
  45. }
  46. },
  47. methods: {
  48. onNavTo(item) {
  49. let temItem = encodeURIComponent(JSON.stringify(item));
  50. uni.navigateTo({
  51. url: "../../game-page/game-detail/game-detail?item=" + temItem
  52. })
  53. },
  54. onBack() {
  55. uni.navigateBack({
  56. delta: 1
  57. })
  58. },
  59. onReachBottom() {
  60. if (this.bDontUpdate) return;
  61. this.page++;
  62. this.onGetData();
  63. },
  64. onGetData() {
  65. let that = this;
  66. uni.showToast({
  67. title: '',
  68. icon: 'loading',
  69. mask: true,
  70. duration: 10000
  71. })
  72. if (that.type == 'recently') {
  73. that.title = "最近在玩";
  74. reqUtil.requestData(config.URL.RECENTLYPLAYINGGETBYPLATFORM, {
  75. page: that.page,
  76. size: that.size
  77. }).then(res => {
  78. console.log('RECENTLYPLAYINGGETBYPLATFORM =====', res);
  79. if (res.code == 0) {
  80. if (res.data.gameList.length < that.size) {
  81. that.bDontUpdate = true;
  82. }
  83. that.list = that.list.concat(res.data.gameList);
  84. }
  85. uni.hideToast();
  86. },
  87. e => {
  88. uni.hideToast();
  89. console.log(e)
  90. });
  91. } else if (that.type == 'watchGame') {
  92. that.title = "关注的游戏";
  93. reqUtil.requestData(config.URL.FAVORITESGETBYPLATFORM, {
  94. page: that.page,
  95. size: that.size
  96. }).then(res => {
  97. console.log('FAVORITESGETBYPLATFORM =====', res);
  98. if (res.code == 0) {
  99. if (res.data.gameList.length < that.size) {
  100. that.bDontUpdate = true;
  101. }
  102. that.list = that.list.concat(res.data.gameList);
  103. }
  104. uni.hideToast();
  105. },
  106. e => {
  107. uni.hideToast();
  108. console.log(e)
  109. });
  110. }
  111. }
  112. }
  113. }
  114. </script>
  115. <style>
  116. .content {
  117. display: flex;
  118. flex-direction: row;
  119. align-items: center;
  120. height: 98px;
  121. }
  122. .content image {
  123. width: 71px;
  124. height: 71px;
  125. margin-left: 40rpx;
  126. margin-right: 40rpx;
  127. border-radius: 12px;
  128. }
  129. .game-item {
  130. position: relative;
  131. background-color: #FFFFFF;
  132. border-radius: 10px;
  133. }
  134. </style>