初始版本提交
This commit is contained in:
121
src/components/DataSourceSelect/components/DatasourceDrawer.vue
Normal file
121
src/components/DataSourceSelect/components/DatasourceDrawer.vue
Normal file
@ -0,0 +1,121 @@
|
||||
<template>
|
||||
<BasicDrawer
|
||||
v-bind="$attrs"
|
||||
@register="registerDrawer"
|
||||
showFooter
|
||||
:title="t('新增数据源')"
|
||||
width="500px"
|
||||
@ok="handleSubmit"
|
||||
>
|
||||
<BasicForm @register="registerForm" />
|
||||
</BasicDrawer>
|
||||
</template>
|
||||
<script lang="tsx" setup>
|
||||
import { h } from 'vue';
|
||||
import { BasicForm, useForm } from '/@/components/Form/index';
|
||||
import { FormSchema } from '/@/components/Table';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
import { addDatasource } from '/@/api/system/datasource';
|
||||
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
|
||||
import { CodeEditor, MODE } from '/@/components/CodeEditor';
|
||||
import { useI18n } from '/@/hooks/web/useI18n';
|
||||
const { t } = useI18n();
|
||||
const schema: FormSchema[] = [
|
||||
{
|
||||
field: 'name',
|
||||
label: t('数据源名称'),
|
||||
component: 'Input',
|
||||
required: true,
|
||||
title: t('基本信息'),
|
||||
colProps: { span: 24 },
|
||||
componentProps: {
|
||||
placeholder: t('请输入数据库名称'),
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'code',
|
||||
label: t('数据源编码'),
|
||||
component: 'Input',
|
||||
required: true,
|
||||
colProps: { span: 24 },
|
||||
componentProps: {
|
||||
placeholder: t('请输入数据库类型'),
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'databaselinkId',
|
||||
label: t('选择数据库'),
|
||||
component: 'DbSelect',
|
||||
required: true,
|
||||
colProps: { span: 24 },
|
||||
componentProps: {
|
||||
placeholder: t('请选择数据库版本'),
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'sqlScript',
|
||||
label: t('SQL脚本'),
|
||||
component: 'Input',
|
||||
colProps: { span: 24 },
|
||||
required: true,
|
||||
render: ({ model, field }) => {
|
||||
return h(CodeEditor, {
|
||||
placeholder: t('请输入'),
|
||||
value: model[field],
|
||||
mode: MODE.SQL,
|
||||
style: {
|
||||
border: '1px solid #d9d9d9',
|
||||
padding: '5px 0',
|
||||
},
|
||||
onChange: (e) => {
|
||||
model[field] = e;
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
label: t('备注'),
|
||||
component: 'InputTextArea',
|
||||
colProps: { span: 24 },
|
||||
componentProps: {
|
||||
placeholder: t('请输入数据库链接'),
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const emit = defineEmits(['success', 'register']);
|
||||
|
||||
const { notification } = useMessage();
|
||||
|
||||
const [registerForm, { resetFields, validate }] = useForm({
|
||||
labelWidth: 100,
|
||||
schemas: schema,
|
||||
showActionButtonGroup: false,
|
||||
actionColOptions: {
|
||||
span: 23,
|
||||
},
|
||||
});
|
||||
|
||||
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async () => {
|
||||
resetFields();
|
||||
setDrawerProps({ confirmLoading: false });
|
||||
});
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
const values = await validate();
|
||||
|
||||
setDrawerProps({ confirmLoading: true });
|
||||
await addDatasource(values);
|
||||
notification.success({
|
||||
message: t('提示'),
|
||||
description: t('数据源新增成功!'),
|
||||
}); //提示消息
|
||||
closeDrawer();
|
||||
emit('success');
|
||||
} finally {
|
||||
setDrawerProps({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
4
src/components/DataSourceSelect/index.ts
Normal file
4
src/components/DataSourceSelect/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { withInstall } from '/@/utils/index';
|
||||
import datasourceSelect from './src/DatasourceSelect.vue';
|
||||
|
||||
export const DatasourceSelect = withInstall(datasourceSelect);
|
||||
81
src/components/DataSourceSelect/src/DatasourceSelect.vue
Normal file
81
src/components/DataSourceSelect/src/DatasourceSelect.vue
Normal file
@ -0,0 +1,81 @@
|
||||
<template>
|
||||
<div>
|
||||
<Select
|
||||
v-model:value="value"
|
||||
style="width: 100%"
|
||||
:options="data.map((item) => ({ value: item.id, label: item.name }))"
|
||||
:placeholder="t('请选择数据选项')"
|
||||
>
|
||||
<template #dropdownRender="{ menuNode: menu }">
|
||||
<component :is="menu" />
|
||||
<Divider style="margin: 4px 0" />
|
||||
<div
|
||||
style="padding: 4px 8px; cursor: pointer"
|
||||
@mousedown="(e) => e.preventDefault()"
|
||||
@click="add"
|
||||
>
|
||||
<PlusOutlined />
|
||||
{{ t('新增') }}
|
||||
</div>
|
||||
</template>
|
||||
</Select>
|
||||
<DatasourceDrawer @register="registerDbDrawer" @success="handleDetailSuccess" />
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { Select, Divider } from 'ant-design-vue';
|
||||
import { PlusOutlined } from '@ant-design/icons-vue';
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
import { getDatasourceList } from '/@/api/system/datasource';
|
||||
import { useDrawer } from '../../Drawer';
|
||||
import DatasourceDrawer from '../components/DatasourceDrawer.vue';
|
||||
import { useI18n } from '/@/hooks/web/useI18n';
|
||||
const { t } = useI18n();
|
||||
const emit = defineEmits(['update:value', 'change']);
|
||||
|
||||
const props = defineProps({
|
||||
value: String,
|
||||
});
|
||||
|
||||
const value = ref();
|
||||
|
||||
const data = ref<Recordable[]>([]);
|
||||
|
||||
onMounted(() => {
|
||||
fetch();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.value,
|
||||
(val) => {
|
||||
value.value = val;
|
||||
|
||||
// emit('change', val);
|
||||
// emit('update:value', value.value);
|
||||
},
|
||||
{ deep: true, immediate: true },
|
||||
);
|
||||
|
||||
watch(
|
||||
() => value,
|
||||
() => {
|
||||
emit('change', value.value);
|
||||
emit('update:value', value.value);
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
async function fetch() {
|
||||
data.value = await getDatasourceList();
|
||||
}
|
||||
|
||||
const [registerDbDrawer, { openDrawer }] = useDrawer();
|
||||
|
||||
const add = () => {
|
||||
openDrawer(true);
|
||||
};
|
||||
|
||||
const handleDetailSuccess = () => {
|
||||
fetch();
|
||||
};
|
||||
</script>
|
||||
Reference in New Issue
Block a user