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.
Files changed (125) hide show
  1. package/.dockerignore +21 -0
  2. package/.editorconfig +11 -0
  3. package/.eslintrc.cjs +14 -0
  4. package/.eslintrc.json +7 -0
  5. package/.prettierrc.js +3 -0
  6. package/.tpl.env +22 -0
  7. package/README.md +260 -0
  8. package/bin/build.sh +28 -0
  9. package/bin/deploy.sh +8 -0
  10. package/bin/dev.sh +10 -0
  11. package/bin/docker/.env +4 -0
  12. package/bin/docker/dev-docker-compose.yml +43 -0
  13. package/bin/docker/dev.Dockerfile +24 -0
  14. package/bin/docker/prod-docker-compose.yml +17 -0
  15. package/bin/docker/prod.Dockerfile +29 -0
  16. package/bin/fdb2.js +142 -0
  17. package/data/connections.demo.json +32 -0
  18. package/env.d.ts +1 -0
  19. package/nw-build.js +120 -0
  20. package/nw-dev.js +65 -0
  21. package/package.json +114 -0
  22. package/public/favicon.ico +0 -0
  23. package/public/index.html +9 -0
  24. package/public/modules/header.tpl +14 -0
  25. package/public/modules/initial_state.tpl +55 -0
  26. package/server/index.ts +677 -0
  27. package/server/model/connection.entity.ts +66 -0
  28. package/server/model/database.entity.ts +246 -0
  29. package/server/service/connection.service.ts +334 -0
  30. package/server/service/database/base.service.ts +363 -0
  31. package/server/service/database/database.service.ts +510 -0
  32. package/server/service/database/index.ts +7 -0
  33. package/server/service/database/mssql.service.ts +723 -0
  34. package/server/service/database/mysql.service.ts +761 -0
  35. package/server/service/database/oracle.service.ts +839 -0
  36. package/server/service/database/postgres.service.ts +744 -0
  37. package/server/service/database/sqlite.service.ts +559 -0
  38. package/server/service/session.service.ts +158 -0
  39. package/server.js +128 -0
  40. package/src/adapter/ajax.ts +135 -0
  41. package/src/assets/base.css +1 -0
  42. package/src/assets/database.css +950 -0
  43. package/src/assets/images/collapse.png +0 -0
  44. package/src/assets/images/no-login.png +0 -0
  45. package/src/assets/images/svg/illustrations/illustration-1.svg +1 -0
  46. package/src/assets/images/svg/illustrations/illustration-2.svg +2 -0
  47. package/src/assets/images/svg/illustrations/illustration-3.svg +50 -0
  48. package/src/assets/images/svg/illustrations/illustration-4.svg +1 -0
  49. package/src/assets/images/svg/illustrations/illustration-5.svg +73 -0
  50. package/src/assets/images/svg/illustrations/illustration-6.svg +89 -0
  51. package/src/assets/images/svg/illustrations/illustration-7.svg +39 -0
  52. package/src/assets/images/svg/illustrations/illustration-8.svg +1 -0
  53. package/src/assets/images/svg/separators/curve-2.svg +3 -0
  54. package/src/assets/images/svg/separators/curve.svg +3 -0
  55. package/src/assets/images/svg/separators/line.svg +3 -0
  56. package/src/assets/images/theme/light/screen-1-1000x800.jpg +0 -0
  57. package/src/assets/images/theme/light/screen-2-1000x800.jpg +0 -0
  58. package/src/assets/login/bg.jpg +0 -0
  59. package/src/assets/login/bg.png +0 -0
  60. package/src/assets/login/left.jpg +0 -0
  61. package/src/assets/logo.svg +73 -0
  62. package/src/assets/logo.webp +0 -0
  63. package/src/assets/main.css +1 -0
  64. package/src/base/config.ts +20 -0
  65. package/src/base/detect.ts +134 -0
  66. package/src/base/entity.ts +92 -0
  67. package/src/base/eventBus.ts +37 -0
  68. package/src/base//345/237/272/347/241/200/345/261/202.md +7 -0
  69. package/src/components/connection-editor/index.vue +590 -0
  70. package/src/components/dataGrid/index.vue +105 -0
  71. package/src/components/dataGrid/pagination.vue +106 -0
  72. package/src/components/loading/index.vue +43 -0
  73. package/src/components/modal/index.ts +181 -0
  74. package/src/components/modal/index.vue +560 -0
  75. package/src/components/toast/index.ts +44 -0
  76. package/src/components/toast/toast.vue +58 -0
  77. package/src/components/user/name.vue +104 -0
  78. package/src/components/user/selector.vue +416 -0
  79. package/src/domain/SysConfig.ts +74 -0
  80. package/src/platform/App.vue +8 -0
  81. package/src/platform/database/components/connection-detail.vue +1154 -0
  82. package/src/platform/database/components/data-editor.vue +478 -0
  83. package/src/platform/database/components/data-import-export.vue +1602 -0
  84. package/src/platform/database/components/database-detail.vue +1173 -0
  85. package/src/platform/database/components/database-monitor.vue +1086 -0
  86. package/src/platform/database/components/db-tools.vue +577 -0
  87. package/src/platform/database/components/query-history.vue +1349 -0
  88. package/src/platform/database/components/sql-executor.vue +738 -0
  89. package/src/platform/database/components/sql-query-editor.vue +1046 -0
  90. package/src/platform/database/components/table-detail.vue +1376 -0
  91. package/src/platform/database/components/table-editor.vue +690 -0
  92. package/src/platform/database/explorer.vue +1840 -0
  93. package/src/platform/database/index.vue +1193 -0
  94. package/src/platform/database/layout.vue +367 -0
  95. package/src/platform/database/router.ts +37 -0
  96. package/src/platform/database/styles/common.scss +602 -0
  97. package/src/platform/database/types/common.ts +445 -0
  98. package/src/platform/database/utils/export.ts +232 -0
  99. package/src/platform/database/utils/helpers.ts +437 -0
  100. package/src/platform/index.ts +33 -0
  101. package/src/platform/router.ts +41 -0
  102. package/src/service/base.ts +128 -0
  103. package/src/service/database.ts +500 -0
  104. package/src/service/login.ts +121 -0
  105. package/src/shims-vue.d.ts +7 -0
  106. package/src/stores/connection.ts +266 -0
  107. package/src/stores/session.ts +87 -0
  108. package/src/typings/database-types.ts +413 -0
  109. package/src/typings/database.ts +364 -0
  110. package/src/typings/global.d.ts +58 -0
  111. package/src/typings/pinia.d.ts +8 -0
  112. package/src/utils/clipboard.ts +30 -0
  113. package/src/utils/database-types.ts +243 -0
  114. package/src/utils/modal.ts +124 -0
  115. package/src/utils/request.ts +55 -0
  116. package/src/utils/sleep.ts +4 -0
  117. package/src/utils/toast.ts +73 -0
  118. package/src/utils/util.ts +171 -0
  119. package/src/utils/xlsx.ts +228 -0
  120. package/tsconfig.json +33 -0
  121. package/tsconfig.server.json +19 -0
  122. package/view/index.html +9 -0
  123. package/view/modules/header.tpl +14 -0
  124. package/view/modules/initial_state.tpl +20 -0
  125. package/vite.config.ts +384 -0
