WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2025-01-22 f0fdb9c479ae8b3bc7029e9ae40fcf76a3baa0cc
跨端通讯,协议注册警告优化
2 files modified
13 ■■■■ changed files
bases/BridgeCenterBase.js 8 ●●●●● patch | view | raw | blame | history
common/Bridge.js 5 ●●●●● patch | view | raw | blame | history
bases/BridgeCenterBase.js
@@ -15,10 +15,12 @@
    _init(tellings) {
        tellings.forEach(method => {
            const name = Fetcher.prototype.stringToCamel(method);
            // BridgeCenter 已注册,但没有定义接收器的协议,提示
            if (typeof this[name] === 'undefined') {
                console.warn('BridgeTelling:未发现“' + method + '”对应接收器!');
            } else {
                // 注册App通知接收器
                console.warn('BridgeTelling:协议【' + method + '】未发现对应接收器!');
            }
            // BridgeCenter 已注册已定义接收器的协议,注册接收器
            else {
                $bridge.register(method, (res, callback) => {
                    this[name](method, res, callback);
                });
common/Bridge.js
@@ -192,6 +192,7 @@
            const { method, param, marker } = data;
            // 转换接收参数键名为驼峰
            const param2 = this.transKeyName('camel', param);
            // 已注册协议
            if (this._receives[method]) {
                // 有通知回调
                if (marker) {
@@ -204,6 +205,10 @@
                    this._receives[method](param2);
                }
            }
            // 未注册的协议
            else {
                console.warn('BridgeTelling:通讯协议【' + method + '】尚未注册!');
            }
        };
    }