feat: 代码生成
This commit is contained in:
parent
c1e58831e1
commit
358efd9630
@ -1,6 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { Recordable } from '@vben/types';
|
import type { Recordable } from '@vben/types';
|
||||||
import type { ColumnsType } from 'ant-design-vue/es/table';
|
import type { ColumnsType } from 'ant-design-vue/es/table';
|
||||||
|
import type { Key } from 'ant-design-vue/es/table/interface';
|
||||||
|
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
@ -69,6 +70,30 @@ async function handleSync(record: Recordable<any>) {
|
|||||||
// reload
|
// reload
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const selectedRowKeys = ref<string[]>([]);
|
||||||
|
function handleSelectChange(selectedKeys: Key[]) {
|
||||||
|
selectedRowKeys.value = selectedKeys as string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量生成代码
|
||||||
|
*/
|
||||||
|
async function handleBatchGen() {
|
||||||
|
if (selectedRowKeys.value.length === 0) {
|
||||||
|
message.info('请选择需要生成代码的表');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const hideLoading = message.loading('下载中...');
|
||||||
|
try {
|
||||||
|
const params = selectedRowKeys.value.join(',');
|
||||||
|
const data = await batchGenCode(params);
|
||||||
|
const timestamp = Date.now();
|
||||||
|
downloadByData(data, `批量代码生成_${timestamp}.zip`);
|
||||||
|
} finally {
|
||||||
|
hideLoading();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleDownload(record: Recordable<any>) {
|
async function handleDownload(record: Recordable<any>) {
|
||||||
const hideLoading = message.loading('下载中...');
|
const hideLoading = message.loading('下载中...');
|
||||||
try {
|
try {
|
||||||
@ -82,6 +107,10 @@ async function handleDownload(record: Recordable<any>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
* @param record
|
||||||
|
*/
|
||||||
async function handleDelete(record: Recordable<any>) {
|
async function handleDelete(record: Recordable<any>) {
|
||||||
await genRemove(record.tableId);
|
await genRemove(record.tableId);
|
||||||
// reload
|
// reload
|
||||||
@ -112,39 +141,76 @@ const [QueryForm] = useVbenForm({
|
|||||||
<Card>
|
<Card>
|
||||||
<QueryForm />
|
<QueryForm />
|
||||||
</Card>
|
</Card>
|
||||||
<Table :columns="columns" :data-source="dataSource" e="middle">
|
<Card
|
||||||
<template #bodyCell="{ record, column }">
|
:body-style="{
|
||||||
<template v-if="column.dataIndex === 'action'">
|
padding: '12px',
|
||||||
<a-button size="small" type="link" @click="handlePreview(record)">
|
display: 'flex',
|
||||||
{{ $t('pages.common.preview') }}
|
flexDirection: 'column',
|
||||||
</a-button>
|
gap: '12px',
|
||||||
<a-button size="small" type="link" @click="handleEdit(record)">
|
}"
|
||||||
{{ $t('pages.common.edit') }}
|
>
|
||||||
</a-button>
|
<div class="flex justify-between">
|
||||||
<Popconfirm
|
<span class="text-lg font-bold">代码生成列表</span>
|
||||||
:title="`确认同步[${record.tableName}]?`"
|
<div class="flex gap-[8px]">
|
||||||
placement="left"
|
<a-button
|
||||||
@confirm="handleSync(record)"
|
:disabled="selectedRowKeys.length === 0"
|
||||||
|
danger
|
||||||
|
type="primary"
|
||||||
>
|
>
|
||||||
<a-button size="small" type="link">
|
删除
|
||||||
{{ $t('pages.common.sync') }}
|
|
||||||
</a-button>
|
|
||||||
</Popconfirm>
|
|
||||||
<a-button size="small" type="link" @click="handleDownload(record)">
|
|
||||||
生成代码
|
|
||||||
</a-button>
|
</a-button>
|
||||||
<Popconfirm
|
<a-button
|
||||||
:title="`确认删除[${record.tableName}]?`"
|
:disabled="selectedRowKeys.length === 0"
|
||||||
placement="left"
|
@click="handleBatchGen"
|
||||||
@confirm="handleDelete(record)"
|
|
||||||
>
|
>
|
||||||
<a-button danger size="small" type="link">
|
{{ $t('pages.common.generate') }}
|
||||||
{{ $t('pages.common.delete') }}
|
</a-button>
|
||||||
|
<a-button type="primary">
|
||||||
|
{{ $t('pages.common.import') }}
|
||||||
|
</a-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Table
|
||||||
|
:columns="columns"
|
||||||
|
:data-source="dataSource"
|
||||||
|
:row-selection="{ selectedRowKeys, onChange: handleSelectChange }"
|
||||||
|
row-key="tableId"
|
||||||
|
size="middle"
|
||||||
|
>
|
||||||
|
<template #bodyCell="{ record, column }">
|
||||||
|
<template v-if="column.dataIndex === 'action'">
|
||||||
|
<a-button size="small" type="link" @click="handlePreview(record)">
|
||||||
|
{{ $t('pages.common.preview') }}
|
||||||
</a-button>
|
</a-button>
|
||||||
</Popconfirm>
|
<a-button size="small" type="link" @click="handleEdit(record)">
|
||||||
|
{{ $t('pages.common.edit') }}
|
||||||
|
</a-button>
|
||||||
|
<Popconfirm
|
||||||
|
:title="`确认同步[${record.tableName}]?`"
|
||||||
|
placement="left"
|
||||||
|
@confirm="handleSync(record)"
|
||||||
|
>
|
||||||
|
<a-button size="small" type="link">
|
||||||
|
{{ $t('pages.common.sync') }}
|
||||||
|
</a-button>
|
||||||
|
</Popconfirm>
|
||||||
|
<a-button size="small" type="link" @click="handleDownload(record)">
|
||||||
|
生成代码
|
||||||
|
</a-button>
|
||||||
|
<Popconfirm
|
||||||
|
:title="`确认删除[${record.tableName}]?`"
|
||||||
|
placement="left"
|
||||||
|
@confirm="handleDelete(record)"
|
||||||
|
>
|
||||||
|
<a-button danger size="small" type="link">
|
||||||
|
{{ $t('pages.common.delete') }}
|
||||||
|
</a-button>
|
||||||
|
</Popconfirm>
|
||||||
|
</template>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</Table>
|
||||||
</Table>
|
</Card>
|
||||||
|
|
||||||
<CodePreviewModal />
|
<CodePreviewModal />
|
||||||
</Page>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
Loading…
Reference in New Issue
Block a user