minix-template
Version:
minix template
499 lines (497 loc) • 11.6 kB
JavaScript
/*
* @Description:
* @Autor: tangsj
* @Date: 2022-05-12 19:08:11
* @LastEditTime: 2022-05-23 16:11:14
*/
import router from '@system.router'
import prompt from '@system.prompt'
export default {
data: {
deviceConnectList:[
{
name:'disconnectBlueConnection',
// url:'pages/base/canlUse/index',
describe:'断开蓝牙连接'
},
{
name:'downFile',
// url:'pages/base/log/index',
describe:'下载文件'
},
{
name:'getBlueStatus',
// url:'pages/base/canlUse/index',
describe:'获取蓝牙状态'
},
{
name:'queryAuthStatus',
// url:'pages/base/log/index',
describe:'查询确权状态'
},
{
name:'queryBlueLuaStatus',
// url:'pages/base/log/index',
describe:'查询lua状态'
},
{
name:'readFirmwareStatus',
// url:'pages/base/canlUse/index',
describe:'查询当前固件指令'
},
{
name:'restartBlueDevice',
// url:'pages/base/log/index',
describe:'重启蓝牙模块'
},
{
name:'sendBlueLuaRequest',
// url:'pages/base/canlUse/index',
describe:'发送Lua请求'
},
{
name:'setupBlueConnection',
// url:'pages/base/log/index',
describe:'建立蓝牙连接'
},
{
name:'startAuthenticRight',
// url:'pages/base/log/index',
describe:'执行设备确权'
},
{
name:'startBlueScan',
// url:'pages/base/canlUse/index',
describe:'开启蓝牙扫描'
},
{
name:'startFirmwareOta',
// url:'pages/base/log/index',
describe:'开始ota升级'
},
{
name:'startReceiveBlueAdvertising',
// url:'pages/base/canlUse/index',
describe:'开始接受广告信息'
},
{
name:'stopBlueScan',
// url:'pages/base/log/index',
describe:'停止蓝牙扫描'
},
{
name:'stopReceiveBlueAdvertising',
// url:'pages/base/log/index',
describe:'停止接受广告信息'
}
]
},
goRouter(url){
router.push({
uri: url,
})
},
/**
* @description: 断开蓝牙连接
* @param {*}
* @return {*}
*/
disconnectBlueConnection(){
const params = {
mac: 'xxxx', //12位蓝牙Mac地址
name: 'midea_xx_xxxx', //蓝牙名称
}
prompt.showToast({
message: params,
duration: 200,
})
this.$app.$def.bridge.disconnectBlueConnection(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description: 下载文件
* @param {*}
* @return {*}
*/
downFile(){
const params = {
url: 'xxx', //下载地址
}
this.$app.$def.bridge.downFile(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description: 获取蓝牙状态
* @param {*}
* @return {*}
*/
getBlueStatus(){
this.$app.$def.bridge.getBlueStatus()
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description: 查询确权状态
* @param {*}
* @return {*}
*/
queryAuthStatus(){
const params = {
name: 'midea_xx_xxxx', //选填
mac: 'xxxxxxxxxxxx', //
}
this.$app.$def.bridge.queryAuthStatus(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description:更新房间信息
* @param {*}
* @return {*}
*/
queryBlueLuaStatus(){
const params = {
mac: 'xxxx', //12位蓝牙Mac地址
name: 'midea_xx_xxxx', //蓝牙名称
applianceId: 'xxx', //设备id
}
this.$app.$def.bridge.queryBlueLuaStatus(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description:查询当前固件指令
* @param {*}
* @return {*}
*/
readFirmwareStatus(){
const params = {
mac: 'xxxx', //12位蓝牙Mac地址
name: 'midea_xx_xxxx', //蓝牙名称
}
this.$app.$def.bridge.readFirmwareStatus(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description:重启蓝牙模块
* @param {*}
* @return {*}
*/
restartBlueDevice(){
const params = {
mac: 'xxxx', //12位蓝牙Mac地址
name: 'midea_xx_xxxx', //蓝牙名称
}
this.$app.$def.bridge.restartBlueDevice(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description:发送Lua请求
* @param {*}
* @return {*}
*/
sendBlueLuaRequest(){
const params = {
mac: 'xxxx', //12位蓝牙Mac地址
name: 'midea_xx_xxxx', //蓝牙名称
applianceId: 'xxx', //设备id,
data: null,
}
this.$app.$def.bridge.sendBlueLuaRequest(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description:建立蓝牙连接
* @param {*}
* @return {*}
*/
setupBlueConnection(){
const params = {
name: 'midea_xx_xxxx', //蓝牙名称
token: 'xxxx', //鉴权 长度32
moduleType: '0', // (^7.3.0) 0代表单蓝牙模组,1,ble+wifi双模组。不传默认单蓝牙模组
mac: 'xxxx', //蓝牙mac地址
applianceId: 'xxx', //设备id
}
this.$app.$def.bridge.setupBlueConnection(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description:执行设备确权
* @param {*}
* @return {*}
*/
startAuthenticRight(){
const params = {
name: 'midea_xx_xxxx', //选填
mac: 'xxxxxxxxxxxx',
applianceId: 'xxxx', //设备deviceId
deviceType: 'xxxx', //设备品类 如“ac”
deviceSn8: 'xxxx', //设备sn8或者设备子类型(看确权指引通过哪个区分,目前只有洗衣机是通过子类型的)
}
this.$app.$def.bridge.startAuthenticRight(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description:开启蓝牙扫描
* @param {*}
* @return {*}
*/
startBlueScan(){
const params = {
duration: 12, //扫描持续时间,
name: '',
mac: '', //云端返回,ios 扫描不到,废弃(二代蓝牙可以扫描到)
}
this.$app.$def.bridge.startBlueScan(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description:开始ota升级
* @param {*}
* @return {*}
*/
startFirmwareOta(){
const params = {
mac: 'xxxx', //12位蓝牙Mac地址
name: 'midea_xx_xxxx', //蓝牙名称
source: 'xxx', //bin文件路径
}
this.$app.$def.bridge.startFirmwareOta(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description:开始接受广告信息
* @param {*}
* @return {*}
*/
startReceiveBlueAdvertising(){
const params = {
id: '12345678', // 监听器的ID,可以传入设备ID
name: '**名称的正则表达式**', // 如:".*midea_ac_.*"
decryptType: 0, // 0表示无需解密,1表示标准蓝牙加密方式(使用设备有:降本体脂秤)
mac: '',
}
this.$app.$def.bridge.startReceiveBlueAdvertising(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description:停止蓝牙扫描
* @param {*}
* @return {*}
*/
stopBlueScan(){
this.$app.$def.bridge.stopBlueScan()
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description:停止接受广告信息
* @param {*}
* @return {*}
*/
stopReceiveBlueAdvertising(){
const params = {
id: '12345678', // 监听器的ID
}
this.$app.$def.bridge.stopReceiveBlueAdvertising(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
testBridge(name){
switch(name){
case 'disconnectBlueConnection':
this.disconnectBlueConnection()
break;
case 'downFile':
this.downFile()
break;
case 'getBlueStatus':
this.getBlueStatus()
break;
case 'queryAuthStatus':
this.queryAuthStatus()
break;
case 'queryBlueLuaStatus':
this.queryBlueLuaStatus()
break;
case 'readFirmwareStatus':
this.readFirmwareStatus()
break;
case 'restartBlueDevice':
this.restartBlueDevice()
break;
case 'sendBlueLuaRequest':
this.sendBlueLuaRequest()
break;
case 'setupBlueConnection':
this.setupBlueConnection()
break;
case 'startAuthenticRight':
this.startAuthenticRight()
break;
case 'startBlueScan':
this.startBlueScan()
break;
case 'startFirmwareOta':
this.startFirmwareOta()
break;
case 'startReceiveBlueAdvertising':
this.startReceiveBlueAdvertising()
break;
case 'stopBlueScan':
this.stopBlueScan()
break;
case 'stopReceiveBlueAdvertising':
this.stopReceiveBlueAdvertising()
break;
default:
break;
}
}
}