This commit is contained in:
2026-02-15 20:08:22 +08:00
parent b972ed3a36
commit 9400ccf229
2 changed files with 15 additions and 9 deletions

View File

@@ -62,7 +62,7 @@ export type RouterViewWorker = {
} & RouteViewBase;
/**
* 去掉不需要保存服务器的数据
* 去掉不需要保存服务器的数据
* @param item
* @returns
*/
@@ -100,6 +100,9 @@ export type RouterViewQuery = {
query: string,
title: string
}
/**
* 后端存储结构
*/
export type RouterViewData = {
data: { items: RouterViewItem[]; }
views: RouterViewQuery[];
@@ -121,7 +124,7 @@ export class QueryProxy {
this.initRouterViewQuery();
this.emitter = new EventEmitter();
}
getDefulatToken() {
private getDefulatToken() {
try {
if (typeof window !== 'undefined' && typeof window.localStorage !== 'undefined') {
return localStorage.getItem('token') || undefined;
@@ -139,7 +142,7 @@ export class QueryProxy {
});
}
initRouterView(item: RouterViewItem) {
private initRouterView(item: RouterViewItem) {
if (item.type === 'api' && item.api?.url) {
const url = item.api.url;
if (item?.api?.query) return item;
@@ -253,6 +256,7 @@ export class QueryProxy {
console.debug(`注册路由: [${r.path}] ${r?.key}`, 'Context');
let metadata = r.metadata || {};
metadata.viewItem = item;
metadata.source = 'query-proxy-context';
this.router.route({
path: r.path,
key: r.key || '',
@@ -268,7 +272,7 @@ export class QueryProxy {
generateId() {
return 'route_' + Math.random().toString(36).substring(2, 9);
}
async callWorker(msg: any, viewItem: RouterViewWorker['worker']): Promise<Result> {
private async callWorker(msg: any, viewItem: RouterViewWorker['worker']): Promise<Result> {
const that = this;
const requestId = this.generateId();
const worker = viewItem?.worker;
@@ -296,7 +300,7 @@ export class QueryProxy {
});
});
}
async initWorker(item?: RouterViewWorker, initRoutes: boolean = true) {
private async initWorker(item?: RouterViewWorker, initRoutes: boolean = true) {
const that = this;
if (!item?.worker?.url) {
console.warn('Worker URL not provided');
@@ -347,6 +351,7 @@ export class QueryProxy {
console.debug(`注册路由: [${r.path}] ${r?.key}`, 'API');
let metadata = r.metadata || {};
metadata.viewItem = item;
metadata.source = 'query-proxy-worker';
this.router.route({
path: r.path,
key: r.key || '',
@@ -364,7 +369,7 @@ export class QueryProxy {
}
}
}
async initPage(item?: RouteViewPage) {
private async initPage(item?: RouteViewPage) {
if (!item?.page?.url) {
console.warn('Page地址未提供');
return;
@@ -381,7 +386,7 @@ export class QueryProxy {
return;
}
}
getQueryByViewId(viewId: string): string | undefined {
private getQueryByViewId(viewId: string): string | undefined {
const view = this.views.find(v => v.id === viewId);
if (view) {
return view.query;
@@ -465,7 +470,7 @@ export class QueryProxy {
item.response = res;
return item;
}
item.response = { code: 500, message: '无法处理的路由类型' };
item.response = { code: 500, message: '无法处理的路由类型', data: item };
return item;
}
}
@@ -477,4 +482,4 @@ export type RouterItem = {
description?: string;
middleware?: string[];
metadata?: Record<string, any>;
}
}

View File

@@ -38,6 +38,7 @@ export const initApi = async (opts: {
let metadata = r.metadata || {};
metadata.viewItem = item;
metadata.url = query.url;
metadata.source = 'query-proxy-api';
router.route({
path: r.path,
key: r.key || '',