From 93fce6494c714cf07bb1467622a89166b1ba3855 Mon Sep 17 00:00:00 2001
From: ray <1490493387@qq.com>
Date: Sat, 3 Aug 2024 19:02:58 +0800
Subject: [PATCH] =?UTF-8?q?style:=20:lipstick:=20=E7=BB=84=E5=90=88?=
=?UTF-8?q?=E5=BC=8F=20API=20=E9=A1=BA=E5=BA=8F=E8=B0=83=E6=95=B4=E5=92=8C?=
=?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=97=A0=E7=94=A8=E5=BC=95=E7=94=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/api/generator.ts | 5 +-
src/views/generator/index.vue | 102 ++++++++++++++++++++++------------
2 files changed, 69 insertions(+), 38 deletions(-)
diff --git a/src/api/generator.ts b/src/api/generator.ts
index 24af262a..c9396e87 100644
--- a/src/api/generator.ts
+++ b/src/api/generator.ts
@@ -1,6 +1,4 @@
import request from "@/utils/request";
-import { FormTypeEnum } from "@/enums/FormTypeEnum";
-import { QueryTypeEnum } from "@/enums/QueryTypeEnum";
const GENERATOR_BASE_URL = "/api/v1/generator";
@@ -178,4 +176,7 @@ export interface FieldConfig {
/** 字段排序 */
fieldSort?: number;
+
+ /** 字典类型 */
+ dictType?: string;
}
diff --git a/src/views/generator/index.vue b/src/views/generator/index.vue
index b882618d..9b06dda6 100644
--- a/src/views/generator/index.vue
+++ b/src/views/generator/index.vue
@@ -154,7 +154,7 @@
+
-
-
+
+ -
-
+
+ -
+ -
@@ -368,24 +381,25 @@ import DictAPI from "@/api/dict";
import MenuAPI from "@/api/menu";
const queryFormRef = ref(ElForm);
-
-const loading = ref(false);
-const fieldLoading = ref(false);
-const loadingText = ref("loading...");
-const total = ref(0);
const queryParams = reactive
({
keywords: undefined,
pageNum: 1,
pageSize: 10,
});
+
+const loading = ref(false);
+const loadingText = ref("loading...");
+
const pageData = ref([]);
-const formData = ref({
- fieldConfigs: [],
-});
+const total = ref(0);
+
const formTypeOptions: Record = FormTypeEnum;
const queryTypeOptions: Record = QueryTypeEnum;
const dictOptions = ref();
const menuOptions = ref([]);
+const formData = ref({
+ fieldConfigs: [],
+});
const dialog = reactive({
visible: false,
@@ -410,9 +424,41 @@ interface TreeNode {
content?: string;
children?: TreeNode[];
}
-
const treeData = ref([]);
+watch(active, (val) => {
+ if (val === 0) {
+ nextBtnText.value = "下一步,字段配置";
+ } else if (val === 1) {
+ prevBtnText.value = "上一步,基础配置";
+ nextBtnText.value = "下一步,确认生成";
+ } else if (val === 2) {
+ prevBtnText.value = "上一步,字段配置";
+ nextBtnText.value = "下载代码";
+ }
+});
+
+watch(copied, () => {
+ if (copied.value) {
+ ElMessage.success("复制成功");
+ }
+});
+
+watch(
+ () => formData.value.fieldConfigs as FieldConfig[],
+ (newVal: FieldConfig[]) => {
+ newVal.forEach((fieldConfig) => {
+ if (
+ fieldConfig.formType === FormTypeEnum.DATE_TIME.value ||
+ fieldConfig.formType === FormTypeEnum.DATE.value
+ ) {
+ fieldConfig.queryType = QueryTypeEnum.BETWEEN.value as number;
+ }
+ });
+ },
+ { deep: true, immediate: true }
+);
+
const initSort = () => {
if (sortFlag.value) {
return;
@@ -455,13 +501,13 @@ function handlePrevClick() {
fieldConfigs: [],
};
nextTick(() => {
- fieldLoading.value = true;
+ loading.value = true;
GeneratorAPI.getGenConfig(currentTableName.value)
.then((data) => {
formData.value = data;
})
.finally(() => {
- fieldLoading.value = false;
+ loading.value = false;
});
});
initSort();
@@ -480,7 +526,7 @@ function handleNextClick() {
ElMessage.error("表名不能为空");
return;
}
- fieldLoading.value = true;
+ loading.value = true;
loadingText.value = "代码生成中,请稍后...";
GeneratorAPI.saveGenConfig(tableName, formData.value)
.then(() => {
@@ -490,7 +536,7 @@ function handleNextClick() {
if (active.value++ >= 2) active.value = 2;
})
.finally(() => {
- fieldLoading.value = false;
+ loading.value = false;
loadingText.value = "loading...";
});
} else {
@@ -508,18 +554,6 @@ function handleNextClick() {
}
}
-watch(active, (val) => {
- if (val === 0) {
- nextBtnText.value = "下一步,字段配置";
- } else if (val === 1) {
- prevBtnText.value = "上一步,基础配置";
- nextBtnText.value = "下一步,确认生成";
- } else if (val === 2) {
- prevBtnText.value = "上一步,字段配置";
- nextBtnText.value = "下载代码";
- }
-});
-
/** 查询 */
function handleQuery() {
loading.value = true;
@@ -637,7 +671,6 @@ function buildTree(
parts.forEach((part) => {
buffer.push(part);
const currentPath = buffer.join(separator);
- console.log("currentPath", currentPath);
if (specialPaths.includes(currentPath)) {
mergedParts.push(currentPath);
buffer = [];
@@ -700,6 +733,7 @@ function handleFileTreeNodeClick(data: TreeNode) {
}
}
+/** 获取文件树节点图标 */
function getFileTreeNodeIcon(label: string) {
if (label.endsWith(".java")) {
return "java";
@@ -719,18 +753,14 @@ function getFileTreeNodeIcon(label: string) {
return "file";
}
+/** 一键复制 */
const handleCopyCode = () => {
if (code.value) {
copy(code.value);
}
};
-watch(copied, () => {
- if (copied.value) {
- ElMessage.success("复制成功");
- }
-});
-
+/** 组件挂载后执行 */
onMounted(() => {
handleQuery();
cmRef.value?.destroy();