diff --git a/packages/uni-app-plus/src/service/api/device/systemInfo.ts b/packages/uni-app-plus/src/service/api/device/systemInfo.ts index b6be43b5e33f09913dcbc8bbb7e007dd872d751d..86d2003067b3f6cb9663cc0333170daeabc153fa 100644 --- a/packages/uni-app-plus/src/service/api/device/systemInfo.ts +++ b/packages/uni-app-plus/src/service/api/device/systemInfo.ts @@ -49,7 +49,6 @@ export const getAppBaseInfo = defineSyncApi( const { hostPackageName, hostName, - osLanguage, hostVersion, hostLanguage, hostTheme, @@ -69,7 +68,7 @@ export const getAppBaseInfo = defineSyncApi( appVersionCode, appLanguage: uni.getLocale(), version: plus.runtime.innerVersion!, - language: osLanguage, + language: hostLanguage, theme: '', hostPackageName, hostName, diff --git a/packages/uni-mp-core/src/api/promise.ts b/packages/uni-mp-core/src/api/promise.ts index 135ecc7c1351094e3b645050c46a22db5ac57f12..e8e9643ef45acc42c6c0c6d53fc6afae224346ff 100644 --- a/packages/uni-mp-core/src/api/promise.ts +++ b/packages/uni-mp-core/src/api/promise.ts @@ -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$/ diff --git a/packages/uni-mp-core/src/api/protocols/enhanceSystemInfo.ts b/packages/uni-mp-core/src/api/protocols/enhanceSystemInfo.ts index c4b5d8ddc2c3ef8056ef1d1096b1b9669be6a106..e34bf069abf866ec221d8766e36613ccb8c9efef 100644 --- a/packages/uni-mp-core/src/api/protocols/enhanceSystemInfo.ts +++ b/packages/uni-mp-core/src/api/protocols/enhanceSystemInfo.ts @@ -1,12 +1,13 @@ 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 +} diff --git a/packages/uni-mp-core/src/api/protocols/getAppBaseInfo.ts b/packages/uni-mp-core/src/api/protocols/getAppBaseInfo.ts new file mode 100644 index 0000000000000000000000000000000000000000..7b3d347b47ebf82dd229f07a6eeeeee62872430e --- /dev/null +++ b/packages/uni-mp-core/src/api/protocols/getAppBaseInfo.ts @@ -0,0 +1,27 @@ +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, + }) + }, +} diff --git a/packages/uni-mp-core/src/api/protocols/getDeviceInfo.ts b/packages/uni-mp-core/src/api/protocols/getDeviceInfo.ts new file mode 100644 index 0000000000000000000000000000000000000000..d68fb00fcb3569e86c50b5980140bb7317be1034 --- /dev/null +++ b/packages/uni-mp-core/src/api/protocols/getDeviceInfo.ts @@ -0,0 +1,22 @@ +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, + }) + }, +} diff --git a/packages/uni-mp-core/src/api/protocols/getWindowInfo.ts b/packages/uni-mp-core/src/api/protocols/getWindowInfo.ts new file mode 100644 index 0000000000000000000000000000000000000000..aa905a8b6f80cca2b98802d8abacfca4ccd4d55e --- /dev/null +++ b/packages/uni-mp-core/src/api/protocols/getWindowInfo.ts @@ -0,0 +1,14 @@ +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, + }) + }, +} diff --git a/packages/uni-mp-core/src/api/protocols/index.ts b/packages/uni-mp-core/src/api/protocols/index.ts index 37ea6bbb5f5f2b493d05093b51aed339defe4a8a..d73f6709336084df6bc174dfb3982b98d0625518 100644 --- a/packages/uni-mp-core/src/api/protocols/index.ts +++ b/packages/uni-mp-core/src/api/protocols/index.ts @@ -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' diff --git a/packages/uni-mp-core/src/index.ts b/packages/uni-mp-core/src/index.ts index f5447b0ad9047c0e991519baf2b4806395da4783..d214083af46fe413eee8934c2f5412c3808eb226 100644 --- a/packages/uni-mp-core/src/index.ts +++ b/packages/uni-mp-core/src/index.ts @@ -54,6 +54,9 @@ export { useDeviceId, populateParameters, showActionSheet, + getDeviceInfo, + getAppBaseInfo, + getWindowInfo, } from './api/protocols' // types export { MiniProgramAppOptions, MiniProgramAppInstance } from './runtime/app' diff --git a/packages/uni-mp-weixin/src/api/protocols.ts b/packages/uni-mp-weixin/src/api/protocols.ts index 4dafa946909a5683f60d1d0074be7a01a28b674a..000f5d69924602f3a05372bed7f6034b01c766bc 100644 --- a/packages/uni-mp-weixin/src/api/protocols.ts +++ b/packages/uni-mp-weixin/src/api/protocols.ts @@ -4,4 +4,7 @@ export { getSystemInfo, getSystemInfoSync, showActionSheet, + getDeviceInfo, + getAppBaseInfo, + getWindowInfo, } from '@dcloudio/uni-mp-core'