game.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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 v-if="(cIndex != -1 && gameShow)||ConnectBindingDevice" 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="(cIndex == -1 && !gameShow) || gameList.length == 0 || ConnectBindingDevice == null" 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','versionCodeState','platform','gamePlatform']),
  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. //默认显示
  105. gameShow: true,
  106. //编码的item
  107. encodeItem: '',
  108. };
  109. },
  110. onLoad(option) {
  111. let _this = this;
  112. console.log("option========:", option);
  113. let _index = 1;
  114. if (option && option.type) {
  115. if (option.type == "game") {
  116. _index = 1;
  117. } else if (option.type == "video") {
  118. _index = 2;
  119. }
  120. }
  121. //获得游戏类目
  122. reqUtil.requestData(config.URL.GAMECATEGORY).then(
  123. res => {
  124. console.log('GAMECATEGORY =====', res);
  125. if (res.code == 0) {
  126. this.tabList = res.data;
  127. this.TabCur = _index;
  128. this.categoryType = this.tabList[_index].categoryType;
  129. this.getGameList(this.categoryType);
  130. }
  131. },
  132. e => {
  133. console.log(e);
  134. }
  135. );
  136. },
  137. onReady() {
  138. let _this = this;
  139. uni.getSystemInfo({
  140. success(res) {
  141. // 计算组件的高度
  142. let view = uni.createSelectorQuery().select('#nav-bar');
  143. view.boundingClientRect(data => {
  144. let navHeight = data.height;
  145. let scrollXHight = uni.upx2px(90);
  146. _this.scrollviewHigh = res.windowHeight - navHeight - scrollXHight;
  147. }).exec();
  148. }
  149. });
  150. },
  151. methods: {
  152. ...mapMutations(['glimitPlayGame']),
  153. // 跳转转换页面
  154. onNavConver() {
  155. uni.reLaunch({
  156. url: '../../conversion-page/conversion/conversion',
  157. success: res => {},
  158. fail: () => {},
  159. complete: () => {}
  160. });
  161. },
  162. //跳转回主页
  163. onNavHome() {
  164. uni.reLaunch({
  165. url: '../../personal-page/personal/personal',
  166. success: res => {},
  167. fail: () => {},
  168. complete: () => {}
  169. });
  170. },
  171. tabSelect(e) {
  172. if (this.TabCur != e.currentTarget.dataset.id) {
  173. //重新设置参数
  174. this.bDontUpdate = false;
  175. this.gameList = [];
  176. this.gamePage = 1;
  177. this.gameSize = 10;
  178. this.TabCur = e.currentTarget.dataset.id;
  179. this.categoryType = e.currentTarget.dataset.category_id;
  180. this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60;
  181. this.getGameList(this.categoryType);
  182. }
  183. },
  184. showClickEvent() {
  185. this.$refs.sideBar.showModal();
  186. },
  187. onNavSearch() {
  188. uni.showToast({
  189. title: '功能尚未开放',
  190. icon: 'none'
  191. })
  192. return;
  193. uni.navigateTo({
  194. url: '../game-search/game-search',
  195. success: res => {},
  196. fail: () => {},
  197. complete: () => {}
  198. });
  199. },
  200. //收藏
  201. onFavoriteAdd(item) {
  202. //添加收藏
  203. let favoritesTemp = {
  204. 'fObjectId': item.gameId,
  205. 'favoritesType': 0,
  206. }
  207. reqUtil.requestData(config.URL.FAVORITESMODIFY, favoritesTemp).then(res => {
  208. console.log('FAVORITESMODIFY =====', res);
  209. if (res.code == 0) {
  210. if (!res.data.bHas) {
  211. item.gameFavorite = false;
  212. uni.showToast({
  213. title: "取消收藏",
  214. icon: "none"
  215. })
  216. } else {
  217. uni.showToast({
  218. title: "收藏成功",
  219. icon: "none"
  220. })
  221. item.gameFavorite = true;
  222. }
  223. }
  224. },
  225. e => {
  226. console.log(e)
  227. });
  228. },
  229. onNavComment() {
  230. uni.showToast({
  231. title: '功能尚未开放',
  232. icon: 'none'
  233. })
  234. return;
  235. uni.navigateTo({
  236. url: '../game-comment/game-comment',
  237. success: res => {},
  238. fail: () => {},
  239. complete: () => {}
  240. });
  241. },
  242. onNavDetail(item) {
  243. // console.log(item);
  244. let temItem = encodeURIComponent(JSON.stringify(item));
  245. // return;
  246. uni.navigateTo({
  247. url: '../game-detail/game-detail?item=' + temItem,
  248. success: res => {},
  249. fail: () => {},
  250. complete: () => {}
  251. });
  252. },
  253. onNavToWebviewGame(item) {
  254. // console.log("====item == ",item);
  255. // if (!this.BLEConnectDevice || this.cIndex == -1) {
  256. // uni.showToast({
  257. // title: "没有连接绑带,请连接后重试!",
  258. // icon: "none"
  259. // })
  260. // return;
  261. // }
  262. //1.先判断模式
  263. //如果都不存在,返回
  264. this.glimitPlayGame({
  265. gameTags: item.gameTags,
  266. callback: () => {
  267. reqUtil.requestData(config.URL.GAMEDETAIL, item).then(res => {
  268. console.log('GAMEDETAIL =====', res);
  269. if (res.code == 0) {
  270. this.encodeItem = encodeURIComponent(JSON.stringify(res.data.gameInfo));
  271. // #ifdef APP-PLUS
  272. uni.navigateTo({
  273. url: '../game-play-sub/game-play-sub?item=' + this.encodeItem,
  274. success: res => {},
  275. fail: () => {},
  276. complete: () => {}
  277. });
  278. // #endif
  279. // #ifdef H5
  280. uni.navigateTo({
  281. url: '../game-play/game-play-web?item=' + this.encodeItem,
  282. success: res => {},
  283. fail: () => {},
  284. complete: () => {}
  285. });
  286. // #endif
  287. }
  288. },
  289. e => {
  290. console.log(e)
  291. });
  292. }
  293. });
  294. },
  295. getGameList(categoryType) {
  296. uni.showToast({
  297. icon: "loading",
  298. title: "",
  299. mask: true,
  300. duration: 10000
  301. })
  302. //获得游戏列表
  303. reqUtil.requestData(
  304. config.URL.GAMELIST_FROM_CATEGORY_PLATFORM, {
  305. categoryType: categoryType,
  306. //endTime 可以不设置,服务器默认设置一个值
  307. endTime: config.endTime,
  308. page: this.gamePage,
  309. size: this.gameSize
  310. }
  311. ).then(res => {
  312. console.log('GAMELIST_FROM_CATEGORY_PLATFORM =====', res);
  313. if (res.code == 0) {
  314. uni.hideToast();
  315. if (res.data.length < this.gameSize) {
  316. this.bDontUpdate = true;
  317. }
  318. if (res.data.length != 0) {
  319. uni.showToast({
  320. icon: "none",
  321. title: "更新成功",
  322. })
  323. } else {
  324. uni.showToast({
  325. icon: "none",
  326. title: "没数据啦",
  327. })
  328. }
  329. this.gameList = this.gameList.concat(res.data);
  330. if (categoryType == 1) {
  331. //game
  332. this.gameShow = this.versionCodeState.showGame;
  333. } else if (categoryType == 2) {
  334. //game
  335. this.gameShow = this.versionCodeState.showVideo;
  336. }
  337. }
  338. },
  339. e => {
  340. console.log(e);
  341. uni.showToast({
  342. icon: "none",
  343. title: "更新出错",
  344. })
  345. }
  346. );
  347. },
  348. onRoundTrigger(data) {
  349. console.log("onRoundTrigger==", data);
  350. // return;
  351. let url = '';
  352. switch (data.item.type) {
  353. case "personal":
  354. //个人中心页面
  355. url = '../../personal-page/personal/personal';
  356. break;
  357. case "game":
  358. url = '../../game-page/game/game';
  359. break;
  360. default:
  361. url = '../../personal-page/personal/personal';
  362. break;
  363. }
  364. uni.reLaunch({
  365. url: url,
  366. success: res => {},
  367. fail: () => {},
  368. complete: () => {}
  369. });
  370. },
  371. lower(e) {
  372. if (this.bDontUpdate) return;
  373. console.log(e);
  374. this.gamePage++;
  375. this.getGameList(this.categoryType);
  376. }
  377. }
  378. };
  379. </script>
  380. <style>
  381. page {
  382. background-color: #fff;
  383. }
  384. .float-png {
  385. position: absolute;
  386. right: 15px;
  387. bottom: 200px;
  388. width: 56px;
  389. height: 56px;
  390. }
  391. .png-search {
  392. width: 50rpx;
  393. height: 100%;
  394. position: absolute;
  395. right: 20px;
  396. top: 0;
  397. bottom: 0;
  398. margin: auto;
  399. display: flex;
  400. justify-content: center;
  401. align-items: center;
  402. /* border: 1rpx solid #000000; */
  403. }
  404. .scrollX {
  405. position: relative;
  406. width: 100%;
  407. height: 90upx;
  408. /* border: 1rpx solid #000000; */
  409. }
  410. .scrollX-padding {
  411. padding: 0 74px 0 20px;
  412. }
  413. .game-item {
  414. display: flex;
  415. justify-content: flex-start;
  416. flex-direction: row;
  417. background-color: white;
  418. margin: 17px 14px 0 17px;
  419. /* border-bottom: 1rpx solid rgba(240, 240, 240, 1); */
  420. }
  421. .game-item-image {
  422. width: 542rpx;
  423. height: 542rpx;
  424. z-index: 99;
  425. }
  426. .head-image {
  427. position: absolute;
  428. bottom: -20px;
  429. left: 0;
  430. margin-left: 17px;
  431. width: 80rpx;
  432. height: 80rpx;
  433. border: 2px solid white;
  434. border-radius: 100px;
  435. z-index: 100;
  436. }
  437. .play-bg-image {
  438. position: absolute;
  439. bottom: 0;
  440. left: 0;
  441. top: 0;
  442. right: 0;
  443. width: 112rpx;
  444. height: 112rpx;
  445. margin: auto;
  446. background: rgba(0, 0, 0, 0.25);
  447. /* opacity: 0.25; */
  448. border-radius: 100px;
  449. z-index: 100;
  450. }
  451. .play-image {
  452. position: absolute;
  453. bottom: 0;
  454. left: 0;
  455. top: 0;
  456. right: 0;
  457. width: 44rpx;
  458. height: 54rpx;
  459. margin: auto;
  460. z-index: 100;
  461. }
  462. .game-image-container {
  463. position: relative;
  464. }
  465. .game-index {
  466. z-index: 300;
  467. }
  468. .cu-color {
  469. color: rgba(191, 191, 193, 1);
  470. }
  471. .right-png {
  472. width: 36rpx;
  473. height: 32rpx;
  474. }
  475. </style>