-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
170 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
[[toc]] | ||
|
||
## 引入 | ||
|
||
```ts | ||
import { initGlobalVue3EBus, initDiffVue3EBus } from 't-comm'; | ||
|
||
// or | ||
|
||
import { initGlobalVue3EBus, initDiffVue3EBus} from 't-comm/lib/e-bus/index'; | ||
``` | ||
|
||
|
||
## `initGlobalVue3EBus` | ||
|
||
|
||
**描述**:<p>挂载统一的eBus,所有实例共用一个</p> | ||
|
||
**参数**: | ||
|
||
|
||
| 参数名 | 描述 | | ||
| --- | --- | | ||
| app | <p>Vue3 应用实例</p> | | ||
|
||
|
||
|
||
<a name="initDiffVue3EBus"></a> | ||
|
||
## `initDiffVue3EBus` | ||
|
||
|
||
**描述**:<p>挂载唯一的eBus,不同实例用不同的</p> | ||
|
||
**参数**: | ||
|
||
|
||
| 参数名 | 描述 | | ||
| --- | --- | | ||
| app | <p>Vue3 应用实例</p> | | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export class EventBus { | ||
private events: Record<string, Array<Function>>; | ||
|
||
constructor() { | ||
this.events = {}; | ||
} | ||
|
||
emit(eventName: string, data: any) { | ||
if (this.events[eventName]) { | ||
this.events[eventName].forEach((fn) => { | ||
fn(data); | ||
}); | ||
} | ||
} | ||
on(eventName: string, fn: any) { | ||
this.events[eventName] = this.events[eventName] || []; | ||
this.events[eventName].push(fn); | ||
} | ||
|
||
off(eventName: string, fn: any) { | ||
if (!fn) { | ||
delete this.events[eventName]; | ||
return; | ||
} | ||
if (this.events[eventName]) { | ||
for (let i = 0; i < this.events[eventName].length; i++) { | ||
if (this.events[eventName][i] === fn) { | ||
this.events[eventName].splice(i, 1); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { EventBus } from './e-bus'; | ||
export { initDiffVue3EBus, initGlobalVue3EBus } from './init'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { EventBus } from './e-bus'; | ||
|
||
|
||
const globalEBus = new EventBus(); | ||
|
||
|
||
/** | ||
* 挂载统一的eBus,所有实例共用一个 | ||
* @param app Vue3 应用实例 | ||
*/ | ||
export const initGlobalVue3EBus = function (app: any) { | ||
if (!app?.config?.globalProperties) { | ||
return app; | ||
} | ||
|
||
app.config.globalProperties.$ebus = globalEBus; | ||
return app; | ||
}; | ||
|
||
|
||
/** | ||
* 挂载唯一的eBus,不同实例用不同的 | ||
* @param app Vue3 应用实例 | ||
*/ | ||
export const initDiffVue3EBus = function (app: any) { | ||
if (!app?.config?.globalProperties) { | ||
return app; | ||
} | ||
|
||
const eBus = new EventBus(); | ||
app.config.globalProperties.$ebus = eBus; | ||
return app; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { morsePwdMixin, getMorsePwdMixin } from './morse-password-mixin'; | ||
export { getMsdkFullScreen } from './msdk-full-screen'; | ||
export { getVisibilityChangeMixin } from './visibllity-change-mixin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { callJsSetFullScreen, callJsReSetFullScreen } from '../msdk/msdk'; | ||
|
||
|
||
/** | ||
* msdk 浏览器全屏方法,点击外链时可全屏,返回时退出全屏 | ||
* @example | ||
* ```ts | ||
* mixins: [getMsdkFullScreen()], | ||
* ``` | ||
*/ | ||
export function getMsdkFullScreen() { | ||
return { | ||
onShow() { | ||
callJsSetFullScreen(); | ||
}, | ||
methods: { | ||
callJsReSetFullScreen() { | ||
callJsReSetFullScreen(); | ||
}, | ||
}, | ||
}; | ||
} |