minix-template
Version:
minix template
274 lines (269 loc) • 6.29 kB
JavaScript
/*
* @Description:
* @Autor: tangsj
* @Date: 2022-04-22 09:27:08
* @LastEditTime: 2022-05-24 15:11:04
*/
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import router from '@system.router'
import prompt from '@system.prompt'
import {commandInterfaceWrapper,globalEventModuleWrapper,customCommandInterface} from '../../../util'
const module = miniXs.requireModule('bridgeModule')
import bridge from '@minix-iot/jsbridge-sdk'
export default {
data: {
baseList:[
{
name:'canlUse',
url:'pages/base/canlUse/index',
describe:'获取某个 API 在当前版本是否可用'
},
{
name:'log',
url:'pages/base/log/index',
describe:'打印日志'
},
{
name:'getSystemInfo',
url:"pages/base/getSystemInfo/index",
describe:'获取系统信息'
},
{
name:'addEventListener',
url:'pages/base/getPluginInfo/index',
describe:'此监听Key用于接收设备上报信息'
},
{
name:'fireGlobalEvent',
url:"pages/base/fireGlobalEvent/index",
describe:'发送全局通知'
},
{
name:'getPluginInfo',
url:'pages/base/getPluginInfo/index',
describe:'返回路径和插件版本等信息'
},
{
name:'interfaceForThirdParty',
url:'pages/base/getPluginInfo/index',
describe:'提供给前端页面调用插件第三方SDK接口'
},
]
},
goRouter(url){
prompt.showToast({
message: url,
duration: 200,
})
router.push({
uri: url,
})
},
/**
* @description: 获取某个api在当前版本是否可用
* @param {*}
* @return {*}
*/
canlUse(){
let params = 'getSystemInfo'
this.$app.$def.bridge.canIUse(params)
.then(res => {
prompt.showToast({
message: res,
duration: 200,
})
})
.catch(err => {
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description: 打印日志
* @param {*}
* @return {*}
*/
log(){
let params = {
level: 'Info',
message: 'info from weex by bridgeService'
}
bridge.log(params)
.then(res => {
prompt.showToast({
message: '测试接口成功',
duration: 200,
})
})
.catch(err => {
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description: 获取系统信息
* @param {*}
* @return {*}
*/
getSystemInfo(){
bridge.getSystemInfo()
.then(res => {
prompt.showToast({
message: '测试接口成功',
duration: 200,
})
})
.catch(err => {
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description: 添加事件监听,并触发
* @param {*}
* @return {*}
*/
addEventListener(){
globalEventModuleWrapper('addEventListener','receiveMessageFromApp',(res) => {
prompt.showToast({
message: '测试接口成功',
duration: 200,
})
})
let params = {
event: 'receiveMessageFromApp', //事件名,
param: {
messageType: 'test', // stringH5用来判断消息类型,然后做相对应的处理
messageBody: {
test: 'woshishui',
}, //传递的json对象
},
}
// 触发
commandInterfaceWrapper({
operation: 'fireGlobalEvent',
params
}).then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description: 返回路径和插件版本等信息
* @param {*}
* @return {*}
*/
getPluginInfo(){
let params = {
folder: 'midea-rooms'
}
commandInterfaceWrapper({
operation: 'getSystemInfo',
params
}).then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description: 提供给前端页面调用插件第三方SDK接口
* @param {*}
* @return {*}
*/
interfaceForThirdParty(){
let params = {
messageType: '', // 第三方SDK用来判断接口名称,
messageContent: '',
}
let subModuleName = 'interfaceForThirdParty'
customCommandInterface(params, {
subModuleName
})
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: err,
duration: 200,
})
})
},
// getSystemInfo(){
// commandInterfaceWrapper({
// operation: 'getSystemInfo',
// params: {
// api: {},
// },
// }).then((res)=>{
// prompt.showToast({
// message: res,
// duration: 200,
// })
// }).catch((err)=>{
// prompt.showToast({
// message: '接口调用失败',
// duration: 200,
// })
// })
// },
testBridge(name){
switch(name){
case 'canlUse':
this.canlUse()
break;
case 'log':
this.log()
break;
case 'getSystemInfo':
this.getSystemInfo()
break;
case 'addEventListener':
this.addEventListener()
break;
case 'getPluginInfo':
this.getPluginInfo()
break;
case 'interfaceForThirdParty':
this.interfaceForThirdParty()
break;
default:
break;
}
}
}