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,478 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="modal fade" :class="{ show: visible }" :style="{ display: visible ? 'block' : 'none' }">
|
|
3
|
+
<div class="modal-dialog modal-lg">
|
|
4
|
+
<div class="modal-content">
|
|
5
|
+
<div class="modal-header" style="padding: 15px;">
|
|
6
|
+
<h5 class="modal-title">
|
|
7
|
+
<i class="bi bi-pencil-square" v-if="isEdit"></i>
|
|
8
|
+
<i class="bi bi-plus-circle" v-else></i>
|
|
9
|
+
{{ isEdit ? '编辑数据' : '新增数据' }}
|
|
10
|
+
</h5>
|
|
11
|
+
<button type="button" class="btn-close" @click="closeModal"></button>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<div class="modal-body">
|
|
15
|
+
<form @submit.prevent="handleSubmit">
|
|
16
|
+
<div class="row g-3">
|
|
17
|
+
<div
|
|
18
|
+
v-for="column in columns"
|
|
19
|
+
:key="column.name"
|
|
20
|
+
:data-type="column.type"
|
|
21
|
+
class="col-md-6"
|
|
22
|
+
>
|
|
23
|
+
<label class="form-label">
|
|
24
|
+
{{ column.name }}
|
|
25
|
+
<span v-if="column.isPrimary" class="text-danger">*</span>
|
|
26
|
+
<small class="text-muted ms-2">{{ column.type }}</small>
|
|
27
|
+
</label>
|
|
28
|
+
|
|
29
|
+
<!-- 主键且自增时禁用编辑或隐藏 -->
|
|
30
|
+
<input
|
|
31
|
+
v-if="column.isPrimary && column.isAutoIncrement"
|
|
32
|
+
type="text"
|
|
33
|
+
data-type="primary"
|
|
34
|
+
class="form-control"
|
|
35
|
+
:value="isEdit ? formData[column.name] : '自动生成'"
|
|
36
|
+
disabled
|
|
37
|
+
readonly
|
|
38
|
+
>
|
|
39
|
+
<!-- 数字输入框 -->
|
|
40
|
+
<input
|
|
41
|
+
v-else-if="isNumberInput(column.type)"
|
|
42
|
+
type="number"
|
|
43
|
+
data-type="number"
|
|
44
|
+
class="form-control"
|
|
45
|
+
v-model="formData[column.name]"
|
|
46
|
+
:placeholder="'请输入' + column.name"
|
|
47
|
+
:required="!column.nullable"
|
|
48
|
+
:step="isDecimalInput(column.type) ? '0.01' : '1'"
|
|
49
|
+
>
|
|
50
|
+
<!-- 日期时间选择器 -->
|
|
51
|
+
<input
|
|
52
|
+
v-else-if="isDateInput(column.type)"
|
|
53
|
+
type="datetime-local"
|
|
54
|
+
class="form-control"
|
|
55
|
+
data-type="date"
|
|
56
|
+
v-model="formData[column.name]"
|
|
57
|
+
:required="!column.nullable"
|
|
58
|
+
>
|
|
59
|
+
<!-- 文本域 -->
|
|
60
|
+
<textarea
|
|
61
|
+
v-else-if="isTextArea(column.type)"
|
|
62
|
+
class="form-control"
|
|
63
|
+
data-type="textarea"
|
|
64
|
+
v-model="formData[column.name]"
|
|
65
|
+
:placeholder="'请输入' + column.name"
|
|
66
|
+
:required="!column.nullable"
|
|
67
|
+
rows="3"
|
|
68
|
+
></textarea>
|
|
69
|
+
<!-- 下拉选择(枚举) -->
|
|
70
|
+
<select
|
|
71
|
+
v-else-if="isEnumInput(column.type)"
|
|
72
|
+
class="form-select"
|
|
73
|
+
data-type="select"
|
|
74
|
+
v-model="formData[column.name]"
|
|
75
|
+
:required="!column.nullable"
|
|
76
|
+
>
|
|
77
|
+
<option value="">请选择...</option>
|
|
78
|
+
<option v-for="option in getEnumOptions(column.type)" :key="option" :value="option">
|
|
79
|
+
{{ option }}
|
|
80
|
+
</option>
|
|
81
|
+
</select>
|
|
82
|
+
<!-- 布尔值 -->
|
|
83
|
+
<select
|
|
84
|
+
v-else-if="isBooleanInput(column.type)"
|
|
85
|
+
class="form-select"
|
|
86
|
+
data-type="boolean"
|
|
87
|
+
v-model="formData[column.name]"
|
|
88
|
+
>
|
|
89
|
+
<option :value="true">是/True</option>
|
|
90
|
+
<option :value="false">否/False</option>
|
|
91
|
+
</select>
|
|
92
|
+
<!-- JSON类型 -->
|
|
93
|
+
<div v-else-if="isJsonInput(column.type, 'input') || isArrayInput(column.type)" class="json-editor">
|
|
94
|
+
<textarea
|
|
95
|
+
class="form-control font-monospace"
|
|
96
|
+
data-type="json"
|
|
97
|
+
v-model="jsonText[column.name]"
|
|
98
|
+
:placeholder="'请输入' + column.name + '的JSON数据'"
|
|
99
|
+
:required="!column.nullable"
|
|
100
|
+
rows="6"
|
|
101
|
+
@input="validateJson(column.name)"
|
|
102
|
+
></textarea>
|
|
103
|
+
<div class="d-flex justify-content-between mt-1">
|
|
104
|
+
<small class="text-muted">{{ jsonError[column.name] || 'JSON格式正确' }}</small>
|
|
105
|
+
<button
|
|
106
|
+
type="button"
|
|
107
|
+
class="btn btn-sm btn-outline-primary"
|
|
108
|
+
@click="formatJson(column.name)"
|
|
109
|
+
>
|
|
110
|
+
格式化
|
|
111
|
+
</button>
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
<!-- 默认输入框 -->
|
|
115
|
+
<input
|
|
116
|
+
v-else
|
|
117
|
+
type="text"
|
|
118
|
+
data-type="normal"
|
|
119
|
+
class="form-control"
|
|
120
|
+
v-model="formData[column.name]"
|
|
121
|
+
:placeholder="'请输入' + column.name"
|
|
122
|
+
:required="!column.nullable"
|
|
123
|
+
>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
</form>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
<div class="modal-footer">
|
|
130
|
+
<button type="button" class="btn btn-secondary" @click="closeModal">
|
|
131
|
+
取消
|
|
132
|
+
</button>
|
|
133
|
+
<button type="button" class="btn btn-primary" @click="handleSubmit" :disabled="loading">
|
|
134
|
+
<span v-if="loading" class="spinner-border spinner-border-sm me-2"></span>
|
|
135
|
+
{{ isEdit ? '更新' : '插入' }}
|
|
136
|
+
</button>
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
</template>
|
|
142
|
+
|
|
143
|
+
<script lang="ts" setup>
|
|
144
|
+
import { ref, watch, computed, nextTick } from 'vue';
|
|
145
|
+
import { DatabaseService } from '@/service/database';
|
|
146
|
+
import { modal } from '@/utils/modal';
|
|
147
|
+
import { isNumericType, isBooleanType, isDateTimeType, isTextType, isJsonType, isArrayType } from '@/utils/database-types';
|
|
148
|
+
import VueJsonPretty from 'vue-json-pretty';
|
|
149
|
+
import 'vue-json-pretty/lib/styles.css';
|
|
150
|
+
|
|
151
|
+
const databaseService = new DatabaseService();
|
|
152
|
+
|
|
153
|
+
const props = defineProps<{
|
|
154
|
+
visible: boolean;
|
|
155
|
+
isEdit: boolean;
|
|
156
|
+
data?: any;
|
|
157
|
+
columns: any[];
|
|
158
|
+
connection?: any;
|
|
159
|
+
database?: string;
|
|
160
|
+
tableName?: string;
|
|
161
|
+
}>();
|
|
162
|
+
|
|
163
|
+
const emit = defineEmits<{
|
|
164
|
+
'close': [];
|
|
165
|
+
'submit': [data: any];
|
|
166
|
+
}>();
|
|
167
|
+
|
|
168
|
+
// 表单数据
|
|
169
|
+
const formData = ref<any>({});
|
|
170
|
+
const loading = ref(false);
|
|
171
|
+
|
|
172
|
+
// JSON 文本数据
|
|
173
|
+
const jsonText = ref<any>({});
|
|
174
|
+
// JSON 验证错误
|
|
175
|
+
const jsonError = ref<any>({});
|
|
176
|
+
|
|
177
|
+
// 监听显示状态变化
|
|
178
|
+
watch(() => props.visible, (visible) => {
|
|
179
|
+
if (visible) {
|
|
180
|
+
initializeFormData();
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// 初始化表单数据
|
|
185
|
+
function initializeFormData() {
|
|
186
|
+
formData.value = {};
|
|
187
|
+
jsonText.value = {};
|
|
188
|
+
jsonError.value = {};
|
|
189
|
+
|
|
190
|
+
props.columns.forEach(column => {
|
|
191
|
+
if (props.isEdit && props.data) {
|
|
192
|
+
// 编辑模式:使用现有数据
|
|
193
|
+
if(isDateInput(column.type)) {
|
|
194
|
+
formData.value[column.name] = props.data[column.name] ? new Date(props.data[column.name]).toISOString().replace('.000Z', '') : null;
|
|
195
|
+
}
|
|
196
|
+
else if (isJsonInput(column.type) || isArrayInput(column.type)) {
|
|
197
|
+
// 对于 JSON 和数组类型,尝试解析为 JSON 对象
|
|
198
|
+
let value = props.data[column.name];
|
|
199
|
+
if (typeof value === 'string') {
|
|
200
|
+
try {
|
|
201
|
+
value = JSON.parse(value);
|
|
202
|
+
} catch (e) {
|
|
203
|
+
// 如果字符串不能解析为 JSON,直接使用字符串
|
|
204
|
+
value = props.data[column.name];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
formData.value[column.name] = value;
|
|
208
|
+
jsonText.value[column.name] = JSON.stringify(value, null, 2);
|
|
209
|
+
}
|
|
210
|
+
else formData.value[column.name] = props.data[column.name];
|
|
211
|
+
} else {
|
|
212
|
+
// 新增模式:设置默认值
|
|
213
|
+
if (column.isPrimary && column.isAutoIncrement) {
|
|
214
|
+
formData.value[column.name] = null; // 自增主键不需要设置
|
|
215
|
+
} else if (column.defaultValue !== null && column.defaultValue !== undefined) {
|
|
216
|
+
formData.value[column.name] = column.defaultValue;
|
|
217
|
+
} else if (column.nullable) {
|
|
218
|
+
formData.value[column.name] = null;
|
|
219
|
+
} else if (isBooleanInput(column.type)) {
|
|
220
|
+
formData.value[column.name] = false;
|
|
221
|
+
} else if (isJsonInput(column.type) || isArrayInput(column.type)) {
|
|
222
|
+
formData.value[column.name] = {};
|
|
223
|
+
jsonText.value[column.name] = '{}';
|
|
224
|
+
} else {
|
|
225
|
+
formData.value[column.name] = '';
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// 判断输入类型
|
|
232
|
+
function isTextInput(type: string): boolean {
|
|
233
|
+
return !isNumericType(type) && !isBooleanType(type) && !isDateTimeType(type) && !isEnumInput(type);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function isNumberInput(type: string): boolean {
|
|
237
|
+
return isNumericType(type);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function isDecimalInput(type: string): boolean {
|
|
241
|
+
return isNumericType(type) && (type.toLowerCase().includes('decimal') || type.toLowerCase().includes('numeric'));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function isDateInput(type: string): boolean {
|
|
245
|
+
return isDateTimeType(type);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function isTextArea(type: string): boolean {
|
|
249
|
+
return isTextType(type);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function isEnumInput(type: string): boolean {
|
|
253
|
+
return type.toLowerCase().startsWith('enum');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function isBooleanInput(type: string): boolean {
|
|
257
|
+
return isBooleanType(type);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function isJsonInput(type: string, inputtype?: string): boolean {
|
|
261
|
+
if(inputtype) {
|
|
262
|
+
console.log(inputtype, type);
|
|
263
|
+
}
|
|
264
|
+
return isJsonType(type);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function isArrayInput(type: string): boolean {
|
|
268
|
+
return isArrayType(type);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// JSON 验证
|
|
272
|
+
function validateJson(columnName: string) {
|
|
273
|
+
try {
|
|
274
|
+
const value = jsonText.value[columnName];
|
|
275
|
+
if (value && value.trim()) {
|
|
276
|
+
const parsed = JSON.parse(value);
|
|
277
|
+
formData.value[columnName] = parsed;
|
|
278
|
+
jsonError.value[columnName] = '';
|
|
279
|
+
} else {
|
|
280
|
+
formData.value[columnName] = null;
|
|
281
|
+
jsonError.value[columnName] = '';
|
|
282
|
+
}
|
|
283
|
+
} catch (error) {
|
|
284
|
+
jsonError.value[columnName] = 'JSON格式错误: ' + (error as Error).message;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// JSON 格式化
|
|
289
|
+
function formatJson(columnName: string) {
|
|
290
|
+
try {
|
|
291
|
+
const value = jsonText.value[columnName];
|
|
292
|
+
if (value && value.trim()) {
|
|
293
|
+
const parsed = JSON.parse(value);
|
|
294
|
+
jsonText.value[columnName] = JSON.stringify(parsed, null, 2);
|
|
295
|
+
formData.value[columnName] = parsed;
|
|
296
|
+
jsonError.value[columnName] = '';
|
|
297
|
+
}
|
|
298
|
+
} catch (error) {
|
|
299
|
+
jsonError.value[columnName] = 'JSON格式错误: ' + (error as Error).message;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// 获取枚举选项
|
|
304
|
+
function getEnumOptions(type: string): string[] {
|
|
305
|
+
const match = type?.match(/enum\((.*)\)/i);
|
|
306
|
+
if (match && match[1]) {
|
|
307
|
+
return match[1].split(',').map((option: string) => {
|
|
308
|
+
return option.trim().replace(/'/g, '');
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
return [];
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// 关闭模态框
|
|
315
|
+
function closeModal() {
|
|
316
|
+
loading.value = false;
|
|
317
|
+
emit('close');
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// 提交表单
|
|
321
|
+
async function handleSubmit() {
|
|
322
|
+
try {
|
|
323
|
+
// 验证所有 JSON 字段
|
|
324
|
+
let hasInvalidJson = false;
|
|
325
|
+
props.columns.forEach(column => {
|
|
326
|
+
if (isJsonInput(column.type) || isArrayInput(column.type)) {
|
|
327
|
+
validateJson(column.name);
|
|
328
|
+
if (jsonError.value[column.name]) {
|
|
329
|
+
hasInvalidJson = true;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
if (hasInvalidJson) {
|
|
335
|
+
modal.error('请修复 JSON 格式错误后再提交');
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
loading.value = true;
|
|
340
|
+
let response;
|
|
341
|
+
|
|
342
|
+
// 准备提交的数据,过滤掉自增字段
|
|
343
|
+
const submitData: any = {};
|
|
344
|
+
Object.keys(formData.value).forEach(key => {
|
|
345
|
+
const column = props.columns.find(col => col.name === key);
|
|
346
|
+
// 如果列存在且不是自增字段,则包含在提交数据中
|
|
347
|
+
if (!column || !column.isAutoIncrement) {
|
|
348
|
+
submitData[key] = formData.value[key];
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
if (props.isEdit && props.data) {
|
|
353
|
+
// 更新数据
|
|
354
|
+
const whereClause = getPrimaryKeyWhere();
|
|
355
|
+
response = await databaseService.updateData(
|
|
356
|
+
props.connection?.id || '',
|
|
357
|
+
props.database || '',
|
|
358
|
+
props.tableName || '',
|
|
359
|
+
submitData,
|
|
360
|
+
whereClause
|
|
361
|
+
);
|
|
362
|
+
} else {
|
|
363
|
+
// 插入新数据
|
|
364
|
+
response = await databaseService.insertData(
|
|
365
|
+
props.connection?.id || '',
|
|
366
|
+
props.database || '',
|
|
367
|
+
props.tableName || '',
|
|
368
|
+
submitData
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (response.ret === 0) {
|
|
373
|
+
modal.success(props.isEdit ? '数据更新成功' : '数据插入成功');
|
|
374
|
+
closeModal();
|
|
375
|
+
nextTick(() => {
|
|
376
|
+
emit('submit', response);
|
|
377
|
+
});
|
|
378
|
+
} else {
|
|
379
|
+
loading.value = false;
|
|
380
|
+
modal.error(response.msg, {
|
|
381
|
+
code: response.ret,
|
|
382
|
+
operation: props.isEdit ? 'UPDATE' : 'INSERT',
|
|
383
|
+
table: props.tableName,
|
|
384
|
+
requestData: formData.value
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
} catch (error) {
|
|
388
|
+
console.error('提交数据失败:', error);
|
|
389
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
390
|
+
modal.error(errorMsg, {
|
|
391
|
+
operation: props.isEdit ? 'UPDATE' : 'INSERT',
|
|
392
|
+
table: props.tableName,
|
|
393
|
+
stack: error instanceof Error ? error.stack : undefined
|
|
394
|
+
});
|
|
395
|
+
loading.value = false;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// 获取主键条件
|
|
400
|
+
function getPrimaryKeyWhere() {
|
|
401
|
+
const primaryKeys = props.columns.filter(col => col.isPrimary);
|
|
402
|
+
const whereClause: any = {};
|
|
403
|
+
|
|
404
|
+
primaryKeys.forEach(key => {
|
|
405
|
+
whereClause[key.name] = props.data[key.name];
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
return whereClause;
|
|
409
|
+
}
|
|
410
|
+
</script>
|
|
411
|
+
|
|
412
|
+
<style scoped>
|
|
413
|
+
.modal {
|
|
414
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
.modal-dialog {
|
|
418
|
+
max-width: 800px;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
.form-label {
|
|
422
|
+
font-weight: 500;
|
|
423
|
+
color: #374151;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
.form-control, .form-select {
|
|
427
|
+
border: 1px solid #d1d5db;
|
|
428
|
+
border-radius: 6px;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
.form-control:focus, .form-select:focus {
|
|
432
|
+
border-color: #3b82f6;
|
|
433
|
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
.modal-header {
|
|
437
|
+
background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
|
|
438
|
+
border-bottom: 1px solid #e2e8f0;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
.modal-title {
|
|
442
|
+
color: #1e293b;
|
|
443
|
+
font-weight: 600;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
.modal-footer {
|
|
447
|
+
background: #f8fafc;
|
|
448
|
+
border-top: 1px solid #e2e8f0;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
.text-danger {
|
|
452
|
+
color: #ef4444;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
.text-muted {
|
|
456
|
+
color: #6b7280;
|
|
457
|
+
font-size: 0.875rem;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
.json-editor textarea {
|
|
461
|
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
|
462
|
+
font-size: 0.875rem;
|
|
463
|
+
line-height: 1.5;
|
|
464
|
+
background-color: #f8fafc;
|
|
465
|
+
border-color: #e2e8f0;
|
|
466
|
+
resize: vertical;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
.json-editor textarea:focus {
|
|
470
|
+
background-color: #ffffff;
|
|
471
|
+
border-color: #3b82f6;
|
|
472
|
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
.json-editor .text-muted {
|
|
476
|
+
font-size: 0.75rem;
|
|
477
|
+
}
|
|
478
|
+
</style>
|