蓝牙小优化,App隐藏时断开设备连接
This commit is contained in:
@ -104,6 +104,7 @@
|
||||
</view>
|
||||
</BottomSlideMenuPlus>
|
||||
|
||||
<MsgBox ref="msgPop" />
|
||||
<global-loading ref="loading" />
|
||||
</view>
|
||||
</template>
|
||||
@ -115,7 +116,15 @@
|
||||
showLoading,
|
||||
hideLoading,
|
||||
updateLoading
|
||||
} from '@/utils/loading.js'
|
||||
} from '@/utils/loading.js';
|
||||
import {
|
||||
MsgSuccess,
|
||||
MsgError,
|
||||
MsgClose,
|
||||
MsgWarning,
|
||||
showPop,
|
||||
MsgClear
|
||||
} from '@/utils/MsgPops.js';
|
||||
const pagePath = "pages/common/addBLE/addEquip";
|
||||
var ble = null;
|
||||
var these = null;
|
||||
@ -490,24 +499,17 @@
|
||||
console.log('定位权限已授予');
|
||||
resolve(true);
|
||||
} else {
|
||||
console.warn('定位权限被拒绝');
|
||||
uni.showModal({
|
||||
title: '权限提醒',
|
||||
content: '为了正常扫描蓝牙设备,需要您开启定位权限',
|
||||
showCancel: false,
|
||||
success: () => {
|
||||
uni.openSetting(); // 引导用户去设置页
|
||||
}
|
||||
});
|
||||
// console.warn('定位权限被拒绝');
|
||||
|
||||
MsgClear(these);
|
||||
showPop({headerTxt:'权限提醒',message:'扫描蓝牙设备,需要您开启定位权限',buttonText:'去开启',okCallback:uni.openSetting},these,true);
|
||||
|
||||
resolve(false);
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
console.error('请求定位权限失败:', error);
|
||||
uni.showToast({
|
||||
title: '权限请求异常',
|
||||
icon: 'none'
|
||||
});
|
||||
|
||||
MsgError('请求定位权限失败:'+error.code,'确定',these);
|
||||
resolve(false);
|
||||
}
|
||||
);
|
||||
@ -537,7 +539,7 @@
|
||||
}
|
||||
}
|
||||
showLoading(these, {
|
||||
text: '正在刷新'
|
||||
text: '正在扫描蓝牙设备'
|
||||
})
|
||||
let time = null;
|
||||
let startSearch = () => {
|
||||
@ -558,10 +560,9 @@
|
||||
if (err.code === 10001) {
|
||||
these.showOpenSetting();
|
||||
} else {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '出现错误:' + err.msg
|
||||
});
|
||||
|
||||
MsgClear(these);
|
||||
MsgError('出现错误:' + err.msg,'确定',these);
|
||||
|
||||
}
|
||||
}).finally(() => {
|
||||
@ -571,7 +572,9 @@
|
||||
|
||||
}
|
||||
|
||||
ble.StopSearch().finally(startSearch);
|
||||
ble.StopSearch().catch(err=>{
|
||||
console.error("err=",err);
|
||||
}).finally(startSearch);
|
||||
|
||||
|
||||
|
||||
@ -806,9 +809,9 @@
|
||||
linkCallback(res);
|
||||
}).catch(ex => {
|
||||
console.error("ex=", ex)
|
||||
uni.showModal({
|
||||
content: "连接失败:" + ex.msg
|
||||
});
|
||||
MsgClear(these);
|
||||
|
||||
MsgError("连接失败:" + ex.msg,'确定',these);
|
||||
hideLoading(these);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user