From b6d4f6632a22fb299ca4cf1ac8ae8bca9cfa23e9 Mon Sep 17 00:00:00 2001
From: autumnal_wind@yeah.net <autumnal_wind@yeah.net>
Date: 星期二, 28 五月 2024 12:14:26 +0800
Subject: [PATCH] feat: 代码生成器优化
---
hs-modules/hs-generator/src/main/resources/vm/vue/index.vue.vm | 221 +++++++++++++++++++++++-------------------------------
1 files changed, 94 insertions(+), 127 deletions(-)
diff --git a/hs-modules/hs-generator/src/main/resources/vm/vue/index.vue.vm b/hs-modules/hs-generator/src/main/resources/vm/vue/index.vue.vm
index 8b132f4..2b99e1b 100644
--- a/hs-modules/hs-generator/src/main/resources/vm/vue/index.vue.vm
+++ b/hs-modules/hs-generator/src/main/resources/vm/vue/index.vue.vm
@@ -2,7 +2,7 @@
<div class="p-2">
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
<div class="search" v-show="showSearch">
- <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
+ <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px" class="-mb-15px">
#foreach($column in $columns)
#if($column.query)
#set($dictType=$column.dictType)
@@ -70,10 +70,7 @@
<template #header>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
- <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['${moduleName}:${businessName}:add']">新增</el-button>
- </el-col>
- <el-col :span="1.5">
- <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['${moduleName}:${businessName}:edit']">修改</el-button>
+ <el-button type="primary" plain icon="Plus" @click="openForm('create')" v-hasPermi="['${moduleName}:${businessName}:add']">新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['${moduleName}:${businessName}:remove']">删除</el-button>
@@ -258,91 +255,113 @@
</template>
<script setup name="${BusinessName}" lang="ts">
-import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName} } from '@/api/${moduleName}/${businessName}';
-import { ${BusinessName}VO, ${BusinessName}Query, ${BusinessName}Form } from '@/api/${moduleName}/${businessName}/types';
+/** 模块导入 */
+import { list${BusinessName}, del${BusinessName}} from '@/api/${moduleName}/${businessName}';
+import { ${BusinessName}VO, ${BusinessName}Query} from '@/api/${moduleName}/${businessName}/types';
+
+defineOptions({ name: '${BusinessName}' })
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
#if(${dicts} != '')
+/** 当前页面引用的数据字典 */
#set($dictsNoSymbol=$dicts.replace("'", ""))
const { ${dictsNoSymbol} } = toRefs<any>(proxy?.useDict(${dicts}));
#end
-
-const ${businessName}List = ref<${BusinessName}VO[]>([]);
-const buttonLoading = ref(false);
+// 是否加载遮罩层
const loading = ref(true);
+// 是否显示查询项
const showSearch = ref(true);
-const ids = ref<Array<string | number>>([]);
+const ${businessName}List = ref<${BusinessName}VO[]>([]);
+// 列表选中的记录Id
+const ids = ref<Array<number | string>>([]);
+// 单选
const single = ref(true);
+// 多选
const multiple = ref(true);
+// 总记录数
const total = ref(0);
+
#foreach ($column in $columns)
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
+// 日期范围
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
const dateRange${AttrName} = ref<[DateModelType, DateModelType]>(['', '']);
#end
#end
const queryFormRef = ref<ElFormInstance>();
-const ${businessName}FormRef = ref<ElFormInstance>();
-
-const dialog = reactive<DialogOption>({
- visible: false,
- title: ''
-});
-
-const initFormData: ${BusinessName}Form = {
-#foreach ($column in $columns)
-#if($column.insert || $column.edit)
-#if($column.htmlType == "checkbox")
- $column.javaField: []#if($foreach.count != $columns.size()),#end
-#else
- $column.javaField: undefined#if($foreach.count != $columns.size()),#end
-#end
-#end
-#end
-}
-const data = reactive<PageData<${BusinessName}Form, ${BusinessName}Query>>({
- form: {...initFormData},
- queryParams: {
+// 查询参数
+const queryParams = reactive({
pageNum: 1,
pageSize: 10,
-#foreach ($column in $columns)
-#if($column.query)
-#if($column.htmlType != "datetime" || $column.queryType != "BETWEEN")
- $column.javaField: undefined,
-#end
-#end
-#end
- params: {
-#foreach ($column in $columns)
-#if($column.query)
-#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
- $column.javaField: undefined#if($foreach.count != $columns.size()),#end
-#end
-#end
-#end
- }
- },
- rules: {
-#foreach ($column in $columns)
-#if($column.insert || $column.edit)
-#if($column.required)
-#set($parentheseIndex=$column.columnComment.indexOf("("))
-#if($parentheseIndex != -1)
-#set($comment=$column.columnComment.substring(0, $parentheseIndex))
-#else
-#set($comment=$column.columnComment)
-#end
- $column.javaField: [
- { required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
- ]#if($foreach.count != $columns.size()),#end
-#end
-#end
-#end
- }
-});
+ #foreach ($column in $columns)
+ #if($column.query)
+ #if($column.htmlType != "datetime" || $column.queryType != "BETWEEN")
+ $column.javaField: '',
+ #end
+ #end
+ #end
+})
+## const ${businessName}FormRef = ref<ElFormInstance>();
+##
+## const dialog = reactive<DialogOption>({
+## visible: false,
+## title: ''
+## });
-const { queryParams, form, rules } = toRefs(data);
+## const initFormData: ${BusinessName}Form = {
+## #foreach ($column in $columns)
+## #if($column.insert || $column.edit)
+## #if($column.htmlType == "checkbox")
+## $column.javaField: []#if($foreach.count != $columns.size()),#end
+## #else
+## $column.javaField: undefined#if($foreach.count != $columns.size()),#end
+## #end
+## #end
+## #end
+## }
+## const data = reactive<PageData<${BusinessName}Form, ${BusinessName}Query>>({
+## form: {...initFormData},
+## queryParams: {
+## pageNum: 1,
+## pageSize: 10,
+## #foreach ($column in $columns)
+## #if($column.query)
+## #if($column.htmlType != "datetime" || $column.queryType != "BETWEEN")
+## $column.javaField: undefined,
+## #end
+## #end
+## #end
+## params: {
+## #foreach ($column in $columns)
+## #if($column.query)
+## #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
+## $column.javaField: undefined#if($foreach.count != $columns.size()),#end
+## #end
+## #end
+## #end
+## }
+## },
+## rules: {
+## #foreach ($column in $columns)
+## #if($column.insert || $column.edit)
+## #if($column.required)
+## #set($parentheseIndex=$column.columnComment.indexOf("("))
+## #if($parentheseIndex != -1)
+## #set($comment=$column.columnComment.substring(0, $parentheseIndex))
+## #else
+## #set($comment=$column.columnComment)
+## #end
+## $column.javaField: [
+## { required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
+## ]#if($foreach.count != $columns.size()),#end
+## #end
+## #end
+## #end
+## }
+## });
+##
+## const { queryParams, form, rules } = toRefs(data);
/** 查询${functionName}列表 */
const getList = async () => {
@@ -359,22 +378,10 @@
proxy?.addDateRange(queryParams.value, dateRange${AttrName}.value, '${AttrName}');
#end
#end
- const res = await list${BusinessName}(queryParams.value);
+ const res = await list${BusinessName}(queryParams);
${businessName}List.value = res.rows;
total.value = res.total;
loading.value = false;
-}
-
-/** 取消按钮 */
-const cancel = () => {
- reset();
- dialog.visible = false;
-}
-
-/** 表单重置 */
-const reset = () => {
- form.value = {...initFormData};
- ${businessName}FormRef.value?.resetFields();
}
/** 搜索按钮操作 */
@@ -402,50 +409,6 @@
multiple.value = !selection.length;
}
-/** 新增按钮操作 */
-const handleAdd = () => {
- reset();
- dialog.visible = true;
- dialog.title = "添加${functionName}";
-}
-
-/** 修改按钮操作 */
-const handleUpdate = async (row?: ${BusinessName}VO) => {
- reset();
- const _${pkColumn.javaField} = row?.${pkColumn.javaField} || ids.value[0]
- const res = await get${BusinessName}(_${pkColumn.javaField});
- Object.assign(form.value, res.data);
-#foreach ($column in $columns)
- #if($column.htmlType == "checkbox")
- form.value.$column.javaField = form.value.${column.javaField}.split(",");
- #end
-#end
- dialog.visible = true;
- dialog.title = "修改${functionName}";
-}
-
-/** 提交按钮 */
-const submitForm = () => {
- ${businessName}FormRef.value?.validate(async (valid: boolean) => {
- if (valid) {
- buttonLoading.value = true;
- #foreach ($column in $columns)
- #if($column.htmlType == "checkbox")
- form.value.$column.javaField = form.value.${column.javaField}.join(",");
- #end
- #end
- if (form.value.${pkColumn.javaField}) {
- await update${BusinessName}(form.value).finally(() => buttonLoading.value = false);
- } else {
- await add${BusinessName}(form.value).finally(() => buttonLoading.value = false);
- }
- proxy?.#[[$modal]]#.msgSuccess("修改成功");
- dialog.visible = false;
- await getList();
- }
- });
-}
-
/** 删除按钮操作 */
const handleDelete = async (row?: ${BusinessName}VO) => {
const _${pkColumn.javaField}s = row?.${pkColumn.javaField} || ids.value;
@@ -458,10 +421,14 @@
/** 导出按钮操作 */
const handleExport = () => {
proxy?.download('${moduleName}/${businessName}/export', {
- ...queryParams.value
+ ...queryParams
}, `${businessName}_#[[${new Date().getTime()}]]#.xlsx`)
}
-
+/** 弹出框(增加、修改) */
+const detailFormRef = ref();
+const openForm = (type: string, id?: number) => {
+ detailFormRef?.value.open(type, id)
+}
onMounted(() => {
getList();
});
--
Gitblit v1.8.0