3838 <el-form-item label =" Description" >
3939 <el-input v-model =" form.description" :rows =" 2" type =" textarea" />
4040 </el-form-item >
41- <el-form-item label =" Type" >
41+ <el-form-item label =" Type" prop = " type " >
4242 <el-select
4343 v-model =" form.type"
4444 placeholder =" Select Type"
7272 </el-form-item >
7373 </div >
7474 <div v-else >
75- <el-form-item label =" Host/Ip" >
76- <el-input v-model =" config .host" />
75+ <el-form-item label =" Host/Ip" prop = " host " >
76+ <el-input v-model =" form .host" />
7777 </el-form-item >
78- <el-form-item label =" Port" >
79- <el-input v-model =" config .port" />
78+ <el-form-item label =" Port" prop = " port " >
79+ <el-input v-model =" form .port" />
8080 </el-form-item >
8181 <el-form-item label =" Username" >
82- <el-input v-model =" config .username" />
82+ <el-input v-model =" form .username" />
8383 </el-form-item >
8484 <el-form-item label =" Password" >
85- <el-input v-model =" config .password" type =" password" show-password />
85+ <el-input v-model =" form .password" type =" password" show-password />
8686 </el-form-item >
87- <el-form-item label =" Database" >
88- <el-input v-model =" config .database" />
87+ <el-form-item label =" Database" prop = " database " >
88+ <el-input v-model =" form .database" />
8989 </el-form-item >
90- <el-form-item label =" Connect Mode" v-if =" form.type === 'oracle'" >
91- <el-radio-group v-model =" config .mode" >
90+ <el-form-item label =" Connect Mode" v-if =" form.type === 'oracle'" prop = " mode " >
91+ <el-radio-group v-model =" form .mode" >
9292 <el-radio value =" service_name" >Service Name</el-radio >
9393 <el-radio value =" sid" >SID</el-radio >
9494 </el-radio-group >
9595 </el-form-item >
9696 <el-form-item label =" Extra JDBC String" >
97- <el-input v-model =" config .extraJdbc" />
97+ <el-input v-model =" form .extraJdbc" />
9898 </el-form-item >
99- <el-form-item label =" Schema" v-if =" haveSchema.includes(form.type)" >
100- <el-input v-model =" config .dbSchema" />
99+ <el-form-item label =" Schema" v-if =" haveSchema.includes(form.type)" prop = " dbSchema " >
100+ <el-input v-model =" form .dbSchema" />
101101 <el-button link type =" primary" :icon =" Plus" v-if =" false"
102102 >Get Schema</el-button
103103 >
@@ -189,6 +189,24 @@ const rules = reactive<FormRules>({
189189 { required: true , message: " Please input name" , trigger: " blur" },
190190 { min: 1 , max: 50 , message: " Length should be 1 to 50" , trigger: " blur" },
191191 ],
192+ type: [
193+ { required: true , message: " Please choose database type" ,trigger: " change" }
194+ ],
195+ host: [
196+ { required: true , message: " Please input host" ,trigger: " blur" }
197+ ],
198+ port: [
199+ { required: true , message: " Please input port" ,trigger: " blur" }
200+ ],
201+ database: [
202+ { required: true , message: " Please input database" ,trigger: " blur" }
203+ ],
204+ mode: [
205+ { required: true , message: " Please choose mode" ,trigger: " change" }
206+ ],
207+ dbSchema: [
208+ { required: true , message: " Please input schema" ,trigger: " blur" }
209+ ]
192210});
193211
194212const dialogVisible = ref <boolean >(false );
@@ -197,8 +215,6 @@ const form = ref<any>({
197215 description: " " ,
198216 type: " mysql" ,
199217 configuration: " " ,
200- });
201- const config = ref <any >({
202218 driver: " " ,
203219 host: " " ,
204220 port: 0 ,
@@ -234,16 +250,16 @@ const open = (item: any, editTable: boolean = false) => {
234250 form .value .configuration = item .configuration ;
235251 if (item .configuration ) {
236252 const configuration = JSON .parse (decrypted (item .configuration ));
237- config .value .host = configuration .host ;
238- config .value .port = configuration .port ;
239- config .value .username = configuration .username ;
240- config .value .password = configuration .password ;
241- config .value .database = configuration .database ;
242- config .value .extraJdbc = configuration .extraJdbc ;
243- config .value .dbSchema = configuration .dbSchema ;
244- config .value .filename = configuration .filename ;
245- config .value .sheets = configuration .sheets ;
246- config .value .mode = configuration .mode ;
253+ form .value .host = configuration .host ;
254+ form .value .port = configuration .port ;
255+ form .value .username = configuration .username ;
256+ form .value .password = configuration .password ;
257+ form .value .database = configuration .database ;
258+ form .value .extraJdbc = configuration .extraJdbc ;
259+ form .value .dbSchema = configuration .dbSchema ;
260+ form .value .filename = configuration .filename ;
261+ form .value .sheets = configuration .sheets ;
262+ form .value .mode = configuration .mode ;
247263 }
248264
249265 if (editTable ) {
@@ -258,11 +274,12 @@ const open = (item: any, editTable: boolean = false) => {
258274 return ele .table_name ;
259275 });
260276 if (item .type === " excel" ) {
261- tableList .value = config .value .sheets ;
277+ tableList .value = form .value .sheets ;
262278 } else {
263279 tableListLoading .value = true ;
280+ const requestObj = buildConf ()
264281 datasourceApi
265- .getTablesByConf (form . value )
282+ .getTablesByConf (requestObj )
266283 .then ((table ) => {
267284 tableList .value = table ;
268285 checkList .value = checkList .value .filter ((ele : string ) => {
@@ -290,8 +307,6 @@ const open = (item: any, editTable: boolean = false) => {
290307 description: " " ,
291308 type: " mysql" ,
292309 configuration: " " ,
293- };
294- config .value = {
295310 driver: " " ,
296311 host: " " ,
297312 port: 0 ,
@@ -303,7 +318,7 @@ const open = (item: any, editTable: boolean = false) => {
303318 filename: " " ,
304319 sheets: [],
305320 mode: " service_name" ,
306- };
321+ }
307322 }
308323 dialogVisible .value = true ;
309324};
@@ -320,11 +335,11 @@ const save = async (formEl: FormInstance | undefined) => {
320335 return { table_name: ele .tableName , table_comment: ele .tableComment };
321336 });
322337
323- buildConf ();
338+ const requestObj = buildConf ();
324339 if (form .value .id ) {
325340 if (! isEditTable .value ) {
326341 // only update datasource config info
327- datasourceApi .update (form . value ).then ((res ) => {
342+ datasourceApi .update (requestObj ).then ((res ) => {
328343 console .log (res );
329344 close ();
330345 emit (" refresh" );
@@ -336,8 +351,8 @@ const save = async (formEl: FormInstance | undefined) => {
336351 });
337352 }
338353 } else {
339- form . value .tables = list ;
340- datasourceApi .add (form . value ).then ((res : any ) => {
354+ requestObj .tables = list ;
355+ datasourceApi .add (requestObj ).then ((res : any ) => {
341356 console .log (res );
342357 close ();
343358 emit (" refresh" );
@@ -350,23 +365,36 @@ const save = async (formEl: FormInstance | undefined) => {
350365const buildConf = () => {
351366 form .value .configuration = encrypted (
352367 JSON .stringify ({
353- host: config .value .host ,
354- port: config .value .port ,
355- username: config .value .username ,
356- password: config .value .password ,
357- database: config .value .database ,
358- extraJdbc: config .value .extraJdbc ,
359- dbSchema: config .value .dbSchema ,
360- filename: config .value .filename ,
361- sheets: config .value .sheets ,
362- mode: config .value .mode ,
368+ host: form .value .host ,
369+ port: form .value .port ,
370+ username: form .value .username ,
371+ password: form .value .password ,
372+ database: form .value .database ,
373+ extraJdbc: form .value .extraJdbc ,
374+ dbSchema: form .value .dbSchema ,
375+ filename: form .value .filename ,
376+ sheets: form .value .sheets ,
377+ mode: form .value .mode ,
363378 })
364- );
379+ )
380+ const obj = JSON .parse (JSON .stringify (form .value ))
381+ delete obj .driver
382+ delete obj .host
383+ delete obj .port
384+ delete obj .username
385+ delete obj .password
386+ delete obj .database
387+ delete obj .extraJdbc
388+ delete obj .dbSchema
389+ delete obj .filename
390+ delete obj .sheets
391+ delete obj .mode
392+ return obj
365393};
366394
367395const check = () => {
368- buildConf ();
369- datasourceApi .check (form . value ).then ((res : any ) => {
396+ const requestObj = buildConf ();
397+ datasourceApi .check (requestObj ).then ((res : any ) => {
370398 if (res ) {
371399 ElMessage ({
372400 message: " Connect success" ,
@@ -394,12 +422,12 @@ const next = async (formEl: FormInstance | undefined) => {
394422 }
395423 } else {
396424 // check status if success do next
397- buildConf ();
398- datasourceApi .check (form . value ).then ((res : boolean ) => {
425+ const requestObj = buildConf ();
426+ datasourceApi .check (requestObj ).then ((res : boolean ) => {
399427 if (res ) {
400428 active .value ++ ;
401429 // request tables
402- datasourceApi .getTablesByConf (form . value ).then ((res ) => {
430+ datasourceApi .getTablesByConf (requestObj ).then ((res ) => {
403431 tableList .value = res ;
404432 });
405433 } else {
@@ -428,8 +456,8 @@ const beforeUpload = (rawFile: any) => {
428456};
429457
430458const onSuccess = (response : any ) => {
431- config .value .filename = response .data .filename ;
432- config .value .sheets = response .data .sheets ;
459+ form .value .filename = response .data .filename ;
460+ form .value .sheets = response .data .sheets ;
433461 tableList .value = response .data .sheets ;
434462 excelUploadSuccess .value = true ;
435463};
0 commit comments