feat: ✨ 代码生成支持字典类型
This commit is contained in:
@@ -34,7 +34,6 @@ class DictAPI {
|
|||||||
* 新增字典
|
* 新增字典
|
||||||
*
|
*
|
||||||
* @param data 字典表单数据
|
* @param data 字典表单数据
|
||||||
* @returns 请求结果
|
|
||||||
*/
|
*/
|
||||||
static add(data: DictForm) {
|
static add(data: DictForm) {
|
||||||
return request({
|
return request({
|
||||||
@@ -49,7 +48,6 @@ class DictAPI {
|
|||||||
*
|
*
|
||||||
* @param id 字典ID
|
* @param id 字典ID
|
||||||
* @param data 字典表单数据
|
* @param data 字典表单数据
|
||||||
* @returns 请求结果
|
|
||||||
*/
|
*/
|
||||||
static update(id: number, data: DictForm) {
|
static update(id: number, data: DictForm) {
|
||||||
return request({
|
return request({
|
||||||
@@ -63,7 +61,6 @@ class DictAPI {
|
|||||||
* 删除字典
|
* 删除字典
|
||||||
*
|
*
|
||||||
* @param ids 字典ID,多个以英文逗号(,)分隔
|
* @param ids 字典ID,多个以英文逗号(,)分隔
|
||||||
* @returns 请求结果
|
|
||||||
*/
|
*/
|
||||||
static deleteByIds(ids: string) {
|
static deleteByIds(ids: string) {
|
||||||
return request({
|
return request({
|
||||||
@@ -72,6 +69,18 @@ class DictAPI {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典列表
|
||||||
|
*
|
||||||
|
* @returns 字典列表
|
||||||
|
*/
|
||||||
|
static getList() {
|
||||||
|
return request<any, OptionType[]>({
|
||||||
|
url: `${DICT_BASE_URL}/list`,
|
||||||
|
method: "get",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取字典的数据项
|
* 获取字典的数据项
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -223,6 +223,21 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column label="查询方式">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-form-item>
|
||||||
|
<el-select v-model="scope.row.queryType" placeholder="请选择">
|
||||||
|
<el-option
|
||||||
|
v-for="(option, key) in queryTypeOptions"
|
||||||
|
:key="key"
|
||||||
|
:label="option.label"
|
||||||
|
:value="option.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
<el-table-column label="表单类型">
|
<el-table-column label="表单类型">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
@@ -238,13 +253,13 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|
||||||
<el-table-column label="查询方式">
|
<el-table-column label="字典类型">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-select v-model="scope.row.queryType" placeholder="请选择">
|
<el-select v-model="scope.row.dictType" placeholder="请选择">
|
||||||
<el-option
|
<el-option
|
||||||
v-for="(option, key) in queryTypeOptions"
|
v-for="option in dictOptions"
|
||||||
:key="key"
|
:key="option.value"
|
||||||
:label="option.label"
|
:label="option.label"
|
||||||
:value="option.value"
|
:value="option.value"
|
||||||
/>
|
/>
|
||||||
@@ -316,8 +331,8 @@ defineOptions({
|
|||||||
import "codemirror/mode/javascript/javascript.js";
|
import "codemirror/mode/javascript/javascript.js";
|
||||||
import Codemirror from "codemirror-editor-vue3";
|
import Codemirror from "codemirror-editor-vue3";
|
||||||
import type { CmComponentRef } from "codemirror-editor-vue3";
|
import type { CmComponentRef } from "codemirror-editor-vue3";
|
||||||
import type { Editor, EditorConfiguration } from "codemirror";
|
import type { EditorConfiguration } from "codemirror";
|
||||||
const { copy, copied } = useClipboard();
|
|
||||||
import { FormTypeEnum } from "@/enums/FormTypeEnum";
|
import { FormTypeEnum } from "@/enums/FormTypeEnum";
|
||||||
import { QueryTypeEnum } from "@/enums/QueryTypeEnum";
|
import { QueryTypeEnum } from "@/enums/QueryTypeEnum";
|
||||||
|
|
||||||
@@ -327,29 +342,29 @@ import GeneratorAPI, {
|
|||||||
TablePageQuery,
|
TablePageQuery,
|
||||||
} from "@/api/generator";
|
} from "@/api/generator";
|
||||||
|
|
||||||
|
import DictAPI from "@/api/dict";
|
||||||
|
|
||||||
const queryFormRef = ref(ElForm);
|
const queryFormRef = ref(ElForm);
|
||||||
|
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const loadingText = ref("loading...");
|
const loadingText = ref("loading...");
|
||||||
const total = ref(0);
|
const total = ref(0);
|
||||||
|
|
||||||
const queryParams = reactive<TablePageQuery>({
|
const queryParams = reactive<TablePageQuery>({
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
});
|
});
|
||||||
|
|
||||||
const pageData = ref<TablePageVO[]>([]);
|
const pageData = ref<TablePageVO[]>([]);
|
||||||
|
|
||||||
const formData = ref<GenConfigForm>({});
|
const formData = ref<GenConfigForm>({});
|
||||||
|
|
||||||
const formTypeOptions: Record<string, OptionType> = FormTypeEnum;
|
const formTypeOptions: Record<string, OptionType> = FormTypeEnum;
|
||||||
const queryTypeOptions: Record<string, OptionType> = QueryTypeEnum;
|
const queryTypeOptions: Record<string, OptionType> = QueryTypeEnum;
|
||||||
|
const dictOptions = ref<OptionType[]>();
|
||||||
|
|
||||||
const dialog = reactive({
|
const dialog = reactive({
|
||||||
visible: false,
|
visible: false,
|
||||||
title: "",
|
title: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { copy, copied } = useClipboard();
|
||||||
const code = ref();
|
const code = ref();
|
||||||
const cmRef = ref<CmComponentRef>();
|
const cmRef = ref<CmComponentRef>();
|
||||||
const cmOptions: EditorConfiguration = {
|
const cmOptions: EditorConfiguration = {
|
||||||
@@ -436,15 +451,21 @@ function handleCloseDialog() {
|
|||||||
/** 打开弹窗 */
|
/** 打开弹窗 */
|
||||||
function handleOpenDialog(tableName: string) {
|
function handleOpenDialog(tableName: string) {
|
||||||
dialog.visible = true;
|
dialog.visible = true;
|
||||||
GeneratorAPI.getGenConfig(tableName).then((data) => {
|
|
||||||
dialog.title = `${tableName} 代码生成`;
|
// 获取字典数据
|
||||||
formData.value = data;
|
DictAPI.getList().then((data) => {
|
||||||
if (formData.value.id) {
|
dictOptions.value = data;
|
||||||
active.value = 2;
|
|
||||||
handlePreview(tableName);
|
GeneratorAPI.getGenConfig(tableName).then((data) => {
|
||||||
} else {
|
dialog.title = `${tableName} 代码生成`;
|
||||||
active.value = 0;
|
formData.value = data;
|
||||||
}
|
if (formData.value.id) {
|
||||||
|
active.value = 2;
|
||||||
|
handlePreview(tableName);
|
||||||
|
} else {
|
||||||
|
active.value = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,8 +473,7 @@ function handleOpenDialog(tableName: string) {
|
|||||||
function handlePreview(tableName: string) {
|
function handlePreview(tableName: string) {
|
||||||
treeData.value = [];
|
treeData.value = [];
|
||||||
GeneratorAPI.getPreviewData(tableName).then((data) => {
|
GeneratorAPI.getPreviewData(tableName).then((data) => {
|
||||||
dialog.title = `预览 ${tableName}`;
|
dialog.title = `代码生成 ${tableName}`;
|
||||||
|
|
||||||
// 组装树形结构完善代码
|
// 组装树形结构完善代码
|
||||||
const tree = buildTree(data);
|
const tree = buildTree(data);
|
||||||
treeData.value = [tree];
|
treeData.value = [tree];
|
||||||
|
|||||||
Reference in New Issue
Block a user