Skip to content

Commit 846b8cd

Browse files
committed
feat: datasource ui
1 parent c6210ee commit 846b8cd

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

frontend/src/views/ds/form.vue

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
title="Add Datasource"
55
width="500"
66
>
7-
<el-form :model="form" label-width="auto">
8-
<el-form-item label="Name">
7+
<el-form :model="form" label-width="auto" ref="dsFormRef" :rules="rules">
8+
<el-form-item label="Name" prop="name">
99
<el-input v-model="form.name" />
1010
</el-form-item>
1111
<el-form-item label="Description">
@@ -40,19 +40,28 @@
4040
<div style="display: flex;justify-content: flex-end;">
4141
<el-button @click="close">Cancel</el-button>
4242
<el-button @click="check">Test Connect</el-button>
43-
<el-button type="primary" @click="save">Save</el-button>
43+
<el-button type="primary" @click="save(dsFormRef)">Save</el-button>
4444
</div>
4545
</el-form>
4646
</el-dialog>
4747
</template>
4848
<script lang="ts" setup>
49-
import { ref } from 'vue'
49+
import { ref, reactive } from 'vue'
5050
import { datasourceApi } from '@/api/datasource'
5151
import { encrypted, decrypted } from './js/aes'
5252
import { ElMessage } from 'element-plus'
53+
import type { FormInstance, FormRules } from 'element-plus'
5354
55+
const dsFormRef = ref<FormInstance>()
5456
const emit = defineEmits(['refresh'])
5557
58+
const rules = reactive<FormRules>({
59+
name: [
60+
{ required: true, message: 'Please input name', trigger: 'blur' },
61+
{ min: 1, max: 50, message: 'Length should be 1 to 50', trigger: 'blur' },
62+
],
63+
})
64+
5665
const dialogVisible = ref<boolean>(false)
5766
const dsType = [
5867
{label:"MySQL", value:"mysql"}
@@ -109,27 +118,32 @@ const open = (item: any) => {
109118
dialogVisible.value = true
110119
}
111120
112-
const save = () => {
113-
form.value.configuration = encrypted(JSON.stringify({
114-
host:config.value.host,
115-
port:config.value.port,
116-
username:config.value.username,
117-
password:config.value.password,
118-
database:config.value.database
119-
}))
120-
if (form.value.id) {
121-
datasourceApi.update(form.value).then((res) => {
122-
console.log(res)
123-
close()
124-
emit('refresh')
125-
})
126-
} else {
127-
datasourceApi.add(form.value).then((res: any) => {
128-
console.log(res)
129-
close()
130-
emit('refresh')
131-
})
132-
}
121+
const save = async(formEl: FormInstance | undefined) => {
122+
if(!formEl) return
123+
await formEl.validate((valid) => {
124+
if (valid) {
125+
form.value.configuration = encrypted(JSON.stringify({
126+
host:config.value.host,
127+
port:config.value.port,
128+
username:config.value.username,
129+
password:config.value.password,
130+
database:config.value.database
131+
}))
132+
if (form.value.id) {
133+
datasourceApi.update(form.value).then((res) => {
134+
console.log(res)
135+
close()
136+
emit('refresh')
137+
})
138+
} else {
139+
datasourceApi.add(form.value).then((res: any) => {
140+
console.log(res)
141+
close()
142+
emit('refresh')
143+
})
144+
}
145+
}
146+
})
133147
}
134148
135149
const check = () => {

0 commit comments

Comments
 (0)