This commit is contained in:
2025-10-28 11:09:54 +08:00
parent 0f04bbe1f9
commit 57ef842adf
14 changed files with 143 additions and 60 deletions

4
src/apps/ai/app.ts Normal file
View File

@@ -0,0 +1,4 @@
import { QueryRouterServer } from '@kevisual/router/browser'
import { useContextKey } from '@kevisual/context'
const app = useContextKey('app', new QueryRouterServer())
export { app }

6
src/apps/ai/index.ts Normal file
View File

@@ -0,0 +1,6 @@
import { app } from './app'
import './routes/login'
export { app }

View File

@@ -0,0 +1,14 @@
import { app } from '../../app'
app.route({
path: 'login',
description: '登录应用,参数 username 是用户名password 是密码',
}).define(async (ctx) => {
const { username, password } = ctx.query;
ctx.body = {
message: `User ${username} logged in successfully.`,
}
}
).addTo(app)

View File

@@ -0,0 +1,42 @@
import { app } from '../ai';
import { useEffect, useState } from 'react';
const getAppRoutes = () => {
const appRoutes = app.routes.map((route) => {
return {
path: route.path,
key: route.key,
description: route.description,
metadata: route.metadata,
}
});
return appRoutes;
}
const fetchTest = async () => {
const url = 'http://localhost:51015/api/router';
const response = await fetch(url);
const data = await response.json();
console.log('Fetch Test Data:', data);
}
const dynamicImport = async () => {
const module = await import('http://localhost:4321/test-import.js');
console.log('Dynamically Imported Module:', module);
console.log('Test Function Output:', module.test());
}
export const App = () => {
const [appRoutes, setAppRoutes] = useState(getAppRoutes());
useEffect(() => {
setAppRoutes(getAppRoutes());
}, []);
return <div>Web Command App
<pre onClick={async () => {
await dynamicImport()
setAppRoutes(getAppRoutes());
}
}>{JSON.stringify(appRoutes, null, 2)}</pre>
</div >;
}