feat(generator): 新增代码批量生成功能
This commit is contained in:
@@ -10,6 +10,7 @@ export interface TableRecord {
|
|||||||
charset: string;
|
charset: string;
|
||||||
createTime?: string;
|
createTime?: string;
|
||||||
isConfiged: boolean;
|
isConfiged: boolean;
|
||||||
|
disabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TableParam {
|
export interface TableParam {
|
||||||
@@ -87,9 +88,9 @@ export function preview(tableName: string) {
|
|||||||
return axios.get<GeneratePreviewRecord[]>(`${BASE_URL}/preview/${tableName}`);
|
return axios.get<GeneratePreviewRecord[]>(`${BASE_URL}/preview/${tableName}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generate(tableName: string) {
|
export function generate(tableNames: Array<string>) {
|
||||||
return axios.request({
|
return axios.request({
|
||||||
url: `${BASE_URL}/${tableName}`,
|
url: `${BASE_URL}/${tableNames}`,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
responseType: 'blob',
|
responseType: 'blob',
|
||||||
});
|
});
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
preview,
|
preview,
|
||||||
generate,
|
generate,
|
||||||
} from '@/api/tool/generator';
|
} from '@/api/tool/generator';
|
||||||
|
import {TableData} from "@arco-design/web-vue";
|
||||||
|
|
||||||
const { proxy } = getCurrentInstance() as any;
|
const { proxy } = getCurrentInstance() as any;
|
||||||
const { form_type_enum, query_type_enum } = proxy.useDict(
|
const { form_type_enum, query_type_enum } = proxy.useDict(
|
||||||
@@ -27,12 +28,16 @@
|
|||||||
|
|
||||||
const queryFormRef = ref();
|
const queryFormRef = ref();
|
||||||
const formRef = ref();
|
const formRef = ref();
|
||||||
|
const tableRef = ref();
|
||||||
const { copy, copied } = useClipboard();
|
const { copy, copied } = useClipboard();
|
||||||
const extensions = [java(), javascript()];
|
const extensions = [java(), javascript()];
|
||||||
const tableList = ref<TableRecord[]>([]);
|
const tableList = ref<TableRecord[]>([]);
|
||||||
const fieldConfigList = ref<FieldConfigRecord[]>([]);
|
const fieldConfigList = ref<FieldConfigRecord[]>([]);
|
||||||
const total = ref(0);
|
const total = ref(0);
|
||||||
|
const ids = ref<Array<string>>([]);
|
||||||
const title = ref('');
|
const title = ref('');
|
||||||
|
const single = ref(true);
|
||||||
|
const multiple = ref(true);
|
||||||
const showQuery = ref(true);
|
const showQuery = ref(true);
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const visible = ref(false);
|
const visible = ref(false);
|
||||||
@@ -80,6 +85,45 @@
|
|||||||
};
|
};
|
||||||
getList();
|
getList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点击行选择器
|
||||||
|
*/
|
||||||
|
const handleSelect = (rowKeys: any, rowKey: any, record: TableData) => {
|
||||||
|
if (rowKeys.find((key: any) => key === rowKey)) {
|
||||||
|
if (record.children) {
|
||||||
|
record.children.forEach((r) => {
|
||||||
|
tableRef.value.select(r.id);
|
||||||
|
rowKeys.push(r.id);
|
||||||
|
if (r.children) {
|
||||||
|
handleSelect(rowKeys, rowKey, r);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (record.children) {
|
||||||
|
record.children.forEach((r) => {
|
||||||
|
rowKeys.splice(
|
||||||
|
rowKeys.findIndex((key: number | undefined) => key === r.id),
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
tableRef.value.select(r.id, false);
|
||||||
|
if (r.children) {
|
||||||
|
handleSelect(rowKeys, rowKey, r);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 已选择的数据行发生改变
|
||||||
|
*
|
||||||
|
* @param rowKeys ID 列表
|
||||||
|
*/
|
||||||
|
const handleSelectionChange = (rowKeys: Array<any>) => {
|
||||||
|
ids.value = rowKeys;
|
||||||
|
single.value = rowKeys.length !== 1;
|
||||||
|
multiple.value = !rowKeys.length;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打开配置对话框
|
* 打开配置对话框
|
||||||
*
|
*
|
||||||
@@ -199,13 +243,24 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量生成代码
|
||||||
|
*/
|
||||||
|
const handleBatchGenerate = () => {
|
||||||
|
if (ids.value.length === 0) {
|
||||||
|
proxy.$message.info('请选择生成的表数据');
|
||||||
|
} else {
|
||||||
|
handleGenerate(ids.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成代码
|
* 生成代码
|
||||||
*
|
*
|
||||||
* @param tableName 表名称
|
* @param tableNames 表名称
|
||||||
*/
|
*/
|
||||||
const handleGenerate = (tableName: string) => {
|
const handleGenerate = (tableNames: Array<string>) => {
|
||||||
generate(tableName).then((res) => {
|
generate(tableNames).then((res) => {
|
||||||
const contentDisposition = res.headers['content-disposition'];
|
const contentDisposition = res.headers['content-disposition'];
|
||||||
const pattern = new RegExp('filename=([^;]+\\.[^\\.;]+);*');
|
const pattern = new RegExp('filename=([^;]+\\.[^\\.;]+);*');
|
||||||
const result = pattern.exec(contentDisposition) || '';
|
const result = pattern.exec(contentDisposition) || '';
|
||||||
@@ -300,6 +355,12 @@
|
|||||||
<a-button @click="resetQuery">
|
<a-button @click="resetQuery">
|
||||||
<template #icon><icon-refresh /></template>重置
|
<template #icon><icon-refresh /></template>重置
|
||||||
</a-button>
|
</a-button>
|
||||||
|
<a-button
|
||||||
|
type="outline"
|
||||||
|
@click="handleBatchGenerate"
|
||||||
|
>
|
||||||
|
<template #icon><icon-robot-add /></template>批量生成
|
||||||
|
</a-button>
|
||||||
</a-space>
|
</a-space>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-form>
|
</a-form>
|
||||||
@@ -311,6 +372,11 @@
|
|||||||
row-key="tableName"
|
row-key="tableName"
|
||||||
:data="tableList"
|
:data="tableList"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
|
:row-selection="{
|
||||||
|
type: 'checkbox',
|
||||||
|
showCheckedAll: true,
|
||||||
|
onlyCurrent: false,
|
||||||
|
}"
|
||||||
:pagination="{
|
:pagination="{
|
||||||
showTotal: true,
|
showTotal: true,
|
||||||
showPageSize: true,
|
showPageSize: true,
|
||||||
@@ -321,6 +387,8 @@
|
|||||||
column-resizable
|
column-resizable
|
||||||
stripe
|
stripe
|
||||||
size="large"
|
size="large"
|
||||||
|
@select="handleSelect"
|
||||||
|
@selection-change="handleSelectionChange"
|
||||||
@page-change="handlePageChange"
|
@page-change="handlePageChange"
|
||||||
@page-size-change="handlePageSizeChange"
|
@page-size-change="handlePageSizeChange"
|
||||||
>
|
>
|
||||||
@@ -359,7 +427,7 @@
|
|||||||
size="small"
|
size="small"
|
||||||
:title="record.isConfiged ? '生成' : '请先进行生成配置'"
|
:title="record.isConfiged ? '生成' : '请先进行生成配置'"
|
||||||
:disabled="!record.isConfiged"
|
:disabled="!record.isConfiged"
|
||||||
@click="handleGenerate(record.tableName)"
|
@click="handleGenerate([record.tableName])"
|
||||||
>
|
>
|
||||||
<template #icon><icon-robot-add /></template>生成
|
<template #icon><icon-robot-add /></template>生成
|
||||||
</a-button>
|
</a-button>
|
||||||
|
Reference in New Issue
Block a user