提交 1a03411b 编写于 作者: D DCloud_LXH

feat(mp-weixin): getDeviceInfo、getAppBaseInfo、getWindowInfo

上级 bfa6eb46
......@@ -41,7 +41,7 @@ export function getDeviceInfo () {
export function getAppBaseInfo () {
weexGetSystemInfoSync()
const {
hostPackageName, hostName, osLanguage,
hostPackageName, hostName,
hostVersion, hostLanguage, hostTheme,
appId, appName, appVersion, appVersionCode
} = systemInfo
......@@ -56,7 +56,7 @@ export function getAppBaseInfo () {
appVersionCode,
appLanguage: uni.getLocale(),
version: plus.runtime.innerVersion,
language: osLanguage,
language: hostLanguage,
theme: '',
hostPackageName,
hostName,
......
function getDeviceBrand (model) {
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' }
return ''
}
const UUID_KEY = '__DC_STAT_UUID'
let deviceId
export function useDeviceId (result) {
export function useDeviceId(result) {
deviceId = deviceId || __GLOBAL__.getStorageSync(UUID_KEY)
if (!deviceId) {
deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7)
......@@ -17,7 +18,7 @@ export function useDeviceId (result) {
result.deviceId = deviceId
}
export function addSafeAreaInsets (result) {
export function addSafeAreaInsets(result) {
if (result.safeArea) {
const safeArea = result.safeArea
result.safeAreaInsets = {
......@@ -29,7 +30,7 @@ export function addSafeAreaInsets (result) {
}
}
export function populateParameters (result) {
export function populateParameters(result) {
const {
brand, model, system,
language, theme, version,
......@@ -59,38 +60,17 @@ export function populateParameters (result) {
}
// 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
}
}
}
let deviceType = getGetDeviceType(result, model)
// deviceModel
let deviceBrand = model.split(' ')[0].toLocaleLowerCase()
if (__PLATFORM__ === 'mp-toutiao' || __PLATFORM__ === 'mp-lark' || isQuickApp) {
deviceBrand = brand.toLocaleLowerCase()
} else {
deviceBrand = getDeviceBrand(deviceBrand)
}
let deviceBrand = getDeviceBrand(brand, model, isQuickApp)
// hostName
let _hostName = hostName || __PLATFORM__.split('-')[1] // mp-jd
if (__PLATFORM__ === 'mp-weixin') {
if (environment) {
_hostName = environment
} else if (result.host) {
} else if (result.host && fromRes.host.env) {
_hostName = result.host.env
}
}
......@@ -147,3 +127,42 @@ export function populateParameters (result) {
Object.assign(result, parameters)
}
export function getGetDeviceType(result, model) {
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
}
}
}
return deviceType
}
export function getDeviceBrand(
brand,
model,
isQuickApp = false
) {
let deviceBrand = model.split(' ')[0].toLocaleLowerCase()
if (
__PLATFORM__ === 'mp-toutiao' ||
__PLATFORM__ === 'mp-lark' ||
isQuickApp
) {
deviceBrand = brand.toLocaleLowerCase()
} else {
deviceBrand = _getDeviceBrand(deviceBrand)
}
return deviceBrand
}
\ No newline at end of file
export default {
returnValue: function (result) {
const { version, language, SDKVersion, theme } = result
let _hostName = __PLATFORM__.split('-')[1] // mp-jd
if (__PLATFORM__ === 'mp-weixin') {
if (result.host && result.host.env) {
_hostName = result.host.env
}
}
Object.assign(result, {
hostVersion: version,
hostLanguage: language.replace('_', '-'),
hostName: _hostName,
hostSDKVersion: SDKVersion,
hostTheme: theme,
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,
})
}
}
import { useDeviceId, getGetDeviceType, getDeviceBrand } from './enhance-system-info';
export default {
returnValue: function (result) {
const { brand, model } = result
let deviceType = getGetDeviceType(result, model)
let deviceBrand = getDeviceBrand(brand, model)
useDeviceId(result)
Object.assign(result, {
deviceType,
deviceBrand,
deviceModel: model,
})
}
}
import { addSafeAreaInsets } from './enhance-system-info';
export default {
returnValue: function (result) {
addSafeAreaInsets(result)
Object.assign(result, {
windowTop: 0,
windowBottom: 0,
})
}
}
......@@ -3,6 +3,9 @@ import redirectTo from '../../helpers/redirect-to'
import previewImage from '../../helpers/normalize-preview-image'
import getSystemInfo from '../../helpers/system-info'
import showActionSheet from '../../helpers/show-action-sheet'
import getAppBaseInfo from '../../helpers/get-app-base-info'
import getDeviceInfo from '../../helpers/get-device-info'
import getWindowInfo from '../../helpers/get-window-info'
export const protocols = {
redirectTo,
......@@ -10,7 +13,10 @@ export const protocols = {
previewImage,
getSystemInfo,
getSystemInfoSync: getSystemInfo,
showActionSheet
showActionSheet,
getAppBaseInfo,
getDeviceInfo,
getWindowInfo
}
export const todos = [
'vibrate',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册