提交 a121dc67 编写于 作者: D DCloud_LXH

feat: getSystemInfo

上级 890829eb
......@@ -104,7 +104,10 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) {
'process.env.RUN_BY_HBUILDERX': process.env.RUN_BY_HBUILDERX,
'process.env.UNI_AUTOMATOR_WS_ENDPOINT': JSON.stringify(process.env.UNI_AUTOMATOR_WS_ENDPOINT),
'process.env.UNI_STAT_UNI_CLOUD': process.env.UNI_STAT_UNI_CLOUD || '',
'process.env.UNI_STAT_DEBUG': process.env.UNI_STAT_DEBUG || ''
'process.env.UNI_STAT_DEBUG': process.env.UNI_STAT_DEBUG || '',
'process.env.UNI_COMPILER_VERSION': JSON.stringify(process.env.UNI_COMPILER_VERSION),
'process.env.UNI_APP_VERSION_NAME': JSON.stringify(process.env.UNI_APP_VERSION_NAME),
'process.env.UNI_APP_VERSION_CODE': JSON.stringify(process.env.UNI_APP_VERSION_CODE)
}
if (process.env.UNI_USING_VUE3) {
Object.assign(defines, {
......
......@@ -31,6 +31,8 @@ const manifestJsonObj = getManifestJson()
process.env.UNI_APP_ID = manifestJsonObj.appid || ''
process.env.UNI_APP_NAME = manifestJsonObj.name || ''
process.env.UNI_PLATFORM = process.env.UNI_PLATFORM || 'h5'
process.env.UNI_APP_VERSION_NAME = manifestJsonObj.versionName
process.env.UNI_APP_VERSION_CODE = manifestJsonObj.versionCode
// 小程序 vue3 标记
if (process.env.UNI_PLATFORM.indexOf('mp-') === 0) {
......@@ -388,6 +390,11 @@ const warningMsg =
const needWarning = !platformOptions.usingComponents || usingComponentsAbsent
let hasNVue = false
// 输出编译器版本等信息
const pagesPkg = require('@dcloudio/webpack-uni-pages-loader/package.json')
process.env.UNI_COMPILER_VERSION = ''
if (pagesPkg) {
process.env.UNI_COMPILER_VERSION = pagesPkg['uni-app'].compilerVersion
}
const compileModeUrl = 'https://ask.dcloud.net.cn/article/36074'
if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
const compileMode = (process.env.UNI_USING_V3_NATIVE ? '(v3)' : '') + '' + (isNVueCompiler ? 'uni-app' : 'weex')
......@@ -397,12 +404,8 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
}))
} else if (process.env.UNI_PLATFORM !== 'h5' && process.env.UNI_PLATFORM !== 'quickapp-native') {
try {
let info = ''
let info = process.env.UNI_COMPILER_VERSION
if (process.env.UNI_PLATFORM === 'app-plus') {
const pagesPkg = require('@dcloudio/webpack-uni-pages-loader/package.json')
if (pagesPkg) {
info = uniI18n.__('compilerVersion') + '' + pagesPkg['uni-app'].compilerVersion
}
if (process.env.UNI_USING_V3) {
console.log(info)
} else {
......
......@@ -443,6 +443,11 @@ global['____${h5.appid}____'] = true;
delete global['____${h5.appid}____'];
global.__uniConfig = ${JSON.stringify(pagesJson)};
global.__uniConfig.compilerVersion = '${compilerVersion}';
global.__uniConfig.uniPlatform = '${process.env.UNI_PLATFORM}';
global.__uniConfig.appId = '${process.env.UNI_APP_ID}';
global.__uniConfig.appName = '${process.env.UNI_APP_NAME}';
global.__uniConfig.appVersion = '${process.env.UNI_APP_VERSION_NAME}';
global.__uniConfig.appVersionCode = '${process.env.UNI_APP_VERSION_CODE}';
global.__uniConfig.router = ${JSON.stringify(h5.router)};
global.__uniConfig.publicPath = ${JSON.stringify(h5.publicPath)};
global.__uniConfig['async'] = ${JSON.stringify(h5.async)};
......
......@@ -372,7 +372,7 @@ export class CanvasContext {
this.path = []
this.subpath = []
this.path.push({
method: "beginPath",
method: 'beginPath',
data: []
})
}
......
......@@ -18,9 +18,12 @@ export function getSystemInfoSync () {
}
export function getSystemInfo () {
const platform = plus.os.name.toLowerCase()
const ios = platform === 'ios'
const isAndroid = platform === 'android'
const { getSystemInfoSync } = weex.requireModule('plus')
const info = getSystemInfoSync()
const { deviceBrand, deviceModel, osName, osVersion, osLanguage } = info
const brand = deviceBrand.toLowerCase()
const _osName = osName.toLowerCase()
const ios = _osName === 'ios'
const {
screenWidth,
screenHeight
......@@ -76,21 +79,21 @@ export function getSystemInfo () {
height: windowHeightReal - safeAreaInsets.top - safeAreaInsets.bottom
}
return {
return Object.assign({
errMsg: 'getSystemInfo:ok',
brand: plus.device.vendor,
model: plus.device.model,
brand: brand,
model: deviceModel,
pixelRatio: plus.screen.scale,
screenWidth,
screenHeight,
windowWidth,
windowHeight,
statusBarHeight,
language: plus.os.language,
system: `${ios ? 'iOS' : isAndroid ? 'Android' : ''} ${plus.os.version}`,
language: osLanguage,
system: `${osName} ${osVersion}`,
version: plus.runtime.innerVersion,
fontSizeSetting: '',
platform,
platform: _osName,
SDKVersion: '',
windowTop,
windowBottom,
......@@ -102,5 +105,8 @@ export function getSystemInfo () {
left: safeAreaInsets.left
},
deviceId: deviceId()
}
}
}, info, {
deviceBrand: brand,
osName: _osName
})
}
import getWindowOffset from 'uni-platform/helpers/get-window-offset'
import deviceId from 'uni-platform/helpers/uuid'
import safeAreaInsets from 'safe-area-insets'
import { IEVersion, getDeviceBrand } from 'uni-shared'
const ua = navigator.userAgent
/**
......@@ -45,6 +46,7 @@ export function getSystemInfoSync () {
var osname
var osversion
var model
let deviceType = 'phone'
if (isIOS) {
osname = 'iOS'
......@@ -89,8 +91,11 @@ export function getSystemInfoSync () {
model = 'iPad'
osname = 'iOS'
osversion = typeof window.BigInt === 'function' ? '14.0' : '13.0'
deviceType = 'pad'
} else if (isWindows || isMac || isLinux) {
model = 'PC'
osname = 'PC'
deviceType = 'pc'
const osversionFind = ua.match(/\((.+?)\)/)[1]
if (isWindows) {
......@@ -147,6 +152,7 @@ export function getSystemInfoSync () {
} else {
osname = 'Other'
osversion = '0'
deviceType = 'other'
}
var system = `${osname} ${osversion}`
......@@ -168,6 +174,30 @@ export function getSystemInfoSync () {
windowHeight -= windowTop
windowHeight -= windowBottom
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 index = 0; index < browseVendors.length; index++) {
const vendor = browseVendors[index]
const reg = new RegExp(`(${vendor})/(\\S*)\\b`)
if (reg.test(ua)) {
browserName = vendors[index]
browseVersion = ua.match(reg)[2]
}
}
}
// deviceBrand
let deviceBrand = ''
if (model) {
const _model = model.toLocaleLowerCase()
deviceBrand = getDeviceBrand(_model) ||
getDeviceBrand(osname.toLocaleLowerCase()) ||
_model.split(' ')[0]
}
return {
windowTop,
windowBottom,
......@@ -180,7 +210,10 @@ export function getSystemInfoSync () {
statusBarHeight,
system,
platform,
deviceBrand,
deviceType,
model,
deviceModel: model,
safeArea,
safeAreaInsets: {
top: safeAreaInsets.top,
......@@ -188,7 +221,25 @@ export function getSystemInfoSync () {
bottom: safeAreaInsets.bottom,
left: safeAreaInsets.left
},
deviceId: deviceId()
deviceId: deviceId(),
SDKVersion: '',
ua,
uniPlatform: 'web',
browserName,
browseVersion,
osLanguage: language,
osName: osname,
osVersion: osversion,
hostLanguage: language,
version: __uniConfig.appVersion,
uniCompileVersion: __uniConfig.compilerVersion,
uniRuntimeVersion: __uniConfig.compilerVersion,
appId: __uniConfig.appId,
appName: __uniConfig.appName,
appVersion: __uniConfig.appVersion,
appVersionCode: __uniConfig.appVersionCode,
osTheme: '',
hostTheme: ''
}
}
/**
......
import { getStorageSync } from './storage'
import { addSafeAreaInsets, populateParameters } from '../../mp-weixin/helpers/enhance-system-info'
const UUID_KEY = '__DC_STAT_UUID'
let deviceId
......@@ -14,18 +15,6 @@ function addUuid (result) {
result.deviceId = deviceId
}
function addSafeAreaInsets (result) {
if (result.safeArea) {
const safeArea = result.safeArea
result.safeAreaInsets = {
top: safeArea.top,
left: safeArea.left,
right: result.windowWidth - safeArea.right,
bottom: result.windowHeight - safeArea.bottom
}
}
}
function normalizePlatform (result) {
let platform = result.platform ? result.platform.toLowerCase() : 'devtools'
if (!~['android', 'ios'].indexOf(platform)) {
......@@ -39,5 +28,6 @@ export default {
addUuid(result)
addSafeAreaInsets(result)
normalizePlatform(result)
populateParameters(result)
}
}
// import navigateTo from 'uni-helpers/navigate-to'
// import redirectTo from '../../../mp-weixin/helpers/redirect-to'
// import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
// import getSystemInfo from '../../../mp-weixin/helpers/system-info'
import getSystemInfo from '../../../mp-weixin/helpers/system-info'
// import getUserProfile from '../../../mp-weixin/helpers/get-user-profile'
// 需要做转换的 API 列表
......@@ -9,8 +9,8 @@ export const protocols = {
// navigateTo,
// redirectTo,
// previewImage,
// getSystemInfo,
// getSystemInfoSync: getSystemInfo,
getSystemInfo,
getSystemInfoSync: getSystemInfo
// getUserProfile
}
......
import { getDeviceBrand } from 'uni-shared'
const UUID_KEY = '__DC_STAT_UUID'
let deviceId
export function useDeviceId(result) {
deviceId = deviceId || __GLOBAL__.getStorageSync(UUID_KEY)
if (!deviceId) {
deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7)
__GLOBAL__.setStorage({
key: UUID_KEY,
data: deviceId
})
}
result.deviceId = deviceId
}
export function addSafeAreaInsets(result) {
if (result.safeArea) {
const safeArea = result.safeArea
result.safeAreaInsets = {
top: safeArea.top,
left: safeArea.left,
right: result.windowWidth - safeArea.right,
bottom: result.screenHeight - safeArea.bottom
}
}
}
export function populateParameters(result) {
const { brand, model, system, language, theme, version, hostName, platform } = result
// osName osVersion
let osName = ''
let osVersion = ''
if (__PLATFORM__ === 'mp-alipay') {
osName = platform.toLocaleLowerCase()
osVersion = system
} else {
osName = system.split(' ')[0] || ''
osVersion = system.split(' ')[1] || ''
}
let hostVersion = version
// host 枚举值 https://smartprogram.baidu.com/docs/develop/api/device_sys/hostlist/
if (__PLATFORM__ === 'mp-baidu') {
hostVersion = result.swanNativeVersion || version
}
// deviceType
let deviceType = result.deviceType || 'phone'
if (__PLATFORM__ !== 'mp-baidu') {
const deviceTypeMaps = {
ipad: 'pad',
windows: 'pc',
mac: 'pc'
}
const deviceTypeMapsKeys = Object.keys(deviceTypeMaps)
const _model = model.toLocaleLowerCase()
for (let index = 0; index < deviceTypeMapsKeys.length; index++) {
const _m = deviceTypeMapsKeys[index]
if (_model.indexOf(_m) !== -1) {
deviceType = deviceTypeMaps[_m]
break
}
}
}
// deviceModel
let deviceBrand = model.split(' ')[0].toLocaleLowerCase()
if (__PLATFORM__ === 'mp-toutiao' || __PLATFORM__ === 'mp-lark') {
deviceBrand = brand.toLocaleLowerCase()
} else {
deviceBrand = getDeviceBrand(deviceBrand)
}
// hostName
let _hostName = hostName // mp-jd
if (__PLATFORM__ === 'mp-weixin') _hostName = (result.host || {}).env
if (__PLATFORM__ === 'mp-baidu' || __PLATFORM__ === 'mp-kuaishou')
_hostName = result.host
if (__PLATFORM__ === 'mp-qq') _hostName = result.AppPlatform
if (__PLATFORM__ === 'mp-toutiao' || __PLATFORM__ === 'mp-lark')
_hostName = result.appName
if (__PLATFORM__ === 'mp-alipay') _hostName = result.app
// wx.getAccountInfoSync
const parameters = {
appId: process.env.UNI_APP_ID,
appName: process.env.UNI_APP_NAME,
appVersion: process.env.UNI_APP_VERSION_NAME,
appVersionCode: process.env.UNI_APP_VERSION_CODE,
uniCompileVersion: process.env.UNI_COMPILER_VERSION,
uniRuntimeVersion: process.env.UNI_COMPILER_VERSION,
uniPlatform: process.env.UNI_PLATFORM,
deviceBrand,
deviceModel: model,
deviceType,
osName,
osVersion,
osLanguage: language,
osTheme: theme,
hostVersion,
hostLanguage: language,
hostName: _hostName,
// TODO
ua: '',
hostTheme: '',
hostPackageName: '',
browserName: '',
browseVersion: ''
}
Object.assign(result, parameters)
}
\ No newline at end of file
const UUID_KEY = '__DC_STAT_UUID'
let deviceId
function addUuid (result) {
deviceId = deviceId || __GLOBAL__.getStorageSync(UUID_KEY)
if (!deviceId) {
deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7)
__GLOBAL__.setStorage({
key: UUID_KEY,
data: deviceId
})
}
result.deviceId = deviceId
}
function addSafeAreaInsets (result) {
if (result.safeArea) {
const safeArea = result.safeArea
result.safeAreaInsets = {
top: safeArea.top,
left: safeArea.left,
right: result.windowWidth - safeArea.right,
bottom: Math.abs(result.screenHeight - safeArea.bottom)
}
}
}
import { useDeviceId, addSafeAreaInsets, populateParameters } from './enhance-system-info'
export default {
returnValue: function (result) {
addUuid(result)
useDeviceId(result)
addSafeAreaInsets(result)
populateParameters(result)
}
}
// import navigateTo from 'uni-helpers/navigate-to'
// import redirectTo from '../../../mp-weixin/helpers/redirect-to'
// import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
// import getSystemInfo from '../../../mp-weixin/helpers/system-info'
import getSystemInfo from '../../../mp-weixin/helpers/system-info'
// import getUserProfile from '../../../mp-weixin/helpers/get-user-profile'
// 需要做转换的 API 列表
......@@ -9,8 +9,8 @@ export const protocols = {
// navigateTo,
// redirectTo,
// previewImage,
// getSystemInfo,
// getSystemInfoSync: getSystemInfo,
getSystemInfo,
getSystemInfoSync: getSystemInfo
// getUserProfile
}
......
......@@ -195,3 +195,31 @@ export function deepClone (vnodes, createElement) {
}
export * from './uni-id-mixin'
export 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
}
}
export 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' }
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册