From 363145d7531cc97f842d5b7a4e520ac870737065 Mon Sep 17 00:00:00 2001
From: Tevin <tingquanren@163.com>
Date: Fri, 31 Mar 2023 15:21:56 +0800
Subject: [PATCH] 调整跨端通讯接收中心,提取部分公共代码到基类

---
 bases/BridgeCenterBase.js |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/bases/BridgeCenterBase.js b/bases/BridgeCenterBase.js
index 118676f..07b6b91 100644
--- a/bases/BridgeCenterBase.js
+++ b/bases/BridgeCenterBase.js
@@ -26,15 +26,28 @@
         });
     }
 
+    /**
+     * 获取当前页面
+     * @return {Taro.Page}
+     */
     $getCurrentPage() {
         const pages = Taro.getCurrentPages();
         return pages[pages.length - 1];
     }
 
+    /**
+     * 获取当前页面路径
+     * @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];
@@ -43,6 +56,16 @@
         } else {
             return null;
         }
+    }
+
+    /**
+     * 判断当前页面是否在列表中
+     * @param {Array} allows=[]
+     * @return {boolean}
+     */
+    $isCurPageInside(allows = []) {
+        const url = this.$getCurrentPagePath();
+        return allows.indexOf(url) >= 0;
     }
 
     _checkPage(url, callback) {
@@ -56,6 +79,11 @@
         }
     }
 
+    /**
+     * 打开指定页面
+     * @param {String} url
+     * @param {Function} callback
+     */
     $openPage(url, callback) {
         const curPage = this.$isCurrentPage(url);
         // 需打开的是当前页面
@@ -71,6 +99,23 @@
         }
     }
 
+    /**
+     * 当前页下发通讯
+     * @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;

--
Gitblit v1.9.1