minix-template
Version:
minix template
288 lines (286 loc) • 6.33 kB
JavaScript
/*
* @Description:
* @Autor: tangsj
* @Date: 2022-04-29 14:48:09
* @LastEditTime: 2022-05-23 15:46:13
*/
import router from '@system.router'
import prompt from '@system.prompt'
export default {
data: {
baseList:[
{
name:'connectBluetooth',
// url:'pages/base/canlUse/index',
describe:'连接蓝牙设备'
},
{
name:'startBluetoothDiscovery',
// url:'pages/base/log/index',
describe:'开始扫描附近蓝牙设备'
},
{
name:'stopBluetoothDiscovery',
// url:"pages/base/getSystemInfo/index",
describe:'结束扫描附近蓝牙设备'
},
{
name:'getAllConnectedDeviceInfo',
describe:'获取已发现的所有设备信息'
},
{
name:'readBlueToothData',
// url:"pages/base/fireGlobalEvent/index",
describe:'读取蓝牙数据'
},
{
name:'sendBlueToothData',
// url:'pages/base/getPluginInfo/index',
describe:'发送蓝牙数据'
},
{
name:'blueToothEnable',
describe:'打开蓝牙(只Android端支持)'
},
{
name:'disConnectBluetooth',
describe:'断开蓝牙连接'
},
{
name:'getBluetoothStatus',
describe:'获取手机系统蓝牙开关状态'
},
]
},
goRouter(url){
router.push({
uri: url,
})
},
/**
* @description: 连接蓝牙设备
* @param {*}
* @return {*}
*/
connectBluetooth(){
const params = {
deviceId: '20:f4:78:70:6d:ee'
}
this.$app.$def.bridge.connectBluetooth(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description: 开始扫描附近蓝牙设备
* @param {*}
* @return {*}
*/
startBluetoothDiscovery(){
const params = {
name: 'QWQ001-', // 可选 筛选的名字
mac: '1812', // 可选 筛选的mac
duration: '5', //单位秒, 可选
};
this.$app.$def.bridge.startBluetoothDiscovery(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description: 结束扫描附近蓝牙设备
* @param {*}
* @return {*}
*/
stopBluetoothDiscovery(){
this.$app.$def.bridge.stopBluetoothDiscovery()
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description: 获取已发现的所有设备信息
* @param {*}
* @return {*}
*/
getAllConnectedDeviceInfo(){
this.$app.$def.bridge.getAllConnectedDeviceInfo()
.then((res)=>{
prompt.showToast({
message:"接口调用成功",
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message:err,
duration: 200,
})
})
},
/**
* @description: 读取蓝牙数据
* @param {*}
* @return {*}
*/
readBlueToothData (){
const params = {
"mac": "111111",
"serviceUuid": "3333",
"readUuid": "2222"
}
this.$app.$def.bridge.readBlueToothData(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: err,
duration: 200,
})
})
},
/**
* @description: 发送蓝牙数据
* @param {*}
* @return {*}
*/
sendBlueToothData(){
const params = params = {
"mac": "11111111",
"serviceUuid": "服务通道的uuid",
"writeUuid": "写通道的uuid",
"data": "数据的16进制字符串"
}
this.$app.$def.bridge.sendBlueToothData(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: err,
duration: 200,
})
})
},
/**
* @description: 打开蓝牙(只Android端支持)
* @param {*}
* @return {*}
*/
blueToothEnable(){
this.$app.$def.bridge.blueToothEnable()
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: err,
duration: 200,
})
})
},
/**
* @description: 断开蓝牙连接
* @param {*}
* @return {*}
*/
disConnectBluetooth(){
const params = {
"mac": "11111111"
}
this.$app.$def.bridge.disConnectBluetooth(params)
.then((res)=>{
prompt.showToast({
message:"接口调用成功",
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: err,
duration: 200,
})
})
},
/**
* @description: 获取手机系统蓝牙开关状态
* @param {*}
* @return {*}
*/
getBluetoothStatus(){
this.$app.$def.bridge.getBluetoothStatus()
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: err,
duration: 200,
})
})
},
testBridge(name){
switch(name){
case 'connectBluetooth':
this.connectBluetooth()
break;
case 'startBluetoothDiscovery':
this.startBluetoothDiscovery()
break;
case 'stopBluetoothDiscovery':
this.stopBluetoothDiscovery()
break;
case 'getAllConnectedDeviceInfo':
this.getAllConnectedDeviceInfo()
break;
case 'readBlueToothData':
this.readBlueToothData()
break;
case 'sendBlueToothData':
this.sendBlueToothData()
break;
case 'blueToothEnable':
this.blueToothEnable()
break;
case 'disConnectBluetooth':
this.disConnectBluetooth()
break;
case 'getBluetoothStatus':
this.getBluetoothStatus()
break;
default:
break;
}
}
}