feat: 首页更新

This commit is contained in:
2025-11-11 18:48:54 +08:00
parent 230191f181
commit b48cce06f4
43 changed files with 3186 additions and 1029 deletions

View File

@@ -24,7 +24,7 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
import { router } from 'expo-router';
import { config } from '../config';
import { transformRequest, parseResponse } from './helper';
import { cloneDeep, pick } from 'lodash-es';
import { cloneDeep, pick, includes } from 'lodash-es';
import md5 from 'md5';
/**
@@ -304,6 +304,10 @@ api.interceptors.response.use(
});
}
if (includes([500, 502, 503], error.response?.status) && includes(['371130'], `${error.config?.headers?.cmdId}`)) {
router.replace('/maintenance' as any);
}
// 处理不同的错误状态码
if (error.response) {
const { status, data } = error.response;

View File

@@ -1,6 +1,7 @@
import { HmacMD5 } from 'crypto-js';
import Base64 from 'crypto-js/enc-base64';
import Latin1 from 'crypto-js/enc-latin1';
import { Platform } from 'react-native';
import md5 from 'md5';
import { AxiosResponse } from 'axios';
import * as des from './des';
@@ -8,11 +9,11 @@ import NetworkError from './error';
import { toNumber, toString, startsWith, isString, isNumber } from 'lodash-es';
import { NetworkTypeEnum } from '@/constants/network';
import appConfig from '../config';
// import storageManager, { STORAGE_KEYS } from '../storageManager';
// import NetworkError from './error'
// import { storeToRefs, useTenantStore, useUserStore, useAppStore, start } from '../index';
// import { isMobile, getBetPlatform } from '@star/utils';
// import { langToNum } from '@star/languages';
type PlatformType = 'IOS' | 'ANDROID' | 'H5_IOS';
// 请求到的数据返回
export type NetworkResponse<T> = {
@@ -20,38 +21,16 @@ export type NetworkResponse<T> = {
data: T;
};
export const getBetPlatform = (isReturnIndex = false) => {
const getBetPlatform = (): PlatformType => {
// 5=PC; 7=HOMESCREEN_IOS; 6=HOMESCREEN_ANDROID; 4=H5_IOS 3=IOS 2=H5_ANDROID; 1=ANDROID 8=马甲包
return 'H5_IOS';
// const platform = new URLSearchParams(window.location.search).get('platform');
// if (platform) {
// return platform?.includes('IOS') ? 'IOS' : platform?.includes('ANDROID') ? 'ANDROID' : '';
// }
// if (isAppMJB()) {
// return 'APPS_ANDROID';
// }
// if (isPWA()) {
// if (isIOS()) {
// return isReturnIndex ? 4 : 'HS_IOS';
// } else {
// return isReturnIndex ? 2 : 'HS_ANDROID';
// }
// }
// if (isAndroid()) {
// if (BASE_CONFIG.appVersion > 0) {
// return isReturnIndex ? 1 : 'ANDROID';
// } else {
// return isReturnIndex ? 2 : 'H5_ANDROID';
// }
// }
// if (isIOS()) {
// if (BASE_CONFIG.appVersion > 0) {
// return isReturnIndex ? 3 : 'IOS';
// } else {
// return isReturnIndex ? 4 : 'H5_IOS';
// }
// }
// return isReturnIndex ? 5 : 'PC';
switch (Platform.OS) {
case 'ios':
return 'IOS';
case 'android':
return 'ANDROID';
default:
return 'H5_IOS';
}
};
const uuid = (len: number, radix: number) => {
@@ -85,7 +64,7 @@ const uuid = (len: number, radix: number) => {
};
// 格式化要发送的数据
export const formatSendData = (data: any, type: number = 0) => {
const formatSendData = (data: any, type: number = 0) => {
// url code
if (type === 0) {
const arr: any[] = [];
@@ -107,44 +86,44 @@ export const formatSendData = (data: any, type: number = 0) => {
return JSON.stringify(data);
};
export const getP = (p: any) => {
const getP = (p: any) => {
return HmacMD5(p, '7NEkojNzfkk=').toString();
};
export const enD = (rk: string, str: string) => {
const enD = (rk: string, str: string) => {
const enc = des.des(rk, str, 1, 0, null, 1);
return Base64.stringify(Latin1.parse(enc));
};
export const dnD = (rk: string, str: string) => {
const dnD = (rk: string, str: string) => {
const s = Latin1.stringify(Base64.parse(str));
const d = des.des(rk, s, 0, 0, null, 1);
return d;
};
export const enP = (rk: string, vk: string, t: number) => {
const enP = (rk: string, vk: string, t: number) => {
const enc = des.des(vk, rk + t, 1, 0, null, 1);
return Base64.stringify(Latin1.parse(enc));
};
export const dnP = (vk: string, str: string) => {
const dnP = (vk: string, str: string) => {
const s = Latin1.stringify(Base64.parse(str));
const p = des.des(vk, s, 0, 0, null, 1);
return p;
};
export const enC = (rk: string, vk: string, m: string) => {
const enC = (rk: string, vk: string, m: string) => {
const enc = HmacMD5(m + rk, vk);
return Base64.stringify(enc);
};
export const getRequestKey = (cmdId: number, data: any) => {
const getRequestKey = (cmdId: number, data: any) => {
return `${cmdId}&${data ? md5(JSON.stringify(data)) : ''}`;
};
// 加工请求数据
export const transformRequest = (config: any) => {
const { headerType = 2, paramType = 0, cmdId, tid, ...reset } = config.headers;
const { headerType = 2, paramType = 0, cmdId, ...reset } = config.headers;
const headers: Record<string, any> = {};
// const { tenantInfo } = storeToRefs(useTenantStore());
// const { userInfo } = storeToRefs(useUserStore());
@@ -153,10 +132,8 @@ export const transformRequest = (config: any) => {
const rk = md5(toString(Math.random() + t)).substring(0, 8);
const vk = appConfig.app.vk as string;
const pwds = enP(rk, vk, t);
// const tid = cmdId !== '371130' ? storageManager.session.getItem(STORAGE_KEYS.TENANT_TID) : '';
const tenantInfo = {
tid: 3,
};
let userInfo = {
cust_id: '',
cust_name: '',
@@ -221,7 +198,7 @@ export const transformRequest = (config: any) => {
headers.cmdId = cmdId;
headers.aseqId = appConfig.app.aseqId;
headers.nc = appConfig.app.nc;
headers.tid = tid ?? tenantInfo.tid ?? '';
headers.tid = 3;
// 试玩游戏cust_id=0 header需要保持一致
headers.custId = (config.data?.cust_id === 0 ? '0' : '') || userInfo?.cust_id || '';
headers.reqId = uuid(32, 16);