react-native-device-info

This commit is contained in:
wkj 2023-12-15 00:47:14 +08:00
parent b94d0e38c9
commit 0b9b8b989d
7 changed files with 20 additions and 7 deletions

View File

@ -6,7 +6,7 @@ export class Navigator extends Feature {
constructor() { constructor() {
super(); super();
this.namespace = ''; this.namespace = '';
this.base = 'http://oaklocalhost'; // 使用URL解析链接时 相对路径需要使用构建一个完整链接 this.base = 'http://oak-localhost'; // 使用URL解析链接时 相对路径需要使用构建一个完整链接
} }
setNamespace(namespace) { setNamespace(namespace) {
this.namespace = namespace; this.namespace = namespace;
@ -23,7 +23,7 @@ export class Navigator extends Feature {
const urlParse = new URL(url.toString(), this.base); const urlParse = new URL(url.toString(), this.base);
let url2 = urlParse.toString(); let url2 = urlParse.toString();
if (process.env.OAK_PLATFORM !== 'web') { if (process.env.OAK_PLATFORM !== 'web') {
url2 = decodeURIComponent(url2) url2 = decodeURIComponent(url2);
} }
return url2.replace(this.base, ''); return url2.replace(this.base, '');
} }

View File

@ -1,10 +1,14 @@
import { Platform } from 'react-native'; import { Platform } from 'react-native';
import { getLocales } from 'react-native-localize'; import { getLocales } from 'react-native-localize';
import { getDeviceId } from 'react-native-device-info';
export async function getEnv() { export async function getEnv() {
const language = getLocales()[0].languageTag; const language = getLocales()[0].languageTag;
const deviceId = getDeviceId();
const fullEnv = { const fullEnv = {
...Platform, ...Platform,
visitorId: deviceId,
language, language,
type: 'native',
}; };
const briefEnv = { const briefEnv = {
brand: fullEnv.constants.Brand, brand: fullEnv.constants.Brand,

View File

@ -9,7 +9,7 @@ class Navigator extends Feature_1.Feature {
constructor() { constructor() {
super(); super();
this.namespace = ''; this.namespace = '';
this.base = 'http://localhost'; // 使用URL解析链接时 相对路径需要使用构建一个完整链接 this.base = 'http://oak-localhost'; // 使用URL解析链接时 相对路径需要使用构建一个完整链接
} }
setNamespace(namespace) { setNamespace(namespace) {
this.namespace = namespace; this.namespace = namespace;
@ -25,7 +25,9 @@ class Navigator extends Feature_1.Feature {
urlFormat(url) { urlFormat(url) {
const urlParse = new url_1.url(url.toString(), this.base); const urlParse = new url_1.url(url.toString(), this.base);
let url2 = urlParse.toString(); let url2 = urlParse.toString();
if (process.env.OAK_PLATFORM !== 'web') {
url2 = decodeURIComponent(url2); url2 = decodeURIComponent(url2);
}
return url2.replace(this.base, ''); return url2.replace(this.base, '');
} }
constructState(pathname, state, search) { constructState(pathname, state, search) {

View File

@ -3,11 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.getEnv = void 0; exports.getEnv = void 0;
const react_native_1 = require("react-native"); const react_native_1 = require("react-native");
const react_native_localize_1 = require("react-native-localize"); const react_native_localize_1 = require("react-native-localize");
const react_native_device_info_1 = require("react-native-device-info");
async function getEnv() { async function getEnv() {
const language = (0, react_native_localize_1.getLocales)()[0].languageTag; const language = (0, react_native_localize_1.getLocales)()[0].languageTag;
const deviceId = (0, react_native_device_info_1.getDeviceId)();
const fullEnv = { const fullEnv = {
...react_native_1.Platform, ...react_native_1.Platform,
visitorId: deviceId,
language, language,
type: 'native',
}; };
const briefEnv = { const briefEnv = {
brand: fullEnv.constants.Brand, brand: fullEnv.constants.Brand,

View File

@ -25,6 +25,7 @@
"oak-domain": "file:../oak-domain", "oak-domain": "file:../oak-domain",
"oak-memory-tree-store": "file:../oak-memory-tree-store", "oak-memory-tree-store": "file:../oak-memory-tree-store",
"ol": "^7.3.0", "ol": "^7.3.0",
"react-native-device-info": "^10.12.0",
"react-native-localize": "^3.0.4", "react-native-localize": "^3.0.4",
"react-responsive": "^9.0.2", "react-responsive": "^9.0.2",
"rmc-pull-to-refresh": "^1.0.13", "rmc-pull-to-refresh": "^1.0.13",

View File

@ -12,7 +12,7 @@ export class Navigator extends Feature {
constructor() { constructor() {
super(); super();
this.namespace = ''; this.namespace = '';
this.base = 'http://oaklocalhost'; // 使用URL解析链接时 相对路径需要使用构建一个完整链接 this.base = 'http://oak-localhost'; // 使用URL解析链接时 相对路径需要使用构建一个完整链接
} }
setNamespace(namespace: string) { setNamespace(namespace: string) {
@ -35,8 +35,6 @@ export class Navigator extends Feature {
if (process.env.OAK_PLATFORM !== 'web') { if (process.env.OAK_PLATFORM !== 'web') {
url2 = decodeURIComponent(url2) url2 = decodeURIComponent(url2)
} }
// url2 = decodeURIComponent(url2)
return url2.replace(this.base, ''); return url2.replace(this.base, '');
} }

View File

@ -1,12 +1,16 @@
import { NativeEnv, BriefEnv } from 'oak-domain/lib/types/Environment'; import { NativeEnv, BriefEnv } from 'oak-domain/lib/types/Environment';
import { Platform } from 'react-native'; import { Platform } from 'react-native';
import { getLocales } from 'react-native-localize'; import { getLocales } from 'react-native-localize';
import { getDeviceId } from 'react-native-device-info';
export async function getEnv() { export async function getEnv() {
const language = getLocales()[0].languageTag; const language = getLocales()[0].languageTag;
const deviceId = getDeviceId();
const fullEnv = { const fullEnv = {
...Platform, ...Platform,
visitorId: deviceId,
language, language,
type: 'native',
} as NativeEnv; } as NativeEnv;
const briefEnv: BriefEnv = { const briefEnv: BriefEnv = {