From fc8133ed1d1d6a389fb0fe637a3d48a6558e2879 Mon Sep 17 00:00:00 2001
From: liukangdong <898885815@qq.com>
Date: 星期一, 29 七月 2024 13:46:28 +0800
Subject: [PATCH] Merge branch 'master' of http://139.186.142.91:10010/r/productDev/zbomyoujia
---
wechat_jiaxuan/utils/login-sdk.js | 67 +++++++++++++++++++++++++++++++++
1 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/wechat_jiaxuan/utils/login-sdk.js b/wechat_jiaxuan/utils/login-sdk.js
new file mode 100644
index 0000000..8293c47
--- /dev/null
+++ b/wechat_jiaxuan/utils/login-sdk.js
@@ -0,0 +1,67 @@
+let isLogin = false;
+
+// 鍙戝竷璁㈤槄妯″紡
+class Publisher {
+ constructor() {
+ this.map = new Map();
+ }
+ on(key, callback) {
+ let arr = this.map.get(key) || [];
+ arr.push(callback);
+ this.map.set(key, arr);
+ }
+ emit(key, data = {}) {
+ if (this.map.has(key)) {
+ this.map.get(key).forEach((item) => {
+ item.call(this, data);
+ });
+ }
+ }
+}
+
+let publisher = new Publisher();
+
+// 椤甸潰鎵╁睍
+const oldPage = Page;
+Page = function (pageParams) {
+ const { onLoad, onShow, onReady } = pageParams;
+
+ pageParams.onLoad = function (params) {
+ // 鍒ゆ柇鏄惁鐧婚檰
+ if (isLogin) {
+ onLoad && onLoad.call(this, params);
+ } else {
+ publisher.on("login", () => {
+ isLogin = true;
+ onLoad && onLoad.call(this, params);
+ });
+ }
+ };
+
+ pageParams.onShow = function () {
+ // 鍒ゆ柇鏄惁鐧婚檰
+ if (isLogin) {
+ onShow && onShow.call(this);
+ } else {
+ publisher.on("login", () => {
+ onShow && onShow.call(this);
+ });
+ }
+ };
+
+ pageParams.onReady = function () {
+ // 鍒ゆ柇鏄惁鐧婚檰
+ if (isLogin) {
+ onReady && onReady.call(this);
+ } else {
+ publisher.on("login", () => {
+ onReady && onReady.call(this);
+ });
+ }
+ };
+ return oldPage(pageParams);
+};
+
+module.exports = {
+ publisher,
+};
--
Gitblit v1.9.3