Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/utils/get-system-info.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import Taro from '@tarojs/taro'
import Taro, {
canIUse,
getAppBaseInfo as taroGetAppBaseInfo,
getDeviceInfo as taroGetDeviceInfo,
getSystemInfoSync,
getWindowInfo as taroGetWindowInfo,
} from '@tarojs/taro'

interface IDeviceInfo
extends Omit<Taro.getDeviceInfo.Result, 'deviceAbi' | 'CPUType'> {}
Expand All @@ -8,27 +14,21 @@ interface IDeviceInfo
* @returns {IDeviceInfo} 设备基础信息
*/
export const getDeviceInfo = (): IDeviceInfo => {
return Taro.canIUse('getDeviceInfo')
? Taro.getDeviceInfo()
: Taro.getSystemInfoSync()
return canIUse('getDeviceInfo') ? taroGetDeviceInfo() : getSystemInfoSync()
}

/**
* 获取窗口信息,兼容新旧 API
* @returns {Taro.getWindowInfo.Result} 窗口信息
*/
export const getWindowInfo = (): Taro.getWindowInfo.Result => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个文件里是不是都用taroGetxxx就行了,不需要引入Taro了

return Taro.canIUse('getWindowInfo')
? Taro.getWindowInfo()
: Taro.getSystemInfoSync()
return canIUse('getWindowInfo') ? taroGetWindowInfo() : getSystemInfoSync()
}

/**
* 获取应用基础信息,兼容新旧 API
* @returns {Taro.getAppBaseInfo.Result} 应用基础信息
*/
export const getAppBaseInfo = (): Taro.getAppBaseInfo.Result => {
return Taro.canIUse('getAppBaseInfo')
? Taro.getAppBaseInfo()
: Taro.getSystemInfoSync()
return canIUse('getAppBaseInfo') ? taroGetAppBaseInfo() : getSystemInfoSync()
}
8 changes: 4 additions & 4 deletions src/utils/platform-taro.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Taro from '@tarojs/taro'
import { getEnv } from '@tarojs/taro'

export const harmony = () => {
return ['harmony', 'harmonyhybrid', 'jdharmony'].includes(
Taro.getEnv().toLowerCase()
getEnv().toLowerCase()
)
}
export const web = () => {
return ['web'].includes(Taro.getEnv().toLowerCase())
return ['web'].includes(getEnv().toLowerCase())
}

export const miniprogram = () => {
return ['mini'].includes(Taro.getEnv().toLowerCase())
return ['mini'].includes(getEnv().toLowerCase())
}
Loading