99 <el-input v-model =" form.name" />
1010 </el-form-item >
1111 <el-form-item label =" Description" >
12- <el-input v-model =" form.desc " :rows =" 2" type =" textarea" />
12+ <el-input v-model =" form.description " :rows =" 2" type =" textarea" />
1313 </el-form-item >
1414 <el-form-item label =" Type" >
1515 <el-select v-model =" form.type" placeholder =" Select Type" >
3737 <el-input v-model =" form.database" />
3838 </el-form-item >
3939
40- <el-form-item >
40+ <div style =" display : flex ;justify-content : flex-end ;" >
41+ <el-button @click =" close" >Cancel</el-button >
4142 <el-button @click =" check" >Test Connect</el-button >
4243 <el-button type =" primary" @click =" save" >Save</el-button >
43- </el-form-item >
44+ </div >
4445 </el-form >
4546 </el-dialog >
4647</template >
4748<script lang="ts" setup>
48- import { reactive } from ' vue'
4949import { ref } from ' vue'
5050import { datasourceApi } from ' @/api/datasource'
5151
52+ const emit = defineEmits ([' refresh' ])
53+
5254const dialogVisible = ref <boolean >(false )
5355const dsType = [
5456 {label:" MySQL" , value:" mysql" }
5557]
56- const form = reactive ({
58+ const form = ref < any > ({
5759 name:' ' ,
58- desc :' ' ,
60+ description :' ' ,
5961 type:' mysql' ,
62+ driver:' ' ,
6063 host:' ' ,
6164 port:0 ,
6265 username:' ' ,
@@ -65,19 +68,51 @@ const form = reactive({
6568 configuration: ' '
6669})
6770
68- const open = () => {
71+ const close = () => {
72+ dialogVisible .value = false
73+ }
74+
75+ const open = (item : any ) => {
76+ if (item ) {
77+ form .value .id = item .id
78+ form .value .name = item .name
79+ form .value .description = item .description
80+ form .value .type = item .type
81+ const configuration = JSON .parse (item .configuration )
82+ form .value .host = configuration .host
83+ form .value .port = configuration .port
84+ form .value .username = configuration .username
85+ form .value .password = configuration .password
86+ form .value .database = configuration .database
87+ }
6988 dialogVisible .value = true
7089}
7190
7291const save = () => {
73- form .configuration = JSON .stringify ({host:form .host ,port:form .port ,username:form .username ,password:form .password ,database:form .database })
74- datasourceApi .add (form ).then ((res : any ) => {
75- console .log (res )
92+ form .value .configuration = JSON .stringify ({
93+ host:form .value .host ,
94+ port:form .value .port ,
95+ username:form .value .username ,
96+ password:form .value .password ,
97+ database:form .value .database
7698 })
99+ if (form .value .id ) {
100+ datasourceApi .update (form .value ).then ((res ) => {
101+ console .log (res )
102+ close ()
103+ emit (' refresh' )
104+ })
105+ } else {
106+ datasourceApi .add (form .value ).then ((res : any ) => {
107+ console .log (res )
108+ close ()
109+ emit (' refresh' )
110+ })
111+ }
77112}
78113
79114const check = () => {
80- datasourceApi .check (form ).then ((res : any ) => {
115+ datasourceApi .check (form . value ).then ((res : any ) => {
81116 console .log (res )
82117 })
83118}
0 commit comments