2024-10-05 18:01:17 +08:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { useVbenModal, type VbenFormProps } from '@vben/common-ui';
|
|
|
|
|
2024-10-17 15:16:22 +08:00
|
|
|
import { useVbenVxeGrid, type VxeGridProps } from '#/adapter/vxe-table';
|
2024-10-09 16:46:06 +08:00
|
|
|
import {
|
|
|
|
getDataSourceNames,
|
|
|
|
importTable,
|
|
|
|
readyToGenList,
|
|
|
|
} from '#/api/tool/gen';
|
2024-10-05 18:01:17 +08:00
|
|
|
|
|
|
|
const emit = defineEmits<{ reload: [] }>();
|
|
|
|
|
|
|
|
const formOptions: VbenFormProps = {
|
|
|
|
schema: [
|
|
|
|
{
|
|
|
|
label: '数据源',
|
|
|
|
fieldName: 'dataName',
|
|
|
|
component: 'Select',
|
|
|
|
defaultValue: 'master',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '表名称',
|
|
|
|
fieldName: 'tableName',
|
|
|
|
component: 'Input',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '表描述',
|
|
|
|
fieldName: 'tableComment',
|
|
|
|
component: 'Input',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
commonConfig: {
|
|
|
|
labelWidth: 60,
|
|
|
|
},
|
|
|
|
showCollapseButton: false,
|
|
|
|
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3',
|
|
|
|
};
|
|
|
|
|
|
|
|
const gridOptions: VxeGridProps = {
|
|
|
|
checkboxConfig: {
|
|
|
|
highlight: true,
|
|
|
|
reserve: true,
|
|
|
|
trigger: 'row',
|
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
type: 'checkbox',
|
|
|
|
width: 60,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '表名称',
|
|
|
|
field: 'tableName',
|
|
|
|
align: 'left',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '表描述',
|
|
|
|
field: 'tableComment',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '创建时间',
|
|
|
|
field: 'createTime',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '更新时间',
|
|
|
|
field: 'updateTime',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
keepSource: true,
|
|
|
|
size: 'small',
|
2024-10-07 16:56:32 +08:00
|
|
|
minHeight: 400,
|
2024-10-05 18:01:17 +08:00
|
|
|
pagerConfig: {},
|
|
|
|
proxyConfig: {
|
|
|
|
ajax: {
|
2024-10-06 10:00:59 +08:00
|
|
|
query: async ({ page }, formValues = {}) => {
|
2024-10-05 18:01:17 +08:00
|
|
|
return await readyToGenList({
|
|
|
|
pageNum: page.currentPage,
|
|
|
|
pageSize: page.pageSize,
|
|
|
|
...formValues,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
rowConfig: {
|
|
|
|
isHover: true,
|
|
|
|
keyField: 'tableId',
|
|
|
|
},
|
2024-11-11 15:06:36 +08:00
|
|
|
toolbarConfig: {
|
|
|
|
refresh: false,
|
|
|
|
zoom: false,
|
|
|
|
custom: false,
|
|
|
|
},
|
2024-10-05 18:01:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const [BasicTable, tableApi] = useVbenVxeGrid({ formOptions, gridOptions });
|
|
|
|
|
|
|
|
const [BasicModal, modalApi] = useVbenModal({
|
|
|
|
onOpenChange: async (isOpen) => {
|
|
|
|
if (!isOpen) {
|
|
|
|
tableApi.grid.clearCheckboxRow();
|
|
|
|
return null;
|
|
|
|
}
|
2024-10-09 16:46:06 +08:00
|
|
|
const ret = await getDataSourceNames();
|
|
|
|
const dataSourceOptions = ret.map((item) => ({ label: item, value: item }));
|
|
|
|
tableApi.formApi.updateSchema([
|
|
|
|
{
|
|
|
|
fieldName: 'dataName',
|
|
|
|
componentProps: {
|
|
|
|
options: dataSourceOptions,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
2024-10-05 18:01:17 +08:00
|
|
|
},
|
|
|
|
onConfirm: handleSubmit,
|
|
|
|
});
|
|
|
|
|
|
|
|
async function handleSubmit() {
|
|
|
|
try {
|
|
|
|
const records = tableApi.grid.getCheckboxRecords();
|
|
|
|
const tables = records.map((item) => item.tableName);
|
|
|
|
if (tables.length === 0) {
|
|
|
|
modalApi.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
modalApi.modalLoading(true);
|
2024-10-09 16:46:06 +08:00
|
|
|
const { dataName } = await tableApi.formApi.getValues();
|
|
|
|
await importTable(tables.join(','), dataName);
|
2024-10-05 18:01:17 +08:00
|
|
|
emit('reload');
|
|
|
|
modalApi.close();
|
|
|
|
} catch (error) {
|
|
|
|
console.warn(error);
|
|
|
|
} finally {
|
|
|
|
modalApi.modalLoading(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<BasicModal class="w-[800px]" title="导入表">
|
|
|
|
<BasicTable />
|
|
|
|
</BasicModal>
|
|
|
|
</template>
|