78 lines
1.8 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script lang="ts">
import { MyApiResult } from "@/src/BluetoothManager"
import * as Ble from "@/src/BluetoothManager"
// #ifdef APP-PLUS
let firstBackTime = 0
// #endif
export default {
globalData: {
// 连接蓝牙:connect → 服务/特征校验(CLI 读写特征 + 参数只读特征),
// 就绪后发 bleState 0(不再订阅 notify,固件 notify 链路已停用)
ConnectBle(address: string, autoReconnect: boolean){
Ble.connect(address, autoReconnect, function(res: MyApiResult){
console.log("[MCM] connect " + address + ": type=" + res.type + " msg=" + res.message)
if(res.type==0){
Ble.scanServices(function(resSevice: MyApiResult){
console.log("[MCM] scanServices: type=" + resSevice.type + " msg=" + resSevice.message)
if (resSevice.type == 0) {
uni.$emit("bleState", 0)
} else {
uni.$emit("bleState", 10000)
}
});
}else{
uni.$emit("bleState",res.type)
}
})
},
},
onLaunch: function () {
console.log('App Launch')
},
onShow: function () {
console.log('App Show')
},
onHide: function () {
console.log('App Hide')
},
// #ifdef APP-PLUS
onLastPageBackPress: function () {
console.log('App LastPageBackPress')
if (firstBackTime == 0) {
uni.showToast({
title: 'Press Exit Application again',
position: 'bottom',
})
firstBackTime = Date.now()
setTimeout(() => {
firstBackTime = 0
}, 2000)
} else if (Date.now() - firstBackTime < 2000) {
firstBackTime = Date.now()
plus.runtime.quit()
}
},
// #endif
onExit: function () {
console.log('App Exit')
},
methods: {
}
}
</script>
<style>
/*每个页面公共css */
.uni-row {
flex-direction: row;
}
.uni-column {
flex-direction: column;
}
</style>