From bc8f7123657eb2dde8a328928140c94ea0cc3d29 Mon Sep 17 00:00:00 2001
From: Tevin <tingquanren@163.com>
Date: Thu, 16 May 2024 11:52:06 +0800
Subject: [PATCH] Merge branch 'master' of ssh://dev.zhiheiot.com:29418/mob-components

---
 bases/BridgeCenterBase.js |   68 ++++++++++++++++++++++++++++-----
 1 files changed, 57 insertions(+), 11 deletions(-)

diff --git a/bases/BridgeCenterBase.js b/bases/BridgeCenterBase.js
index 5ab17cd..746a4e8 100644
--- a/bases/BridgeCenterBase.js
+++ b/bases/BridgeCenterBase.js
@@ -16,7 +16,7 @@
         tellings.forEach(method => {
             const name = Fetcher.prototype.stringToCamel(method);
             if (typeof this[name] === 'undefined') {
-                console.warn('BridgeTelling:未发现“' + method + '”对于接收器!');
+                console.warn('BridgeTelling:未发现“' + method + '”对应接收器!');
             } else {
                 // 注册App通知接收器
                 $bridge.register(method, (res, callback) => {
@@ -26,15 +26,28 @@
         });
     }
 
+    /**
+     * 获取当前页面
+     * @return {Taro.Page}
+     */
     $getCurrentPage() {
         const pages = Taro.getCurrentPages();
         return pages[pages.length - 1];
     }
 
-    $getCurrentPageUrl() {
-        return this.$getCurrentPage().path;
+    /**
+     * 获取当前页面路径
+     * @return {String}
+     */
+    $getCurrentPagePath() {
+        return this.$getCurrentPage().path.split('?')[0];
     }
 
+    /**
+     * 判断地址是否为当前页面
+     * @param {String} url
+     * @return {Taro.Page|null}
+     */
     $isCurrentPage(url) {
         const pages = Taro.getCurrentPages();
         const curPage = pages[pages.length - 1];
@@ -45,33 +58,66 @@
         }
     }
 
-    _checkPage(url, callback) {
+    /**
+     * 判断当前页面是否在列表中
+     * @param {Array} allows=[]
+     * @return {boolean}
+     */
+    $isCurPageInside(allows = []) {
+        const url = this.$getCurrentPagePath();
+        return allows.indexOf(url) >= 0;
+    }
+
+    _waitCurPage(url, callback) {
         let curPage = this.$isCurrentPage(url);
         if (curPage) {
             callback(curPage);
         } else {
             setTimeout(() => {
-                this._checkPage(url, callback);
+                this._waitCurPage(url, callback);
             }, 100);
         }
     }
 
+    /**
+     * 打开指定页面
+     * @param {String} url
+     * @param {Function} callback
+     */
     $openPage(url, callback) {
         const curPage = this.$isCurrentPage(url);
         // 需打开的是当前页面
         if (curPage) {
             callback(curPage);
         } else {
-            Taro.navigateTo({
-                url,
-                success: () => {
-                    this._checkPage(url, callback);
-                },
-            });
+            Taro.navigateTo({ url });
+            setTimeout(() => {
+                this._waitCurPage(url, callback);
+            }, 100);
         }
     }
 
+    /**
+     * 当前页下发通讯
+     * @param {String} method
+     * @param {Object} res
+     * @param {Function} [callback]
+     */
+    $curPageBridge(method, res, callback) {
+        this.$pageBridge(this.$getCurrentPage(), method, res, callback);
+    }
+
+    /**
+     * 对某个页面下发通知
+     * @param {Taro.Page} page
+     * @param {String} method
+     * @param {Object} res
+     * @param {Function} [callback]
+     */
     $pageBridge(page, method, res, callback) {
+        if (!page.$component || !page.$component.$onBridge) {
+            return;
+        }
         try {
             res = typeof res === 'string' ? JSON.parse(res) : res;
         } catch (e) {

--
Gitblit v1.9.1