fix 数据源管理表单校验

This commit is contained in:
lbw 2023-03-12 11:31:52 +08:00
parent 1063d68063
commit fb764ef176
5 changed files with 142 additions and 112 deletions

140
auto-imports.d.ts vendored
View File

@ -1,73 +1,73 @@
// Generated by 'unplugin-auto-import'
export {};
export {}
declare global {
const EffectScope: typeof import('vue')['EffectScope'];
const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate'];
const computed: typeof import('vue')['computed'];
const createApp: typeof import('vue')['createApp'];
const createPinia: typeof import('pinia')['createPinia'];
const customRef: typeof import('vue')['customRef'];
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent'];
const defineComponent: typeof import('vue')['defineComponent'];
const defineStore: typeof import('pinia')['defineStore'];
const effectScope: typeof import('vue')['effectScope'];
const getActivePinia: typeof import('pinia')['getActivePinia'];
const getCurrentInstance: typeof import('vue')['getCurrentInstance'];
const getCurrentScope: typeof import('vue')['getCurrentScope'];
const h: typeof import('vue')['h'];
const inject: typeof import('vue')['inject'];
const isProxy: typeof import('vue')['isProxy'];
const isReactive: typeof import('vue')['isReactive'];
const isReadonly: typeof import('vue')['isReadonly'];
const isRef: typeof import('vue')['isRef'];
const mapActions: typeof import('pinia')['mapActions'];
const mapGetters: typeof import('pinia')['mapGetters'];
const mapState: typeof import('pinia')['mapState'];
const mapStores: typeof import('pinia')['mapStores'];
const mapWritableState: typeof import('pinia')['mapWritableState'];
const markRaw: typeof import('vue')['markRaw'];
const nextTick: typeof import('vue')['nextTick'];
const onActivated: typeof import('vue')['onActivated'];
const onBeforeMount: typeof import('vue')['onBeforeMount'];
const onBeforeRouteLeave: typeof import('vue-router')['onBeforeRouteLeave'];
const onBeforeRouteUpdate: typeof import('vue-router')['onBeforeRouteUpdate'];
const onBeforeUnmount: typeof import('vue')['onBeforeUnmount'];
const onBeforeUpdate: typeof import('vue')['onBeforeUpdate'];
const onDeactivated: typeof import('vue')['onDeactivated'];
const onErrorCaptured: typeof import('vue')['onErrorCaptured'];
const onMounted: typeof import('vue')['onMounted'];
const onRenderTracked: typeof import('vue')['onRenderTracked'];
const onRenderTriggered: typeof import('vue')['onRenderTriggered'];
const onScopeDispose: typeof import('vue')['onScopeDispose'];
const onServerPrefetch: typeof import('vue')['onServerPrefetch'];
const onUnmounted: typeof import('vue')['onUnmounted'];
const onUpdated: typeof import('vue')['onUpdated'];
const provide: typeof import('vue')['provide'];
const reactive: typeof import('vue')['reactive'];
const readonly: typeof import('vue')['readonly'];
const ref: typeof import('vue')['ref'];
const resolveComponent: typeof import('vue')['resolveComponent'];
const resolveDirective: typeof import('vue')['resolveDirective'];
const setActivePinia: typeof import('pinia')['setActivePinia'];
const setMapStoreSuffix: typeof import('pinia')['setMapStoreSuffix'];
const shallowReactive: typeof import('vue')['shallowReactive'];
const shallowReadonly: typeof import('vue')['shallowReadonly'];
const shallowRef: typeof import('vue')['shallowRef'];
const storeToRefs: typeof import('pinia')['storeToRefs'];
const toRaw: typeof import('vue')['toRaw'];
const toRef: typeof import('vue')['toRef'];
const toRefs: typeof import('vue')['toRefs'];
const triggerRef: typeof import('vue')['triggerRef'];
const unref: typeof import('vue')['unref'];
const useAttrs: typeof import('vue')['useAttrs'];
const useCssModule: typeof import('vue')['useCssModule'];
const useCssVars: typeof import('vue')['useCssVars'];
const useLink: typeof import('vue-router')['useLink'];
const useRoute: typeof import('vue-router')['useRoute'];
const useRouter: typeof import('vue-router')['useRouter'];
const useSlots: typeof import('vue')['useSlots'];
const watch: typeof import('vue')['watch'];
const watchEffect: typeof import('vue')['watchEffect'];
const watchPostEffect: typeof import('vue')['watchPostEffect'];
const watchSyncEffect: typeof import('vue')['watchSyncEffect'];
const EffectScope: typeof import('vue')['EffectScope']
const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate']
const computed: typeof import('vue')['computed']
const createApp: typeof import('vue')['createApp']
const createPinia: typeof import('pinia')['createPinia']
const customRef: typeof import('vue')['customRef']
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
const defineComponent: typeof import('vue')['defineComponent']
const defineStore: typeof import('pinia')['defineStore']
const effectScope: typeof import('vue')['effectScope']
const getActivePinia: typeof import('pinia')['getActivePinia']
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
const getCurrentScope: typeof import('vue')['getCurrentScope']
const h: typeof import('vue')['h']
const inject: typeof import('vue')['inject']
const isProxy: typeof import('vue')['isProxy']
const isReactive: typeof import('vue')['isReactive']
const isReadonly: typeof import('vue')['isReadonly']
const isRef: typeof import('vue')['isRef']
const mapActions: typeof import('pinia')['mapActions']
const mapGetters: typeof import('pinia')['mapGetters']
const mapState: typeof import('pinia')['mapState']
const mapStores: typeof import('pinia')['mapStores']
const mapWritableState: typeof import('pinia')['mapWritableState']
const markRaw: typeof import('vue')['markRaw']
const nextTick: typeof import('vue')['nextTick']
const onActivated: typeof import('vue')['onActivated']
const onBeforeMount: typeof import('vue')['onBeforeMount']
const onBeforeRouteLeave: typeof import('vue-router')['onBeforeRouteLeave']
const onBeforeRouteUpdate: typeof import('vue-router')['onBeforeRouteUpdate']
const onBeforeUnmount: typeof import('vue')['onBeforeUnmount']
const onBeforeUpdate: typeof import('vue')['onBeforeUpdate']
const onDeactivated: typeof import('vue')['onDeactivated']
const onErrorCaptured: typeof import('vue')['onErrorCaptured']
const onMounted: typeof import('vue')['onMounted']
const onRenderTracked: typeof import('vue')['onRenderTracked']
const onRenderTriggered: typeof import('vue')['onRenderTriggered']
const onScopeDispose: typeof import('vue')['onScopeDispose']
const onServerPrefetch: typeof import('vue')['onServerPrefetch']
const onUnmounted: typeof import('vue')['onUnmounted']
const onUpdated: typeof import('vue')['onUpdated']
const provide: typeof import('vue')['provide']
const reactive: typeof import('vue')['reactive']
const readonly: typeof import('vue')['readonly']
const ref: typeof import('vue')['ref']
const resolveComponent: typeof import('vue')['resolveComponent']
const resolveDirective: typeof import('vue')['resolveDirective']
const setActivePinia: typeof import('pinia')['setActivePinia']
const setMapStoreSuffix: typeof import('pinia')['setMapStoreSuffix']
const shallowReactive: typeof import('vue')['shallowReactive']
const shallowReadonly: typeof import('vue')['shallowReadonly']
const shallowRef: typeof import('vue')['shallowRef']
const storeToRefs: typeof import('pinia')['storeToRefs']
const toRaw: typeof import('vue')['toRaw']
const toRef: typeof import('vue')['toRef']
const toRefs: typeof import('vue')['toRefs']
const triggerRef: typeof import('vue')['triggerRef']
const unref: typeof import('vue')['unref']
const useAttrs: typeof import('vue')['useAttrs']
const useCssModule: typeof import('vue')['useCssModule']
const useCssVars: typeof import('vue')['useCssVars']
const useLink: typeof import('vue-router')['useLink']
const useRoute: typeof import('vue-router')['useRoute']
const useRouter: typeof import('vue-router')['useRouter']
const useSlots: typeof import('vue')['useSlots']
const watch: typeof import('vue')['watch']
const watchEffect: typeof import('vue')['watchEffect']
const watchPostEffect: typeof import('vue')['watchPostEffect']
const watchSyncEffect: typeof import('vue')['watchSyncEffect']
}