@@ -0,0 +1,266 @@
1
+ import { defineStore } from 'pinia';
2
+ import { DatabaseService, ConnectionService } from '@/service/database';
3
+ import type { ConnectionEntity, DatabaseEntity, TableEntity } from '@/typings/database';
4
+ import { modal } from '@/utils/modal';
5
+ import { toast } from '@/utils/toast';
6
+
7
+ // 定义连接状态类型
8
+ export type ConnectionState = {
9
+ // 当前连接
10
+ currentConnection: ConnectionEntity | null;
11
+ // 数据库列表
12
+ databases: DatabaseEntity[];
13
+ // 表列表
14
+ tables: TableEntity[];
15
+ // 加载状态
16
+ loading: {
17
+ databases: boolean;
18
+ tables: boolean;
19
+ executing: boolean;
20
+ };
21
+ // 错误信息
22
+ error: string | null;
23
+ };
24
+
25
+ const connectionStoreKey = 'connection-state';
26
+
27
+ // 初始状态
28
+ function getDefaultState(): ConnectionState {
29
+ return getInitialState();
30
+ }
31
+
32
+ // 获取初始状态
33
+ function getInitialState(): ConnectionState {
34
+ return {
35
+ currentConnection: null,
36
+ databases: [],
37
+ tables: [],
38
+ loading: {
39
+ databases: false,
40
+ tables: false,
41
+ executing: false
42
+ },
43
+ error: null
44
+ };
45
+ }
46
+
47
+ const databaseService = new DatabaseService();
48
+ const connectionService = new ConnectionService();
49
+
50
+ export const useConnectionStore = defineStore('connection', {
51
+ state: (): ConnectionState => getDefaultState(),
52
+
53
+ getters: {
54
+ // 是否有当前连接
55
+ hasConnection: (state) => !!state.currentConnection,
56
+
57
+ // 获取当前连接ID
58
+ currentConnectionId: (state) => state.currentConnection?.id || '',
59
+
60
+ // 获取数据库数量
61
+ databaseCount: (state) => state.databases.length,
62
+
63
+ // 获取表数量
64
+ tableCount: (state) => state.tables.length,
65
+
66
+ // 是否正在加载数据库
67
+ isLoadingDatabases: (state) => state.loading.databases,
68
+
69
+ // 是否正在加载表
70
+ isLoadingTables: (state) => state.loading.tables,
71
+
72
+ // 是否正在执行操作
73
+ isExecuting: (state) => state.loading.executing,
74
+ },
75
+
76
+ actions: {
77
+ // 设置当前连接
78
+ setCurrentConnection(connection: ConnectionEntity | null) {
79
+ // 避免重复设置相同的连接
80
+ if (this.currentConnection?.id === connection?.id) return;
81
+
82
+ this.currentConnection = connection;
83
+ // 重置相关数据
84
+ if (connection) {
85
+ this.loadDatabases();
86
+ } else {
87
+ this.databases = [];
88
+ this.tables = [];
89
+ }
90
+ },
91
+
92
+ // 加载数据库列表
93
+ async loadDatabases() {
94
+ if (!this.currentConnection) return;
95
+
96
+ // 防止重复调用
97
+ if (this.loading.databases) return;
98
+
99
+ try {
100
+ this.loading.databases = true;
101
+ this.error = null;
102
+
103
+ const connectionId = this.currentConnection.id;
104
+ if (!connectionId) {
105
+ this.error = '连接ID不存在';
106
+ modal.error(this.error);
107
+ return;
108
+ }
109
+ const result = await databaseService.getDatabases(connectionId);
110
+
111
+ // 处理不同格式的返回数据
112
+ if (result && typeof result === 'object' && 'ret' in result && result.ret === 0) {
113
+ // 处理服务器返回的数据 - 转换字符串数组为对象数组
114
+ const dbList = result.data || [];
115
+ this.databases = dbList.map((db: string) => ({
116
+ name: db,
117
+ size: 0,
118
+ tableCount: 0,
119
+ tables: []
120
+ }));
121
+ } else if (Array.isArray(result)) {
122
+ // 如果直接返回数组
123
+ this.databases = result.map((db: string) => ({
124
+ name: db,
125
+ size: 0,
126
+ tableCount: 0,
127
+ tables: []
128
+ }));
129
+ } else {
130
+ this.error = (result && typeof result === 'object' && 'msg' in result && typeof result.msg === 'string') ? result.msg : '获取数据库列表失败';
131
+ modal.error(this.error);
132
+ }
133
+ } catch (error: any) {
134
+ this.error = error.message || '获取数据库列表失败';
135
+ console.error('获取数据库列表失败:', error);
136
+ modal.error(this.error);
137
+ } finally {
138
+ this.loading.databases = false;
139
+ }
140
+ },
141
+
142
+ // 加载数据库详细信息
143
+ async loadDatabaseInfo(databaseName: string) {
144
+ if (!this.currentConnection) return;
145
+
146
+ try {
147
+ this.loading.executing = true;
148
+ this.error = null;
149
+
150
+ const result = await databaseService.getDatabaseInfo(this.currentConnection.id, databaseName);
151
+
152
+ if (result.ret === 0) {
153
+ const databaseInfo = result.data;
154
+ // 更新数据库信息
155
+ const index = this.databases.findIndex(db => db.name === databaseName);
156
+ if (index !== -1) {
157
+ this.databases[index] = databaseInfo;
158
+ }
159
+ // 更新表列表
160
+ this.tables = databaseInfo.tables || [];
161
+ } else {
162
+ this.error = result.msg || '获取数据库详细信息失败';
163
+ modal.error(this.error);
164
+ }
165
+ } catch (error: any) {
166
+ this.error = error.message || '获取数据库详细信息失败';
167
+ console.error('获取数据库详细信息失败:', error);
168
+ modal.error(this.error);
169
+ } finally {
170
+ this.loading.executing = false;
171
+ }
172
+ },
173
+
174
+ // 加载表列表
175
+ async loadTables(databaseName: string) {
176
+ if (!this.currentConnection) return;
177
+
178
+ try {
179
+ this.loading.tables = true;
180
+ this.error = null;
181
+
182
+ const result = await databaseService.getTables(this.currentConnection.id, databaseName);
183
+
184
+ if (result.ret === 0) {
185
+ this.tables = result.data || [];
186
+ // 更新数据库的表数量
187
+ const index = this.databases.findIndex(db => db.name === databaseName);
188
+ if (index !== -1) {
189
+ this.databases[index].tableCount = this.tables.length;
190
+ }
191
+ } else {
192
+ this.error = result.msg || '获取表列表失败';
193
+ modal.error(this.error);
194
+ }
195
+ } catch (error: any) {
196
+ this.error = error.message || '获取表列表失败';
197
+ console.error('获取表列表失败:', error);
198
+ modal.error(this.error);
199
+ } finally {
200
+ this.loading.tables = false;
201
+ }
202
+ },
203
+
204
+ // 创建数据库
205
+ async createDatabase(databaseName: string, options?: any) {
206
+ if (!this.currentConnection) return;
207
+
208
+ try {
209
+ this.loading.executing = true;
210
+ this.error = null;
211
+
212
+ // 过滤掉空的选项
213
+ const filteredOptions = Object.fromEntries(
214
+ Object.entries(options || {}).filter(([_, value]) => value !== '')
215
+ );
216
+
217
+ await connectionService.createDatabase(this.currentConnection.id, databaseName, filteredOptions);
218
+
219
+ // 重新加载数据库列表
220
+ this.loadDatabases();
221
+ } catch (error: any) {
222
+ this.error = error.message || '创建数据库失败';
223
+ console.error('创建数据库失败:', error);
224
+ throw error;
225
+ } finally {
226
+ this.loading.executing = false;
227
+ }
228
+ },
229
+
230
+ // 测试连接
231
+ async testConnection(connection: ConnectionEntity) {
232
+ try {
233
+ this.loading.executing = true;
234
+ this.error = null;
235
+
236
+ const result = await connectionService.testConnection(connection);
237
+
238
+ if (result.ret === 0) {
239
+ toast.success('连接测试成功');
240
+ return true;
241
+ } else {
242
+ this.error = result.msg || '连接测试失败';
243
+ toast.error(this.error || '连接测试失败');
244
+ return false;
245
+ }
246
+ } catch (error: any) {
247
+ this.error = error.message || '连接测试失败';
248
+ console.error('连接测试失败:', error);
249
+ toast.error(this.error || '连接测试失败');
250
+ return false;
251
+ } finally {
252
+ this.loading.executing = false;
253
+ }
254
+ },
255
+
256
+ // 清除错误信息
257
+ clearError() {
258
+ this.error = null;
259
+ },
260
+
261
+ // 重置状态
262
+ resetState() {
263
+ Object.assign(this.$state, getInitialState());
264
+ }
265
+ }
266
+ });
@@ -0,0 +1,87 @@
1
+ import { defineStore } from 'pinia';
2
+ import type { User } from '@fefeding/common/dist/models/account/user';
3
+ //import type Account from '@fefeding/common/dist/models/account/account';
4
+ import type { Session, } from '@fefeding/common/dist/models/account/session';
5
+ import { sysConfig } from '@/domain/SysConfig';
6
+
7
+
8
+ // 定义会话状态类型
9
+ export type SessionState = Session & {
10
+ lastDate: number
11
+ iat: number,
12
+ }
13
+
14
+ const storage = window.sessionStorage;
15
+
16
+ const sessionStoreKey = 'login-session';
17
+ // 初始状态
18
+ // 从 localStorage 读取默认值
19
+ function getDefaultState() {
20
+ try {
21
+ const locStr = storage.getItem(sessionStoreKey);
22
+ return locStr ? JSON.parse(locStr) : (sysConfig.session || {});
23
+ } catch (e) {
24
+ console.error('Failed to read localStorage:', e);
25
+ return sysConfig.session || {};
26
+ }
27
+ }
28
+
29
+ export const useSessionStore = defineStore('session', {
30
+ state: (): SessionState => getDefaultState(),
31
+
32
+ getters: {
33
+ // 是否登录
34
+ isLoggedIn: (state) => {
35
+ console.log('Recomputing isLoggedIn', state, state.id, state.userId); // 调试
36
+ return !!state.id && !!state.userId;
37
+ },
38
+
39
+ // 获取用户名
40
+ userName: (state) => state.user?.name || '',
41
+
42
+ // 获取登录ID
43
+ userLoginId: (state) => state.loginId,
44
+
45
+ // 获取用户头像
46
+ userAvatar: (state) => state.user?.avatar || '',
47
+ // 登陆token
48
+ token: (state) => state.id || '',
49
+ },
50
+
51
+ actions: {
52
+ // 设置登录状态
53
+ setSession(session: Partial<SessionState>) {
54
+ this.$patch((state) => {
55
+ Object.assign(state, session); // 通过 $patch 触发响应式
56
+ });
57
+ },
58
+
59
+ // 清除登录状态(退出登录)
60
+ clearSession() {
61
+ this.user = null as any;
62
+ this.account = null as any;
63
+ this.id = '';
64
+ this.userId = 0;
65
+ this.loginId = '';
66
+ storage.removeItem?.(sessionStoreKey);
67
+ },
68
+
69
+ // 更新用户信息
70
+ updateUserInfo(user: Partial<User>) {
71
+ if(this.user) {
72
+ this.$patch((state) => {
73
+ // @ts-ignore
74
+ state.user = Object.assign(state.user||{}, user); // 通过 $patch 触发响应式
75
+ });
76
+ }
77
+ },
78
+ },
79
+
80
+ // 持久化存储配置(需要安装pinia-plugin-persistedstate)
81
+ persist: {
82
+ key: sessionStoreKey,
83
+ storage: storage, // 可选sessionStorage
84
+ //paths: ['lastDate', 'id', 'loginId', 'user', 'account', 'userId', 'iat']
85
+ },
86
+ });
87
+