提交 3928facf 编写于 作者: D DCloud_LXH

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

上级 35bdc362
......@@ -49,7 +49,6 @@ export const getAppBaseInfo = defineSyncApi<typeof uni.getAppBaseInfo>(
const {
hostPackageName,
hostName,
osLanguage,
hostVersion,
hostLanguage,
hostTheme,
......@@ -69,7 +68,7 @@ export const getAppBaseInfo = defineSyncApi<typeof uni.getAppBaseInfo>(
appVersionCode,
appLanguage: uni.getLocale(),
version: plus.runtime.innerVersion!,
language: osLanguage,
language: hostLanguage,
theme: '',
hostPackageName,
hostName,
......
......@@ -7,7 +7,7 @@ import {
} from '@dcloudio/uni-api/src/helpers/interceptor'
const SYNC_API_RE =
/^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|requireGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
/^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|requireGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getDeviceInfo|getAppBaseInfo|getWindowInfo/
const CONTEXT_API_RE = /^create|Manager$/
......
import { extend } from '@vue/shared'
function getDeviceBrand(model: string) {
function _getDeviceBrand(model: string) {
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'
......@@ -84,45 +85,17 @@ export function populateParameters(
}
// deviceType
let deviceType = fromRes.deviceType || 'phone'
if (__PLATFORM__ !== 'mp-baidu') {
type DeviceTypeMapsKeys = keyof typeof deviceTypeMaps
const deviceTypeMaps = {
ipad: 'pad',
windows: 'pc',
mac: 'pc',
}
const deviceTypeMapsKeys = Object.keys(
deviceTypeMaps
) as DeviceTypeMapsKeys[]
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(fromRes, 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 (fromRes.host) {
} else if (fromRes.host && fromRes.host.env) {
_hostName = fromRes.host.env
}
}
......@@ -189,3 +162,47 @@ export function populateParameters(
extend(toRes, parameters)
}
export function getGetDeviceType(fromRes: any, model: string) {
// deviceType
let deviceType = fromRes.deviceType || 'phone'
if (__PLATFORM__ !== 'mp-baidu') {
type DeviceTypeMapsKeys = keyof typeof deviceTypeMaps
const deviceTypeMaps = {
ipad: 'pad',
windows: 'pc',
mac: 'pc',
}
const deviceTypeMapsKeys = Object.keys(
deviceTypeMaps
) as DeviceTypeMapsKeys[]
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: string,
model: string,
isQuickApp: boolean = false
) {
// deviceModel
let deviceBrand = model.split(' ')[0].toLocaleLowerCase()
if (
__PLATFORM__ === 'mp-toutiao' ||
__PLATFORM__ === 'mp-lark' ||
isQuickApp
) {
deviceBrand = brand.toLocaleLowerCase()
} else {
deviceBrand = _getDeviceBrand(deviceBrand)
}
return deviceBrand
}
import { MPProtocol } from './types'
import { extend } from '@vue/shared'
export const getAppBaseInfo: MPProtocol = {
returnValue: (fromRes, toRes) => {
const { version, language, SDKVersion, theme } = fromRes
let _hostName = __PLATFORM__.split('-')[1] // mp-jd
if (__PLATFORM__ === 'mp-weixin') {
if (fromRes.host && fromRes.host.env) {
_hostName = fromRes.host.env
}
}
extend(toRes, {
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 { MPProtocol } from './types'
import {
getGetDeviceType,
getDeviceBrand,
useDeviceId,
} from './enhanceSystemInfo'
import { extend } from '@vue/shared'
export const getDeviceInfo: MPProtocol = {
returnValue: (fromRes, toRes) => {
const { brand, model } = fromRes
let deviceType = getGetDeviceType(fromRes, model)
let deviceBrand = getDeviceBrand(brand, model)
useDeviceId()(fromRes, toRes)
extend(toRes, {
deviceType,
deviceBrand,
deviceModel: model,
})
},
}
import { MPProtocol } from './types'
import { extend } from '@vue/shared'
import { addSafeAreaInsets } from './enhanceSystemInfo'
export const getWindowInfo: MPProtocol = {
returnValue: (fromRes, toRes) => {
addSafeAreaInsets(fromRes, toRes)
extend(toRes, {
windowTop: 0,
windowBottom: 0,
})
},
}
......@@ -9,4 +9,7 @@ export { redirectTo } from './redirectTo'
export { previewImage } from './previewImage'
export { showActionSheet } from './showActionSheet'
export { navigateTo, initEventChannel, getEventChannel } from './navigateTo'
export { getDeviceInfo } from './getDeviceInfo'
export { getAppBaseInfo } from './getAppBaseInfo'
export { getWindowInfo } from './getWindowInfo'
export * from './types'
......@@ -54,6 +54,9 @@ export {
useDeviceId,
populateParameters,
showActionSheet,
getDeviceInfo,
getAppBaseInfo,
getWindowInfo,
} from './api/protocols'
// types
export { MiniProgramAppOptions, MiniProgramAppInstance } from './runtime/app'
......
......@@ -4,4 +4,7 @@ export {
getSystemInfo,
getSystemInfoSync,
showActionSheet,
getDeviceInfo,
getAppBaseInfo,
getWindowInfo,
} from '@dcloudio/uni-mp-core'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册