Просмотр исходного кода

feat:【infra】数据源管理:100%

YunaiV 4 месяцев назад
Родитель
Сommit
1991a99116

+ 1 - 0
src/pages-infra/data-source-config/detail/index.vue

@@ -12,6 +12,7 @@
       <wd-cell-group border>
         <wd-cell title="主键编号" :value="String(formData?.id ?? '-')" />
         <wd-cell title="数据源名称" :value="String(formData?.name ?? '-')" />
+        <!-- TODO @AI:参考 /Users/yunai/Java/yudao-ui-admin-uniapp-next-v4/src/pages-infra/api-access-log/detail/index.vue 复制的处理 -->
         <wd-cell title="数据源连接" :value="String(formData?.url ?? '-')" />
         <wd-cell title="用户名" :value="String(formData?.username ?? '-')" />
         <wd-cell title="创建时间" :value="formatDateTime(formData?.createTime) || '-'" />

+ 78 - 1
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<DataSourceConfig>({
+  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()
+})
+</script>
+
+<style lang="scss" scoped>
+</style>

+ 1 - 1
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',