获取系统设置
| 类型 | |||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| GetSystemSettingResult | |||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||
bluetoothError、wifiError 非空的情况就说明权限配置错误,需要根据 文档 正确配置权限。示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见
该 API 不支持 Web,请运行 hello uni-app x 到 App 平台体验
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-common-mt">
<view class="uni-list">
<view class="uni-list-cell system-setting-cell">
<view class="system-setting-label">
<text class="system-info-text">蓝牙的系统开关</text>
</view>
<view class="system-setting-value">
<input class="system-info-input" placeholder-class="system-info-placeholder" type="text" :disabled="true" placeholder="未获取" :value="data.bluetoothEnabled" />
</view>
</view>
<view class="uni-list-cell system-setting-cell">
<view class="system-setting-label">
<text class="system-info-text">地理位置的系统开关</text>
</view>
<view class="system-setting-value">
<input class="system-info-input" placeholder-class="system-info-placeholder" type="text" :disabled="true" placeholder="未获取" :value="data.locationEnabled" />
</view>
</view>
<view class="uni-list-cell system-setting-cell">
<view class="system-setting-label">
<text class="system-info-text">Wi-Fi 的系统开关</text>
</view>
<view class="system-setting-value">
<input class="system-info-input" placeholder-class="system-info-placeholder" type="text" :disabled="true" placeholder="未获取" :value="data.wifiEnabled" />
</view>
</view>
<!-- #ifndef MP-ALIPAY -->
<view class="uni-list-cell system-setting-cell">
<view class="system-setting-label">
<text class="system-info-text">设备方向</text>
</view>
<view class="system-setting-value">
<input class="system-info-input" placeholder-class="system-info-placeholder" type="text" :disabled="true" placeholder="未获取" :value="data.deviceOrientation" />
</view>
</view>
<!-- #endif -->
</view>
<view class="uni-padding-wrap">
<view class="uni-btn-v">
<button type="primary" @tap="getSystemSetting">获取系统设置</button>
</view>
</view>
</view>
</view>
</template>
<script setup lang="ts">
type DataType = {
bluetoothEnabled: string;
locationEnabled: string;
wifiEnabled: string;
deviceOrientation: string;
}
const title = ref('getSystemSetting')
const data = reactive({
bluetoothEnabled: "",
locationEnabled: "",
wifiEnabled: "",
deviceOrientation: ""
} as DataType)
const getSystemSetting = () => {
const res = uni.getSystemSetting();
data.bluetoothEnabled = (res.bluetoothEnabled ?? false) ? "开启" : "关闭";
data.locationEnabled = res.locationEnabled ? "开启" : "关闭";
data.wifiEnabled = (res.wifiEnabled ?? false) ? "开启" : "关闭";
data.deviceOrientation = res.deviceOrientation
if (res.bluetoothError != null) {
data.bluetoothEnabled = "无蓝牙权限"
}
if (res.wifiError != null) {
data.wifiEnabled = "无WiFi权限"
}
}
</script>
<style>
.system-setting-cell {
flex-direction: row;
justify-content: flex-start;
align-items: center;
background-color: var(--list-background-color, #ffffff);
}
.system-setting-label {
width: 180px;
padding-left: 15px;
background-color: var(--list-background-color, #ffffff);
}
.system-setting-value {
flex: 1;
background-color: var(--list-background-color, #ffffff);
}
.system-info-text,
.system-info-input {
color: var(--text-color, #333333);
}
.system-info-input {
height: 24px;
padding: 0;
border-width: 0;
background-color: var(--list-background-color, #ffffff);
}
.system-info-placeholder {
color: var(--active-color, #999999);
}
</style>
| 名称 | 类型 | 必备 | 描述 |
|---|---|---|---|
| errMsg | string | 是 | 错误信息 |