From e91147ca515b2684409d4232ca16fea898f2e329 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Wed, 26 Feb 2025 18:26:20 +0800 Subject: [PATCH] 知识库文档,项目介绍,文案优化 --- common/Bridge.js | 145 +++++++++++++++++++++++++++++------------------- 1 files changed, 87 insertions(+), 58 deletions(-) diff --git a/common/Bridge.js b/common/Bridge.js index 90b8891..841fa9c 100644 --- a/common/Bridge.js +++ b/common/Bridge.js @@ -38,12 +38,11 @@ import { $fileTrans } from '@components/common/FileTransform'; export class Bridge { - constructor() { this._data = { count: 100, - fileSaved: {}, // 已保存图片名称列表 { 'blob:***' : 'bridge:***' } - fileLoaded: {}, // 已读取图片名称列表 { 'bridge:***' : 'blob:***' } + fileSaved: {}, // 已保存图片名称列表 { 'blob:***' : 'bridge:***' } + fileLoaded: {}, // 已读取图片名称列表 { 'bridge:***' : 'blob:***' } }; this._receives = {}; this._earlyInvok = []; @@ -122,7 +121,7 @@ }; }, 5 * 60 * 1000); // 挂载到全局 - this[cbName] = (res) => { + this[cbName] = res => { // res有值,正常通讯 if (typeof res !== 'undefined') { let data; @@ -149,11 +148,13 @@ }; } // 发送 - window.aisim.linking(JSON.stringify({ - method, - param, - callback: cbName ? ('bridge.' + cbName) : '', - })); + window.aisim.linking( + JSON.stringify({ + method, + param, + callback: cbName ? 'bridge.' + cbName : '', + }), + ); } /** @@ -186,15 +187,16 @@ * @private */ _initReceive() { - window.telling = (res) => { + window.telling = res => { const data = typeof res === 'string' ? JSON.parse(res) : res; const { method, param, marker } = data; // 转换接收参数键名为驼峰 const param2 = this.transKeyName('camel', param); + // 已注册协议 if (this._receives[method]) { // 有通知回调 if (marker) { - this._receives[method](param2, (param2) => { + this._receives[method](param2, param2 => { this._sendTelling(method, param2 || {}, marker); }); } @@ -202,6 +204,10 @@ else { this._receives[method](param2); } + } + // 未注册的协议 + else { + console.warn('BridgeTelling:通讯协议【' + method + '】尚未注册!'); } }; } @@ -222,11 +228,13 @@ // 转换发送参数键名为下划线 param = this.transKeyName('underline', param); // 发送 - window.aisim.linking(JSON.stringify({ - method, - param, - marker, - })); + window.aisim.linking( + JSON.stringify({ + method, + param, + marker, + }), + ); } /** @@ -290,8 +298,11 @@ 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, }); @@ -336,7 +347,7 @@ const baseArr = []; let totalSize = 0; let totalCount = 0; - const loadFileChunk = (index) => { + const loadFileChunk = index => { const loadData = { fileName, offset: chunkSize * index, @@ -354,9 +365,12 @@ 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; @@ -391,12 +405,20 @@ 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合并解析异常!', }); } @@ -442,21 +464,25 @@ if (type === 'save') { const list = []; const save = index => { - this.fileSave(names[index], bridgeName => { - list.push(bridgeName); - // 递归下一个 - if (index < names.length - 1) { - setTimeout(() => { - save(index + 1); - }, 10); - } - // 完成 - else { - callback && callback(list); - } - }, err => { - callback && callback(null, err); - }); + this.fileSave( + names[index], + bridgeName => { + list.push(bridgeName); + // 递归下一个 + if (index < names.length - 1) { + setTimeout(() => { + save(index + 1); + }, 10); + } + // 完成 + else { + callback && callback(list); + } + }, + err => { + callback && callback(null, err); + }, + ); }; save(0); } @@ -464,21 +490,25 @@ else if (type === 'load') { const list = []; const load = index => { - this.fileLoad(names[index], objUrl => { - list.push(objUrl); - // 递归下一个 - if (index < names.length - 1) { - setTimeout(() => { - load(index + 1); - }, 10); - } - // 完成 - else { - callback && callback(list); - } - }, err => { - callback && callback(null, err); - }); + this.fileLoad( + names[index], + objUrl => { + list.push(objUrl); + // 递归下一个 + if (index < names.length - 1) { + setTimeout(() => { + load(index + 1); + }, 10); + } + // 完成 + else { + callback && callback(list); + } + }, + err => { + callback && callback(null, err); + }, + ); }; load(0); } @@ -491,7 +521,6 @@ }); } } - } // 全局服务实例 -- Gitblit v1.9.1