Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
feat(generator): 新增代码批量生成功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Bull-BCLS authored and Bull-BCLS committed Mar 23, 2024
1 parent 7792cd3 commit 2353caf
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/api/tool/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface TableRecord {
charset: string;
createTime?: string;
isConfiged: boolean;
disabled: boolean;
}

export interface TableParam {
Expand Down Expand Up @@ -87,9 +88,9 @@ export function preview(tableName: string) {
return axios.get<GeneratePreviewRecord[]>(`${BASE_URL}/preview/${tableName}`);
}

export function generate(tableName: string) {
export function generate(tableNames: Array<string>) {
return axios.request({
url: `${BASE_URL}/${tableName}`,
url: `${BASE_URL}/${tableNames}`,
method: 'post',
responseType: 'blob',
});
Expand Down
76 changes: 72 additions & 4 deletions src/views/tool/generator/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
preview,
generate,
} from '@/api/tool/generator';
import {TableData} from "@arco-design/web-vue";
const { proxy } = getCurrentInstance() as any;
const { form_type_enum, query_type_enum } = proxy.useDict(
Expand All @@ -27,12 +28,16 @@
const queryFormRef = ref();
const formRef = ref();
const tableRef = ref();
const { copy, copied } = useClipboard();
const extensions = [java(), javascript()];
const tableList = ref<TableRecord[]>([]);
const fieldConfigList = ref<FieldConfigRecord[]>([]);
const total = ref(0);
const ids = ref<Array<string>>([]);
const title = ref('');
const single = ref(true);
const multiple = ref(true);
const showQuery = ref(true);
const loading = ref(false);
const visible = ref(false);
Expand Down Expand Up @@ -80,6 +85,45 @@
};
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;
};
/**
* 打开配置对话框
*
Expand Down Expand Up @@ -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) => {
generate(tableName).then((res) => {
const handleGenerate = (tableNames: Array<string>) => {
generate(tableNames).then((res) => {
const contentDisposition = res.headers['content-disposition'];
const pattern = new RegExp('filename=([^;]+\\.[^\\.;]+);*');
const result = pattern.exec(contentDisposition) || '';
Expand Down Expand Up @@ -300,6 +355,12 @@
<a-button @click="resetQuery">
<template #icon><icon-refresh /></template>重置
</a-button>
<a-button
type="outline"
@click="handleBatchGenerate"
>
<template #icon><icon-robot-add /></template>批量生成
</a-button>
</a-space>
</a-form-item>
</a-form>
Expand All @@ -311,6 +372,11 @@
row-key="tableName"
:data="tableList"
:loading="loading"
:row-selection="{
type: 'checkbox',
showCheckedAll: true,
onlyCurrent: false,
}"
:pagination="{
showTotal: true,
showPageSize: true,
Expand All @@ -321,6 +387,8 @@
column-resizable
stripe
size="large"
@select="handleSelect"
@selection-change="handleSelectionChange"
@page-change="handlePageChange"
@page-size-change="handlePageSizeChange"
>
Expand Down Expand Up @@ -359,7 +427,7 @@
size="small"
:title="record.isConfiged ? '生成' : '请先进行生成配置'"
:disabled="!record.isConfiged"
@click="handleGenerate(record.tableName)"
@click="handleGenerate([record.tableName])"
>
<template #icon><icon-robot-add /></template>生成
</a-button>
Expand Down

0 comments on commit 2353caf

Please sign in to comment.