diff --git a/src/pages-infra/data-source-config/detail/index.vue b/src/pages-infra/data-source-config/detail/index.vue index 760cfcf..b0fde6a 100644 --- a/src/pages-infra/data-source-config/detail/index.vue +++ b/src/pages-infra/data-source-config/detail/index.vue @@ -12,6 +12,7 @@ + diff --git a/src/pages-infra/data-source-config/form/index.vue b/src/pages-infra/data-source-config/form/index.vue index 94561d3..4a50811 100644 --- a/src/pages-infra/data-source-config/form/index.vue +++ b/src/pages-infra/data-source-config/form/index.vue @@ -40,7 +40,7 @@ label="密码" label-width="200rpx" prop="password" - type="password" + show-password clearable placeholder="请输入密码" /> @@ -66,3 +66,80 @@ import type { DataSourceConfig } from '@/api/infra/data-source-config' import { computed, onMounted, ref } from 'vue' import { useToast } from 'wot-design-uni' +import { createDataSourceConfig, getDataSourceConfig, updateDataSourceConfig } from '@/api/infra/data-source-config' +import { navigateBackPlus } from '@/utils' + +const props = defineProps<{ + id?: number | any +}>() + +definePage({ + style: { + navigationBarTitleText: '', + navigationStyle: 'custom', + }, +}) + +const toast = useToast() +const getTitle = computed(() => props.id ? '编辑数据源' : '新增数据源') +const formLoading = ref(false) +const formData = ref({ + id: undefined, + name: '', + url: '', + username: '', + password: '', +}) +const formRules = { + name: [{ required: true, message: '数据源名称不能为空' }], + url: [{ required: true, message: '数据源连接不能为空' }], + username: [{ required: true, message: '用户名不能为空' }], + password: [{ required: true, message: '密码不能为空' }], +} +const formRef = ref() + +/** 返回上一页 */ +function handleBack() { + navigateBackPlus('/pages-infra/data-source-config/index') +} + +/** 加载数据源详情 */ +async function getDetail() { + if (!props.id) { + return + } + formData.value = await getDataSourceConfig(props.id) +} + +/** 提交表单 */ +async function handleSubmit() { + const { valid } = await formRef.value.validate() + if (!valid) { + return + } + + formLoading.value = true + try { + if (props.id) { + await updateDataSourceConfig(formData.value) + toast.success('修改成功') + } else { + await createDataSourceConfig(formData.value) + toast.success('新增成功') + } + setTimeout(() => { + handleBack() + }, 500) + } finally { + formLoading.value = false + } +} + +/** 初始化 */ +onMounted(() => { + getDetail() +}) + + + \ No newline at end of file diff --git a/src/pages/index/index.ts b/src/pages/index/index.ts index 9c4607e..a47f468 100644 --- a/src/pages/index/index.ts +++ b/src/pages/index/index.ts @@ -174,7 +174,7 @@ const menuGroupsData: MenuGroup[] = [ { key: 'dataSourceConfig', name: '数据源配置', - icon: 'database', + icon: 'setting', url: '/pages-infra/data-source-config/index', iconColor: '#13c2c2', permission: 'infra:data-source-config:query',