This commit is contained in:
2025-04-04 02:41:02 +08:00
parent cb0510c28e
commit c2877c3d3b
29 changed files with 5544 additions and 1520 deletions

View File

@@ -1,12 +1,8 @@
import type { Page } from '@kevisual/store/page';
import type { QueryRouterServer } from '@kevisual/router';
import { basename } from './modules/basename';
export const page = useContextKey('page', () => {
return new window.Page({
basename,
}) as unknown as Page;
});
export const app = useContextKey('app', () => {
console.error('app not found');
return null as unknown as QueryRouterServer;
});
import { App } from '@kevisual/router';
import { useContextKey } from '@kevisual/use-config/context';
const init = () => {
return new App();
};
export const app = useContextKey('app', init);

View File

@@ -1,16 +0,0 @@
@import "tailwindcss";
@layer components {
.test-loading {
@apply w-20 h-20 bg-gray-300 rounded-full animate-spin;
}
}
#ai-bot-root {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: -100px;
z-index: 9999;
}

16
src/demo-route.ts Normal file
View File

@@ -0,0 +1,16 @@
import { app } from './app.ts';
import { useConfig } from '@kevisual/use-config';
app
.route({
path: 'demo',
key: 'demo',
})
.define(async (ctx) => {
ctx.body = '123';
})
.addTo(app);
const config = useConfig();
console.log('run demo: http://localhost:' + config.port + '/api/router?path=demo&key=demo');

8
src/dev.ts Normal file
View File

@@ -0,0 +1,8 @@
import { useConfig } from '@kevisual/use-config';
import { app } from './index.ts';
const config = useConfig();
app.listen(config.port, () => {
console.log(`server is running at http://localhost:${config.port}`);
});

4
src/index.ts Normal file
View File

@@ -0,0 +1,4 @@
import { app } from './app.ts';
import './demo-route.ts';
export { app };

View File

@@ -1,48 +1,10 @@
import { page, app } from './app.ts';
import { basename } from './modules/basename.ts';
export const render = ({ renderRoot }) => {
renderRoot.innerHTML = `
<h1>Hello, World!</h1>
`;
};
console.log('basename', basename, page, app);
// 单应用实例启动
if (page) {
page.addPage('/app-template', 'home');
page.subscribe('home', () => {
render({
renderRoot: document.getElementById('ai-root'),
});
});
page.addPage('', 'index');
page.subscribe('index', () => {
const root = document.getElementById('ai-root') as HTMLElement;
root.innerHTML = `
<h1>Hello, World!</h1>
`;
});
}
import { useConfig } from '@kevisual/use-config';
import { app } from './index.ts';
if (app) {
app
.route({
path: 'app-template',
key: 'render',
})
.define(async (ctx) => {
let { renderRoot } = ctx.query;
if (!renderRoot) {
ctx.throw(404, 'renderRoot is required');
}
if (typeof renderRoot === 'string') {
renderRoot = document.querySelector(renderRoot);
}
if (!renderRoot) {
ctx.throw(404, 'renderRoot not found');
}
render({
renderRoot,
});
})
.addTo(app);
}
const config = useConfig();
app.listen(config.port, () => {
console.log(`server is running at http://localhost:${config.port}`);
});

View File

@@ -1,2 +0,0 @@
// @ts-ignore
export const basename = DEV_SERVER ? '/' : BASE_NAME;

9
src/modules/mark.ts Normal file
View File

@@ -0,0 +1,9 @@
import { Mark, markModelInit } from '@kevisual/mark';
export { Mark, markModelInit };
export const init = () => {
markModelInit({
tableName: '',
});
};

View File

@@ -1,3 +0,0 @@
import { message } from '@kevisual/system-ui/dist/message';
export { message };

View File

@@ -1,3 +0,0 @@
import { QueryClient } from '@kevisual/query';
export const query = new QueryClient();

1
src/modules/sequelize.ts Normal file
View File

@@ -0,0 +1 @@
export { sequelize, redis } from '@kevisual/code-center-module';

9
src/modules/user.ts Normal file
View File

@@ -0,0 +1,9 @@
import { sequelize, User, UserInit, Org, OrgInit } from '@kevisual/code-center-module';
export { sequelize, User, UserInit, Org, OrgInit };
export const init = () => {
UserInit();
OrgInit();
};
init();

View File

@@ -0,0 +1,78 @@
import { sequelize } from '@kevisual/code-center-module';
import { DataTypes, Model } from 'sequelize';
export type Provider = Partial<InstanceType<typeof ProviderModel>>;
type ModelItem = {
/**
* 模型
*/
model: string;
/**
* 提供者
*/
provider: string;
/**
* 配置, 自有配置
*/
config: Record<string, any>;
/**
* 标题
*/
title: string;
/**
* 描述
*/
description: string;
};
export type ProviderData = {
models: ModelItem[];
config: Record<string, any>; // 共享配置
};
export class ProviderModel extends Model {
declare id: string;
declare title: string;
declare description: string;
declare config: Record<string, any>;
declare data: Record<string, any>;
declare uid: string;
declare createdAt: Date;
declare updatedAt: Date;
}
ProviderModel.init(
{
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
comment: 'id',
},
title: {
type: DataTypes.TEXT,
defaultValue: '',
},
description: {
type: DataTypes.TEXT,
defaultValue: '',
},
config: {
type: DataTypes.JSON,
defaultValue: {},
},
data: {
type: DataTypes.JSON,
defaultValue: {},
},
uid: {
type: DataTypes.UUID,
allowNull: true,
},
},
{
sequelize,
tableName: 'kv_provider',
paranoid: true,
},
);