View File

@ -3,13 +3,15 @@
<el-form ref="dataFormRef" :model="form" :rules="dataRules" formDialogRef label-width="90px">
<el-row :gutter="20">
<el-col :span="12" class="mb20">
<el-form-item :label="t('datasourceconf.name')" prop="name">
<el-input v-model="form.name" :placeholder="t('datasourceconf.inputnameTip')" />
<el-form-item :label="t('datasourceconf.dsType')" prop="dsType">
<el-select v-model="form.dsType" :placeholder="t('datasourceconf.inputdsTypeTip')">
<el-option :key="item.value" :label="item.label" :value="item.value" v-for="item in ds_type"> </el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item :label="t('datasourceconf.url')" prop="url">
<el-input v-model="form.url" :placeholder="t('datasourceconf.inputurlTip')" />
<el-form-item :label="t('datasourceconf.name')" prop="name">
<el-input v-model="form.name" :placeholder="t('datasourceconf.inputnameTip')" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
@ -22,11 +24,6 @@
<el-input v-model="form.password" :placeholder="t('datasourceconf.inputpasswordTip')" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item :label="t('datasourceconf.dsType')" prop="dsType">
<el-input v-model="form.dsType" :placeholder="t('datasourceconf.inputdsTypeTip')" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item :label="t('datasourceconf.confType')" prop="confType">
<el-radio-group v-model="form.confType">
@ -34,26 +31,31 @@
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item :label="t('datasourceconf.dsName')" prop="dsName">
<el-input v-model="form.dsName" :placeholder="t('datasourceconf.inputdsNameTip')" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-col :span="12" class="mb20" v-if="form.confType === 0 && form.dsType === 'mssql'">
<el-form-item :label="t('datasourceconf.instance')" prop="instance">
<el-input v-model="form.instance" :placeholder="t('datasourceconf.inputinstanceTip')" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-col :span="12" class="mb20" v-if="form.confType === 0">
<el-form-item :label="t('datasourceconf.port')" prop="port">
<el-input v-model="form.port" :placeholder="t('datasourceconf.inputportTip')" />
<el-input-number v-model="form.port" :placeholder="t('datasourceconf.inputportTip')" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-col :span="12" class="mb20" v-if="form.confType === 0">
<el-form-item :label="t('datasourceconf.host')" prop="host">
<el-input v-model="form.host" :placeholder="t('datasourceconf.inputhostTip')" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb20" v-if="form.confType === 0">
<el-form-item :label="t('datasourceconf.dsName')" prop="dsName">
<el-input v-model="form.dsName" :placeholder="t('datasourceconf.inputdsNameTip')" />
</el-form-item>
</el-col>
<el-col :span="24" class="mb20" v-if="form.confType === 1">
<el-form-item :label="t('datasourceconf.url')" prop="url">
<el-input v-model="form.url" type="textarea" :placeholder="t('datasourceconf.inputurlTip')" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
@ -66,20 +68,21 @@
</template>
<script setup lang="ts" name="systemDatasourceConfDialog">
// /
const emit = defineEmits(['refresh']);
import { useMessage } from '/@/hooks/message';
import { getObj, addObj, putObj } from '/@/api/gen/datasource';
import { useI18n } from 'vue-i18n';
import { useDict } from '/@/hooks/dict';
// /
const emit = defineEmits(['refresh']);
const { t } = useI18n();
//
const dataFormRef = ref();
const visible = ref(false);
const { ds_config_type } = useDict('ds_config_type');
//
const { ds_config_type, ds_type } = useDict('ds_config_type', 'ds_type');
//
const form = reactive({
@ -94,13 +97,31 @@ const form = reactive({
confType: 0,
dsName: '',
instance: '',
port: '',
port: 0,
host: '',
});
/**
*
* @param {校验数据源名} rule
* @param {*} value
* @param {*} callback
*/
const validateDsName = (_rule, value, callback) => {
var re = /(?=.*[a-z])(?=.*_)/;
if (value && !re.test(value)) {
callback(new Error('数据源名称不合法, 组名_数据源名形式'));
} else {
callback();
}
};
//
const dataRules = ref({
name: [{ required: true, message: '别名不能为空', trigger: 'blur' }],
name: [
{ required: true, message: '别名不能为空', trigger: 'blur' },
{ validator: validateDsName, trigger: 'blur' },
],
url: [{ required: true, message: 'jdbcurl不能为空', trigger: 'blur' }],
username: [{ required: true, message: '用户名不能为空', trigger: 'blur' }],
password: [{ required: true, message: '密码不能为空', trigger: 'blur' }],
@ -113,7 +134,7 @@ const dataRules = ref({
});
//
const openDialog = (id: string) => {
const openDialog = async (id: string) => {
visible.value = true;
form.id = '';
@ -125,7 +146,9 @@ const openDialog = (id: string) => {
// DatasourceConf
if (id) {
form.id = id;
getDatasourceConfData(id);
await getDatasourceConfData(id);
//
form.password = '********';
}
};
@ -138,6 +161,10 @@ const onSubmit = () => {
//
if (form.id) {
if (form.password.indexOf('********') === 0) {
form.password = '';
}
putObj(form)
.then(() => {
useMessage().success(t('common.editSuccessText'));
@ -164,7 +191,7 @@ const onSubmit = () => {
//
const getDatasourceConfData = (id: string) => {
//
getObj(id).then((res: any) => {
return getObj(id).then((res: any) => {
Object.assign(form, res.data);
});
};

View File

@ -4,7 +4,7 @@ export default {
importDatasourceConfTip: '导入数据源',
id: '主键',
name: '别名',
url: 'jdbcurl',
url: 'jdbc-url',
username: '用户名',
password: '密码',
docBtn: '文档',
@ -12,9 +12,9 @@ export default {
updateTime: '更新',
delFlag: '删除标记',
tenantId: '租户ID',
dsType: '数据库类型',
dsType: '类型',
confType: '配置类型',
dsName: '数据库名称',
dsName: '库名称',
instance: '实例',
port: '端口',
host: '主机',

View File

@ -111,7 +111,7 @@ const handleDelete = (row: any) => {
}
useMessageBox()
.confirm(t('common.delConfirmText') + row.id)
.confirm(t('common.delConfirmText'))
.then(() => {
delObj(row.id)
.then(() => {

View File

@ -6,20 +6,23 @@
<el-step title="数据修改" />
</el-steps>
</el-card>
<el-card class="layout-padding-auto" style="margin-top: 20px" shadow="hover" v-if="active === 0">
<generator ref="generatorRef" :tableName="tableName" :dsName="dsName"></generator>
<el-card class="layout-padding-auto" style="margin-top: 20px" shadow="hover">
<!-- 生成基本信息设置 -->
<generator ref="generatorRef" :tableName="tableName" :dsName="dsName" v-if="active === 0" />
<!-- 字段编辑设置 -->
<edit-table ref="editTableRef" :tableName="tableName" :dsName="dsName" v-if="active === 1" />
<div style="text-align: center">
<el-button style="margin-top: 12px" @click="pre" v-if="active > 0">上一步</el-button>
<el-button style="margin-top: 12px" @click="next" v-if="active < 1">下一步</el-button>
<el-button style="margin-top: 12px" @click="preview" v-if="active === 1">保存并预览</el-button>
<el-button style="margin-top: 12px" @click="generatorHandle" v-if="active === 1">保存并生成</el-button>
</div>
</el-card>
<el-card class="layout-padding-auto" style="margin-top: 20px" shadow="hover" v-if="active === 1">
<edit-table ref="editTableRef" :tableName="tableName" :dsName="dsName"></edit-table>
</el-card>
<el-space wrap style="justify-content: center">
<el-button style="margin-top: 12px" @click="pre" v-if="active > 0">上一步</el-button>
<el-button style="margin-top: 12px" @click="next" v-if="active < 1">下一步</el-button>
<el-button style="margin-top: 12px" @click="preview" v-if="active === 1">保存并预览</el-button>
<el-button style="margin-top: 12px" @click="generatorHandle" v-if="active === 1">保存并生成</el-button>
</el-space>
<preview-dialog ref="previewDialogRef"></preview-dialog>
<!-- 预览基本信息 -->
<preview-dialog ref="previewDialogRef" />
</div>
</template>