| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- import { API_LOGIN, APP_ROUTES, success, APP_GAME_CARD_INFO } from "../../api";
- import { AppKernel } from "../../app/AppKernel";
- import { LoginType } from "../../define/Define";
- import { LOCAL_SIGN } from "../../constants/Localkey";
- import { Http } from "../../request";
- import { getEnterPlatform, localStorageSet } from "../../utils/Helper";
- import { IGameInfo } from "../pageSlice/data";
- import { IRoutesResponse, IUserData, IWithdrawChannel } from "./data";
- class MainStore {
- private _firstLaunch = true;
- private _hallServerUrl: string;
- private _isGuest: boolean;
- private _userInfo: IUserData;
- private _isLogin: boolean;
- private _upgradeBonus: number;
- private _registerBonus: number;
- private _recommendGame: string;
- private _serviceLink: string;
- private _landscapeGames: string[];
- private _withdrawChannel: IWithdrawChannel;
- private _serverKick: boolean;
- private _gameCardInfo = {};
- public gameID = 0;
- public gameLink = "";
- public get firstLaunch() { return this._firstLaunch; }
- public get hallServerUrl() { return this._hallServerUrl; }
- public get isGuest() { return this._isGuest; }
- public get userInfo() { return this._userInfo; }
- public get userID() { return this._userInfo?.UserID ?? 0; }
- public get isLogin() { return this._isLogin; }
- public get isBindPhone() {
- if (!this.userInfo) return false;
- const phone = this.userInfo.Phone || '';
- return phone.startsWith(this.userInfo.RegisterLocation)
- }
- public get upgradeBonus() { return this._upgradeBonus; }
- public get registerBonus() { return this._registerBonus; }
- public get recommendGame() { return this._recommendGame; }
- public get serviceLink() { return this._serviceLink; }
- public get landscapeGames() { return this._landscapeGames; }
- public get withdrawChannel() { return this._withdrawChannel; }
- public get serverKick() { return this._serverKick; }
- async reqGetRoutes() {
- const platform = AppKernel.platform;
- const params: any = {
- ad_id: platform.getUrlParam("ad_id"),
- adset_id: platform.getUrlParam("adset_id"),
- campaign_id: platform.getUrlParam("campaign_id"),
- pixel: platform.getUrlParam("pixel"),
- };
- if (window.navigator && window.navigator.userAgent) {
- params.ua = window.navigator.userAgent;
- }
- // let ia = getInAppBrowser();
- // if (ia != null && ia !== "") {
- // params.params.ia = ia;
- // }
- /// TODO: 所有的启动参数
- // let urlvars = global.getUrlvars();
- // if (urlvars != null && urlvars !== "") {
- // params.params.urlvars = urlvars;
- // }
- // let pwa = checkIsStandalone() || isTWA();
- // if (pwa) {
- // params.params.pwa = 1;
- // }
- if (typeof document !== "undefined") {
- params.cookie = document.cookie || "";
- }
- params.platform = getEnterPlatform();
- const res: IRoutesResponse = await Http.call(APP_ROUTES, params);
- if (!res || res.code !== 0) {
- return false;
- }
- this._firstLaunch = false;
- let hallServerUrl = '';
- let guest = 0;
- let upgradeBonus = 0;
- let registerBonus = 0;
- let recommendGame = '';
- let serviceLink = "";
- let landscapeGames = [];
- let withdrawChannel: IWithdrawChannel = null;
- const conf = res.conf;
- if (conf) {
- if (!!conf.hall) hallServerUrl = conf.hall;
- // if (!!conf.DOLLAR) global.DOLLAR = conf.DOLLAR;
- // if (!!conf.currency) global.currency = conf.currency;
- // global.pf = conf.pf;
- // console.log(`>>>>>>>> global.pf: ${JSON.stringify(global.pf)}`)
- // //平台配置
- // if (!!conf.pf && !!conf.pf.id) {
- // let { type, id } = conf.pf;
- // initTrackAll(type, id, isLogin ? userInfo.UserID : null);
- // }
- // //promoteInstall
- // if (!!conf.promoteInstall) promoteInstall = conf.promoteInstall;
- //guest
- if (!!conf.guest) guest = conf.guest;
- // 绑定手机奖励
- if (!!conf.upgradeBonus) upgradeBonus = conf.upgradeBonus;
- // 初始注册奖励
- if (!!conf.registerBonus) registerBonus = conf.registerBonus;
- ///领取注册奖励后进入的游戏
- if (!!conf.recommendGame) recommendGame = conf.recommendGame;
- //客服地址
- if (!!conf.serviceLink) serviceLink = conf.serviceLink;
- // //弹出转盘
- // if (!!conf.popWheel) popWheel = conf.popWheel;
- // //弹出绑定电话奖励,并显示浮标
- // if (!!conf.popBindPhone) popBindPhone = hasPhone ? 0 : conf.popBindPhone;
- // //显示首冲浮标
- // if (!!conf.firstBonus) firstBonus = conf.firstBonus;
- // //显示救济浮标
- // if (!!conf.openRelief) openRelief = conf.openRelief;
- // //sport 配置
- if (!!conf.bb) {
- // bbConf = conf.bb;
- // if (userInfo != null) userInfo.bb = bbConf;
- }
- // if (!!conf.loginOpen) loginOpen = conf.loginOpen;
- // if (!!conf.registerOpen) registerOpen = conf.registerOpen;
- // if (!!conf.popFirst) popFirst = conf.popFirst;
- // if (!!conf.showInstall) showInstall = conf.showInstall;
- // //download 配置
- // if (!!conf.download) download = conf.download;
- // if (!!conf.vipConfig) vipConfig = conf.vipConfig;
- if (!!conf.LandscapeGames) landscapeGames = conf.LandscapeGames;
- // // adjust相关配置
- // if (!!conf.AdjustToken && !!conf.AdjustConfig) global.tracker.initAdjust(conf.AdjustToken, conf.AdjustConfig);
- // if (!!conf.popPwaBonus) popPwaBonus = conf.popPwaBonus;
- // if (!!conf.outLimit) outLimit = conf.outLimit;
- if (!!conf.withdrawChannel) withdrawChannel = conf.withdrawChannelNew;
- // if (!!conf.freeChannel) freeChannel = conf.freeChannel;
- // if (!!conf.slotsPartner) slotsPartner = conf.slotsPartner;
- // if (!!conf.sharePop) sharePop = conf.sharePop;
- // googleRedirectH5 = parseGoogleRedirectH5Conf(conf);
- // googleRedirectH5Bonus = parseGoogleRedirectH5BonusConf(conf);
- // if (conf.jumpapk === 1 || conf.jumpapk === "1" || conf.jumpapk === 2 || conf.jumpapk === "2" || conf.jumpapk === 3 || conf.jumpapk === "3") {
- // googleRedirectJumpApk = Number(conf.jumpapk);
- // localStorageSet(LOCAL_GOOGLE_REDIRECT_JUMPAPK, conf.jumpapk);
- // } else {
- // localStorageSet(LOCAL_GOOGLE_REDIRECT_JUMPAPK, "");
- // }
- // if (conf.jumplater != null) jumplater = Number(conf.jumplater) || 0;
- // if (conf.weight1234 != null) fbGuideWeight = conf.weight1234;
- // // 注册后自动进游戏
- // if (conf.isAutoEnterGame != null) isAutoEnterGame = conf.isAutoEnterGame;
- // // 强制引导开关
- // if (conf.jumpios != null) jumpToH5 = conf.jumpios;
- // // 内置客服JS
- // if (!!conf.servicejs) SsqHelp.setServicejs(conf.servicejs);
- }
- const user = res.user;
- this.parseLogin(user);
- this._hallServerUrl = hallServerUrl;
- this._isGuest = guest === 1;
- this._upgradeBonus = upgradeBonus;
- this._registerBonus = registerBonus;
- this._recommendGame = recommendGame;
- this._serviceLink = serviceLink;
- this._landscapeGames = landscapeGames;
- this._withdrawChannel = withdrawChannel;
- return true;
- }
- async reqLogin(arg) {
- const loginType = arg.type;
- // const lang = global.i18n?.getCurrLang?.() || "";
- const params: any = {
- type: loginType,
- password: arg?.password,
- platform: getEnterPlatform(),
- // lang
- }
- switch (loginType) {
- case LoginType.ID:
- params.account = arg.account;
- break;
- case LoginType.PHONE:
- params.country = arg.country;
- params.account = arg.phone;
- break;
- case LoginType.MAIL:
- params.account = arg.email;
- break;
- case LoginType.GUEST:
- delete params.password;
- break;
- }
- const res = await Http.call<IUserData>(API_LOGIN, params)
- if (success(res)) {
- this.parseLogin(res.data);
- return true;
- }
- return false;
- }
- private parseLogin(data: IUserData) {
- if (!data || typeof data !== 'object') return;
- this.gameID = 0;
- this._isLogin = true;
- this._userInfo = data;
- this._serverKick = false;
- if (!!data.recommendGame) this._recommendGame = data.recommendGame;
- if (!!data.sign) localStorageSet(LOCAL_SIGN, data.sign);
- if (data.reg === 1) {
- // 新注册的
- }
- }
- clearGame() {
- this.gameID = 0;
- this.gameLink = "";
- }
- setServerKick(value: boolean) {
- this._serverKick = value;
- }
- updateHallBalance(balance: number) {
- if (!this._userInfo || !Number.isFinite(balance)) return;
- if ((this._userInfo.vip || 0) > 0) {
- this._userInfo.Score = balance;
- } else {
- this._userInfo.InsureScore = balance;
- }
- }
- async getGameCardInfo(gameId: number) {
- if (this._gameCardInfo[gameId]) {
- return this._gameCardInfo[gameId];
- }
- const payload = await Http.call<IGameInfo>(APP_GAME_CARD_INFO, { id: gameId })
- if (!success(payload) || !payload.data) {
- return null;
- }
- const gameInfo = payload.data;
- const id = Number(gameInfo.id);
- const level = gameInfo.level_info ? 1 : 0;
- const cardInfo = { ...gameInfo, level };
- this._gameCardInfo[id] = cardInfo;
- return cardInfo;
- }
- }
- export const mainStore = new MainStore();
|