6161 <div style =" display : flex ;justify-content : flex-end ;margin-top : 20px ;" >
6262 <el-button @click =" close" >Cancel</el-button >
6363 <el-button v-show =" !isCreate && !isEditTable" @click =" check" >Test Connect</el-button >
64- <el-button v-show =" active === 1 && isCreate" type =" primary" @click =" next" >Next</el-button >
64+ <el-button v-show =" active === 1 && isCreate" type =" primary" @click =" next(dsFormRef) " >Next</el-button >
6565 <el-button v-show =" active === 2 && isCreate" @click =" preview" >Preview</el-button >
6666 <el-button v-show =" active === 2 || !isCreate" type =" primary" @click =" save(dsFormRef)" >Save</el-button >
6767 </div >
@@ -113,46 +113,58 @@ const close = () => {
113113 isCreate .value = true
114114 active .value = 1
115115 isEditTable .value = false
116+ checkList .value = []
117+ tableList .value = []
116118}
117119
118120const open = (item : any , editTable : boolean = false ) => {
119- if (editTable ) {
120- active .value = 2
121- isEditTable .value = true
121+ isEditTable .value = false
122+ if (item ) {
122123 isCreate .value = false
123- // request tables
124+ form .value .id = item .id
125+ form .value .name = item .name
126+ form .value .description = item .description
127+ form .value .type = item .type
128+ form .value .configuration = item .configuration
129+ if (item .configuration ) {
130+ const configuration = JSON .parse (decrypted (item .configuration ))
131+ config .value .host = configuration .host
132+ config .value .port = configuration .port
133+ config .value .username = configuration .username
134+ config .value .password = configuration .password
135+ config .value .database = configuration .database
136+ }
137+
138+ if (editTable ) {
139+ active .value = 2
140+ isEditTable .value = true
141+ isCreate .value = false
142+ // request tables and check tables
143+ datasourceApi .tableList (item .id ).then ((res ) => {
144+ checkList .value = res .map ((ele : any ) => {return ele .table_name })
145+ datasourceApi .getTablesByConf (form .value ).then ((res ) => {
146+ tableList .value = res
147+ })
148+ })
149+ }
124150 } else {
151+ isCreate .value = true
125152 isEditTable .value = false
126- if (item ) {
127- isCreate .value = false
128- form .value .id = item .id
129- form .value .name = item .name
130- form .value .description = item .description
131- form .value .type = item .type
132- if (item .configuration ) {
133- const configuration = JSON .parse (decrypted (item .configuration ))
134- config .value .host = configuration .host
135- config .value .port = configuration .port
136- config .value .username = configuration .username
137- config .value .password = configuration .password
138- config .value .database = configuration .database
139- }
140- } else {
141- isCreate .value = true
142- form .value = {
143- name:' ' ,
144- description:' ' ,
145- type:' mysql' ,
146- configuration: ' '
147- }
148- config .value = {
149- driver:' ' ,
150- host:' ' ,
151- port:0 ,
152- username:' ' ,
153- password:' ' ,
154- database:' ' ,
155- }
153+ checkList .value = []
154+ tableList .value = []
155+ form .value = {
156+ name:' ' ,
157+ description:' ' ,
158+ type:' mysql' ,
159+ configuration: ' '
160+ }
161+ config .value = {
162+ driver:' ' ,
163+ host:' ' ,
164+ port:0 ,
165+ username:' ' ,
166+ password:' ' ,
167+ database:' ' ,
156168 }
157169 }
158170 dialogVisible .value = true
@@ -162,6 +174,10 @@ const save = async(formEl: FormInstance | undefined) => {
162174 if (! formEl ) return
163175 await formEl .validate ((valid ) => {
164176 if (valid ) {
177+ const list = tableList .value
178+ .filter ((ele : any ) => {return checkList .value .includes (ele .tableName )})
179+ .map ((ele : any ) => {return {" table_name" : ele .tableName , " table_comment" : ele .tableComment }})
180+
165181 form .value .configuration = encrypted (JSON .stringify ({
166182 host:config .value .host ,
167183 port:config .value .port ,
@@ -179,9 +195,12 @@ const save = async(formEl: FormInstance | undefined) => {
179195 })
180196 } else {
181197 // save table and field
198+ datasourceApi .chooseTables (form .value .id , list ).then (() => {
199+ close ()
200+ })
182201 }
183202 } else {
184- form .value .tables = [{ " table_name " : " core_dataset_table " },{ " table_name " : " pre_user " }] // todo test
203+ form .value .tables = list
185204 datasourceApi .add (form .value ).then ((res : any ) => {
186205 console .log (res )
187206 close ()
@@ -215,15 +234,20 @@ const check = () => {
215234 })
216235}
217236
218- const next = () => {
219- // check status if success do next
220- buildConf ()
221- datasourceApi .check (form .value ).then ((res : boolean ) => {
222- if (res ) {
223- active .value ++
224- // request tables
225- datasourceApi .getTablesByConf (form .value ).then ((res ) => {
226- tableList .value = res
237+ const next = async (formEl : FormInstance | undefined ) => {
238+ if (! formEl ) return
239+ await formEl .validate ((valid ) => {
240+ if (valid ) {
241+ // check status if success do next
242+ buildConf ()
243+ datasourceApi .check (form .value ).then ((res : boolean ) => {
244+ if (res ) {
245+ active .value ++
246+ // request tables
247+ datasourceApi .getTablesByConf (form .value ).then ((res ) => {
248+ tableList .value = res
249+ })
250+ }
227251 })
228252 }
229253 })
0 commit comments