fc.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <template>
  2. <view>
  3. <!-- rgba(116, 172, 240, 1)-->
  4. <uni-nav-bar id="nav-bar" :status-bar="true" :border="false" @clickLeft="onBack()" @clickRight="onNavConver" title="全部游戏"
  5. :fixed="true">
  6. <view slot="left">
  7. <view class=" flex align-center margin-left">
  8. <image class="p-left-arrow" src="../../../static/p-left-arrow.png"></image>
  9. </view>
  10. </view>
  11. <view slot="right">
  12. <view class="align-center text-13px" style="width: 130rpx;">
  13. 我的游戏
  14. </view>
  15. </view>
  16. </uni-nav-bar>
  17. <view class="cu-bar search bg-white">
  18. <view class="search-form ">
  19. <text class="cuIcon-search"></text>
  20. <!-- @focus="InputFocus" @blur="InputBlur" -->
  21. <input :adjust-position="false" type="text" placeholder="搜索游戏" confirm-type="search"></input>
  22. </view>
  23. </view>
  24. <view class="scrollX">
  25. <scroll-view scroll-x class="bg-white nav scrollX-padding" scroll-with-animation :scroll-left="scrollLeft">
  26. <view class="cu-item text-15px" :class="index == TabCur ? 'text-bold black text-22px' : 'cu-color'" v-for="(item, index) in tabList"
  27. :key="index" @tap="tabSelect" :data-id="index" :data-category_id="item.categoryType" >
  28. {{ item.categoryName }}
  29. </view>
  30. </scroll-view>
  31. </view>
  32. <button @click="getFile">getFile</button>
  33. <button @click="navGame">game</button>
  34. <scroll-view scroll-y="true" :style="{ height: scrollviewHigh + 'px' }" @scrolltolower="lower">
  35. <view class="fc-list">
  36. <view class="fc-li" v-for="(item, index) in gameList" :key="index" :data-id="index" @tap="onNavToWebviewGame(item)">
  37. <image mode="aspectFill" class="game-item-image" :src="item.gamePicture"></image>
  38. <view class="fc-bottom-container">
  39. <view class="text-center text-white text-bold">{{item.gameName}}</view>
  40. <view class="text-center text-white">{{item.gamePlayNum}}人在玩</view>
  41. </view>
  42. <view v-if="item.bDownload" class="play-bg-download">
  43. <view class="text-center text-white text-bold">下载中...</view>
  44. <view class="text-center text-white text-bold margin-sm">{{item.progressVal}}%</view>
  45. </view>
  46. </view>
  47. </view>
  48. <view v-if="gameList.length == 0" class="text-16px text-gray text-center margin">没有更多数据</view>
  49. <view style="height: 17px;"></view>
  50. </scroll-view>
  51. <!-- https://www.yuyekeji.cn/Cocos/TestDownload -->
  52. <!-- <view class="web-view">
  53. <web-view class="web-view-child" src = 'https://www.yuyekeji.cn/Cocos/TestEmulatrix15'></web-view>
  54. </view> -->
  55. </view>
  56. </template>
  57. <script>
  58. import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue';
  59. import sideBar from '@/components/side-bar/side-bar.vue';
  60. import config from '../../../common/config.js';
  61. import reqUtil from '../../../util/util-js/requstUtil.js';
  62. import roundMenu from "@/components/round-menu/round-menu.vue";
  63. import {
  64. mapState
  65. } from 'vuex';
  66. export default {
  67. components: {
  68. uniNavBar,
  69. sideBar,
  70. roundMenu
  71. },
  72. computed: mapState(['ConnectBindingDevice', 'BLEConnectDevice', 'cIndex']),
  73. data() {
  74. return {
  75. // tabList: [{
  76. // categoryType: 1,
  77. // categoryName: "全部"
  78. // }, {
  79. // categoryType: 1,
  80. // categoryName: "热门"
  81. // }, {
  82. // categoryType: 1,
  83. // categoryName: "对战"
  84. // }, {
  85. // categoryType: 1,
  86. // categoryName: "最新"
  87. // }, {
  88. // categoryType: 1,
  89. // categoryName: "益智"
  90. // }, {
  91. // categoryType: 1,
  92. // categoryName: "单机"
  93. // }],
  94. tabList: [],
  95. TabCur: 0,
  96. Category: 0,
  97. scrollLeft: 0,
  98. scrollviewHigh: '',
  99. bDontUpdate: false,
  100. //游戏列表
  101. gameList: [{
  102. gameIcon: "/static/avatar/1.png",
  103. gamePicture: "/static/conversion/game.png",
  104. gameName: "giabbit.nes",
  105. gamePlayNum: 100,
  106. gameDownloadUrl: "https://www.yuyekeji.cn/Cocos/FCEmulator/roms/giabbit/giabbit.nes",
  107. gameFileName: "giabbit",
  108. suffix: "nes",
  109. type: "NES",
  110. task: null,
  111. progressVal: 0,
  112. bFileExists: false,
  113. bDownload: false,
  114. }, {
  115. gameIcon: "/static/avatar/1.png",
  116. gamePicture: "/static/conversion/game.png",
  117. gameName: "giabbit.nes",
  118. gamePlayNum: 100,
  119. gameDownloadUrl: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",
  120. gameFileName: "big_buck_bunny",
  121. suffix: "mp4",
  122. type: "mp4",
  123. task: null,
  124. progressVal: 0,
  125. bFileExists: false,
  126. bDownload: false,
  127. }],
  128. gamePage: 1,
  129. gameSize: 10,
  130. //编码的item
  131. encodeItem: ''
  132. };
  133. },
  134. onLoad(option) {
  135. let _this = this;
  136. // console.log("option========:", option);
  137. // let _index = 1;
  138. // if (option && option.type) {
  139. // if (option.type == "game") {
  140. // _index = 1;
  141. // } else if (option.type == "video") {
  142. // _index = 2;
  143. // }
  144. // }
  145. //获得游戏类目
  146. reqUtil.requestData(config.URL.FCCATEGORYBYTYPE,{categoryType:1}).then(
  147. res => {
  148. // console.log('FCCATEGORYBYTYPE =====', res);
  149. if (res.code == 0) {
  150. this.tabList = res.data;
  151. this.TabCur = 0;
  152. this.categoryType = this.tabList[0].categoryType;
  153. this.getGameList(this.categoryType);
  154. }
  155. },
  156. e => {
  157. console.log(e);
  158. }
  159. );
  160. },
  161. onReady() {
  162. let _this = this;
  163. uni.getSystemInfo({
  164. success(res) {
  165. // 计算组件的高度
  166. let view = uni.createSelectorQuery().select('#nav-bar');
  167. view.boundingClientRect(data => {
  168. let navHeight = data.height;
  169. let scrollXHight = uni.upx2px(90);
  170. _this.scrollviewHigh = res.windowHeight - navHeight - scrollXHight;
  171. }).exec();
  172. }
  173. });
  174. },
  175. methods: {
  176. onBack() {
  177. uni.navigateBack({
  178. delta: 1
  179. })
  180. },
  181. // 跳转转换页面
  182. onNavConver() {
  183. uni.navigateTo({
  184. url: '../fc-list/fc-list',
  185. success: res => {},
  186. fail: () => {},
  187. complete: () => {}
  188. });
  189. },
  190. tabSelect(e) {
  191. if (this.TabCur != e.currentTarget.dataset.id) {
  192. //重新设置参数
  193. this.bDontUpdate = false;
  194. this.gameList = [];
  195. this.gamePage = 1;
  196. this.gameSize = 10;
  197. this.TabCur = e.currentTarget.dataset.id;
  198. this.categoryType = e.currentTarget.dataset.category_id;
  199. this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60;
  200. this.getGameList(this.categoryType);
  201. }
  202. },
  203. showClickEvent() {
  204. this.$refs.sideBar.showModal();
  205. },
  206. onNavSearch() {
  207. uni.showToast({
  208. title: '功能尚未开放',
  209. icon: 'none'
  210. })
  211. return;
  212. uni.navigateTo({
  213. url: '../game-search/game-search',
  214. success: res => {},
  215. fail: () => {},
  216. complete: () => {}
  217. });
  218. },
  219. //收藏
  220. onFavoriteAdd(item) {
  221. //添加收藏
  222. let favoritesTemp = {
  223. 'fObjectId': item.gameId,
  224. 'favoritesType': 0,
  225. }
  226. reqUtil.requestData(config.URL.FAVORITESMODIFY, favoritesTemp).then(res => {
  227. console.log('FAVORITESMODIFY =====', res);
  228. if (res.code == 0) {
  229. if (!res.data.bHas) {
  230. item.gameFavorite = false;
  231. uni.showToast({
  232. title: "取消收藏",
  233. icon: "none"
  234. })
  235. } else {
  236. uni.showToast({
  237. title: "收藏成功",
  238. icon: "none"
  239. })
  240. item.gameFavorite = true;
  241. }
  242. }
  243. },
  244. e => {
  245. console.log(e)
  246. });
  247. },
  248. onNavComment() {
  249. uni.showToast({
  250. title: '功能尚未开放',
  251. icon: 'none'
  252. })
  253. return;
  254. uni.navigateTo({
  255. url: '../game-comment/game-comment',
  256. success: res => {},
  257. fail: () => {},
  258. complete: () => {}
  259. });
  260. },
  261. onNavDetail(item) {
  262. // console.log(item);
  263. let temItem = encodeURIComponent(JSON.stringify(item));
  264. // return;
  265. uni.navigateTo({
  266. url: '../game-detail/game-detail?item=' + temItem,
  267. success: res => {},
  268. fail: () => {},
  269. complete: () => {}
  270. });
  271. },
  272. onNavToWebviewGame(item) {
  273. //#ifdef H5
  274. console.log("h5");
  275. let _FCList = uni.getStorageSync("FCList");
  276. if (_FCList) {
  277. item.task = null;
  278. _FCList.push(item);
  279. uni.setStorageSync("FCList", _FCList);
  280. } else {
  281. uni.setStorageSync("FCList", [item]);
  282. }
  283. //#endif
  284. //#ifdef APP-PLUS
  285. console.log("====item == ", item);
  286. let downloadUrl = item.gameDownloadUrl;
  287. let name = item.gameFileName;
  288. item.task = plus.downloader.createDownload(downloadUrl, {
  289. filename: '_doc/' + name
  290. });
  291. item.task.addEventListener("statechanged", (download, status) => {
  292. // console.log("status", status);
  293. //连接服务器后
  294. // no default
  295. switch (download.state) {
  296. case 1:
  297. console.log('开始下载');
  298. // item.bDownload = true;
  299. break;
  300. case 2:
  301. console.log('链接到服务器...');
  302. item.bDownload = true;
  303. break;
  304. case 3:
  305. if (status !== 200) {
  306. uni.showToast({
  307. title: 'status=' + status
  308. })
  309. return;
  310. }
  311. item.progressVal = Math.ceil(download.downloadedSize / download.totalSize * 100);
  312. // _this.precent = progressVal;
  313. console.log(item.progressVal);
  314. break;
  315. case 4:
  316. // 下载完成
  317. console.log("监听下载 success: " + download.getFileName());
  318. setTimeout(() => {
  319. item.bDownload = false;
  320. }, 500)
  321. //todo 下载完成,设置记录数据到本地,
  322. let _FCList = plus.storage.getItem("FCList");
  323. console.log("_FCList:", _FCList);
  324. if (_FCList) {
  325. item.task = null;
  326. _FCList.push(item);
  327. plus.storage.setItem("FCList", _FCList);
  328. console.log("_FCList1:", _FCList);
  329. } else {
  330. plus.storage.setItem("FCList", [item])
  331. console.log("_FCList2:", [item]);
  332. }
  333. break;
  334. }
  335. }, false);
  336. item.task.start();
  337. //#endif
  338. return;
  339. if (!this.BLEConnectDevice || this.cIndex == -1) {
  340. uni.showToast({
  341. title: "没有连接绑带,请连接后重试!",
  342. icon: "none"
  343. })
  344. return;
  345. }
  346. reqUtil.requestData(config.URL.GAMEDETAIL, item).then(res => {
  347. console.log('GAMEDETAIL =====', res);
  348. if (res.code == 0) {
  349. this.encodeItem = encodeURIComponent(JSON.stringify(res.data.gameInfo));
  350. // #ifdef APP-PLUS
  351. uni.navigateTo({
  352. url: '../game-play-sub/game-play-sub?item=' + this.encodeItem,
  353. success: res => {},
  354. fail: () => {},
  355. complete: () => {}
  356. });
  357. // #endif
  358. // #ifdef H5
  359. uni.navigateTo({
  360. url: '../game-play/game-play-web?item=' + this.encodeItem,
  361. success: res => {},
  362. fail: () => {},
  363. complete: () => {}
  364. });
  365. // #endif
  366. }
  367. },
  368. e => {
  369. console.log(e)
  370. });
  371. },
  372. getGameList(categoryType) {
  373. uni.showToast({
  374. icon: "loading",
  375. title: "",
  376. mask: true,
  377. duration: 10000
  378. })
  379. //获得游戏列表
  380. reqUtil.requestData(
  381. config.URL.FCListByCategory, {
  382. categoryNumber: categoryType,//类目编号
  383. //endTime 可以不设置,服务器默认设置一个值
  384. // endTime: config.endTime,
  385. page: this.gamePage,
  386. size: this.gameSize
  387. }
  388. ).then(res => {
  389. console.log('GAMELIST_FROM_CATEGORY =====', res);
  390. if (res.code == 0) {
  391. uni.hideToast();
  392. if (res.data.length < this.gameSize) {
  393. this.bDontUpdate = true;
  394. }
  395. if (res.data.length != 0) {
  396. uni.showToast({
  397. icon: "none",
  398. title: "更新成功",
  399. })
  400. } else {
  401. uni.showToast({
  402. icon: "none",
  403. title: "没数据啦",
  404. })
  405. }
  406. this.gameList = this.gameList.concat(res.data);
  407. }
  408. },
  409. e => {
  410. console.log(e);
  411. uni.showToast({
  412. icon: "none",
  413. title: "更新出错",
  414. })
  415. }
  416. );
  417. },
  418. onRoundTrigger(data) {
  419. console.log("onRoundTrigger==", data);
  420. // return;
  421. let url = '';
  422. switch (data.item.type) {
  423. case "personal":
  424. //个人中心页面
  425. url = '../../personal-page/personal/personal';
  426. break;
  427. case "game":
  428. url = '../../game-page/game/game';
  429. break;
  430. default:
  431. url = '../../personal-page/personal/personal';
  432. break;
  433. }
  434. uni.reLaunch({
  435. url: url,
  436. success: res => {},
  437. fail: () => {},
  438. complete: () => {}
  439. });
  440. },
  441. lower(e) {
  442. return;
  443. if (this.bDontUpdate) return;
  444. console.log(e);
  445. this.gamePage++;
  446. this.getGameList(this.categoryType);
  447. },
  448. getFile() {
  449. let url = "_doc/uniapp_save/1603173965127.nes";
  450. uni.getSavedFileList({
  451. success: function(res) {
  452. console.log(res.fileList);
  453. for (var i = 0, len = res.fileList.length; i < len; i++) {
  454. var path = plus.io.convertLocalFileSystemURL(res.fileList[i].filePath);
  455. console.log(path);
  456. }
  457. }
  458. });
  459. },
  460. navGame() {
  461. plus.io.requestFileSystem(plus.io.PRIVATE_DOC, function(fs) {
  462. // 可通过fs操作PRIVATE_DOC文件系统
  463. var directoryReader = fs.root.createReader();
  464. directoryReader.readEntries(function(entries) {
  465. var i;
  466. for (i = 0; i < entries.length; i++) {
  467. console.log(entries[i].name);
  468. }
  469. }, function(e) {
  470. console.log("Read entries failed: " + e.message);
  471. });
  472. }, function(e) {
  473. console.log("Request file system failed: ", e.message);
  474. });
  475. }
  476. }
  477. };
  478. </script>
  479. <style>
  480. .page {
  481. height: 100vh;
  482. }
  483. page {
  484. background-color: #fff;
  485. }
  486. .float-png {
  487. position: absolute;
  488. right: 15px;
  489. bottom: 200px;
  490. width: 56px;
  491. height: 56px;
  492. }
  493. .png-search {
  494. width: 50rpx;
  495. height: 100%;
  496. position: absolute;
  497. right: 20px;
  498. top: 0;
  499. bottom: 0;
  500. margin: auto;
  501. display: flex;
  502. justify-content: center;
  503. align-items: center;
  504. /* border: 1rpx solid #000000; */
  505. }
  506. .scrollX {
  507. position: relative;
  508. width: 100%;
  509. height: 90rpx;
  510. margin-bottom: 10px;
  511. /* border: 1rpx solid #000000; */
  512. }
  513. .scrollX-padding {
  514. padding: 0 20px;
  515. }
  516. .game-item {
  517. /* display: flex; */
  518. /* justify-content: space-between; */
  519. /* flex-direction: row; */
  520. /* background-color: white; */
  521. flex: 0 0 33.3%;
  522. max-width: 33.3%;
  523. width: 226rpx;
  524. height: 270rpx;
  525. margin: 17px 10px 0 10px;
  526. border: 1rpx solid #000000;
  527. border-radius: 10rpx;
  528. position: relative;
  529. /* border-bottom: 1rpx solid rgba(240, 240, 240, 1); */
  530. }
  531. .game-item-image {
  532. width: 100%;
  533. height: 100%;
  534. border-radius: 10rpx;
  535. z-index: 99;
  536. }
  537. .head-image {
  538. position: absolute;
  539. bottom: -20px;
  540. left: 0;
  541. margin-left: 17px;
  542. width: 80rpx;
  543. height: 80rpx;
  544. border: 2px solid white;
  545. border-radius: 100px;
  546. z-index: 100;
  547. }
  548. .play-bg-download {
  549. position: absolute;
  550. bottom: 0;
  551. left: 0;
  552. top: 0;
  553. right: 0;
  554. margin: auto;
  555. background: rgba(0, 0, 0, 0.3);
  556. z-index: 100;
  557. display: flex;
  558. flex-direction: column;
  559. justify-content: center;
  560. text-align: center;
  561. border-radius: 12rpx;
  562. }
  563. .play-image {
  564. position: absolute;
  565. bottom: 0;
  566. left: 0;
  567. top: 0;
  568. right: 0;
  569. width: 44rpx;
  570. height: 54rpx;
  571. margin: auto;
  572. z-index: 100;
  573. }
  574. .game-image-container {
  575. position: relative;
  576. }
  577. .game-index {
  578. z-index: 300;
  579. }
  580. .cu-color {
  581. color: rgba(191, 191, 193, 1);
  582. }
  583. .right-png {
  584. width: 36rpx;
  585. height: 32rpx;
  586. }
  587. .fc-bottom-container {
  588. position: absolute;
  589. bottom: 0;
  590. left: 0;
  591. /* top: 0; */
  592. right: 0;
  593. width: 100%;
  594. height: 80rpx;
  595. border-radius: 0 0 10rpx 10rpx;
  596. margin: auto;
  597. z-index: 100;
  598. background: linear-gradient(left, rgb(66, 202, 96), rgb(23, 193, 14));
  599. }
  600. .fc-list {
  601. display: flex;
  602. flex-wrap: wrap;
  603. padding: 10px 10rpx 0px;
  604. justify-content: flex-start;
  605. }
  606. .fc-li {
  607. border-radius: 12rpx;
  608. width: 32%;
  609. height: 270rpx;
  610. margin: 0 0 20rpx 8rpx;
  611. position: relative;
  612. z-index: 1;
  613. }
  614. .fc-li::after {
  615. content: "";
  616. position: absolute;
  617. z-index: -1;
  618. background-color: inherit;
  619. width: 100%;
  620. height: 100%;
  621. left: 0;
  622. bottom: -10%;
  623. border-radius: 10upx;
  624. opacity: 0.2;
  625. transform: scale(0.9, 0.9);
  626. }
  627. .fc.cur {
  628. color: #fff;
  629. background: rgb(94, 185, 94);
  630. box-shadow: 4upx 4upx 6upx rgba(94, 185, 94, 0.4);
  631. }
  632. .web-view {
  633. position: relative;
  634. display: flex;
  635. flex-direction: column;
  636. border-style: solid;
  637. border-width: 1rpx;
  638. border: 1rpx solid #007AFF;
  639. }
  640. .web-view-child {
  641. width: 650rpx;
  642. height: 1280rpx;
  643. /* flex: 1; */
  644. }
  645. </style>