外观
getSystemInfo 系统信息获取
约 279 字小于 1 分钟
2024-01-01
介绍
提供获取系统信息和窗口信息的工具函数。
getSystemInfo(): any
获取系统信息,基于uni.getSystemInfoSync。
- 返回值
<Object>系统信息对象
getWindowInfo(): any
获取窗口信息,优先使用uni.getWindowInfo,在不支持的平台上回退到getSystemInfo。
- 返回值
<Object>窗口信息对象
getOsName(): string
获取当前运行平台的操作系统名称。
- 返回值
<String>当前平台的操作系统名称(小写)
示例代码
<template>
<view>
<text>系统信息获取</text>
<button @click="getInfo">获取信息</button>
<view v-if="systemInfo">
<text>设备型号: {{ systemInfo.model }}</text>
<text>操作系统: {{ systemInfo.system }}</text>
<text>屏幕宽度: {{ systemInfo.screenWidth }}px</text>
<text>屏幕高度: {{ systemInfo.screenHeight }}px</text>
</view>
<view v-if="osName">
<text>操作系统名称: {{ osName }}</text>
</view>
</view>
</template>
<script setup lang="uts">
import { ref } from 'vue'
import { getSystemInfo, getWindowInfo, getOsName } from '@/uni_modules/uview-unix'
const systemInfo = ref<any>(null)
const windowInfo = ref<any>(null)
const osName = ref('')
const getInfo = () => {
// 获取系统信息
systemInfo.value = getSystemInfo()
// 获取窗口信息
windowInfo.value = getWindowInfo()
// 获取操作系统名称
osName.value = getOsName()
console.log('系统信息:', systemInfo.value)
console.log('窗口信息:', windowInfo.value)
console.log('操作系统名称:', osName.value)
}
</script>