| | |
| | | import { $fileTrans } from '@components/common/FileTransform'; |
| | | |
| | | export class Bridge { |
| | | |
| | | constructor() { |
| | | this._data = { |
| | | count: 100, |
| | |
| | | }; |
| | | }, 5 * 60 * 1000); |
| | | // 挂载到全局 |
| | | this[cbName] = (res) => { |
| | | this[cbName] = res => { |
| | | // res有值,正常通讯 |
| | | if (typeof res !== 'undefined') { |
| | | let data; |
| | |
| | | }; |
| | | } |
| | | // 发送 |
| | | window.aisim.linking(JSON.stringify({ |
| | | window.aisim.linking( |
| | | JSON.stringify({ |
| | | method, |
| | | param, |
| | | callback: cbName ? ('bridge.' + cbName) : '', |
| | | })); |
| | | callback: cbName ? 'bridge.' + cbName : '', |
| | | }), |
| | | ); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @private |
| | | */ |
| | | _initReceive() { |
| | | window.telling = (res) => { |
| | | window.telling = res => { |
| | | const data = typeof res === 'string' ? JSON.parse(res) : res; |
| | | const { method, param, marker } = data; |
| | | // 转换接收参数键名为驼峰 |
| | |
| | | if (this._receives[method]) { |
| | | // 有通知回调 |
| | | if (marker) { |
| | | this._receives[method](param2, (param2) => { |
| | | this._receives[method](param2, param2 => { |
| | | this._sendTelling(method, param2 || {}, marker); |
| | | }); |
| | | } |
| | |
| | | // 转换发送参数键名为下划线 |
| | | param = this.transKeyName('underline', param); |
| | | // 发送 |
| | | window.aisim.linking(JSON.stringify({ |
| | | window.aisim.linking( |
| | | JSON.stringify({ |
| | | method, |
| | | param, |
| | | marker, |
| | | })); |
| | | }), |
| | | ); |
| | | } |
| | | |
| | | /** |
| | |
| | | fileName: writeData.fileName, |
| | | currentIdx: writeData.currentIdx, |
| | | totalIdx: writeData.total, |
| | | data: (writeData.data || '').substr(0, 10) |
| | | + '...(共' + (writeData.data || '').length + '个base64字符)', |
| | | data: |
| | | (writeData.data || '').substr(0, 10) + |
| | | '...(共' + |
| | | (writeData.data || '').length + |
| | | '个base64字符)', |
| | | }, |
| | | response: res, |
| | | }); |
| | |
| | | const baseArr = []; |
| | | let totalSize = 0; |
| | | let totalCount = 0; |
| | | const loadFileChunk = (index) => { |
| | | const loadFileChunk = index => { |
| | | const loadData = { |
| | | fileName, |
| | | offset: chunkSize * index, |
| | |
| | | response: { |
| | | result: res.result, |
| | | msg: res.msg, |
| | | 'total_size': res.totalSize, |
| | | data: (res.data || '').substr(0, 10) |
| | | + '...(共' + (res.data || '').length + '个base64字符)', |
| | | total_size: res.totalSize, |
| | | data: |
| | | (res.data || '').substr(0, 10) + |
| | | '...(共' + |
| | | (res.data || '').length + |
| | | '个base64字符)', |
| | | }, |
| | | }); |
| | | return; |
| | |
| | | response: { |
| | | result: res.result, |
| | | msg: res.msg, |
| | | 'total_size': res.totalSize, |
| | | data: (res.data || '').substr(0, 10) |
| | | + '...(共' + (res.data || '').length + '个base64字符)', |
| | | total_size: res.totalSize, |
| | | data: |
| | | (res.data || '').substr(0, 10) + |
| | | '...(共' + |
| | | (res.data || '').length + |
| | | '个base64字符)', |
| | | }, |
| | | base64Arr: baseData.baseArr.map(baseItem => (baseItem || []).substr(0, 10) |
| | | + '...(共' + (res.data || '').length + '个base64字符)'), |
| | | base64Arr: baseData.baseArr.map( |
| | | baseItem => |
| | | (baseItem || []).substr(0, 10) + |
| | | '...(共' + |
| | | (res.data || '').length + |
| | | '个base64字符)', |
| | | ), |
| | | message: 'Base64合并解析异常!', |
| | | }); |
| | | } |
| | |
| | | if (type === 'save') { |
| | | const list = []; |
| | | const save = index => { |
| | | this.fileSave(names[index], bridgeName => { |
| | | this.fileSave( |
| | | names[index], |
| | | bridgeName => { |
| | | list.push(bridgeName); |
| | | // 递归下一个 |
| | | if (index < names.length - 1) { |
| | |
| | | else { |
| | | callback && callback(list); |
| | | } |
| | | }, err => { |
| | | }, |
| | | err => { |
| | | callback && callback(null, err); |
| | | }); |
| | | }, |
| | | ); |
| | | }; |
| | | save(0); |
| | | } |
| | |
| | | else if (type === 'load') { |
| | | const list = []; |
| | | const load = index => { |
| | | this.fileLoad(names[index], objUrl => { |
| | | this.fileLoad( |
| | | names[index], |
| | | objUrl => { |
| | | list.push(objUrl); |
| | | // 递归下一个 |
| | | if (index < names.length - 1) { |
| | |
| | | else { |
| | | callback && callback(list); |
| | | } |
| | | }, err => { |
| | | }, |
| | | err => { |
| | | callback && callback(null, err); |
| | | }); |
| | | }, |
| | | ); |
| | | }; |
| | | load(0); |
| | | } |
| | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | // 全局服务实例 |