MoreGameData.ts 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /**
  2. * @description 互推数据类
  3. * @author kaka
  4. */
  5. import JsbSystem from "../../mk/system/JsbSystem"
  6. export default class MoreGameData {
  7. /**推荐游戏信息 */
  8. private _moreGameList = null
  9. set moreGameList(value) {
  10. this._moreGameList = value;
  11. this.init_moreGameList = true;
  12. }
  13. get moreGameList() {
  14. return this._moreGameList;
  15. }
  16. /** 刷新标志位 */
  17. init_moreGameList = false;
  18. /** 下载中列表 */
  19. private static downLoadTaskMap: Map<string, DownloadTaskClazz> = new Map<string, any>()
  20. /** 测试数据 */
  21. private testData = {
  22. "normal": [
  23. {
  24. "nebulaAppId": "wxd2e694c55d457ded",
  25. "title": "爱上切水果",
  26. "introduction": "切水果、切水果、切、切、切!",
  27. "downloadUrl": "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/hutui/CutFruit.apk",
  28. "packageName": "com.aries.asqsg.mz",
  29. "icon": "https://oss.duiweize.com/fission/5vp7CPeadkABlgIe.png",
  30. "banner": "https://oss.duiweize.com/fission/EXrqiYF6BkC1ZsZf.png",
  31. },
  32. {
  33. "nebulaAppId": "wx74fee17e08a29836",
  34. "title": "炮火掠夺",
  35. "introduction": "大炮一响,黄金万两!",
  36. "downloadUrl": "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/hutui/FirePillage.apk",
  37. "packageName": "com.aries.firepillage.mz",
  38. "icon": "https://oss.duiweize.com/fission/BZ9ZUicxgCbWb33D.png",
  39. "banner": "https://oss.duiweize.com/fission/vGPWCE2tuGZwLSJH.png",
  40. }
  41. ],
  42. "banner": [
  43. {
  44. "nebulaAppId": "wx07895e2f78748daf",
  45. "title": "豪车大富翁",
  46. "introduction": "豪车、金钱、美女,你要的这里都有!",
  47. "downloadUrl": "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/hutui/HundredsOfMillions.apk",
  48. "packageName": "org.cocos2d.hundredsofmillion.mk.mz",
  49. "icon": "https://oss.duiweize.com/fission/fviQN9OpUmmqpTjU.png",
  50. "banner": "https://oss.duiweize.com/fission/eWUxr3OySHIohqtB.png",
  51. "banner2": "https://oss.duiweize.com/fission/eWUxr3OySHIohqtB.png",
  52. },
  53. {
  54. "nebulaAppId": "wx22b3f0f8005f0e51",
  55. "title": "航海传奇",
  56. "introduction": " 战舰、短裙、红包,你想要的都有!",
  57. "downloadUrl": "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/hutui/LegendOfNavigation.apk",
  58. "packageName": "com.aries.hhcq.mz",
  59. "icon": "https://oss.duiweize.com/fission/ZqDsgbj9PT94RcG0.png",
  60. "banner": "https://oss.duiweize.com/fission/goS05API8LtqB0QH.png",
  61. "banner2": "https://oss.duiweize.com/fission/goS05API8LtqB0QH.png",
  62. }
  63. ]
  64. }
  65. async sendRecommendList() {
  66. // if (this._moreGameList == null || this._moreGameList == undefined) {
  67. // let data = {};
  68. // let response = await mk.http.sendRequest('/fission/recommendList', 'POST', JSON.stringify(data))
  69. // if (response.errcode != 0) {
  70. // return;
  71. // }
  72. // this.moreGameList(response.data);
  73. // }
  74. // else {
  75. // this.init_moreGameList = true;
  76. // }
  77. //test
  78. this.moreGameList = this.testData;
  79. //刷新主界面按钮状态
  80. // if (cc.isValid(UiM.Instance.hallNode)) {
  81. // let main = UiM.Instance.hallNode.getComponent(Main)
  82. // if (this.moreGameList == null || this.moreGameList == undefined) {
  83. // main.moreGameBtn.node.active = false
  84. // return
  85. // }
  86. // if ((this.moreGameList.banner == null || this.moreGameList.banner == undefined || this.moreGameList.banner.length == 0)
  87. // && (this.moreGameList.normal == null || this.moreGameList.normal == undefined || this.moreGameList.normal.length == 0)) {
  88. // main.moreGameBtn.node.active = false
  89. // return
  90. // }
  91. // if (cc.sys.platform == cc.sys.ANDROID) {
  92. // main.setMoreGameSp(this.moreGameList.normal)
  93. // }
  94. // main.moreGameBtn.node.active = true
  95. // }
  96. }
  97. /**上报 */
  98. sendAppDownloadLog(downLoadAppId: string) {
  99. let data = { "downloadAppId": downLoadAppId };
  100. let response = mk.http.sendRequest('/fission/appDownloadLog', 'POST', JSON.stringify(data));
  101. }
  102. /**
  103. * 下载
  104. * @param data
  105. * @returns 下载任务
  106. */
  107. createNewTask(data): DownloadTaskClazz {
  108. let name = data.nebulaAppId + ".apk"
  109. let url = data.downloadUrl
  110. let packageName = data.packageName
  111. if (packageName != "") {
  112. let isExist = JsbSystem.ifCanStartGame(packageName, true)
  113. if (isExist) {
  114. // JsbSystem.sendEvent('hutuiEventLaunch_' + data.nebulaAppId, "互推启动" + data.title, 'hutuiEventLaunch')
  115. //判断在原生环境下存在就直接启动
  116. return null
  117. }
  118. }
  119. if (JsbSystem.isFileExist(name)) {
  120. JsbSystem.installApk(name);
  121. return null;
  122. }
  123. if (MoreGameData.downLoadTaskMap[data.nebulaAppId]) {
  124. // EffectNode.instance.PlayTipSimple('正在下载中...')
  125. return null
  126. }
  127. // EffectNode.instance.PlayTipSimple('开始下载...')
  128. let downLoadTask = new DownloadTaskClazz(0, 0, data.nebulaAppId, null)
  129. let curTask = JsbSystem.downFile2Local(url, data.nebulaAppId + ".apk", (locaPath) => {
  130. // LogUtil.logV("sendAppDownloadLog", "success")
  131. downLoadTask.progress = -2
  132. this.sendAppDownloadLog(data.nebulaAppId)
  133. setTimeout(() => {
  134. JsbSystem.installApk(name)
  135. }, 1)
  136. }, () => {
  137. downLoadTask.progress = -1
  138. MoreGameData.downLoadTaskMap[data.nebulaAppId] = null
  139. // EffectNode.instance.PlayTip('下载失败,请稍后再试')
  140. }, (task: jsb.DownloaderTask, bytesReceived: number, totalBytesReceived: number, totalBytesExpected: number) => {
  141. downLoadTask.progress = bytesReceived
  142. downLoadTask.totalBytesReceives = totalBytesReceived
  143. })
  144. downLoadTask.downloadTask = curTask
  145. MoreGameData.downLoadTaskMap[data.nebulaAppId] = downLoadTask
  146. // AdM.onSendEvent('hutuiEventDown_' + data.nebulaAppId, "互推下载" + data.title, 'hutuiEventDown')
  147. return downLoadTask
  148. }
  149. getTaskInfo(appId): DownloadTaskClazz {
  150. return MoreGameData.downLoadTaskMap[appId]
  151. }
  152. // /** 随机获取推荐位游戏 展示在更多游戏界面中部 可能是空*/
  153. // getRandomBanner() {
  154. // if (!this.moreGameList.banner || this.moreGameList.banner.length <= 0) {
  155. // return null
  156. // }
  157. // let index = Utils.rnd(0, this.moreGameList.banner.length - 1)
  158. // let data = this.moreGameList.banner[index]
  159. // return data
  160. // }
  161. /** 随机获取信息流位游戏 展示在十倍领取*/
  162. getRandomSteam() {
  163. if (!this.moreGameList) {
  164. return null
  165. }
  166. let index = mk.math.random(0, this.moreGameList.stream.length - 1)
  167. let data = this.moreGameList.stream[index]
  168. return data
  169. }
  170. /** 随机获取底部位游戏 展示在更多游戏界面列表小图*/
  171. getRandomNormal() {
  172. if (!this.moreGameList) {
  173. return null
  174. }
  175. let index = mk.math.random(0, this.moreGameList.normal.length - 1)
  176. let data = this.moreGameList.normal[index]
  177. return data
  178. }
  179. }
  180. /** 下载任务 */
  181. class DownloadTaskClazz {
  182. private _progress = 0
  183. private _totalBytesReceives = 0
  184. private _nebulaAppId = ""
  185. private _downloadTask = null
  186. constructor(progress, totalBytesReceives, nebulaAppId, downloadTask) {
  187. this._progress = progress
  188. this._totalBytesReceives = totalBytesReceives
  189. this._nebulaAppId = nebulaAppId
  190. this._downloadTask = downloadTask
  191. }
  192. public get progress(): number {
  193. return this._progress
  194. }
  195. public set progress(progress: number) {
  196. this._progress = progress
  197. }
  198. public get totalBytesReceives(): number {
  199. return this._totalBytesReceives
  200. }
  201. public set totalBytesReceives(totalBytesReceives: number) {
  202. this._totalBytesReceives = totalBytesReceives
  203. }
  204. public get downloadTask(): any {
  205. return this._downloadTask
  206. }
  207. public set downloadTask(downloadTask: any) {
  208. this._downloadTask = downloadTask
  209. }
  210. }