2222 </el-select >
2323 </el-form-item >
2424 <el-form-item label =" Host/Ip" >
25- <el-input v-model =" form .host" />
25+ <el-input v-model =" config .host" />
2626 </el-form-item >
2727 <el-form-item label =" Port" >
28- <el-input v-model =" form .port" />
28+ <el-input v-model =" config .port" />
2929 </el-form-item >
3030 <el-form-item label =" Username" >
31- <el-input v-model =" form .username" />
31+ <el-input v-model =" config .username" />
3232 </el-form-item >
3333 <el-form-item label =" Password" >
34- <el-input v-model =" form .password" />
34+ <el-input v-model =" config .password" />
3535 </el-form-item >
3636 <el-form-item label =" Database" >
37- <el-input v-model =" form .database" />
37+ <el-input v-model =" config .database" />
3838 </el-form-item >
3939
4040 <div style =" display : flex ;justify-content : flex-end ;" >
4848<script lang="ts" setup>
4949import { ref } from ' vue'
5050import { datasourceApi } from ' @/api/datasource'
51+ import { encrypted , decrypted } from ' ./js/aes'
5152
5253const emit = defineEmits ([' refresh' ])
5354
@@ -59,13 +60,15 @@ const form = ref<any>({
5960 name:' ' ,
6061 description:' ' ,
6162 type:' mysql' ,
63+ configuration: ' '
64+ })
65+ const config = ref <any >({
6266 driver:' ' ,
6367 host:' ' ,
6468 port:0 ,
6569 username:' ' ,
6670 password:' ' ,
6771 database:' ' ,
68- configuration: ' '
6972})
7073
7174const close = () => {
@@ -78,24 +81,43 @@ const open = (item: any) => {
7881 form .value .name = item .name
7982 form .value .description = item .description
8083 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
84+ if (item .configuration ) {
85+ const configuration = JSON .parse (decrypted (item .configuration ))
86+ config .value .host = configuration .host
87+ config .value .port = configuration .port
88+ config .value .username = configuration .username
89+ config .value .password = configuration .password
90+ config .value .database = configuration .database
91+ }
92+ } else {
93+ form .value = {
94+ driver:' ' ,
95+ host:' ' ,
96+ port:0 ,
97+ username:' ' ,
98+ password:' ' ,
99+ database:' ' ,
100+ }
101+ config .value = {
102+ driver:' ' ,
103+ host:' ' ,
104+ port:0 ,
105+ username:' ' ,
106+ password:' ' ,
107+ database:' ' ,
108+ }
87109 }
88110 dialogVisible .value = true
89111}
90112
91113const save = () => {
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
98- })
114+ form .value .configuration = encrypted ( JSON .stringify ({
115+ host:config .value .host ,
116+ port:config .value .port ,
117+ username:config .value .username ,
118+ password:config .value .password ,
119+ database:config .value .database
120+ }))
99121 if (form .value .id ) {
100122 datasourceApi .update (form .value ).then ((res ) => {
101123 console .log (res )
@@ -112,6 +134,13 @@ const save = () => {
112134}
113135
114136const check = () => {
137+ form .value .configuration = encrypted (JSON .stringify ({
138+ host:config .value .host ,
139+ port:config .value .port ,
140+ username:config .value .username ,
141+ password:config .value .password ,
142+ database:config .value .database
143+ }))
115144 datasourceApi .check (form .value ).then ((res : any ) => {
116145 console .log (res )
117146 })
@@ -120,4 +149,4 @@ const check = () => {
120149defineExpose ({ open })
121150 </script >
122151<style lang="less" scoped>
123- </style >
152+ </style >./js/aes
0 commit comments