|
@@ -1,33 +1,33 @@
|
|
|
-const eventBus = {
|
|
|
- // 存储所有事件和对应的订阅者
|
|
|
- eventList: new Map(),
|
|
|
- // 订阅事件
|
|
|
- on(event, callback) {
|
|
|
- if (!this.eventList.has(event)) {
|
|
|
- this.eventList.set(event, new Set())
|
|
|
- }
|
|
|
- this.eventList.get(event).add(callback)
|
|
|
- },
|
|
|
- // 取消订阅事件
|
|
|
- off(event, callback) {
|
|
|
- if (this.eventList.has(event)) {
|
|
|
- const callbacks = this.eventList.get(event)
|
|
|
- callbacks.delete(callback)
|
|
|
- if (callbacks.size === 0) {
|
|
|
- this.eventList.delete(event)
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- // 发布事件
|
|
|
- emit(event, ...args) {
|
|
|
- if (this.eventList.has(event)) {
|
|
|
- const callbacks = this.eventList.get(event)
|
|
|
- callbacks.forEach((callback) => {
|
|
|
- callback.call(null, ...args)
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+const eventBus = {
|
|
|
+ // 存储所有事件和对应的订阅者
|
|
|
+ eventList: new Map(),
|
|
|
+ // 订阅事件
|
|
|
+ on(event, callback) {
|
|
|
+ if (!this.eventList.has(event)) {
|
|
|
+ this.eventList.set(event, new Set())
|
|
|
+ }
|
|
|
+ this.eventList.get(event).add(callback)
|
|
|
+ },
|
|
|
+ // 取消订阅事件
|
|
|
+ off(event, callback) {
|
|
|
+ if (this.eventList.has(event)) {
|
|
|
+ const callbacks = this.eventList.get(event)
|
|
|
+ callbacks.delete(callback)
|
|
|
+ if (callbacks.size === 0) {
|
|
|
+ this.eventList.delete(event)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 发布事件
|
|
|
+ emit(event, ...args) {
|
|
|
+ if (this.eventList.has(event)) {
|
|
|
+ const callbacks = this.eventList.get(event)
|
|
|
+ callbacks.forEach((callback) => {
|
|
|
+ callback.call(null, ...args)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
function selectIndex(index) {
|
|
|
var pages = getCurrentPages();
|
|
@@ -41,14 +41,17 @@ function selectIndex(index) {
|
|
|
}
|
|
|
|
|
|
function eventOn(curPage) {
|
|
|
+
|
|
|
getApp().eventBus.on('rightChange', data => {
|
|
|
// var pages = getCurrentPages();
|
|
|
// var curPage = pages[pages.length - 1]
|
|
|
+
|
|
|
if (data !== curPage.data.rightId) {
|
|
|
+ console.log("页面:");
|
|
|
+
|
|
|
curPage.setData({
|
|
|
rightId: data
|
|
|
})
|
|
|
- console.log("页面:"+curPage.data.rightId);
|
|
|
if (curPage.data.rightId === 2) {
|
|
|
let num = curPage.data.rightId === 1 ? 2 : 1
|
|
|
if (typeof curPage.getTabBar === 'function' &&
|