fix: change
This commit is contained in:
parent
3df20a1ad8
commit
ef6b2da614
5
README.md
Normal file
5
README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# 默认依赖模块
|
||||
|
||||
```sh
|
||||
import { start } from 'https://kevisual.xiongxiao.me/user/tab/tab-leader.js'
|
||||
```
|
@ -5,8 +5,9 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "rm -rf dist && rollup -c",
|
||||
"build:app": "npm run build && rsync dist/* ../deploy/dist",
|
||||
"watch": "rollup -c -w",
|
||||
"prepub": "cp README.md dist",
|
||||
"pub": "envision switchOrg user && envision deploy ./dist -k tab -v 0.0.1",
|
||||
"clean": "rm -rf dist"
|
||||
},
|
||||
"keywords": [],
|
||||
@ -20,6 +21,7 @@
|
||||
"devDependencies": {
|
||||
"@kevisual/router": "0.0.6-alpha-2",
|
||||
"@kevisual/store": "0.0.1-alpha.7",
|
||||
"@kevisual/system-lib": "^0.0.6",
|
||||
"eventemitter3": "^5.0.1",
|
||||
"nanoid": "^5.0.9",
|
||||
"@rollup/plugin-commonjs": "^28.0.1",
|
||||
|
@ -1,9 +0,0 @@
|
||||
# 默认依赖模块
|
||||
|
||||
```sh
|
||||
import { nanoid } from 'nanoid';
|
||||
import { QueryRouterServer } from '@kevisual/router/browser';
|
||||
import { useContextKey } from '@kevisual/store/context';
|
||||
import { useConfigKey } from '@kevisual/store/config';
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
```
|
@ -19,7 +19,8 @@ export default [
|
||||
replace({
|
||||
preventAssignment: true, // 必须设置为 true
|
||||
delimiters: ['', ''], // 确保完全匹配
|
||||
"import { nanoid } from 'nanoid'": "import { nanoid } from 'https://cdn.jsdelivr.net/npm/nanoid@4.0.0/nanoid.min.js'",
|
||||
// "import { nanoid } from 'nanoid'": "import { nanoid } from 'https://cdn.jsdelivr.net/npm/nanoid@4.0.0/nanoid.min.js'",
|
||||
'@kevisual/system-lib/dist': 'https://kevisual.xiongxiao.me/system/lib', // 将本地路径替换为远程 URL
|
||||
}),
|
||||
,
|
||||
resolve({ browser: true }),
|
||||
@ -29,7 +30,7 @@ export default [
|
||||
external: [
|
||||
'nanoid',
|
||||
//
|
||||
'@kevisual/router/browser',
|
||||
// '@kevisual/router/browser',
|
||||
],
|
||||
},
|
||||
{
|
||||
|
30
src/index.ts
30
src/index.ts
@ -1,6 +1,6 @@
|
||||
import { QueryRouterServer } from '@kevisual/router/browser';
|
||||
import { useContextKey } from '@kevisual/store/config';
|
||||
import { useConfigKey } from '@kevisual/store/config';
|
||||
import { QueryRouterServer } from '@kevisual/system-lib/dist/router-browser.js';
|
||||
import { useContextKey } from '@kevisual/system-lib/dist/web-config.js';
|
||||
import { useConfigKey } from '@kevisual/system-lib/dist/web-config.js';
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
|
||||
export const emitter = useContextKey('emitter', () => {
|
||||
@ -15,7 +15,7 @@ export const app = useContextKey('app', () => {
|
||||
|
||||
const generateRandom = () => {
|
||||
// return Math.random().toString(36).substring(8);
|
||||
return crypto.randomUUID();
|
||||
return 'a-' + crypto.randomUUID();
|
||||
};
|
||||
export const tabId = useConfigKey('tabId', () => {
|
||||
return generateRandom();
|
||||
@ -29,6 +29,8 @@ export const tabConfig = useConfigKey('tabConfig', () => {
|
||||
title: 'tab random' + random,
|
||||
description: 'tab config',
|
||||
tabId: useConfigKey('tabId', () => {}),
|
||||
type: 'single',
|
||||
tabKey: 'default',
|
||||
};
|
||||
});
|
||||
|
||||
@ -115,7 +117,11 @@ app
|
||||
description: '获取所有的打开的 tab',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
ctx.body = Array.from(openTabs);
|
||||
ctx.body = {
|
||||
openTabs: Array.from(openTabs),
|
||||
tab: tabId,
|
||||
tabConfig,
|
||||
};
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
@ -233,7 +239,7 @@ const channel = useContextKey('channel', () => {
|
||||
});
|
||||
|
||||
channel.addEventListener('message', (event) => {
|
||||
const { requestId, to, source, responseId } = event.data;
|
||||
const { requestId, to, source, tabKey, responseId } = event.data;
|
||||
if (responseId && to === tabId) {
|
||||
// 有 id 的消息, 这是这个模块请求返回回来的消息,不被其他模块处理。
|
||||
emitter.emit(responseId, event.data);
|
||||
@ -241,7 +247,7 @@ channel.addEventListener('message', (event) => {
|
||||
}
|
||||
|
||||
// console.log('channel message', event.data);
|
||||
if (to === 'all' || to === tabId) {
|
||||
if (to === 'all' || to === tabId || tabKey === tabConfig.tabKey) {
|
||||
const { path, key, payload, ...rest } = event.data;
|
||||
if (!path) {
|
||||
return;
|
||||
@ -424,8 +430,16 @@ const introduceMe = () => {
|
||||
}
|
||||
};
|
||||
|
||||
export const start = () => {
|
||||
type StartOpts = {
|
||||
config?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
};
|
||||
export const start = (opts?: StartOpts) => {
|
||||
init();
|
||||
if (opts?.config) {
|
||||
Object.assign(tabConfig, opts?.config || {});
|
||||
}
|
||||
setTimeout(() => {
|
||||
if (meIsMax === '1') {
|
||||
console.log('I am max', openTime);
|
||||
|
Loading…
x
Reference in New Issue
Block a user