UNPKG

minix-template

Version:

minix template

574 lines (572 loc) 14.3 kB
/* * @Description: * @Autor: tangsj * @Date: 2022-05-12 19:08:11 * @LastEditTime: 2022-05-23 16:12:01 */ import router from '@system.router' import prompt from '@system.prompt' export default { data: { deviceManageList:[ { name:'addDevice', // url:'pages/base/canlUse/index', describe:'根据配网指引数据配网' }, { name:'checkDeviceOTAUpdate', // url:'pages/base/log/index', describe:'检测设备OTA版本' }, { name:'deviceUpdateNotify', // url:'pages/base/canlUse/index', describe:'设备插件页设备属性、状态改变后,通知原生刷新数据接口' }, { name:'getApplianceSubtype', // url:'pages/base/log/index', describe:'获取当前家电设备id下的家电型号' }, { name:'getCurrentApplianceID', // url:'pages/base/log/index', describe:'获取当前家电设备id' }, { name:'getDeviceConnectInfo', // url:'pages/base/canlUse/index', describe:'获取配网指引' }, { name:'getDeviceInfo', // url:'pages/base/log/index', describe:'获取设备信息,如果设备id没指定则是获取当前设备的信息' }, { name:'getDeviceList', // url:'pages/base/canlUse/index', describe:'获取指定家庭指定房间的设备列表' }, { name:'getDeviceOTAUpgradeInfo', // url:'pages/base/log/index', describe:'获取OTA升级信息' }, { name:'getDevicePluginInfo', // url:'pages/base/log/index', describe:'获取指定家电id的插件下载与否和版本信息' }, { name:'getDeviceSN', // url:'pages/base/canlUse/index', describe:'获取当前家电设备id下的解密后的sn' }, { name:'luaControl', // url:'pages/base/log/index', describe:'lua控制家' }, { name:'luaQuery', // url:'pages/base/canlUse/index', describe:'lua查询家电情况' }, { name:'startCmdProcess', // url:'pages/base/log/index', describe:'推荐使用sendLuaRequest(Lua控制)代替此接口做设备控制/查询' }, { name:'subscribeMessage', // url:'pages/base/log/index', describe:'订阅/取消订阅 ' }, { name:'toConfigDevice', // url:'pages/base/canlUse/index', describe:'获取配网指引并进入配网页面' }, { name:'unbindDevice', // url:'pages/base/log/index', describe:'解绑删除设备' }, { name:'updateDeviceInfo', // url:'pages/base/log/index', describe:'更新设备信息,通知设备属性变更设备名称、房间id和房间名' } ] }, goRouter(url){ router.push({ uri: url, }) }, /** * @description: 根据配网指引数据配网 * @param {*} * @return {*} */ addDevice(){ const params = { data: { category: 'xx', mode: 0, } } this.$app.$def.bridge.addDevice(params).then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 检测设备OTA版本 * @param {*} * @return {*} */ checkDeviceOTAUpdate(){ const params = { deviceIds: ['1221'], //家电Id,家电设备Id } this.$app.$def.bridge.checkDeviceOTAUpdate(params).then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 设备插件页(wifi家电,套装子设备)设备属性、状态改变后,通知原生刷新数据接口 * @param {*} * @return {*} */ deviceUpdateNotify(){ const params={ type: 'deviceModify', //通知类型 deviceId: '28821099922', //设备ID param: { //每种通知类型都会传 deviceName: '测试', //更改设备名字时传 roomId: '1', //更改房间时传 roomName: '1' //更改房间时传 } } this.$app.$def.bridge.deviceUpdateNotify(params).then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 获取当前家电设备id下的家电型号 * @param {*} * @return {*} */ getApplianceSubtype(){ this.$app.$def.bridge.getApplianceSubtype().then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description:获取当前家电设备id * @param {*} * @return {*} */ getCurrentApplianceID(){ this.$app.$def.bridge.getCurrentApplianceID().then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description:获取配网指引 * @param {*} * @return {*} */ getDeviceConnectInfo(){ const params = { deviceType: 0xac, sn8: 12345678, mode: 0, enterpriseCode: '1', } this.$app.$def.bridge.getDeviceConnectInfo(params).then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description:获取设备信息,如果设备id没指定则是获取当前设备的信息 * @param {*} * @return {*} */ getDeviceInfo(){ const params = { applianceCode: '11', //家电id } this.$app.$def.bridge.getDeviceInfo(params).then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description:获取指定家庭指定房间的设备列表 * @param {*} * @return {*} */ getDeviceList(){ const params = { familyId: '2121', //家庭id, roomId: '1111', //房间id } this.$app.$def.bridge.getDeviceList(params).then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description:获取OTA升级信息 * @param {*} * @return {*} */ getDeviceOTAUpgradeInfo(){ const params = { deviceIds: JSON.stringify(['121', '1']), // 家电id组 } this.$app.$def.bridge.getDeviceOTAUpgradeInfo(params).then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description:获取指定家电id的插件下载与否和版本信息 * @param {*} * @return {*} */ getDevicePluginInfo(){ const params = { deviceId: '1', //家电id, deviceSn8: '123', deviceType: '1', deviceSubType: '2', } this.$app.$def.bridge.getDevicePluginInfo(params).then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description:获取当前家电设备id下的解密后的sn * @param {*} * @return {*} */ getDeviceSN(){ this.$app.$def.bridge.getDeviceSN().then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description:lua控制家 * @param {*} * @return {*} */ luaControl(){ const params = { params: '', //查询/控制参数, applianceId: '', // 设备id name mock Data文件名,于dummy文件夹下,通过name匹配相应模拟数据文件 mode: 0, //lua发送类型:0:优先局域网发送,不在局域网则广域网透传(默认);1:只发送广域网透传,若广域网透传失败,则直接返回错误信息 name:'' } this.$app.$def.bridge.luaControl(params).then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description:lua查询家电情况 * @param {*} * @return {*} */ luaQuery(){ const params = { params: '222', //查询/控制参数, applianceId: '1', // 设备id name mock Data文件名,于dummy文件夹下,通过name匹配相应模拟数据文件 mode: 0, //lua发送类型:0:优先局域网发送,不在局域网则广域网透传(默认);1:只发送广域网透传,若广域网透传失败,则直接返回错误信息 name:'测试' } this.$app.$def.bridge.luaQuery(params).then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description:推荐使用sendLuaRequest(Lua控制)代替此接口做设备控制/查询 * @param {*} * @return {*} */ startCmdProcess(){ const params = JSON.stringify({ name: '测试', // mock模拟数据key,可以在mock.js中配置模拟数据,通过name匹配相应模拟数据 messageBody: '123', // 十六进制指令 }) this.$app.$def.bridge.startCmdProcess(params).then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description:订阅/取消订阅 * @param {*} * @return {*} */ subscribeMessage(){ const params = { deviceId: '1' } this.$app.$def.bridge.subscribeMessage(params).then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description:获取配网指引并进入配网页面 * @param {*} * @return {*} */ toConfigDevice(){ const params = { sn8: '123', deviceType: '1', //设备类型 mode: 0, //配网模式(0 AP、1 快连、3 蓝牙) enterpriseCode: '1', //企业码 } this.$app.$def.bridge.toConfigDevice(params).then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description:解绑删除设备 * @param {*} * @return {*} */ unbindDevice(){ const params = { applianceCode: '1', //家电id isOtherEquipment: '11', //第三方设备, applianceList: [ { applianceCode: '1', //家电id isOtherEquipment: '12', //第三方设备 }, ], } this.$app.$def.bridge.unbindDevice(params).then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description:更新设备信息(设备名,设备描述),通知设备属性变更设备名称、房间id和房间名 * @param {*} * @return {*} */ updateDeviceInfo(){ const params = { name: '测试房间', roomId: '1' } this.$app.$def.bridge.updateDeviceInfo(params).then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, testBridge(name){ switch(name){ case 'addDevice': this.addDevice() break; case 'checkDeviceOTAUpdate': this.checkDeviceOTAUpdate() break; case 'deviceUpdateNotify': this.deviceUpdateNotify() break; case 'getApplianceSubtype': this.getApplianceSubtype() break; case 'getCurrentApplianceID': this.getCurrentApplianceID() break; case 'getDeviceConnectInfo': this.getDeviceConnectInfo() break; case 'getDeviceInfo': this.getDeviceInfo() break; case 'getDeviceList': this.getDeviceList() break; case 'getDeviceOTAUpgradeInfo': this.getDeviceOTAUpgradeInfo() break; case 'getDevicePluginInfo': this.getDevicePluginInfo() break; case 'getDeviceSN': this.getDeviceSN() break; case 'luaControl': this.luaControl() break; case 'luaQuery': this.luaQuery() break; case 'startCmdProcess': this.startCmdProcess() break; case 'subscribeMessage': this.subscribeMessage() break; case 'toConfigDevice': this.toConfigDevice() break; case 'unbindDevice': this.unbindDevice() break; case 'updateDeviceInfo': this.updateDeviceInfo() break; default: break; } } }