fix:wifi页面新增授权失败的逻辑
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
import { ref, computed, onMounted, onUnmounted } from "vue";
|
import { ref, computed, onMounted, onUnmounted } from "vue";
|
||||||
import { onShow } from "@dcloudio/uni-app";
|
import { onShow } from "@dcloudio/uni-app";
|
||||||
import Container from "@/components/Container.vue";
|
import Container from "@/components/Container.vue";
|
||||||
|
import ScreenHint from "@/components/ScreenHint.vue";
|
||||||
|
|
||||||
const STATES = {
|
const STATES = {
|
||||||
SCANNING: "SCANNING",
|
SCANNING: "SCANNING",
|
||||||
@@ -32,28 +33,28 @@ const isRefreshing = ref(false);
|
|||||||
const progress = ref(0);
|
const progress = ref(0);
|
||||||
let progressTimer = null;
|
let progressTimer = null;
|
||||||
let timeoutTimer = null;
|
let timeoutTimer = null;
|
||||||
let wifiPermissionModalVisible = false;
|
// 控制授权拒绝弹窗显示/隐藏
|
||||||
|
const wifiAuthDeniedVisible = ref(false);
|
||||||
|
|
||||||
// 判断 WiFi 列表失败是否由用户拒绝位置授权引起。
|
// 判断 WiFi 列表失败是否由用户拒绝授权引起(兼容 errno:103 及各平台 errMsg 变体)。
|
||||||
const isWifiPermissionDenied = (err) => {
|
const isWifiPermissionDenied = (err) => {
|
||||||
|
if (err?.errno === 103) return true;
|
||||||
const errMsg = err?.errMsg || "";
|
const errMsg = err?.errMsg || "";
|
||||||
return /auth deny|authorize|permission denied|user denied|scope\.userLocation/i.test(errMsg);
|
return /auth den|authorize|permission denied|user denied|scope\.userLocation/i.test(errMsg);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 提示用户改用手动输入 WiFi 名称和密码。
|
// 显示授权拒绝弹窗,通过 ScreenHint 组件呈现。
|
||||||
const showWifiPermissionDeniedModal = () => {
|
const showWifiPermissionDeniedModal = () => {
|
||||||
if (wifiPermissionModalVisible) return;
|
wifiAuthDeniedVisible.value = true;
|
||||||
wifiPermissionModalVisible = true;
|
};
|
||||||
uni.showModal({
|
|
||||||
title: "无法获取 WiFi 列表",
|
// 用户点击「重新授权」时,打开小程序权限设置页;无论授权结果如何,
|
||||||
content: "无法获取附近 WiFi 列表,请手动输入 WiFi 名称和密码完成连接。",
|
// 返回后自动重新扫描,兼容微信层与系统层权限变更两种情况。
|
||||||
cancelText: "取消",
|
const handleReauthorize = () => {
|
||||||
confirmText: "去输入",
|
wifiAuthDeniedVisible.value = false;
|
||||||
success(res) {
|
uni.openSetting({
|
||||||
if (res.confirm) selectOther();
|
success() {
|
||||||
},
|
startScanning();
|
||||||
complete() {
|
|
||||||
wifiPermissionModalVisible = false;
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -580,10 +581,64 @@ onUnmounted(() => {
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 授权拒绝弹窗 -->
|
||||||
|
<ScreenHint :show="wifiAuthDeniedVisible" :onClose="() => (wifiAuthDeniedVisible = false)">
|
||||||
|
<view class="wifi-auth-denied">
|
||||||
|
<text class="wifi-auth-denied-text">拒绝授权获取wifi列表失败,请重新授权或手动输入</text>
|
||||||
|
<view class="wifi-auth-denied-btns">
|
||||||
|
<view class="wifi-auth-denied-btn cancel-btn" @click="wifiAuthDeniedVisible = false">
|
||||||
|
<text>取消授权</text>
|
||||||
|
</view>
|
||||||
|
<view class="wifi-auth-denied-btn confirm-btn" @click="handleReauthorize">
|
||||||
|
<text>重新授权</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</ScreenHint>
|
||||||
</Container>
|
</Container>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
.wifi-auth-denied {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
padding: 32rpx 40rpx 24rpx;
|
||||||
|
gap: 32rpx;
|
||||||
|
}
|
||||||
|
.wifi-auth-denied-text {
|
||||||
|
color: #fff;
|
||||||
|
font-size: 28rpx;
|
||||||
|
text-align: center;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
.wifi-auth-denied-btns {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
gap: 24rpx;
|
||||||
|
width: 100%;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.wifi-auth-denied-btn {
|
||||||
|
flex: 1;
|
||||||
|
height: 72rpx;
|
||||||
|
border-radius: 36rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 28rpx;
|
||||||
|
}
|
||||||
|
.wifi-auth-denied-btn.cancel-btn {
|
||||||
|
background: rgba(255, 255, 255, 0.15);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.wifi-auth-denied-btn.confirm-btn {
|
||||||
|
background: rgba(254, 216, 71, 1);
|
||||||
|
color: #1a1a2e;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
.wifi-banner {
|
.wifi-banner {
|
||||||
background-color: rgba(255, 200, 0, 0.12);
|
background-color: rgba(255, 200, 0, 0.12);
|
||||||
border: 1rpx solid rgba(254, 216, 71, 0.5);
|
border: 1rpx solid rgba(254, 216, 71, 0.5);
|
||||||
|
|||||||
Reference in New Issue
Block a user