fdb2 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +21 -0
- package/.editorconfig +11 -0
- package/.eslintrc.cjs +14 -0
- package/.eslintrc.json +7 -0
- package/.prettierrc.js +3 -0
- package/.tpl.env +22 -0
- package/README.md +260 -0
- package/bin/build.sh +28 -0
- package/bin/deploy.sh +8 -0
- package/bin/dev.sh +10 -0
- package/bin/docker/.env +4 -0
- package/bin/docker/dev-docker-compose.yml +43 -0
- package/bin/docker/dev.Dockerfile +24 -0
- package/bin/docker/prod-docker-compose.yml +17 -0
- package/bin/docker/prod.Dockerfile +29 -0
- package/bin/fdb2.js +142 -0
- package/data/connections.demo.json +32 -0
- package/env.d.ts +1 -0
- package/nw-build.js +120 -0
- package/nw-dev.js +65 -0
- package/package.json +114 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +9 -0
- package/public/modules/header.tpl +14 -0
- package/public/modules/initial_state.tpl +55 -0
- package/server/index.ts +677 -0
- package/server/model/connection.entity.ts +66 -0
- package/server/model/database.entity.ts +246 -0
- package/server/service/connection.service.ts +334 -0
- package/server/service/database/base.service.ts +363 -0
- package/server/service/database/database.service.ts +510 -0
- package/server/service/database/index.ts +7 -0
- package/server/service/database/mssql.service.ts +723 -0
- package/server/service/database/mysql.service.ts +761 -0
- package/server/service/database/oracle.service.ts +839 -0
- package/server/service/database/postgres.service.ts +744 -0
- package/server/service/database/sqlite.service.ts +559 -0
- package/server/service/session.service.ts +158 -0
- package/server.js +128 -0
- package/src/adapter/ajax.ts +135 -0
- package/src/assets/base.css +1 -0
- package/src/assets/database.css +950 -0
- package/src/assets/images/collapse.png +0 -0
- package/src/assets/images/no-login.png +0 -0
- package/src/assets/images/svg/illustrations/illustration-1.svg +1 -0
- package/src/assets/images/svg/illustrations/illustration-2.svg +2 -0
- package/src/assets/images/svg/illustrations/illustration-3.svg +50 -0
- package/src/assets/images/svg/illustrations/illustration-4.svg +1 -0
- package/src/assets/images/svg/illustrations/illustration-5.svg +73 -0
- package/src/assets/images/svg/illustrations/illustration-6.svg +89 -0
- package/src/assets/images/svg/illustrations/illustration-7.svg +39 -0
- package/src/assets/images/svg/illustrations/illustration-8.svg +1 -0
- package/src/assets/images/svg/separators/curve-2.svg +3 -0
- package/src/assets/images/svg/separators/curve.svg +3 -0
- package/src/assets/images/svg/separators/line.svg +3 -0
- package/src/assets/images/theme/light/screen-1-1000x800.jpg +0 -0
- package/src/assets/images/theme/light/screen-2-1000x800.jpg +0 -0
- package/src/assets/login/bg.jpg +0 -0
- package/src/assets/login/bg.png +0 -0
- package/src/assets/login/left.jpg +0 -0
- package/src/assets/logo.svg +73 -0
- package/src/assets/logo.webp +0 -0
- package/src/assets/main.css +1 -0
- package/src/base/config.ts +20 -0
- package/src/base/detect.ts +134 -0
- package/src/base/entity.ts +92 -0
- package/src/base/eventBus.ts +37 -0
- package/src/base//345/237/272/347/241/200/345/261/202.md +7 -0
- package/src/components/connection-editor/index.vue +590 -0
- package/src/components/dataGrid/index.vue +105 -0
- package/src/components/dataGrid/pagination.vue +106 -0
- package/src/components/loading/index.vue +43 -0
- package/src/components/modal/index.ts +181 -0
- package/src/components/modal/index.vue +560 -0
- package/src/components/toast/index.ts +44 -0
- package/src/components/toast/toast.vue +58 -0
- package/src/components/user/name.vue +104 -0
- package/src/components/user/selector.vue +416 -0
- package/src/domain/SysConfig.ts +74 -0
- package/src/platform/App.vue +8 -0
- package/src/platform/database/components/connection-detail.vue +1154 -0
- package/src/platform/database/components/data-editor.vue +478 -0
- package/src/platform/database/components/data-import-export.vue +1602 -0
- package/src/platform/database/components/database-detail.vue +1173 -0
- package/src/platform/database/components/database-monitor.vue +1086 -0
- package/src/platform/database/components/db-tools.vue +577 -0
- package/src/platform/database/components/query-history.vue +1349 -0
- package/src/platform/database/components/sql-executor.vue +738 -0
- package/src/platform/database/components/sql-query-editor.vue +1046 -0
- package/src/platform/database/components/table-detail.vue +1376 -0
- package/src/platform/database/components/table-editor.vue +690 -0
- package/src/platform/database/explorer.vue +1840 -0
- package/src/platform/database/index.vue +1193 -0
- package/src/platform/database/layout.vue +367 -0
- package/src/platform/database/router.ts +37 -0
- package/src/platform/database/styles/common.scss +602 -0
- package/src/platform/database/types/common.ts +445 -0
- package/src/platform/database/utils/export.ts +232 -0
- package/src/platform/database/utils/helpers.ts +437 -0
- package/src/platform/index.ts +33 -0
- package/src/platform/router.ts +41 -0
- package/src/service/base.ts +128 -0
- package/src/service/database.ts +500 -0
- package/src/service/login.ts +121 -0
- package/src/shims-vue.d.ts +7 -0
- package/src/stores/connection.ts +266 -0
- package/src/stores/session.ts +87 -0
- package/src/typings/database-types.ts +413 -0
- package/src/typings/database.ts +364 -0
- package/src/typings/global.d.ts +58 -0
- package/src/typings/pinia.d.ts +8 -0
- package/src/utils/clipboard.ts +30 -0
- package/src/utils/database-types.ts +243 -0
- package/src/utils/modal.ts +124 -0
- package/src/utils/request.ts +55 -0
- package/src/utils/sleep.ts +4 -0
- package/src/utils/toast.ts +73 -0
- package/src/utils/util.ts +171 -0
- package/src/utils/xlsx.ts +228 -0
- package/tsconfig.json +33 -0
- package/tsconfig.server.json +19 -0
- package/view/index.html +9 -0
- package/view/modules/header.tpl +14 -0
- package/view/modules/initial_state.tpl +20 -0
- package/vite.config.ts +384 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"moduleResolution": "Node",
|
|
6
|
+
"outDir": "./dist/server",
|
|
7
|
+
"rootDir": "./server",
|
|
8
|
+
"strict": false,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"declarationMap": true,
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"noEmit": false
|
|
16
|
+
},
|
|
17
|
+
"include": ["server/**/*"],
|
|
18
|
+
"exclude": ["**/__tests__/*", "**/*.spec.ts", "server/service/session.service.ts"]
|
|
19
|
+
}
|
package/view/index.html
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<head>
|
|
2
|
+
<meta charset="UTF-8" />
|
|
3
|
+
<base href="{{viteTarget}}" />
|
|
4
|
+
{% include "./initial_state.tpl" %}
|
|
5
|
+
<link rel="icon" href="{{prefix}}/public/favicon.png" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>fdb2-数据库管理</title>
|
|
8
|
+
<meta name="description" content="{{description}}">
|
|
9
|
+
<script>
|
|
10
|
+
window.addEventListener('vite:preloadError', function (event) {
|
|
11
|
+
console.error(event);
|
|
12
|
+
});
|
|
13
|
+
</script>
|
|
14
|
+
</head>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script type="text/template" id="__INITIAL_STATE__">
|
|
2
|
+
{{ data | dump | safe }}
|
|
3
|
+
</script>
|
|
4
|
+
<script type="text/template" id="__DEFAULTINITIAL_STATE__">
|
|
5
|
+
{{ __DEFAULTINITIAL_STATE__ }}
|
|
6
|
+
</script>
|
|
7
|
+
<script>
|
|
8
|
+
function __get_templateJson(id) {
|
|
9
|
+
try {
|
|
10
|
+
var tag = document.getElementById(id);
|
|
11
|
+
var obj = JSON.parse(tag.innerHTML);
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
var __INITIAL_STATE__ = __get_templateJson('__INITIAL_STATE__');
|
|
19
|
+
if(!__INITIAL_STATE__) __INITIAL_STATE__ = __get_templateJson('__DEFAULTINITIAL_STATE__');
|
|
20
|
+
</script>
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { fileURLToPath, URL } from 'node:url';
|
|
2
|
+
import * as http from "node:http";
|
|
3
|
+
import * as url from "node:url";
|
|
4
|
+
import { defineConfig, type Connect, type PluginOption } from 'vite';
|
|
5
|
+
|
|
6
|
+
import vue from '@vitejs/plugin-vue';
|
|
7
|
+
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
8
|
+
import CopyPlugin from 'vite-plugin-files-copy';
|
|
9
|
+
import ViteNunjucksPlugin from '@fefeding/vite-nunjucks-plugin';
|
|
10
|
+
import * as path from 'path';
|
|
11
|
+
import * as fs from 'fs';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const urlPrefix = process.env.PREFIX ? `/${process.env.PREFIX}` : '';
|
|
15
|
+
console.log(urlPrefix);
|
|
16
|
+
|
|
17
|
+
const defaultInitState = {
|
|
18
|
+
"config": {"prefix": urlPrefix, "apiUrl": process.env.API_URL||""},
|
|
19
|
+
"sso": {"baseUrl":process.env.SSO_URL||'',"appId":process.env.APP_ID||2},
|
|
20
|
+
"title": process.env.TITLE
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const nunjucksPlugin = ViteNunjucksPlugin({
|
|
24
|
+
variables: {
|
|
25
|
+
prefix: '', // 构建时,去掉这种prefix前缀,vite会处理依赖关系
|
|
26
|
+
viteTarget: '',// 构建之后的不加base
|
|
27
|
+
__DEFAULTINITIAL_STATE__: JSON.stringify(defaultInitState),
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const viewDir = path.resolve(__dirname, './view');
|
|
32
|
+
// https://vitejs.dev/config/
|
|
33
|
+
const config = defineConfig({
|
|
34
|
+
publicDir: false,
|
|
35
|
+
|
|
36
|
+
plugins: [
|
|
37
|
+
vue() as PluginOption,
|
|
38
|
+
vueJsx() as PluginOption,
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
CopyPlugin({
|
|
41
|
+
patterns: []
|
|
42
|
+
}),
|
|
43
|
+
nunjucksPlugin,
|
|
44
|
+
{
|
|
45
|
+
name: 'copy-server-files',
|
|
46
|
+
writeBundle: async () => {
|
|
47
|
+
const serverSrcDir = path.resolve(__dirname, './server');
|
|
48
|
+
const serverDistDir = path.resolve(__dirname, './dist/server');
|
|
49
|
+
|
|
50
|
+
if (!fs.existsSync(serverDistDir)) {
|
|
51
|
+
fs.mkdirSync(serverDistDir, { recursive: true });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const copyRecursiveSync = (src: string, dest: string) => {
|
|
55
|
+
const exists = fs.existsSync(src);
|
|
56
|
+
const stats = exists && fs.statSync(src);
|
|
57
|
+
const isDirectory = exists && stats.isDirectory();
|
|
58
|
+
|
|
59
|
+
if (isDirectory) {
|
|
60
|
+
if (!fs.existsSync(dest)) {
|
|
61
|
+
fs.mkdirSync(dest);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fs.readdirSync(src).forEach(childItemName => {
|
|
65
|
+
copyRecursiveSync(
|
|
66
|
+
path.join(src, childItemName),
|
|
67
|
+
path.join(dest, childItemName)
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
if (src.endsWith('.ts') || src.endsWith('.js')) {
|
|
72
|
+
fs.copyFileSync(src, dest);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
copyRecursiveSync(serverSrcDir, serverDistDir);
|
|
78
|
+
console.log('Server files copied to', serverDistDir);
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'fix-html-paths',
|
|
83
|
+
writeBundle: async () => {
|
|
84
|
+
const publicDir = path.resolve(__dirname, './dist/public');
|
|
85
|
+
const htmlFiles = ['index.html', 'view/index.html'];
|
|
86
|
+
|
|
87
|
+
htmlFiles.forEach(htmlFile => {
|
|
88
|
+
const htmlPath = path.join(publicDir, htmlFile);
|
|
89
|
+
|
|
90
|
+
if (fs.existsSync(htmlPath)) {
|
|
91
|
+
let html = fs.readFileSync(htmlPath, 'utf-8');
|
|
92
|
+
|
|
93
|
+
html = html.replace(/\.\.\/([a-zA-Z0-9_-]+\.(js|css|woff|woff2|png|jpg|jpeg|gif|svg|ico))/g, '/public/$1');
|
|
94
|
+
html = html.replace(/(src|href)="([a-zA-Z0-9_-]+\.(js|css))"/g, (match, attr, filename) => {
|
|
95
|
+
if (!filename.startsWith('/') && !filename.startsWith('.')) {
|
|
96
|
+
return `${attr}="/public/${filename}"`;
|
|
97
|
+
}
|
|
98
|
+
return match;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
fs.writeFileSync(htmlPath, html);
|
|
102
|
+
console.log(`Fixed paths in: ${htmlFile}`);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// 将 view/index.html 移动到 dist/view/ 目录
|
|
107
|
+
const viewHtmlPath = path.join(publicDir, 'view/index.html');
|
|
108
|
+
const destViewDir = path.resolve(__dirname, './dist/view');
|
|
109
|
+
const destViewHtmlPath = path.join(destViewDir, 'index.html');
|
|
110
|
+
|
|
111
|
+
if (fs.existsSync(viewHtmlPath)) {
|
|
112
|
+
if (!fs.existsSync(destViewDir)) {
|
|
113
|
+
fs.mkdirSync(destViewDir, { recursive: true });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let html = fs.readFileSync(viewHtmlPath, 'utf-8');
|
|
117
|
+
fs.writeFileSync(destViewHtmlPath, html);
|
|
118
|
+
fs.unlinkSync(viewHtmlPath);
|
|
119
|
+
|
|
120
|
+
// 删除空的 view 目录
|
|
121
|
+
const viewDir = path.join(publicDir, 'view');
|
|
122
|
+
if (fs.existsSync(viewDir)) {
|
|
123
|
+
const files = fs.readdirSync(viewDir);
|
|
124
|
+
if (files.length === 0) {
|
|
125
|
+
fs.rmdirSync(viewDir);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
console.log(`Moved view/index.html to dist/view/index.html`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
// {
|
|
134
|
+
// // 动态加载静态入口文件,用于路径拼接
|
|
135
|
+
// name: "inject-assets",
|
|
136
|
+
// transformIndexHtml(html, ctx: any) {
|
|
137
|
+
// if (ctx.chunk?.fileName && html.includes('__vitejs_load_entry(')) {
|
|
138
|
+
// // 移除所有 <script type="module"> 标签(包括 Vite 注入的入口脚本)
|
|
139
|
+
// html = html.replace(
|
|
140
|
+
// /<script\s*type="module"\s*[^\>]*\s*src="([^"]+)"\s*>\s*<\/script>/g, (match, src) => {
|
|
141
|
+
// if(!src || /^(http(s)?:)?\/\//i.test(src)) return match;
|
|
142
|
+
// console.log('replace script', src, urlPrefix);
|
|
143
|
+
|
|
144
|
+
// if(src.startsWith(urlPrefix)) src = src.replace(urlPrefix, '');
|
|
145
|
+
// return "<script>" +
|
|
146
|
+
// ` window.__vitejs_load_entry && window.__vitejs_load_entry('${src}', 'script');` +
|
|
147
|
+
// "</script>";
|
|
148
|
+
// }
|
|
149
|
+
// );
|
|
150
|
+
// // 移除所有 <link rel="modulepreload"> 标签(预加载脚本)
|
|
151
|
+
// html = html.replace(/<link\s*rel="modulepreload"\s*[^\>]*\s*href="([^"]+)"\s*\/?>/g, (match, href) => {
|
|
152
|
+
// if(!href || /^(http(s)?:)?\/\//i.test(href)) return match;
|
|
153
|
+
// console.log('replace modulepreload', href, urlPrefix);
|
|
154
|
+
|
|
155
|
+
// if(href.startsWith(urlPrefix)) href = href.replace(urlPrefix, '');
|
|
156
|
+
// return "<script>" +
|
|
157
|
+
// ` window.__vitejs_load_entry && window.__vitejs_load_entry('${href}', 'modulepreload');` +
|
|
158
|
+
// "</script>";
|
|
159
|
+
// }
|
|
160
|
+
// );
|
|
161
|
+
// // 移除所有 <link rel="stylesheet"> 标签(如果不需要 Vite 处理的 CSS)
|
|
162
|
+
// html = html.replace(/<link\s*rel="stylesheet"\s*[^\>]*\s*href="([^"]+)"\s*\/?>/g, (match, href) => {
|
|
163
|
+
// if(!href || /^(http(s)?:)?\/\//i.test(href)) return match;
|
|
164
|
+
// console.log('replace stylesheet', href, urlPrefix);
|
|
165
|
+
|
|
166
|
+
// if(href.startsWith(urlPrefix)) href = href.replace(urlPrefix, '');
|
|
167
|
+
// return "<script>" +
|
|
168
|
+
// ` window.__vitejs_load_entry && window.__vitejs_load_entry('${href}', 'stylesheet');` +
|
|
169
|
+
// "</script>";
|
|
170
|
+
// }
|
|
171
|
+
// );
|
|
172
|
+
// html = html.replace(/<link\s*rel="icon"\s*[^\>]*\s*href="([^"]+)"\s*\/?>/g, (match, href) => {
|
|
173
|
+
// if(!href || /^(http(s)?:)?\/\//i.test(href)) return match;
|
|
174
|
+
// console.log('replace icon', href, urlPrefix);
|
|
175
|
+
|
|
176
|
+
// if(href.startsWith(urlPrefix)) href = href.replace(urlPrefix, '');
|
|
177
|
+
// return "<script>" +
|
|
178
|
+
// ` window.__vitejs_load_entry && window.__vitejs_load_entry('${href}', 'icon');` +
|
|
179
|
+
// "</script>";
|
|
180
|
+
// }
|
|
181
|
+
// );
|
|
182
|
+
// }
|
|
183
|
+
// return html;
|
|
184
|
+
// },
|
|
185
|
+
// },
|
|
186
|
+
{
|
|
187
|
+
name: 'vite-plugin-spa-fallback-with-nunjucks',
|
|
188
|
+
configureServer(server) {
|
|
189
|
+
return () => {
|
|
190
|
+
server.middlewares.use(async (req: http.IncomingMessage, res: http.ServerResponse, next: Connect.NextFunction) => {
|
|
191
|
+
const requestUrl = req.url || '';
|
|
192
|
+
console.log('SPA Fallback Middleware:', requestUrl);
|
|
193
|
+
// 1. 忽略 API 路由
|
|
194
|
+
if (requestUrl.startsWith('/api/')) {
|
|
195
|
+
return next();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// 2. 忽略静态资源请求 (必须让 Vite 自己处理,否则 CSS/JS 404)
|
|
199
|
+
// 简单的扩展名检测,或者让 Vite 处理 404 也可以,但显式检测更高效
|
|
200
|
+
if (requestUrl !== '/index.html' && /\.[a-zA-Z0-9]{1,4}$/.test(requestUrl) || requestUrl.includes('@vite/client')) {
|
|
201
|
+
return next();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// 3. 回退逻辑:渲染 view/index.html
|
|
205
|
+
// 关键:使用 server.transformRequest 确保经过 Nunjucks 和 Vite 处理
|
|
206
|
+
try {
|
|
207
|
+
const indexPath = path.resolve(viewDir, requestUrl.replace('/', ''));
|
|
208
|
+
console.log('Resolved indexPath:', indexPath);
|
|
209
|
+
if (!fs.existsSync(indexPath)) {
|
|
210
|
+
return next(); // 文件不存在,交给 Vite 报 404
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
let html = fs.readFileSync(indexPath, 'utf-8');
|
|
214
|
+
html = await nunjucksPlugin.transformIndexHtml(html, { path: indexPath });
|
|
215
|
+
res.statusCode = 200;
|
|
216
|
+
res.setHeader('Content-Type', 'text/html');
|
|
217
|
+
res.end(html);
|
|
218
|
+
} catch (e: any) {
|
|
219
|
+
console.error("SPA Fallback Transform Error:", e.message);
|
|
220
|
+
// 如果转换失败(比如语法错误),交给 Vite 处理
|
|
221
|
+
return next(e);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: 'server-api',
|
|
229
|
+
configureServer(server) {
|
|
230
|
+
server.middlewares.use((req: Connect.IncomingMessage, res: http.ServerResponse, next: Connect.NextFunction) => {
|
|
231
|
+
if (req.url?.startsWith('/api/')) {
|
|
232
|
+
// 示例:直接执行机器操作(如读取文件)
|
|
233
|
+
if (!serverRoute(req, res, next)) {
|
|
234
|
+
res.statusCode = 404;
|
|
235
|
+
res.end('Not Found');
|
|
236
|
+
}
|
|
237
|
+
} else {
|
|
238
|
+
next();
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
resolve: {
|
|
245
|
+
alias: {
|
|
246
|
+
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
247
|
+
'#': fileURLToPath(new URL('../', import.meta.url)),
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
build: {
|
|
251
|
+
outDir: 'dist/public',
|
|
252
|
+
assetsInlineLimit: 4096,
|
|
253
|
+
manifest: true,
|
|
254
|
+
minify: false,
|
|
255
|
+
modulePreload: true,
|
|
256
|
+
rollupOptions: {
|
|
257
|
+
external: [
|
|
258
|
+
'../../server/index',
|
|
259
|
+
'./server/index'
|
|
260
|
+
],
|
|
261
|
+
input: getViewInputs(viewDir),
|
|
262
|
+
output: {
|
|
263
|
+
entryFileNames: '[name].js',
|
|
264
|
+
chunkFileNames: '[name].js',
|
|
265
|
+
assetFileNames: '[name].[ext]',
|
|
266
|
+
manualChunks(id, mod) {
|
|
267
|
+
const ms = [...id.matchAll(/\/node_modules\/([^\/]+)\//ig)];
|
|
268
|
+
if(ms && ms.length) {
|
|
269
|
+
const m = ms[ms.length -1];
|
|
270
|
+
if(m && m[1]) {
|
|
271
|
+
if(m[1].includes('@vue') || m[1].includes('vue-') || m[1] == 'vue') return 'vue';
|
|
272
|
+
if(m[1].includes('element-plus')) return 'element-plus';
|
|
273
|
+
if(m[1].includes('lodash')) return 'lodash';
|
|
274
|
+
if(m[1].includes('bootstrap')) return 'bootstrap';
|
|
275
|
+
if(m[1].includes('echarts')) return 'echarts';
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
base: urlPrefix,
|
|
283
|
+
server: {
|
|
284
|
+
host: '0.0.0.0',
|
|
285
|
+
port: +`${process.env.VITE_PORT}` || 9300,
|
|
286
|
+
cors: true,
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
export default config;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* 获取指定目录下的所有.html文件,并返回一个对象,该对象将每个文件名(不带.html扩展名)映射到其完整路径。
|
|
293
|
+
* @param dir 指定的目录
|
|
294
|
+
* @returns 返回文件名到路径的映射对象
|
|
295
|
+
*/
|
|
296
|
+
function getViewInputs(dir: string): { [key: string]: string } {
|
|
297
|
+
const entries = fs.readdirSync(dir);
|
|
298
|
+
const htmlFiles = entries.filter(filename => filename.endsWith('.html'));
|
|
299
|
+
const inputObj: { [key: string]: string } = {};
|
|
300
|
+
|
|
301
|
+
for (const file of htmlFiles) {
|
|
302
|
+
const name = path.basename(file, '.html'); // 获取文件名,不包括扩展名
|
|
303
|
+
inputObj[name] = path.resolve(dir, file);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// input: {
|
|
307
|
+
// index: resolve(__dirname, "./view/index.html"),
|
|
308
|
+
// mobile: resolve(__dirname, "./view/mobile.html"),
|
|
309
|
+
// }
|
|
310
|
+
return inputObj;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
// 路由处理函数
|
|
316
|
+
async function serverRoute(req: Connect.IncomingMessage, res: http.ServerResponse, next: Connect.NextFunction) {
|
|
317
|
+
try {
|
|
318
|
+
console.log('request', req.url);
|
|
319
|
+
if (!req.url?.startsWith('/api/')) {
|
|
320
|
+
return next();
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const parsedUrl = url.parse(req.url, true);
|
|
324
|
+
const pathname = parsedUrl.pathname || '';
|
|
325
|
+
const method = req.method?.toLowerCase();
|
|
326
|
+
|
|
327
|
+
// 统一处理为POST请求
|
|
328
|
+
if (method !== 'post') {
|
|
329
|
+
return sendError(res, 'Only POST method is allowed', 405);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const body = await getRequestBody(req);
|
|
333
|
+
|
|
334
|
+
// 路由分发
|
|
335
|
+
if (pathname.startsWith('/api/database/')) {
|
|
336
|
+
try {
|
|
337
|
+
// 动态导入 server 模块,避免在 Vite 配置加载时就导入 sqlite3
|
|
338
|
+
const serverModule = await import('./server/index');
|
|
339
|
+
const data = await serverModule.handleDatabaseRoutes(pathname, body);
|
|
340
|
+
sendJSON(res, data);
|
|
341
|
+
}
|
|
342
|
+
catch(error) {
|
|
343
|
+
console.error(error);
|
|
344
|
+
// @ts-ignore
|
|
345
|
+
sendError(res, error?.message || '系统异常', 200);
|
|
346
|
+
}
|
|
347
|
+
} else {
|
|
348
|
+
sendError(res, 'API not found', 404);
|
|
349
|
+
}
|
|
350
|
+
} catch (error: any) {
|
|
351
|
+
console.error('Route error:', error);
|
|
352
|
+
sendError(res, error.message || 'Internal server error', 500);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// 响应助手函数
|
|
356
|
+
function sendJSON(res: http.ServerResponse, data: any, statusCode = 200) {
|
|
357
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
358
|
+
res.end(JSON.stringify({ ret: 0, msg: 'success', data }));
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function sendError(res: http.ServerResponse, message: string, statusCode = 500) {
|
|
362
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
363
|
+
res.end(JSON.stringify({ ret: statusCode, msg: message }));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// 获取POST请求体
|
|
367
|
+
async function getRequestBody(req: http.IncomingMessage): Promise<any> {
|
|
368
|
+
return new Promise((resolve, reject) => {
|
|
369
|
+
let body = '';
|
|
370
|
+
req.on('data', chunk => {
|
|
371
|
+
body += chunk.toString();
|
|
372
|
+
});
|
|
373
|
+
req.on('end', () => {
|
|
374
|
+
try {
|
|
375
|
+
resolve(body ? JSON.parse(body) : {});
|
|
376
|
+
} catch (e) {
|
|
377
|
+
reject(e);
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
req.on('error', reject);
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|