From 646ff849dbe8e07a63d81ae86917373cd39ef223 Mon Sep 17 00:00:00 2001
From: autumnal_wind@yeah.net <autumnal_wind@yeah.net>
Date: 星期三, 29 五月 2024 16:12:05 +0800
Subject: [PATCH] feat: 代码生成器优化(前端index.vue和DetailForm.vue模板)

---
 hs-modules/hs-generator/src/main/resources/vm/vue/index.vue.vm      |   26 +++++++++++++++-----------
 hs-modules/hs-generator/src/main/resources/vm/vue/DetailForm.vue.vm |   34 +++++++++++++++++++++++++++-------
 2 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/hs-modules/hs-generator/src/main/resources/vm/vue/DetailForm.vue.vm b/hs-modules/hs-generator/src/main/resources/vm/vue/DetailForm.vue.vm
index 765cf3c..16777ae 100644
--- a/hs-modules/hs-generator/src/main/resources/vm/vue/DetailForm.vue.vm
+++ b/hs-modules/hs-generator/src/main/resources/vm/vue/DetailForm.vue.vm
@@ -114,8 +114,8 @@
 </template>
 
 <script setup name="${BusinessName}" lang="ts">
-import * as ${businessName}Api from '@/api/${moduleName}/${businessName}';
-import { ${BusinessName}VO, ${BusinessName}Query, ${BusinessName}Form } from '@/api/${moduleName}/${businessName}/types';
+import * as ${BusinessName}Api from '@/api/${moduleName}/${businessName}';
+import { ${BusinessName}Form } from '@/api/${moduleName}/${businessName}/types';
 import {useI18n} from "vue-i18n";
 
 defineOptions({ name: '${BusinessName}Form' })
@@ -124,6 +124,9 @@
 // const props = defineProps({})
 
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
+// 国际化
+const { t } = useI18n()
+
 #if(${dicts} != '')
 #set($dictsNoSymbol=$dicts.replace("'", ""))
 /** 数据字典 */
@@ -145,9 +148,9 @@
 // 表单数据
 const formData = ref<${BusinessName}Form>({
     #foreach ($column in $columns)
-    #if($column.query)
+    #if($column.insert || $column.edit)
     #if($column.htmlType != "datetime" || $column.queryType != "BETWEEN")
-    $column.javaField: undefined,
+    $column.javaField: '',
     #end
     #end
     #end
@@ -170,14 +173,31 @@
 #end
 #end
 })
-
+/** 当前组件方法 */
+/** 窗体打开事件 */
+const open = async (type: string, id?: number) => {
+    dialog.visible = true
+    dialog.title = t('action.' + type)
+    formType.value = type
+    resetForm()
+    // 修改时,设置数据
+    if (id) {
+        formLoading.value = true
+        try {
+            const res = await ${BusinessName}Api.get${BusinessName}(id);
+            Object.assign(formData.value, res.data);
+        } finally {
+            formLoading.value = false
+        }
+    }
+}
 /** 表单重置 */
 const resetForm = () => {
     formData.value = {
     #foreach ($column in $columns)
-    #if($column.query)
+    #if($column.insert || $column.edit)
     #if($column.htmlType != "datetime" || $column.queryType != "BETWEEN")
-        $column.javaField: undefined,
+        $column.javaField: '',
     #end
     #end
     #end
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 6444767..9bdf94f 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
@@ -72,6 +72,9 @@
           <el-col :span="1.5">
             <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="success" plain icon="Edit" :disabled="single" @click="openForm('update')" v-hasPermi="['system:post:edit']">修改</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>
           </el-col>
@@ -123,7 +126,7 @@
         <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
           <template #default="scope">
             <el-tooltip content="修改" placement="top">
-              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['${moduleName}:${businessName}:edit']"></el-button>
+              <el-button link type="primary" icon="Edit" @click="openForm('update',scope.row)" v-hasPermi="['${moduleName}:${businessName}:edit']"></el-button>
             </el-tooltip>
             <el-tooltip content="删除" placement="top">
               <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['${moduleName}:${businessName}:remove']"></el-button>
@@ -131,7 +134,7 @@
           </template>
         </el-table-column>
       </el-table>
-
+        <!-- 翻页组件 -->
       <pagination
           v-show="total>0"
           :total="total"
@@ -148,8 +151,8 @@
 <script setup name="${BusinessName}" lang="ts">
 /** 模块导入 */
 import { list${BusinessName}, del${BusinessName}} from '@/api/${moduleName}/${businessName}';
-import { ${BusinessName}VO, ${BusinessName}Query} from '@/api/${moduleName}/${businessName}/types';
-import DetailForm from "@/views/${moduleName}/${businessName}/DetailForm.vue";
+import { ${BusinessName}VO} from '@/api/${moduleName}/${businessName}/types';
+import DetailForm from './DetailForm.vue';
 
 defineOptions({ name: '${BusinessName}' })
 
@@ -180,18 +183,18 @@
 const dateRange${AttrName} = ref<[DateModelType, DateModelType]>(['', '']);
 #end
 #end
-
+// 查询窗体Ref
 const queryFormRef = ref<ElFormInstance>();
 // 查询参数
 const queryParams = reactive({
     pageNum: 1,
     pageSize: 10,
     #foreach ($column in $columns)
-        #if($column.query)
-            #if($column.htmlType != "datetime" || $column.queryType != "BETWEEN")
+    #if($column.query)
+    #if($column.htmlType != "datetime" || $column.queryType != "BETWEEN")
     $column.javaField: '',
-            #end
-        #end
+    #end
+    #end
     #end
 })
 
@@ -218,7 +221,7 @@
 
 /** 搜索按钮操作 */
 const handleQuery = () => {
-  queryParams.value.pageNum = 1;
+  queryParams.pageNum = 1;
   getList();
 }
 
@@ -258,7 +261,8 @@
 }
 /** 弹出框(增加、修改) */
 const detailFormRef = ref();
-const openForm = (type: string, id?: number) => {
+const openForm = (type: string, row?: ${BusinessName}VO) => {
+    const id = row?.${pkColumn.javaField} || ids.value[0];
     detailFormRef?.value.open(type, id)
 }
 onMounted(() => {

--
Gitblit v1.8.0