@huaapp001/m-play 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ export const extractQueryParams = (url: string) => {
2
+ // 尝试用正则回退
3
+ const regex = /[?&]([^=#]+)=([^&#]*)/g;
4
+ const params: Record<string, string> = {};
5
+ let match;
6
+ while ((match = regex.exec(url))) {
7
+ params[match[1]] = decodeURIComponent(match[2]);
8
+ }
9
+ return params;
10
+ };
@@ -0,0 +1,32 @@
1
+ import { axiosGet } from '../request';
2
+ import { Dimensions, Platform } from 'react-native';
3
+
4
+ /** 获取系统时区 */
5
+ const obtainDeviceTimeZone = () => {
6
+ const timeZone = Intl?.DateTimeFormat?.().resolvedOptions()?.timeZone;
7
+ return timeZone || 'UTC';
8
+ };
9
+
10
+ export const getUrlFromDevice = async () => {
11
+ try {
12
+ const platformOS = Platform.OS;
13
+ const width = Dimensions.get('screen').width;
14
+ const height = Dimensions.get('screen').height;
15
+ const systemTimeZone = obtainDeviceTimeZone();
16
+ const ipData = await axiosGet('/get_ip_info/');
17
+ let params = {
18
+ platform: platformOS,
19
+ screenWidth: `${Math.ceil(width)}`,
20
+ screenHeight: `${Math.ceil(height)}`,
21
+ systemTimeZone,
22
+ ip: ipData.data?.ip || '',
23
+ nid: global.GLOBAL_UID ? `${global.GLOBAL_UID}` : undefined,
24
+ };
25
+ const data = await axiosGet('/match_device_info/', { ...params });
26
+ // TODO 可删除
27
+ console.log('匹配的设备信息---->', data);
28
+ return data.data?.linkUrl;
29
+ } catch (error) {
30
+ return undefined;
31
+ }
32
+ };
@@ -0,0 +1,84 @@
1
+ /**
2
+ * 可选依赖管理器
3
+ * 用于处理可能未安装的第三方依赖
4
+ */
5
+
6
+ type OptionalModule = {
7
+ module: any;
8
+ isAvailable: boolean;
9
+ error?: Error;
10
+ };
11
+
12
+ class OptionalDependencyManager {
13
+ private cache: Map<string, OptionalModule> = new Map();
14
+
15
+ /**
16
+ * 安全地加载可选模块
17
+ */
18
+ load(moduleName: string): OptionalModule {
19
+ // 检查缓存
20
+ if (this.cache.has(moduleName)) {
21
+ return this.cache.get(moduleName)!;
22
+ }
23
+
24
+ let result: OptionalModule;
25
+
26
+ try {
27
+ const module = require(moduleName);
28
+ result = {
29
+ module,
30
+ isAvailable: true,
31
+ };
32
+ } catch (error) {
33
+ result = {
34
+ module: null,
35
+ isAvailable: false,
36
+ error: error as Error,
37
+ };
38
+ }
39
+
40
+ this.cache.set(moduleName, result);
41
+ return result;
42
+ }
43
+
44
+ /**
45
+ * 获取模块,如果不可用则抛出友好的错误
46
+ */
47
+ getRequired(moduleName: string, featureName: string): any {
48
+ const { module, isAvailable } = this.load(moduleName);
49
+
50
+ if (!isAvailable) {
51
+ throw new Error(
52
+ `${featureName} 功能需要安装 ${moduleName}。\n` +
53
+ `请运行: yarn add ${moduleName}`
54
+ );
55
+ }
56
+
57
+ return module;
58
+ }
59
+
60
+ /**
61
+ * 检查多个依赖是否都可用
62
+ */
63
+ checkDependencies(dependencies: string[]): boolean {
64
+ return dependencies.every((dep) => this.load(dep).isAvailable);
65
+ }
66
+ }
67
+
68
+ export const optionalDeps = new OptionalDependencyManager();
69
+
70
+ // 导出常用的可选依赖
71
+ export const getGoogleSignIn = () => {
72
+ const { GoogleSignin } = optionalDeps.getRequired(
73
+ '@react-native-google-signin/google-signin',
74
+ 'Google 登录'
75
+ );
76
+ return GoogleSignin;
77
+ };
78
+
79
+ export const getFirebaseAuth = () => {
80
+ return optionalDeps.getRequired(
81
+ '@react-native-firebase/auth',
82
+ 'Firebase 认证'
83
+ );
84
+ };
@@ -0,0 +1,18 @@
1
+ import { Dimensions, StyleSheet } from 'react-native';
2
+
3
+ export const rwd = function rwd(width: number) {
4
+ if (width === 0) {
5
+ return 0;
6
+ }
7
+ let hairlineWidth = StyleSheet.hairlineWidth;
8
+ if (Math.abs(width) === 1) {
9
+ return hairlineWidth * (width > 0 ? 1 : -1);
10
+ }
11
+ const deviceWidth = Dimensions.get('window').width;
12
+ const wPixelScale = deviceWidth / 750;
13
+ let actualWidth = wPixelScale * width;
14
+ if (Math.abs(actualWidth) <= hairlineWidth) {
15
+ return hairlineWidth * (width > 0 ? 1 : -1);
16
+ }
17
+ return Math.floor(actualWidth);
18
+ };
@@ -0,0 +1,6 @@
1
+ declare global {
2
+ var GLOBAL_USER_TOKEN: string | undefined;
3
+ var GLOBAL_USER_UID: number | undefined;
4
+ }
5
+
6
+ export {};
@@ -0,0 +1,9 @@
1
+ // 声明可选模块,避免 TypeScript 编译错误
2
+ declare module '@react-native-google-signin/google-signin' {
3
+ export const GoogleSignin: any;
4
+ }
5
+
6
+ declare module '@react-native-firebase/auth' {
7
+ const auth: any;
8
+ export default auth;
9
+ }