feat(app): 添加平台信息工具并将其集成到应用初始化中

- 创建 utils/platform.ts 以提取并规范化设备/操作系统信息
- 将 globalData 中的普通 `system` 字符串替换为结构化的 `platformInfo` 对象
- 推导硬件/软件详情、设备类别和平台标志
- 更新 TypeScript 类型定义以支持新的平台数据类型
This commit is contained in:
熊熊熊子路 committed 2026-07-31 11:31:31 +08:00
1 parent 58cd96aaa3
commit f19f4b8d41
3 files changed
+150 -6

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
const MOBILE_CLIENT_PLATFORMS: ClientPlatformType[] = ['ios', 'android', 'ohos']
const DESKTOP_CLIENT_PLATFORMS: ClientPlatformType[] = ['windows', 'mac', 'ohos_pc']
function normalizeClientPlatform(platform: string): ClientPlatformType {
switch (platform.toLowerCase()) {
case 'ios':
case 'android':
case 'ohos':
case 'ohos_pc':
case 'windows':
case 'mac':
case 'devtools':
return platform.toLowerCase() as ClientPlatformType
default:
return 'unknown'
}
}
function resolveOperatingSystem(platform: ClientPlatformType): OperatingSystemType {
switch (platform) {
case 'ios':
return 'ios'
case 'android':
return 'android'
case 'ohos':
case 'ohos_pc':
return 'harmonyos'
case 'windows':
return 'windows'
case 'mac':
return 'macos'
case 'devtools':
return 'devtools'
default:
return 'unknown'
}
}
function resolveDeviceClass(platform: ClientPlatformType): HardwareDeviceClassType {
if (MOBILE_CLIENT_PLATFORMS.includes(platform)) {
return 'mobile'
}
if (DESKTOP_CLIENT_PLATFORMS.includes(platform)) {
return 'desktop'
}
return platform === 'devtools' ? 'devtools' : 'unknown'
}
export function getPlatformInfo(): PlatformInfoType {
const deviceInfo = wx.getDeviceInfo()
const appBaseInfo = wx.getAppBaseInfo()
const rawClientPlatform = deviceInfo.platform || ''
const clientPlatform = normalizeClientPlatform(rawClientPlatform)
const deviceClass = resolveDeviceClass(clientPlatform)
return {
hardware: {
deviceClass,
brand: deviceInfo.brand || '',
model: deviceInfo.model || '',
abi: deviceInfo.abi || '',
deviceAbi: deviceInfo.deviceAbi || '',
cpuType: deviceInfo.cpuType || '',
memorySize: deviceInfo.memorySize || '',
},
software: {
clientPlatform,
rawClientPlatform,
operatingSystem: resolveOperatingSystem(clientPlatform),
system: deviceInfo.system || '',
wechatVersion: appBaseInfo.version || '',
baseLibraryVersion: appBaseInfo.SDKVersion || '',
hostAppId: appBaseInfo.host?.appId || '',
},
isMobile: deviceClass === 'mobile',
isDesktop: deviceClass === 'desktop',
isDevtools: deviceClass === 'devtools',
}
}