MainStore.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. import { API_LOGIN, APP_ROUTES, success, APP_GAME_CARD_INFO } from "../../api";
  2. import { AppKernel } from "../../app/AppKernel";
  3. import { LoginType } from "../../define/Define";
  4. import { LOCAL_SIGN } from "../../constants/Localkey";
  5. import { Http } from "../../request";
  6. import { getEnterPlatform, localStorageSet } from "../../utils/Helper";
  7. import { IGameInfo } from "../pageSlice/data";
  8. import { IRoutesResponse, IUserData, IWithdrawChannel } from "./data";
  9. class MainStore {
  10. private _firstLaunch = true;
  11. private _hallServerUrl: string;
  12. private _isGuest: boolean;
  13. private _userInfo: IUserData;
  14. private _isLogin: boolean;
  15. private _upgradeBonus: number;
  16. private _registerBonus: number;
  17. private _recommendGame: string;
  18. private _serviceLink: string;
  19. private _landscapeGames: string[];
  20. private _withdrawChannel: IWithdrawChannel;
  21. private _serverKick: boolean;
  22. private _gameCardInfo = {};
  23. public gameID = 0;
  24. public gameLink = "";
  25. public get firstLaunch() { return this._firstLaunch; }
  26. public get hallServerUrl() { return this._hallServerUrl; }
  27. public get isGuest() { return this._isGuest; }
  28. public get userInfo() { return this._userInfo; }
  29. public get userID() { return this._userInfo?.UserID ?? 0; }
  30. public get isLogin() { return this._isLogin; }
  31. public get isBindPhone() {
  32. if (!this.userInfo) return false;
  33. const phone = this.userInfo.Phone || '';
  34. return phone.startsWith(this.userInfo.RegisterLocation)
  35. }
  36. public get upgradeBonus() { return this._upgradeBonus; }
  37. public get registerBonus() { return this._registerBonus; }
  38. public get recommendGame() { return this._recommendGame; }
  39. public get serviceLink() { return this._serviceLink; }
  40. public get landscapeGames() { return this._landscapeGames; }
  41. public get withdrawChannel() { return this._withdrawChannel; }
  42. public get serverKick() { return this._serverKick; }
  43. async reqGetRoutes() {
  44. const platform = AppKernel.platform;
  45. const params: any = {
  46. ad_id: platform.getUrlParam("ad_id"),
  47. adset_id: platform.getUrlParam("adset_id"),
  48. campaign_id: platform.getUrlParam("campaign_id"),
  49. pixel: platform.getUrlParam("pixel"),
  50. };
  51. if (window.navigator && window.navigator.userAgent) {
  52. params.ua = window.navigator.userAgent;
  53. }
  54. // let ia = getInAppBrowser();
  55. // if (ia != null && ia !== "") {
  56. // params.params.ia = ia;
  57. // }
  58. /// TODO: 所有的启动参数
  59. // let urlvars = global.getUrlvars();
  60. // if (urlvars != null && urlvars !== "") {
  61. // params.params.urlvars = urlvars;
  62. // }
  63. // let pwa = checkIsStandalone() || isTWA();
  64. // if (pwa) {
  65. // params.params.pwa = 1;
  66. // }
  67. if (typeof document !== "undefined") {
  68. params.cookie = document.cookie || "";
  69. }
  70. params.platform = getEnterPlatform();
  71. const res: IRoutesResponse = await Http.call(APP_ROUTES, params);
  72. if (!res || res.code !== 0) {
  73. return false;
  74. }
  75. this._firstLaunch = false;
  76. let hallServerUrl = '';
  77. let guest = 0;
  78. let upgradeBonus = 0;
  79. let registerBonus = 0;
  80. let recommendGame = '';
  81. let serviceLink = "";
  82. let landscapeGames = [];
  83. let withdrawChannel: IWithdrawChannel = null;
  84. const conf = res.conf;
  85. if (conf) {
  86. if (!!conf.hall) hallServerUrl = conf.hall;
  87. // if (!!conf.DOLLAR) global.DOLLAR = conf.DOLLAR;
  88. // if (!!conf.currency) global.currency = conf.currency;
  89. // global.pf = conf.pf;
  90. // console.log(`>>>>>>>> global.pf: ${JSON.stringify(global.pf)}`)
  91. // //平台配置
  92. // if (!!conf.pf && !!conf.pf.id) {
  93. // let { type, id } = conf.pf;
  94. // initTrackAll(type, id, isLogin ? userInfo.UserID : null);
  95. // }
  96. // //promoteInstall
  97. // if (!!conf.promoteInstall) promoteInstall = conf.promoteInstall;
  98. //guest
  99. if (!!conf.guest) guest = conf.guest;
  100. // 绑定手机奖励
  101. if (!!conf.upgradeBonus) upgradeBonus = conf.upgradeBonus;
  102. // 初始注册奖励
  103. if (!!conf.registerBonus) registerBonus = conf.registerBonus;
  104. ///领取注册奖励后进入的游戏
  105. if (!!conf.recommendGame) recommendGame = conf.recommendGame;
  106. //客服地址
  107. if (!!conf.serviceLink) serviceLink = conf.serviceLink;
  108. // //弹出转盘
  109. // if (!!conf.popWheel) popWheel = conf.popWheel;
  110. // //弹出绑定电话奖励,并显示浮标
  111. // if (!!conf.popBindPhone) popBindPhone = hasPhone ? 0 : conf.popBindPhone;
  112. // //显示首冲浮标
  113. // if (!!conf.firstBonus) firstBonus = conf.firstBonus;
  114. // //显示救济浮标
  115. // if (!!conf.openRelief) openRelief = conf.openRelief;
  116. // //sport 配置
  117. if (!!conf.bb) {
  118. // bbConf = conf.bb;
  119. // if (userInfo != null) userInfo.bb = bbConf;
  120. }
  121. // if (!!conf.loginOpen) loginOpen = conf.loginOpen;
  122. // if (!!conf.registerOpen) registerOpen = conf.registerOpen;
  123. // if (!!conf.popFirst) popFirst = conf.popFirst;
  124. // if (!!conf.showInstall) showInstall = conf.showInstall;
  125. // //download 配置
  126. // if (!!conf.download) download = conf.download;
  127. // if (!!conf.vipConfig) vipConfig = conf.vipConfig;
  128. if (!!conf.LandscapeGames) landscapeGames = conf.LandscapeGames;
  129. // // adjust相关配置
  130. // if (!!conf.AdjustToken && !!conf.AdjustConfig) global.tracker.initAdjust(conf.AdjustToken, conf.AdjustConfig);
  131. // if (!!conf.popPwaBonus) popPwaBonus = conf.popPwaBonus;
  132. // if (!!conf.outLimit) outLimit = conf.outLimit;
  133. if (!!conf.withdrawChannel) withdrawChannel = conf.withdrawChannelNew;
  134. // if (!!conf.freeChannel) freeChannel = conf.freeChannel;
  135. // if (!!conf.slotsPartner) slotsPartner = conf.slotsPartner;
  136. // if (!!conf.sharePop) sharePop = conf.sharePop;
  137. // googleRedirectH5 = parseGoogleRedirectH5Conf(conf);
  138. // googleRedirectH5Bonus = parseGoogleRedirectH5BonusConf(conf);
  139. // if (conf.jumpapk === 1 || conf.jumpapk === "1" || conf.jumpapk === 2 || conf.jumpapk === "2" || conf.jumpapk === 3 || conf.jumpapk === "3") {
  140. // googleRedirectJumpApk = Number(conf.jumpapk);
  141. // localStorageSet(LOCAL_GOOGLE_REDIRECT_JUMPAPK, conf.jumpapk);
  142. // } else {
  143. // localStorageSet(LOCAL_GOOGLE_REDIRECT_JUMPAPK, "");
  144. // }
  145. // if (conf.jumplater != null) jumplater = Number(conf.jumplater) || 0;
  146. // if (conf.weight1234 != null) fbGuideWeight = conf.weight1234;
  147. // // 注册后自动进游戏
  148. // if (conf.isAutoEnterGame != null) isAutoEnterGame = conf.isAutoEnterGame;
  149. // // 强制引导开关
  150. // if (conf.jumpios != null) jumpToH5 = conf.jumpios;
  151. // // 内置客服JS
  152. // if (!!conf.servicejs) SsqHelp.setServicejs(conf.servicejs);
  153. }
  154. const user = res.user;
  155. this.parseLogin(user);
  156. this._hallServerUrl = hallServerUrl;
  157. this._isGuest = guest === 1;
  158. this._upgradeBonus = upgradeBonus;
  159. this._registerBonus = registerBonus;
  160. this._recommendGame = recommendGame;
  161. this._serviceLink = serviceLink;
  162. this._landscapeGames = landscapeGames;
  163. this._withdrawChannel = withdrawChannel;
  164. return true;
  165. }
  166. async reqLogin(arg) {
  167. const loginType = arg.type;
  168. // const lang = global.i18n?.getCurrLang?.() || "";
  169. const params: any = {
  170. type: loginType,
  171. password: arg?.password,
  172. platform: getEnterPlatform(),
  173. // lang
  174. }
  175. switch (loginType) {
  176. case LoginType.ID:
  177. params.account = arg.account;
  178. break;
  179. case LoginType.PHONE:
  180. params.country = arg.country;
  181. params.account = arg.phone;
  182. break;
  183. case LoginType.MAIL:
  184. params.account = arg.email;
  185. break;
  186. case LoginType.GUEST:
  187. delete params.password;
  188. break;
  189. }
  190. const res = await Http.call<IUserData>(API_LOGIN, params)
  191. if (success(res)) {
  192. this.parseLogin(res.data);
  193. return true;
  194. }
  195. return false;
  196. }
  197. private parseLogin(data: IUserData) {
  198. if (!data || typeof data !== 'object') return;
  199. this.gameID = 0;
  200. this._isLogin = true;
  201. this._userInfo = data;
  202. this._serverKick = false;
  203. if (!!data.recommendGame) this._recommendGame = data.recommendGame;
  204. if (!!data.sign) localStorageSet(LOCAL_SIGN, data.sign);
  205. if (data.reg === 1) {
  206. // 新注册的
  207. }
  208. }
  209. clearGame() {
  210. this.gameID = 0;
  211. this.gameLink = "";
  212. }
  213. setServerKick(value: boolean) {
  214. this._serverKick = value;
  215. }
  216. updateHallBalance(balance: number) {
  217. if (!this._userInfo || !Number.isFinite(balance)) return;
  218. if ((this._userInfo.vip || 0) > 0) {
  219. this._userInfo.Score = balance;
  220. } else {
  221. this._userInfo.InsureScore = balance;
  222. }
  223. }
  224. async getGameCardInfo(gameId: number) {
  225. if (this._gameCardInfo[gameId]) {
  226. return this._gameCardInfo[gameId];
  227. }
  228. const payload = await Http.call<IGameInfo>(APP_GAME_CARD_INFO, { id: gameId })
  229. if (!success(payload) || !payload.data) {
  230. return null;
  231. }
  232. const gameInfo = payload.data;
  233. const id = Number(gameInfo.id);
  234. const level = gameInfo.level_info ? 1 : 0;
  235. const cardInfo = { ...gameInfo, level };
  236. this._gameCardInfo[id] = cardInfo;
  237. return cardInfo;
  238. }
  239. }
  240. export const mainStore = new MainStore();