From 62be1f07b449299496a67a3a55af0308d8774558 Mon Sep 17 00:00:00 2001 From: junjun Date: Thu, 29 May 2025 15:20:05 +0800 Subject: [PATCH] feat(datasource): form check --- frontend/src/views/ds/form.vue | 134 ++++++++++++++++++++------------- 1 file changed, 81 insertions(+), 53 deletions(-) diff --git a/frontend/src/views/ds/form.vue b/frontend/src/views/ds/form.vue index 30da7e49..a94a9f0e 100644 --- a/frontend/src/views/ds/form.vue +++ b/frontend/src/views/ds/form.vue @@ -38,7 +38,7 @@ - +
- - + + - - + + - + - + - - + + - - + + Service Name SID - + - - + + Get Schema @@ -189,6 +189,24 @@ const rules = reactive({ { required: true, message: "Please input name", trigger: "blur" }, { min: 1, max: 50, message: "Length should be 1 to 50", trigger: "blur" }, ], + type: [ + { required: true, message: "Please choose database type" ,trigger: "change"} + ], + host: [ + { required: true, message: "Please input host" ,trigger: "blur"} + ], + port: [ + { required: true, message: "Please input port" ,trigger: "blur"} + ], + database: [ + { required: true, message: "Please input database" ,trigger: "blur"} + ], + mode: [ + { required: true, message: "Please choose mode" ,trigger: "change"} + ], + dbSchema: [ + { required: true, message: "Please input schema" ,trigger: "blur"} + ] }); const dialogVisible = ref(false); @@ -197,8 +215,6 @@ const form = ref({ description: "", type: "mysql", configuration: "", -}); -const config = ref({ driver: "", host: "", port: 0, @@ -234,16 +250,16 @@ const open = (item: any, editTable: boolean = false) => { form.value.configuration = item.configuration; if (item.configuration) { const configuration = JSON.parse(decrypted(item.configuration)); - config.value.host = configuration.host; - config.value.port = configuration.port; - config.value.username = configuration.username; - config.value.password = configuration.password; - config.value.database = configuration.database; - config.value.extraJdbc = configuration.extraJdbc; - config.value.dbSchema = configuration.dbSchema; - config.value.filename = configuration.filename; - config.value.sheets = configuration.sheets; - config.value.mode = configuration.mode; + form.value.host = configuration.host; + form.value.port = configuration.port; + form.value.username = configuration.username; + form.value.password = configuration.password; + form.value.database = configuration.database; + form.value.extraJdbc = configuration.extraJdbc; + form.value.dbSchema = configuration.dbSchema; + form.value.filename = configuration.filename; + form.value.sheets = configuration.sheets; + form.value.mode = configuration.mode; } if (editTable) { @@ -258,11 +274,12 @@ const open = (item: any, editTable: boolean = false) => { return ele.table_name; }); if (item.type === "excel") { - tableList.value = config.value.sheets; + tableList.value = form.value.sheets; } else { tableListLoading.value = true; + const requestObj = buildConf() datasourceApi - .getTablesByConf(form.value) + .getTablesByConf(requestObj) .then((table) => { tableList.value = table; checkList.value = checkList.value.filter((ele: string) => { @@ -290,8 +307,6 @@ const open = (item: any, editTable: boolean = false) => { description: "", type: "mysql", configuration: "", - }; - config.value = { driver: "", host: "", port: 0, @@ -303,7 +318,7 @@ const open = (item: any, editTable: boolean = false) => { filename: "", sheets: [], mode: "service_name", - }; + } } dialogVisible.value = true; }; @@ -320,11 +335,11 @@ const save = async (formEl: FormInstance | undefined) => { return { table_name: ele.tableName, table_comment: ele.tableComment }; }); - buildConf(); + const requestObj = buildConf(); if (form.value.id) { if (!isEditTable.value) { // only update datasource config info - datasourceApi.update(form.value).then((res) => { + datasourceApi.update(requestObj).then((res) => { console.log(res); close(); emit("refresh"); @@ -336,8 +351,8 @@ const save = async (formEl: FormInstance | undefined) => { }); } } else { - form.value.tables = list; - datasourceApi.add(form.value).then((res: any) => { + requestObj.tables = list; + datasourceApi.add(requestObj).then((res: any) => { console.log(res); close(); emit("refresh"); @@ -350,23 +365,36 @@ const save = async (formEl: FormInstance | undefined) => { const buildConf = () => { form.value.configuration = encrypted( JSON.stringify({ - host: config.value.host, - port: config.value.port, - username: config.value.username, - password: config.value.password, - database: config.value.database, - extraJdbc: config.value.extraJdbc, - dbSchema: config.value.dbSchema, - filename: config.value.filename, - sheets: config.value.sheets, - mode: config.value.mode, + host: form.value.host, + port: form.value.port, + username: form.value.username, + password: form.value.password, + database: form.value.database, + extraJdbc: form.value.extraJdbc, + dbSchema: form.value.dbSchema, + filename: form.value.filename, + sheets: form.value.sheets, + mode: form.value.mode, }) - ); + ) + const obj = JSON.parse(JSON.stringify(form.value)) + delete obj.driver + delete obj.host + delete obj.port + delete obj.username + delete obj.password + delete obj.database + delete obj.extraJdbc + delete obj.dbSchema + delete obj.filename + delete obj.sheets + delete obj.mode + return obj }; const check = () => { - buildConf(); - datasourceApi.check(form.value).then((res: any) => { + const requestObj = buildConf(); + datasourceApi.check(requestObj).then((res: any) => { if (res) { ElMessage({ message: "Connect success", @@ -394,12 +422,12 @@ const next = async (formEl: FormInstance | undefined) => { } } else { // check status if success do next - buildConf(); - datasourceApi.check(form.value).then((res: boolean) => { + const requestObj = buildConf(); + datasourceApi.check(requestObj).then((res: boolean) => { if (res) { active.value++; // request tables - datasourceApi.getTablesByConf(form.value).then((res) => { + datasourceApi.getTablesByConf(requestObj).then((res) => { tableList.value = res; }); } else { @@ -428,8 +456,8 @@ const beforeUpload = (rawFile: any) => { }; const onSuccess = (response: any) => { - config.value.filename = response.data.filename; - config.value.sheets = response.data.sheets; + form.value.filename = response.data.filename; + form.value.sheets = response.data.sheets; tableList.value = response.data.sheets; excelUploadSuccess.value = true; };