minix-template
Version:
minix template
271 lines (267 loc) • 7.04 kB
JavaScript
/*
* @Description:
* @Autor: tangsj
* @Date: 2022-05-06 16:42:57
* @LastEditTime: 2022-05-24 19:45:31
*/
import router from '@system.router'
import prompt from '@system.prompt'
import {bridgeModuleWrapper} from '../../../util'
import bridge from '@minix-iot/jsbridge-sdk'
export default {
data: {
httpList:[
{
name:'uploadFile',
// url:'pages/base/canlUse/index',
describe:'http文件上传'
},
{
name:'downloadFile',
// url:'pages/base/log/index',
describe:'http文件下载'
},
{
name:'requestDataTransmit',
// url:'pages/base/log/index',
describe:'服务透传接口,提供给插件发送请求至事业部的品类服务器'
},
{
name:'sendCentralCloudRequest',
// url:'pages/base/canlUse/index',
describe:'发送给中台的通用网络请求接口'
},
{
name:'uploadLocalFile',
// url:'pages/base/log/index',
describe:'通用上传本地文件'
},
{
name:'uploadFileToOss',
// url:'pages/base/log/index',
describe:'上传文件到阿里 oss'
}
]
},
goRouter(url){
router.push({
uri: url,
})
},
/**
* @description: http文件上传
* @param {*}
* @return {*}
*/
uploadFile(){
const params={
url: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3105753044,45676271&fm=26&gp=0.jpg',
filePath: 'downFiles/timg.jpeg',
name: "keyname",
header: {},
formData: {}, //HTTP 请求中其他额外的 form data
timeout: 10000
}
this.$app.$def.bridge.uploadFile(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description: http文件下载
* @param {*}
* @return {*}
*/
downloadFile(){
const params={
url:'https://pics3.baidu.com/feed/8644ebf81a4c510fcd65599b8681e02ad62aa5ea.jpeg?token=56a3bc1eb0af07d69f13ca9cb2dff4f9&s=D582FE1E9DA9E0135AC1B0FC0300D071',
header: {
acessToken: 'ceshi',
},
timeout: '20000',
}
this.$app.$def.bridge.downloadFile(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
})
},
/**
* @description: 插件发送请求至事业部的品类服务器
* @param {*}
* @return {*}
*/
requestDataTransmit(){
const params={
type: '0xDB', //插件调用可以不传,因为容器中会再获取一次,接口测试必须传type
queryStrings: {
applianceId: '3298544979980',
expendType: '3',
handleType: 'GetWasherCost',
resultType: '1',
time: '20210621',
type: '0xDB',
},
transmitData: {
data: 'handleType=GetWasherCost&applianceId=3298544979980&resultType=1&expendType=3&time=20210621',
},
}
this.$app.$def.bridge.requestDataTransmit(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: err,
duration: 200,
})
})
},
/**
* @description:发送给中台的通用网络请求接口
* @param {*}
* @return {*}
*/
sendCentralCloudRequest(){
const params={
url: 'gateway/subdevice/search', //请求接口路径,
method: 'POST', //POST/GET, 默认POST
headers: {}, //请求header
data: {}, //请求参数
bizType: '0', //^6.1.0 业务类型,0:IoT请求(默认);1:中国区请求
}
// bridgeModuleWrapper('sendCentralCloundRequest', params)
// .then((res)=>{
// prompt.showToast({
// message: res,
// duration: 200,
// })
// }).catch((err)=>{
// prompt.showToast({
// message: err,
// duration: 200,
// })
// })
this.$app.$def.bridge.sendCentralCloudRequest(params)
.then((res)=>{
prompt.showToast({
message: res,
duration: 200,
})
}).catch((err)=>{
prompt.showToast({
message: err,
duration: 200,
})
})
},
/**
* @description:通用上传本地文件
* @param {*}
* @return {*}
*/
uploadLocalFile(){
const params={
// url: 'https://mp-sit.smartmidea.net/mas/v5/app/proxy?alias=/ccrm2-core/uploadApi/upload', //注意: 需要服务器完整url地址
domain: 'https://mp-sit.smartmidea.net/mas/v5/app/proxy?alias=', // 域名
path: '/ccrm2-core/uploadApi/upload', // path
// /ccrm2-core/uploadApi/upload, /api-pub/pub/commonFile/upload
filePath: 'testFile1.txt', //要上传文件资源的路径 (本地相对路径) WeexApp目录说明;(testFile1.txt)(test3333.jpeg)
timeout: 'xxxx', //超时时间,单位为毫秒;
fileKey: 'xxx', // 数据关联的名称。原生在post表单中传输文件的key值,缺省默认值为“file”.。
netParam: {
xxx: 'xxx', //weex需要原生填充给服务器的post 表单参数1
xxx: 'xxx', // weex需要原生填充给服务器的post 表单参数2
},
imgParam: {
//如上传图片需要额外参数处理,此参数有值
maxWidth: '',
maxHeight: '',
compressRage: '',
},
mimeType: 'text/plain', //默认为application/octet-stream,上传图片为image/jpg
}
this.$app.$def.bridge.uploadLocalFile(
params,
(res)=>{
prompt.showToast({
message: res,
duration: 200,
})
},
(err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
}
)
},
/**
* @description: 上传文件到阿里 oss
* @param {*}
* @return {*}
*/
uploadFileToOss(){
const params={
fileList: ['/Unzip'], //本地文件路径
}
this.$app.$def.bridge.uploadFileToOss(
params,
(res)=>{
prompt.showToast({
message: res,
duration: 200,
})
},
(err)=>{
prompt.showToast({
message: '接口调用失败',
duration: 200,
})
}
)
},
testBridge(name){
// this[name]();
switch(name){
case 'uploadFile':
this.uploadFile()
break;
case 'downloadFile':
this.downloadFile()
break;
case 'requestDataTransmit':
this.requestDataTransmit()
break;
case 'sendCentralCloudRequest':
this.sendCentralCloudRequest()
break;
case 'uploadLocalFile':
this.uploadLocalFile()
break;
case 'uploadFileToOss':
this.uploadFileToOss()
break;
default:
break;
}
}
}