- 创建 utils/platform.ts 以提取并规范化设备/操作系统信息 - 将 globalData 中的普通 `system` 字符串替换为结构化的 `platformInfo` 对象 - 推导硬件/软件详情、设备类别和平台标志 - 更新 TypeScript 类型定义以支持新的平台数据类型
58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
/// <reference path="./types/index.d.ts" />
|
|
/// <reference path="./npm.d.ts" />
|
|
|
|
/** 微信小程序当前运行的客户端平台,对应 wx.getDeviceInfo().platform */
|
|
type ClientPlatformType = 'ios' | 'android' | 'ohos' | 'ohos_pc' | 'windows' | 'mac' | 'devtools' | 'unknown'
|
|
|
|
/** 根据客户端平台归一化后的操作系统类型 */
|
|
type OperatingSystemType = 'ios' | 'android' | 'harmonyos' | 'windows' | 'macos' | 'devtools' | 'unknown'
|
|
|
|
/** 根据客户端平台归类的硬件设备类别 */
|
|
type HardwareDeviceClassType = 'mobile' | 'desktop' | 'devtools' | 'unknown'
|
|
|
|
interface HardwarePlatformInfoType {
|
|
deviceClass: HardwareDeviceClassType
|
|
brand: string
|
|
model: string
|
|
abi: string
|
|
deviceAbi: string
|
|
cpuType: string
|
|
memorySize: string
|
|
}
|
|
|
|
interface SoftwarePlatformInfoType {
|
|
clientPlatform: ClientPlatformType
|
|
rawClientPlatform: string
|
|
operatingSystem: OperatingSystemType
|
|
system: string
|
|
wechatVersion: string
|
|
baseLibraryVersion: string
|
|
hostAppId: string
|
|
}
|
|
|
|
interface PlatformInfoType {
|
|
hardware: HardwarePlatformInfoType
|
|
software: SoftwarePlatformInfoType
|
|
isMobile: boolean
|
|
isDesktop: boolean
|
|
isDevtools: boolean
|
|
}
|
|
|
|
interface IAppOption {
|
|
globalData: {
|
|
navBarHeight: number,
|
|
navBarContentHeight: number,
|
|
statusBarHeight: number,
|
|
menuRight: number,
|
|
menuTop: number,
|
|
menuHeight: number,
|
|
tabbarHeight: number,
|
|
safeAreaBottom: number,
|
|
safeAreaInsetBottom: number
|
|
platformInfo: PlatformInfoType
|
|
token: string
|
|
userInfo?: WechatMiniprogram.UserInfo
|
|
}
|
|
userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback
|
|
}
|