From 0b9b8b989dc6f0247bb124144be0f02644c74afe Mon Sep 17 00:00:00 2001 From: wkj <278599135@.com> Date: Fri, 15 Dec 2023 00:47:14 +0800 Subject: [PATCH] react-native-device-info --- es/features/navigator.common.js | 4 ++-- es/utils/env/env.native.js | 4 ++++ lib/features/navigator.common.js | 6 ++++-- lib/utils/env/env.native.js | 4 ++++ package.json | 1 + src/features/navigator.common.ts | 4 +--- src/utils/env/env.native.ts | 4 ++++ 7 files changed, 20 insertions(+), 7 deletions(-) diff --git a/es/features/navigator.common.js b/es/features/navigator.common.js index cb590147..8c1e977b 100644 --- a/es/features/navigator.common.js +++ b/es/features/navigator.common.js @@ -6,7 +6,7 @@ export class Navigator extends Feature { constructor() { super(); this.namespace = ''; - this.base = 'http://oaklocalhost'; // 使用URL解析链接时 相对路径需要使用构建一个完整链接 + this.base = 'http://oak-localhost'; // 使用URL解析链接时 相对路径需要使用构建一个完整链接 } setNamespace(namespace) { this.namespace = namespace; @@ -23,7 +23,7 @@ export class Navigator extends Feature { const urlParse = new URL(url.toString(), this.base); let url2 = urlParse.toString(); if (process.env.OAK_PLATFORM !== 'web') { - url2 = decodeURIComponent(url2) + url2 = decodeURIComponent(url2); } return url2.replace(this.base, ''); } diff --git a/es/utils/env/env.native.js b/es/utils/env/env.native.js index 793f97a5..dac3e885 100644 --- a/es/utils/env/env.native.js +++ b/es/utils/env/env.native.js @@ -1,10 +1,14 @@ import { Platform } from 'react-native'; import { getLocales } from 'react-native-localize'; +import { getDeviceId } from 'react-native-device-info'; export async function getEnv() { const language = getLocales()[0].languageTag; + const deviceId = getDeviceId(); const fullEnv = { ...Platform, + visitorId: deviceId, language, + type: 'native', }; const briefEnv = { brand: fullEnv.constants.Brand, diff --git a/lib/features/navigator.common.js b/lib/features/navigator.common.js index 7fcc02cf..4a07b4d2 100644 --- a/lib/features/navigator.common.js +++ b/lib/features/navigator.common.js @@ -9,7 +9,7 @@ class Navigator extends Feature_1.Feature { constructor() { super(); this.namespace = ''; - this.base = 'http://localhost'; // 使用URL解析链接时 相对路径需要使用构建一个完整链接 + this.base = 'http://oak-localhost'; // 使用URL解析链接时 相对路径需要使用构建一个完整链接 } setNamespace(namespace) { this.namespace = namespace; @@ -25,7 +25,9 @@ class Navigator extends Feature_1.Feature { urlFormat(url) { const urlParse = new url_1.url(url.toString(), this.base); let url2 = urlParse.toString(); - url2 = decodeURIComponent(url2); + if (process.env.OAK_PLATFORM !== 'web') { + url2 = decodeURIComponent(url2); + } return url2.replace(this.base, ''); } constructState(pathname, state, search) { diff --git a/lib/utils/env/env.native.js b/lib/utils/env/env.native.js index 16f0d2ba..ed7abb23 100644 --- a/lib/utils/env/env.native.js +++ b/lib/utils/env/env.native.js @@ -3,11 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.getEnv = void 0; const react_native_1 = require("react-native"); const react_native_localize_1 = require("react-native-localize"); +const react_native_device_info_1 = require("react-native-device-info"); async function getEnv() { const language = (0, react_native_localize_1.getLocales)()[0].languageTag; + const deviceId = (0, react_native_device_info_1.getDeviceId)(); const fullEnv = { ...react_native_1.Platform, + visitorId: deviceId, language, + type: 'native', }; const briefEnv = { brand: fullEnv.constants.Brand, diff --git a/package.json b/package.json index 60201e55..4c8b36da 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "oak-domain": "file:../oak-domain", "oak-memory-tree-store": "file:../oak-memory-tree-store", "ol": "^7.3.0", + "react-native-device-info": "^10.12.0", "react-native-localize": "^3.0.4", "react-responsive": "^9.0.2", "rmc-pull-to-refresh": "^1.0.13", diff --git a/src/features/navigator.common.ts b/src/features/navigator.common.ts index 16285848..0a1e9b63 100644 --- a/src/features/navigator.common.ts +++ b/src/features/navigator.common.ts @@ -12,7 +12,7 @@ export class Navigator extends Feature { constructor() { super(); this.namespace = ''; - this.base = 'http://oaklocalhost'; // 使用URL解析链接时 相对路径需要使用构建一个完整链接 + this.base = 'http://oak-localhost'; // 使用URL解析链接时 相对路径需要使用构建一个完整链接 } setNamespace(namespace: string) { @@ -35,8 +35,6 @@ export class Navigator extends Feature { if (process.env.OAK_PLATFORM !== 'web') { url2 = decodeURIComponent(url2) } - // url2 = decodeURIComponent(url2) - return url2.replace(this.base, ''); } diff --git a/src/utils/env/env.native.ts b/src/utils/env/env.native.ts index c2ce0057..1701aaec 100644 --- a/src/utils/env/env.native.ts +++ b/src/utils/env/env.native.ts @@ -1,12 +1,16 @@ import { NativeEnv, BriefEnv } from 'oak-domain/lib/types/Environment'; import { Platform } from 'react-native'; import { getLocales } from 'react-native-localize'; +import { getDeviceId } from 'react-native-device-info'; export async function getEnv() { const language = getLocales()[0].languageTag; + const deviceId = getDeviceId(); const fullEnv = { ...Platform, + visitorId: deviceId, language, + type: 'native', } as NativeEnv; const briefEnv: BriefEnv = {