From 23423ab3d97225127c0bf163a4f0e7196097308a Mon Sep 17 00:00:00 2001 From: xxm1995 Date: Wed, 8 Mar 2023 17:59:32 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E5=8A=A8=E6=80=81=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=BA=90=E7=AE=A1=E7=90=86,=20=E5=AD=97=E5=85=B8=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E9=97=AE=E9=A2=98fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Bootx/Query/Query.ts | 3 +- .../dynamicsource/DynamicDataSource.api.ts | 79 ++++++++++++++ .../dynamicsource/DynamicDataSourceEdit.vue | 40 +++++-- .../dynamicsource/DynamicDataSourceList.vue | 100 ++++++++++++++---- src/views/modules/system/dict/DictEdit.vue | 3 +- .../modules/system/dict/DictItemEdit.vue | 1 + 6 files changed, 194 insertions(+), 32 deletions(-) diff --git a/src/components/Bootx/Query/Query.ts b/src/components/Bootx/Query/Query.ts index d23d230b8..b5edeedd7 100644 --- a/src/components/Bootx/Query/Query.ts +++ b/src/components/Bootx/Query/Query.ts @@ -1,4 +1,5 @@ import { LabeledValueType } from 'ant-design-vue/lib/vc-tree-select/TreeSelect' +import { LabeledValue } from "ant-design-vue/lib/select"; // 数字 export const NUMBER = 'number' @@ -32,7 +33,7 @@ export interface QueryField { // 精度 precision?: number // 查询列表 - selectList?: LabeledValueType[] | null + selectList?: LabeledValue[] | null // 时间格式化 format?: string | null } diff --git a/src/views/modules/develop/dynamicsource/DynamicDataSource.api.ts b/src/views/modules/develop/dynamicsource/DynamicDataSource.api.ts index 7643986cd..1ea8ebf56 100644 --- a/src/views/modules/develop/dynamicsource/DynamicDataSource.api.ts +++ b/src/views/modules/develop/dynamicsource/DynamicDataSource.api.ts @@ -1,6 +1,7 @@ import { defHttp } from '/@/utils/http/axios' import { PageResult, Result } from '/#/axios' import { BaseEntity } from '/#/web' +import { LabeledValue } from 'ant-design-vue/lib/select' /** * 分页 @@ -52,6 +53,55 @@ export const testConnection = (obj: DynamicDataSource) => { }) } +/** + * 测试连接 + */ +export const testConnectionById = (id) => { + return defHttp.get>({ + url: '/dynamic/source/testConnectionById', + params: { id }, + }) +} + +/** + * 根据id进行添加到连接池中 + */ +export const addDynamicDataSourceById = (id) => { + return defHttp.post>({ + url: '/dynamic/source/addDynamicDataSourceById', + params: { id }, + }) +} + +/** + * 判断编码是否被使用 + */ +export const existsByCode = (id) => { + return defHttp.post>({ + url: '/dynamic/source/existsByCode', + params: { id }, + }) +} + +/** + * 判断编码是否被使用 + */ +export const existsByCodeNotId = (id, code) => { + return defHttp.post>({ + url: '/dynamic/source/existsByCodeNotId', + params: { id, code }, + }) +} +/** + * 判断是否已经添加到连接池中 + */ +export const existsByDataSourceKey = (code) => { + return defHttp.get>({ + url: '/dynamic/source/existsByDataSourceKey', + params: { code }, + }) +} + /** * 删除 */ @@ -92,3 +142,32 @@ export interface DynamicDataSource extends BaseEntity { // 备注 remark?: string } + +/** + * 数据类型列表 + */ +export const databaseTypes = [ + { value: 'mysql', label: 'MySQL' }, + { value: 'oracle', label: 'Oracle' }, + { value: 'mssql', label: 'SQLServer' }, +] as LabeledValue[] + +/** + * 数据类型关联信息列表 + */ +export // 数据列表 +const databaseTypeMap = { + mysql: { + dbDriver: 'com.mysql.cj.jdbc.Driver', + dbUrl: + 'jdbc:mysql://127.0.0.1:3306/bootx?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai', + }, + oracle: { + dbDriver: 'oracle.jdbc.OracleDriver', + dbUrl: 'jdbc:oracle:thin:@127.0.0.1:1521:BOOTX', + }, + mssql: { + dbDriver: 'com.microsoft.sqlserver.jdbc.SQLServerDriver', + dbUrl: 'jdbc:mysql://127.0.0.1:3306/bootx?characterEncoding=UTF-8&useUnicode=true&useSSL=false', + }, +} diff --git a/src/views/modules/develop/dynamicsource/DynamicDataSourceEdit.vue b/src/views/modules/develop/dynamicsource/DynamicDataSourceEdit.vue index 5bc36f96c..7a1426f15 100644 --- a/src/views/modules/develop/dynamicsource/DynamicDataSourceEdit.vue +++ b/src/views/modules/develop/dynamicsource/DynamicDataSourceEdit.vue @@ -14,13 +14,13 @@ - + - - + + @@ -52,11 +52,22 @@ import { nextTick, reactive } from 'vue' import { $ref } from 'vue/macros' import useFormEdit from '/@/hooks/bootx/useFormEdit' - import { add, get, update, DynamicDataSource, testConnection } from './DynamicDataSource.api' + import { + add, + get, + update, + DynamicDataSource, + testConnection, + existsByCode, + existsByCodeNotId, + databaseTypes, + databaseTypeMap, + } from './DynamicDataSource.api' import { FormInstance, Rule } from 'ant-design-vue/lib/form' import { FormEditType } from '/@/enums/formTypeEnum' import BasicDrawer from '/@/components/Drawer/src/BasicDrawer.vue' import { useMessage } from '/@/hooks/web/useMessage' + import { useValidate } from '/@/hooks/bootx/useValidate' const { initFormEditType, @@ -73,13 +84,15 @@ formEditType, } = useFormEdit() const { createMessage } = useMessage() + const { existsByServer } = useValidate() + // 表单 const formRef = $ref() + let form = $ref({ id: null, code: '', name: '', - databaseType: '', dbDriver: '', dbUrl: '', dbUsername: '', @@ -88,7 +101,10 @@ }) // 校验 const rules = reactive({ - code: [{ required: true, message: '编码不可为空' }], + code: [ + { required: true, message: '编码不可为空' }, + { validator: validateCode, trigger: 'blur' }, + ], name: [{ required: true, message: '名称不可为空' }], databaseType: [{ required: true, message: '请选择数据库类型' }], dbDriver: [{ required: true, message: '驱动不可为空' }], @@ -104,6 +120,11 @@ resetForm() getInfo(id, editType) } + // 编码更新 + function validateCode() { + const { code, id } = form + return existsByServer(code, id, formEditType, existsByCode, existsByCodeNotId) + } // 获取信息 function getInfo(id, editType: FormEditType) { if ([FormEditType.Edit, FormEditType.Show].includes(editType)) { @@ -127,7 +148,12 @@ } }) } - + // 数据源类型变换回调 + function changeDatabaseType() { + const e = form.databaseType as string + form.dbDriver = databaseTypeMap[e]?.dbDriver + form.dbUrl = databaseTypeMap[e]?.dbUrl + } // 保存 function handleOk() { formRef?.validate().then(async () => { diff --git a/src/views/modules/develop/dynamicsource/DynamicDataSourceList.vue b/src/views/modules/develop/dynamicsource/DynamicDataSourceList.vue index 8ec65c2ba..4d0661194 100644 --- a/src/views/modules/develop/dynamicsource/DynamicDataSourceList.vue +++ b/src/views/modules/develop/dynamicsource/DynamicDataSourceList.vue @@ -15,25 +15,38 @@ - + + + - + @@ -53,7 +66,7 @@ diff --git a/src/views/modules/system/dict/DictEdit.vue b/src/views/modules/system/dict/DictEdit.vue index 75a03f6e5..64df639db 100644 --- a/src/views/modules/system/dict/DictEdit.vue +++ b/src/views/modules/system/dict/DictEdit.vue @@ -25,7 +25,7 @@ - +