| | |
| | | _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); |
| | | }); |
| | |
| | | return allows.indexOf(url) >= 0; |
| | | } |
| | | |
| | | _checkPage(url, callback) { |
| | | _waitCurPage(url, callback) { |
| | | let curPage = this.$isCurrentPage(url); |
| | | if (curPage) { |
| | | callback(curPage); |
| | | } else { |
| | | setTimeout(() => { |
| | | this._checkPage(url, callback); |
| | | this._waitCurPage(url, callback); |
| | | }, 100); |
| | | } |
| | | } |
| | |
| | | if (curPage) { |
| | | callback(curPage); |
| | | } else { |
| | | Taro.navigateTo({ |
| | | url, |
| | | success: () => { |
| | | this._checkPage(url, callback); |
| | | }, |
| | | }); |
| | | Taro.navigateTo({ url }); |
| | | setTimeout(() => { |
| | | this._waitCurPage(url, callback); |
| | | }, 100); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | try { |
| | | res = typeof res === 'string' ? JSON.parse(res) : res; |
| | | } catch (e) { |
| | | } |
| | | } catch (e) {} |
| | | page.$component.$onBridge(method, res, callback); |
| | | } |
| | | |
| | | } |
| | | |