更新 @kevisual/api 版本至 0.0.13,提升 @kevisual/router 和 @kevisual/js-filter 版本,重构 RouterViewApi、RouterViewContext 和 RouterViewWorker 类型,合并公共属性以提高代码可读性
This commit is contained in:
@@ -4,33 +4,30 @@ import { filter } from '@kevisual/js-filter'
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
|
||||
export type RouterViewItem = RouterViewApi | RouterViewContext | RouterViewWorker;
|
||||
export type RouterViewApi = {
|
||||
type RouteViewBase = {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
enabled?: boolean;
|
||||
}
|
||||
export type RouterViewApi = {
|
||||
type: 'api',
|
||||
api: {
|
||||
url: string,
|
||||
// 已初始化的query实例
|
||||
query?: Query
|
||||
}
|
||||
}
|
||||
} & RouteViewBase;
|
||||
|
||||
export type RouterViewContext = {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
type: 'context',
|
||||
context: {
|
||||
key: string,
|
||||
// 从context中获取router
|
||||
router?: QueryRouterServer
|
||||
}
|
||||
}
|
||||
} & RouteViewBase;
|
||||
export type RouterViewWorker = {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
type: 'worker',
|
||||
worker: {
|
||||
type: 'Worker' | 'SharedWorker' | 'serviceWorker',
|
||||
@@ -45,7 +42,8 @@ export type RouterViewWorker = {
|
||||
type: 'module' | 'classic'
|
||||
}
|
||||
}
|
||||
}
|
||||
} & RouteViewBase;
|
||||
|
||||
export type RouterViewQuery = {
|
||||
id: string,
|
||||
query: string,
|
||||
@@ -82,7 +80,7 @@ export class QueryProxy {
|
||||
}
|
||||
}
|
||||
async initRouterViewQuery() {
|
||||
this.routerViewItems = this.routerViewItems?.map(item => {
|
||||
this.routerViewItems = this.routerViewItems.map(item => {
|
||||
if (item.type === 'api' && item.api?.url) {
|
||||
const url = item.api.url;
|
||||
if (item?.api?.query) return item;
|
||||
@@ -127,6 +125,9 @@ export class QueryProxy {
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}).filter(item => {
|
||||
const enabled = item.enabled ?? true;
|
||||
return enabled;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user