game.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <template>
  2. <view>
  3. <!-- rgba(116, 172, 240, 1)-->
  4. <uni-nav-bar id="nav-bar" status-bar="true" backgroundColor="rgba(153, 150, 252, 255)" @clickLeft="showClickEvent('DrawerModalL')"
  5. @clickRight="onNavHome" title="娱乐" color="#FFFFFF" fixed="true">
  6. <view slot="left">
  7. <view class=" flex align-center margin-left">
  8. <image class="png-more" src="../../../static/more.png"></image>
  9. </view>
  10. </view>
  11. <view slot="right">
  12. <view class=" flex align-center " style="margin-right: 10rpx;">
  13. <view class="cuIcon-home text-20px-before"></view>
  14. </view>
  15. </view>
  16. </uni-nav-bar>
  17. <view class="scrollX">
  18. <scroll-view scroll-x class="bg-white nav solid-bottom scrollX-padding" scroll-with-animation :scroll-left="scrollLeft">
  19. <view class="cu-item text-18px" :class="index == TabCur ? 'make-text-bPurple cur' : 'cu-color'" v-for="(item, index) in tabList"
  20. :key="index" @tap="tabSelect" :data-id="index" :data-category_id="item.categoryType" v-if="item.categoryType !== 0">
  21. {{ item.categoryName }}
  22. </view>
  23. </scroll-view>
  24. <view class="png-search">
  25. <!-- <image style="width: 50rpx; height: 50rpx;" src="/static/search.png" @tap="onNavSearch"></image> -->
  26. </view>
  27. </view>
  28. <scroll-view scroll-y="true" :style="{ height: scrollviewHigh + 'px' }" @scrolltolower="lower">
  29. <view class="game-item card-view" v-for="(item, index) in gameList" :key="index" :data-id="index">
  30. <view @tap="onNavToWebviewGame(item)">
  31. <view class="game-image-container">
  32. <image mode="aspectFill" class="game-item-image" :src="item.gamePicture"></image>
  33. <image class="head-image" :src="item.gameIcon"></image>
  34. <view class="play-bg-image">
  35. <image class="play-image" src="/static/play.png"></image>
  36. </view>
  37. </view>
  38. <view class="cu-list menu-avatar">
  39. <view class="cu-item">
  40. <view class="content flex-sub">
  41. <view>{{ item.gameName }}</view>
  42. <view class='flex flex-wrap ' style="margin: 10rpx 0;">
  43. <view style="padding-right:5rpx;" v-for="(item,index) in item.gameTags" :key="index">
  44. <view class='cu-tag line-purple radius'>{{item.tagName}}</view>
  45. </view>
  46. </view>
  47. <!-- <view class="text-sm flex justify-between" style="color:rgba(201, 201, 201, 1);">{{item.createTime}}</view> -->
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="text-gray text-sm text-center padding flex flex-direction" style="width: 100%;">
  53. <view @tap="onFavoriteAdd(item)">
  54. <image class="margin-lr-xs right-png" style="margin: 25px 0;" :src="item.gameFavorite?'/static/favorite_r.png':'/static/favorite_g.png'"
  55. mode="aspectFill"></image>
  56. </view>
  57. <view style="margin-top: 30px;" @tap="onNavComment">
  58. <!-- <image class="margin-lr-xs right-png" style="margin: 20px 0;" src="/static/info_g.png" mode="aspectFill"></image> -->
  59. </view>
  60. <view style="margin-top: 60px;" @tap="onNavDetail(item)">
  61. <view class="cuIcon-moreandroid margin-lr-xs" style="font-size: 20px; margin: 10px 0; color: #d6d6d6;"></view>
  62. </view>
  63. </view>
  64. </view>
  65. <view v-if="gameList.length == 0" class="text-16px text-gray text-center margin">没有更多数据</view>
  66. <view style="height: 17px;"></view>
  67. </scroll-view>
  68. <!-- <view class="float-png">
  69. <image src="/static/conversion@2x.png" mode="aspectFit" @tap="onNavConver"></image>
  70. </view> -->
  71. <round-menu @trigger="onRoundTrigger"></round-menu>
  72. <sideBar ref="sideBar"></sideBar>
  73. </view>
  74. </template>
  75. <script>
  76. import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue';
  77. import sideBar from '@/components/side-bar/side-bar.vue';
  78. import config from '../../../common/config.js';
  79. import reqUtil from '../../../util/util-js/requstUtil.js';
  80. import roundMenu from "@/components/round-menu/round-menu.vue";
  81. import {
  82. mapState,
  83. mapMutations
  84. } from 'vuex';
  85. export default {
  86. components: {
  87. uniNavBar,
  88. sideBar,
  89. roundMenu
  90. },
  91. computed: mapState(['ConnectBindingDevice', 'BLEConnectDevice', 'cIndex']),
  92. data() {
  93. return {
  94. tabList: [],
  95. TabCur: 0,
  96. Category: 0,
  97. scrollLeft: 0,
  98. scrollviewHigh: '',
  99. bDontUpdate: false,
  100. //游戏列表
  101. gameList: [],
  102. gamePage: 1,
  103. gameSize: 10,
  104. //编码的item
  105. encodeItem: '',
  106. };
  107. },
  108. onLoad(option) {
  109. let _this = this;
  110. console.log("option========:", option);
  111. let _index = 1;
  112. if (option && option.type) {
  113. if (option.type == "game") {
  114. _index = 1;
  115. } else if (option.type == "video") {
  116. _index = 2;
  117. }
  118. }
  119. //获得游戏类目
  120. reqUtil.requestData(config.URL.GAMECATEGORY).then(
  121. res => {
  122. console.log('GAMECATEGORY =====', res);
  123. if (res.code == 0) {
  124. this.tabList = res.data;
  125. this.TabCur = _index;
  126. this.categoryType = this.tabList[_index].categoryType;
  127. this.getGameList(this.categoryType);
  128. }
  129. },
  130. e => {
  131. console.log(e);
  132. }
  133. );
  134. },
  135. onReady() {
  136. let _this = this;
  137. uni.getSystemInfo({
  138. success(res) {
  139. // 计算组件的高度
  140. let view = uni.createSelectorQuery().select('#nav-bar');
  141. view.boundingClientRect(data => {
  142. let navHeight = data.height;
  143. let scrollXHight = uni.upx2px(90);
  144. _this.scrollviewHigh = res.windowHeight - navHeight - scrollXHight;
  145. }).exec();
  146. }
  147. });
  148. },
  149. methods: {
  150. ...mapMutations(['glimitPlayGame']),
  151. // 跳转转换页面
  152. onNavConver() {
  153. uni.reLaunch({
  154. url: '../../conversion-page/conversion/conversion',
  155. success: res => {},
  156. fail: () => {},
  157. complete: () => {}
  158. });
  159. },
  160. //跳转回主页
  161. onNavHome() {
  162. uni.reLaunch({
  163. url: '../../personal-page/personal/personal',
  164. success: res => {},
  165. fail: () => {},
  166. complete: () => {}
  167. });
  168. },
  169. tabSelect(e) {
  170. if (this.TabCur != e.currentTarget.dataset.id) {
  171. //重新设置参数
  172. this.bDontUpdate = false;
  173. this.gameList = [];
  174. this.gamePage = 1;
  175. this.gameSize = 10;
  176. this.TabCur = e.currentTarget.dataset.id;
  177. this.categoryType = e.currentTarget.dataset.category_id;
  178. this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60;
  179. this.getGameList(this.categoryType);
  180. }
  181. },
  182. showClickEvent() {
  183. this.$refs.sideBar.showModal();
  184. },
  185. onNavSearch() {
  186. uni.showToast({
  187. title: '功能尚未开放',
  188. icon: 'none'
  189. })
  190. return;
  191. uni.navigateTo({
  192. url: '../game-search/game-search',
  193. success: res => {},
  194. fail: () => {},
  195. complete: () => {}
  196. });
  197. },
  198. //收藏
  199. onFavoriteAdd(item) {
  200. //添加收藏
  201. let favoritesTemp = {
  202. 'fObjectId': item.gameId,
  203. 'favoritesType': 0,
  204. }
  205. reqUtil.requestData(config.URL.FAVORITESMODIFY, favoritesTemp).then(res => {
  206. console.log('FAVORITESMODIFY =====', res);
  207. if (res.code == 0) {
  208. if (!res.data.bHas) {
  209. item.gameFavorite = false;
  210. uni.showToast({
  211. title: "取消收藏",
  212. icon: "none"
  213. })
  214. } else {
  215. uni.showToast({
  216. title: "收藏成功",
  217. icon: "none"
  218. })
  219. item.gameFavorite = true;
  220. }
  221. }
  222. },
  223. e => {
  224. console.log(e)
  225. });
  226. },
  227. onNavComment() {
  228. uni.showToast({
  229. title: '功能尚未开放',
  230. icon: 'none'
  231. })
  232. return;
  233. uni.navigateTo({
  234. url: '../game-comment/game-comment',
  235. success: res => {},
  236. fail: () => {},
  237. complete: () => {}
  238. });
  239. },
  240. onNavDetail(item) {
  241. // console.log(item);
  242. let temItem = encodeURIComponent(JSON.stringify(item));
  243. // return;
  244. uni.navigateTo({
  245. url: '../game-detail/game-detail?item=' + temItem,
  246. success: res => {},
  247. fail: () => {},
  248. complete: () => {}
  249. });
  250. },
  251. onNavToWebviewGame(item) {
  252. // console.log("====item == ",item);
  253. // if (!this.BLEConnectDevice || this.cIndex == -1) {
  254. // uni.showToast({
  255. // title: "没有连接绑带,请连接后重试!",
  256. // icon: "none"
  257. // })
  258. // return;
  259. // }
  260. //1.先判断模式
  261. //如果都不存在,返回
  262. this.glimitPlayGame({
  263. gameTags: item.gameTags,
  264. callback: () => {
  265. reqUtil.requestData(config.URL.GAMEDETAIL, item).then(res => {
  266. console.log('GAMEDETAIL =====', res);
  267. if (res.code == 0) {
  268. this.encodeItem = encodeURIComponent(JSON.stringify(res.data.gameInfo));
  269. // #ifdef APP-PLUS
  270. uni.navigateTo({
  271. url: '../game-play-sub/game-play-sub?item=' + this.encodeItem,
  272. success: res => {},
  273. fail: () => {},
  274. complete: () => {}
  275. });
  276. // #endif
  277. // #ifdef H5
  278. uni.navigateTo({
  279. url: '../game-play/game-play-web?item=' + this.encodeItem,
  280. success: res => {},
  281. fail: () => {},
  282. complete: () => {}
  283. });
  284. // #endif
  285. }
  286. },
  287. e => {
  288. console.log(e)
  289. });
  290. }
  291. });
  292. },
  293. getGameList(categoryType) {
  294. uni.showToast({
  295. icon: "loading",
  296. title: "",
  297. mask: true,
  298. duration: 10000
  299. })
  300. //获得游戏列表
  301. reqUtil.requestData(
  302. config.URL.GAMELIST_FROM_CATEGORY, {
  303. categoryType: categoryType,
  304. //endTime 可以不设置,服务器默认设置一个值
  305. endTime: config.endTime,
  306. page: this.gamePage,
  307. size: this.gameSize
  308. }
  309. ).then(res => {
  310. console.log('GAMELIST_FROM_CATEGORY =====', res);
  311. if (res.code == 0) {
  312. uni.hideToast();
  313. if (res.data.length < this.gameSize) {
  314. this.bDontUpdate = true;
  315. }
  316. if (res.data.length != 0) {
  317. uni.showToast({
  318. icon: "none",
  319. title: "更新成功",
  320. })
  321. } else {
  322. uni.showToast({
  323. icon: "none",
  324. title: "没数据啦",
  325. })
  326. }
  327. this.gameList = this.gameList.concat(res.data);
  328. }
  329. },
  330. e => {
  331. console.log(e);
  332. uni.showToast({
  333. icon: "none",
  334. title: "更新出错",
  335. })
  336. }
  337. );
  338. },
  339. onRoundTrigger(data) {
  340. console.log("onRoundTrigger==", data);
  341. // return;
  342. let url = '';
  343. switch (data.item.type) {
  344. case "personal":
  345. //个人中心页面
  346. url = '../../personal-page/personal/personal';
  347. break;
  348. case "game":
  349. url = '../../game-page/game/game';
  350. break;
  351. default:
  352. url = '../../personal-page/personal/personal';
  353. break;
  354. }
  355. uni.reLaunch({
  356. url: url,
  357. success: res => {},
  358. fail: () => {},
  359. complete: () => {}
  360. });
  361. },
  362. lower(e) {
  363. if (this.bDontUpdate) return;
  364. console.log(e);
  365. this.gamePage++;
  366. this.getGameList(this.categoryType);
  367. }
  368. }
  369. };
  370. </script>
  371. <style>
  372. page {
  373. background-color: #fff;
  374. }
  375. .float-png {
  376. position: absolute;
  377. right: 15px;
  378. bottom: 200px;
  379. width: 56px;
  380. height: 56px;
  381. }
  382. .png-search {
  383. width: 50rpx;
  384. height: 100%;
  385. position: absolute;
  386. right: 20px;
  387. top: 0;
  388. bottom: 0;
  389. margin: auto;
  390. display: flex;
  391. justify-content: center;
  392. align-items: center;
  393. /* border: 1rpx solid #000000; */
  394. }
  395. .scrollX {
  396. position: relative;
  397. width: 100%;
  398. height: 90upx;
  399. /* border: 1rpx solid #000000; */
  400. }
  401. .scrollX-padding {
  402. padding: 0 74px 0 20px;
  403. }
  404. .game-item {
  405. display: flex;
  406. justify-content: flex-start;
  407. flex-direction: row;
  408. background-color: white;
  409. margin: 17px 14px 0 17px;
  410. /* border-bottom: 1rpx solid rgba(240, 240, 240, 1); */
  411. }
  412. .game-item-image {
  413. width: 542rpx;
  414. height: 542rpx;
  415. z-index: 99;
  416. }
  417. .head-image {
  418. position: absolute;
  419. bottom: -20px;
  420. left: 0;
  421. margin-left: 17px;
  422. width: 80rpx;
  423. height: 80rpx;
  424. border: 2px solid white;
  425. border-radius: 100px;
  426. z-index: 100;
  427. }
  428. .play-bg-image {
  429. position: absolute;
  430. bottom: 0;
  431. left: 0;
  432. top: 0;
  433. right: 0;
  434. width: 112rpx;
  435. height: 112rpx;
  436. margin: auto;
  437. background: rgba(0, 0, 0, 0.25);
  438. /* opacity: 0.25; */
  439. border-radius: 100px;
  440. z-index: 100;
  441. }
  442. .play-image {
  443. position: absolute;
  444. bottom: 0;
  445. left: 0;
  446. top: 0;
  447. right: 0;
  448. width: 44rpx;
  449. height: 54rpx;
  450. margin: auto;
  451. z-index: 100;
  452. }
  453. .game-image-container {
  454. position: relative;
  455. }
  456. .game-index {
  457. z-index: 300;
  458. }
  459. .cu-color {
  460. color: rgba(191, 191, 193, 1);
  461. }
  462. .right-png {
  463. width: 36rpx;
  464. height: 32rpx;
  465. }
  466. </style>