提交 e11a227f 编写于 作者: D DCloud_LXH

fix: systemInfo ssr

上级 a5f0a378
......@@ -905,13 +905,6 @@ function getRealPath(filePath) {
}
return filePath;
}
const ua = navigator.userAgent;
const isAndroid = /* @__PURE__ */ /android/i.test(ua);
const isIOS = /* @__PURE__ */ /iphone|ipad|ipod/i.test(ua);
const isWindows = /* @__PURE__ */ ua.match(/Windows NT ([\d|\d.\d]*)/i);
const isMac = /* @__PURE__ */ /Macintosh|Mac/i.test(ua);
const isLinux = /* @__PURE__ */ /Linux|X11/i.test(ua);
const isIPadOS = isMac && navigator.maxTouchPoints > 0;
const HTTP_METHODS = [
"GET",
"OPTIONS",
......@@ -10028,198 +10021,11 @@ const getStorageInfoSync = /* @__PURE__ */ defineSyncApi("getStorageInfoSync", (
const getStorageInfo = /* @__PURE__ */ defineAsyncApi("getStorageInfo", (_, { resolve }) => {
resolve(getStorageInfoSync());
});
function IEVersion() {
const userAgent = navigator.userAgent;
const isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
const isEdge = userAgent.indexOf("Edge") > -1 && !isIE;
const isIE11 = userAgent.indexOf("Trident") > -1 && userAgent.indexOf("rv:11.0") > -1;
if (isIE) {
const reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
const fIEVersion = parseFloat(RegExp.$1);
if (fIEVersion > 6) {
return fIEVersion;
} else {
return 6;
}
} else if (isEdge) {
return -1;
} else if (isIE11) {
return 11;
} else {
return -1;
}
}
function getDeviceBrand(model) {
if (/iphone/gi.test(model) || /ipad/gi.test(model) || /mac/gi.test(model)) {
return "apple";
}
if (/windows/gi.test(model)) {
return "microsoft";
}
}
function getBrowserInfo() {
let osname;
let osversion = "0";
let model = "";
let deviceType = "phone";
const language = navigator.language;
if (isIOS) {
osname = "iOS";
const osversionFind = ua.match(/OS\s([\w_]+)\slike/);
if (osversionFind) {
osversion = osversionFind[1].replace(/_/g, ".");
}
const modelFind = ua.match(/\(([a-zA-Z]+);/);
if (modelFind) {
model = modelFind[1];
}
} else if (isAndroid) {
osname = "Android";
const osversionFind = ua.match(/Android[\s/]([\w\.]+)[;\s]/);
if (osversionFind) {
osversion = osversionFind[1];
}
const infoFind = ua.match(/\((.+?)\)/);
const infos = infoFind ? infoFind[1].split(";") : ua.split(" ");
const otherInfo = [
/\bAndroid\b/i,
/\bLinux\b/i,
/\bU\b/i,
/^\s?[a-z][a-z]$/i,
/^\s?[a-z][a-z]-[a-z][a-z]$/i,
/\bwv\b/i,
/\/[\d\.,]+$/,
/^\s?[\d\.,]+$/,
/\bBrowser\b/i,
/\bMobile\b/i
];
for (let i = 0; i < infos.length; i++) {
const info = infos[i];
if (info.indexOf("Build") > 0) {
model = info.split("Build")[0].trim();
break;
}
let other;
for (let o = 0; o < otherInfo.length; o++) {
if (otherInfo[o].test(info)) {
other = true;
break;
}
}
if (!other) {
model = info.trim();
break;
}
}
} else if (isIPadOS) {
model = "iPad";
osname = "iOS";
deviceType = "pad";
osversion = typeof window.BigInt === "function" ? "14.0" : "13.0";
} else if (isWindows || isMac || isLinux) {
model = "PC";
osname = "PC";
deviceType = "pc";
osversion = "0";
let osversionFind = ua.match(/\((.+?)\)/)[1];
if (isWindows) {
osname = "Windows";
switch (isWindows[1]) {
case "5.1":
osversion = "XP";
break;
case "6.0":
osversion = "Vista";
break;
case "6.1":
osversion = "7";
break;
case "6.2":
osversion = "8";
break;
case "6.3":
osversion = "8.1";
break;
case "10.0":
osversion = "10";
break;
}
const framework = osversionFind && osversionFind.match(/[Win|WOW]([\d]+)/);
if (framework) {
osversion += ` x${framework[1]}`;
}
} else if (isMac) {
osname = "Mac";
const _osversion = osversionFind && osversionFind.match(/Mac OS X (.+)/) || "";
if (osversion) {
osversion = _osversion[1].replace(/_/g, ".");
if (osversion.indexOf(";") !== -1) {
osversion = osversion.split(";")[0];
}
}
} else if (isLinux) {
osname = "Linux";
const _osversion = osversionFind && osversionFind.match(/Linux (.*)/) || "";
if (_osversion) {
osversion = _osversion[1];
if (osversion.indexOf(";") !== -1) {
osversion = osversion.split(";")[0];
}
}
}
} else {
osname = "Other";
osversion = "0";
deviceType = "other";
}
const system = `${osname} ${osversion}`;
const platform = osname.toLocaleLowerCase();
let browserName = "";
let browseVersion = String(IEVersion());
if (browseVersion !== "-1") {
browserName = "IE";
} else {
const browseVendors = ["Version", "Firefox", "Chrome", "Edge{0,1}"];
const vendors = ["Safari", "Firefox", "Chrome", "Edge"];
for (let index2 = 0; index2 < browseVendors.length; index2++) {
const vendor = browseVendors[index2];
const reg = new RegExp(`(${vendor})/(\\S*)\\b`);
if (reg.test(ua)) {
browserName = vendors[index2];
browseVersion = ua.match(reg)[2];
}
}
}
let deviceBrand = "";
if (model) {
const _model = model.toLocaleLowerCase();
deviceBrand = getDeviceBrand(_model) || getDeviceBrand(osname.toLocaleLowerCase()) || _model.split(" ")[0];
}
let deviceOrientation = "portrait";
const orientation = typeof window.screen.orientation === "undefined" ? window.orientation : window.screen.orientation.angle;
deviceOrientation = Math.abs(orientation) === 90 ? "landscape" : "portrait";
return {
deviceBrand,
deviceModel: model,
deviceOrientation,
brand: deviceBrand,
model,
system,
platform,
browserName: browserName.toLocaleLowerCase(),
browseVersion,
language,
deviceType,
ua,
osname,
osversion,
theme: ""
};
}
let browserInfo;
function initBrowserInfo() {
browserInfo = getBrowserInfo();
{
return browserInfo = {};
}
}
const getDeviceInfo = /* @__PURE__ */ defineSyncApi("getDeviceInfo", () => {
initBrowserInfo();
......
......@@ -4,10 +4,16 @@ import { getBrowserInfo } from '../base/getBrowserInfo'
import { getWindowInfo } from './getWindowInfo'
import { extend } from '@vue/shared'
let browserInfo: ReturnType<typeof getBrowserInfo>
type BrowserInfo = ReturnType<typeof getBrowserInfo>
let browserInfo: BrowserInfo
let _initBrowserInfo = true
function initBrowserInfo() {
if (__NODE_JS__) {
//TODO 临时搞一下配合 uniCloud 测试
return (browserInfo = {} as BrowserInfo)
}
if (!_initBrowserInfo) return
browserInfo = getBrowserInfo()
}
......@@ -67,7 +73,7 @@ export const getSystemInfoSync = defineSyncApi<typeof uni.getSystemInfoSync>(
return {
deviceId: Date.now() + '' + Math.floor(Math.random() * 1e7),
platform: 'nodejs',
} as unknown as UniApp.GetSystemInfoResult
} as UniApp.GetSystemInfoResult
}
_initBrowserInfo = true
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册