初始化代码
This commit is contained in:
82
uniapp/uni-app/test_fix.html
Normal file
82
uniapp/uni-app/test_fix.html
Normal file
@@ -0,0 +1,82 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>测试uni.openSetting修复</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>uni.openSetting修复测试</h1>
|
||||
<button id="testCheckAuth">测试checkAuth函数</button>
|
||||
<div id="result"></div>
|
||||
|
||||
<script>
|
||||
// 模拟uni-app环境
|
||||
window.uni = {
|
||||
getSetting: () => Promise.resolve([null, { authSetting: {} }]),
|
||||
authorize: () => Promise.resolve([new Error("模拟授权失败"), null]),
|
||||
showModal: (options) => {
|
||||
console.log("显示模态框:", options);
|
||||
// 模拟用户点击确认
|
||||
setTimeout(() => {
|
||||
if (options.success) {
|
||||
options.success({ confirm: true });
|
||||
}
|
||||
}, 100);
|
||||
return Promise.resolve();
|
||||
},
|
||||
hideLoading: () => console.log("隐藏加载中"),
|
||||
showToast: (options) => {
|
||||
console.log("显示提示:", options);
|
||||
document.getElementById("result").innerHTML = `提示: ${options.title}`;
|
||||
return Promise.resolve();
|
||||
}
|
||||
};
|
||||
|
||||
// 模拟H5环境
|
||||
console.log("当前环境: H5");
|
||||
|
||||
// 简化版的checkAuth函数(基于我们修复后的逻辑)
|
||||
async function checkAuth({ type = "userLocation", tip = "" } = {}) {
|
||||
// H5环境下直接返回true,因为H5环境不需要小程序授权
|
||||
// 特殊处理地理位置权限
|
||||
if (type === 'userLocation') {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 检查浏览器是否支持地理位置API
|
||||
if (!navigator.geolocation) {
|
||||
uni.showToast({
|
||||
title: '您的浏览器不支持地理位置功能'
|
||||
});
|
||||
reject(new Error('Geolocation not supported'));
|
||||
return;
|
||||
}
|
||||
|
||||
// 尝试获取当前位置
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
() => resolve(true),
|
||||
(error) => {
|
||||
uni.showToast({
|
||||
title: '获取位置失败,请检查浏览器位置权限设置'
|
||||
});
|
||||
reject(error);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// 其他类型的权限在H5环境下直接返回true
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
// 测试函数
|
||||
document.getElementById("testCheckAuth").addEventListener("click", async () => {
|
||||
try {
|
||||
const result = await checkAuth({ type: "userLocation" });
|
||||
document.getElementById("result").innerHTML = "测试成功: " + result;
|
||||
} catch (error) {
|
||||
document.getElementById("result").innerHTML = "测试失败: " + error.message;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user