Explorar el Código

代码生成器模板调整

bing hace 1 año
padre
commit
96e1d327f6

+ 1 - 1
ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm

@@ -35,7 +35,7 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
 @Validated
 @RequiredArgsConstructor
 @RestController
-@RequestMapping("/${businessName}")
+@RequestMapping("/${moduleName}/${businessName}")
 public class ${ClassName}Controller extends BaseController {
 
     private final I${ClassName}Service ${className}Service;

+ 65 - 67
ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/DetailForm.vue.vm

@@ -1,7 +1,7 @@
 <template>
   <div class="p-2">
-    <Dialog :title="dialog.title" v-model="dialog.visible" width="600px" :draggable="draggable">
-      <el-form ref="formRef" :model="formData" :rules="formRules" label-width="80px" v-loading="formLoading">
+    <el-dialog v-model="dialog.visible" :title="dialog.title" width="600px" :draggable="draggable">
+      <el-form ref="formRef" v-loading="formLoading" :model="formData" :rules="formRules"  label-width="80px">
 #foreach($column in $columns)
 #set($field=$column.javaField)
 #if(($column.insert || $column.edit) && !$column.pk)
@@ -109,14 +109,14 @@
           <el-button @click="dialog.visible = false">取 消</el-button>
         </div>
       </template>
-    </Dialog>
+    </el-dialog>
   </div>
 </template>
 
-<script setup name="${BusinessName}" lang="ts">
+<script setup name="${BusinessName}Form" lang="ts">
 import * as ${BusinessName}Api from '@/api/${moduleName}/${businessName}';
 import { ${BusinessName}Form } from '@/api/${moduleName}/${businessName}/types';
-import {useI18n} from "vue-i18n";
+import { useI18n } from 'vue-i18n';
 
 defineOptions({ name: '${BusinessName}Form' })
 
@@ -134,15 +134,15 @@ const { ${dictsNoSymbol} } = toRefs<any>(proxy?.useDict(${dicts}));
 #end
 // 对话框
 const dialog = reactive<DialogOption>({
-    visible: false,
-    title: ''
+  visible: false,
+  title: ''
 });
 // 窗体是否可以拖动
-const draggable = ref(true)
+const draggable = ref(true);
 // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
-const formLoading = ref(false)
+const formLoading = ref(false);
 // 表单的类型:create - 新增;update - 修改
-const formType = ref('')
+const formType = ref('');
 // 表单引用
 const formRef = ref<ElFormInstance>();
 // 表单数据
@@ -150,17 +150,17 @@ const formData = ref<${BusinessName}Form>({
     #foreach ($column in $columns)
     #if($column.insert || $column.edit)
     #if($column.htmlType == "checkbox")
-        $column.javaField: []#if($foreach.count != $columns.size()),#end
+  $column.javaField: []#if($foreach.count != $columns.size()),#end
     #elseif($column.javaType == "String")
-        $column.javaField: ''#if($foreach.count != $columns.size()),#end
+  $column.javaField: ''#if($foreach.count != $columns.size()),#end
     #elseif($column.javaType == "Integer" || $column.javaType == "Long")
-        $column.javaField: 0#if($foreach.count != $columns.size()),#end
+  $column.javaField: 0#if($foreach.count != $columns.size()),#end
     #else
-        $column.javaField: undefined#if($foreach.count != $columns.size()),#end
+  $column.javaField: undefined#if($foreach.count != $columns.size()),#end
     #end
     #end
     #end
-})
+});
 // 表单校验规则
 const formRules = reactive({
 #foreach ($column in $columns)
@@ -172,75 +172,73 @@ const formRules = reactive({
 #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
+  $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 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
-        }
+  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.insert || $column.edit)
-    #if($column.htmlType != "datetime" || $column.queryType != "BETWEEN")
-        $column.javaField: '',
-    #end
-    #end
-    #end
-    }
+  formData.value = {
+  #foreach ($column in $columns)
+  #if($column.insert || $column.edit)
+  #if($column.htmlType != "datetime" || $column.queryType != "BETWEEN")
+    $column.javaField: '',
+  #end
+  #end
+  #end
+  }
   formRef.value?.resetFields();
-}
+};
 // 传回给父组件的属性与方法
 // 提供 open 方法,用于打开弹窗
-defineExpose({open})
+defineExpose({ open });
 /** 触发父组件的事件 */
 /** 定义 success 事件,用于操作成功后的回调 */
-const emit = defineEmits(['success'])
+const emit = defineEmits(['success']);
 /** 提交按钮 */
 const submitForm = async () => {
-    // 校验表单
-    if (!formRef) return
-    const valid = await formRef.value?.validate()
-    if (!valid) return
-    // 提交请求
-    formLoading.value = true
-    try {
-        const data = formData.value as unknown as ${BusinessName}Form
-        if (formType.value === 'create') {
-            await ${BusinessName}Api.add${BusinessName}(data)
-            proxy?.$modal.msgSuccess("新增成功");
-        } else {
-            await ${BusinessName}Api.update${BusinessName}(data)
-            proxy?.$modal.msgSuccess("修改成功");
-        }
-        dialog.visible = false
-        // 发送操作成功的事件
-        emit('success')
-    } finally {
-        formLoading.value = false
+  // 校验表单
+  if (!formRef) return;
+  const valid = await formRef.value?.validate();
+  if (!valid) return;
+  // 提交请求
+  formLoading.value = true;
+  try {
+    const data = formData.value as unknown as ${BusinessName}Form;
+    if (formType.value === 'create') {
+      await ${BusinessName}Api.add${BusinessName}(data);
+      proxy?.$modal.msgSuccess("新增成功");
+    } else {
+      await ${BusinessName}Api.update${BusinessName}(data);
+      proxy?.$modal.msgSuccess("修改成功");
     }
-}
+    dialog.visible = false;
+    // 发送操作成功的事件
+    emit('success');
+  } finally {
+      formLoading.value = false;
+  }
+};
 
 /** 初始化 */
-onMounted(() => {
-
-});
+onMounted(() => {});
 </script>

+ 52 - 55
ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm

@@ -1,8 +1,8 @@
 <template>
   <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" class="-mb-15px">
+      <div v-show="showSearch" class="search">
+        <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="68px" class="-mb-15px">
 #foreach($column in $columns)
 #if($column.query)
 #set($dictType=$column.dictType)
@@ -20,12 +20,7 @@
 #elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
           <el-form-item label="${comment}" prop="${column.javaField}">
             <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable>
-              <el-option
-                v-for="dict in ${dictType}"
-                :key="dict.value"
-                :label="dict.label"
-                :value="dict.value"
-              />
+              <el-option v-for="dict in ${dictType}" :key="dict.value" :label="dict.label" :value="dict.value" />
             </el-select>
           </el-form-item>
 #elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType)
@@ -70,16 +65,16 @@
       <template #header>
         <el-row :gutter="10" class="mb8">
           <el-col :span="1.5">
-            <el-button type="primary" plain icon="Plus" @click="openForm('create')" v-hasPermi="['${moduleName}:${businessName}:add']">新增</el-button>
+            <el-button v-hasPermi="['${moduleName}:${businessName}:add']" type="primary" plain icon="Plus" @click="openForm('create')">新增</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-button v-hasPermi="['system:post:edit']" type="success" plain icon="Edit" :disabled="single" @click="openForm('update')">修改</el-button>
           </el-col>
           <el-col :span="1.5">
-            <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['${moduleName}:${businessName}:export']">导出</el-button>
+            <el-button v-hasPermi="['${moduleName}:${businessName}:remove']" type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()">删除</el-button>
+          </el-col>
+          <el-col :span="1.5">
+            <el-button v-hasPermi="['${moduleName}:${businessName}:export']" type="warning" plain icon="Download" @click="handleExport">导出</el-button>
           </el-col>
           <right-toolbar v-model:showSearch="showSearch" :columns="columns"  @queryTable="getList"></right-toolbar>
         </el-row>
@@ -87,6 +82,7 @@
 
       <el-table v-loading="loading" :data="${businessName}List" @selection-change="handleSelectionChange">
         <el-table-column type="selection" width="55" align="center" />
+#set($aIndex = 0)
 #foreach($column in $columns)
 #set($javaField=$column.javaField)
 #set($parentheseIndex=$column.columnComment.indexOf("("))
@@ -96,21 +92,23 @@
 #set($comment=$column.columnComment)
 #end
 #if($column.pk)
-        <el-table-column label="${comment}" align="center" prop="${javaField}" v-if="${column.list}" />
+        <el-table-column v-if="${column.list}" label="${comment}" align="center" prop="${javaField}" />
 #elseif($column.list && $column.htmlType == "datetime")
-        <el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
+        <el-table-column v-if="columns[$aIndex].visible" label="${comment}" align="center" prop="${javaField}" width="180">
           <template #default="scope">
             <span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span>
           </template>
         </el-table-column>
+    #set($aIndex = $aIndex + 1)
 #elseif($column.list && $column.htmlType == "imageUpload")
-        <el-table-column label="${comment}" align="center" prop="${javaField}" width="100">
+        <el-table-column v-if="columns[$aIndex].visible" label="${comment}" align="center" prop="${javaField}" width="100">
           <template #default="scope">
             <image-preview :src="scope.row.${javaField}" :width="50" :height="50"/>
           </template>
         </el-table-column>
+    #set($aIndex = $aIndex + 1)
 #elseif($column.list && $column.dictType && "" != $column.dictType)
-        <el-table-column label="${comment}" align="center" prop="${javaField}">
+        <el-table-column v-if="columns[$aIndex].visible" label="${comment}" align="center" prop="${javaField}">
           <template #default="scope">
 #if($column.htmlType == "checkbox")
             <dict-tag :options="${column.dictType}" :value="scope.row.${javaField} ? scope.row.${javaField}.split(',') : []"/>
@@ -119,39 +117,35 @@
 #end
           </template>
         </el-table-column>
+    #set($aIndex = $aIndex + 1)
 #elseif($column.list && "" != $javaField)
-        <el-table-column label="${comment}" align="center" prop="${javaField}" />
+        <el-table-column v-if="columns[$aIndex].visible" label="${comment}" align="center" prop="${javaField}" />
+    #set($aIndex = $aIndex + 1)
 #end
 #end
         <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="openForm('update',scope.row)" v-hasPermi="['${moduleName}:${businessName}:edit']"></el-button>
+              <el-button v-hasPermi="['${moduleName}:${businessName}:edit']" link type="primary" icon="Edit" @click="openForm('update',scope.row)"></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>
+              <el-button v-hasPermi="['${moduleName}:${businessName}:remove']" link type="primary" icon="Delete" @click="handleDelete(scope.row)"></el-button>
             </el-tooltip>
           </template>
         </el-table-column>
       </el-table>
-        <!-- 翻页组件 -->
-      <pagination
-          v-show="total>0"
-          :total="total"
-          v-model:page="queryParams.pageNum"
-          v-model:limit="queryParams.pageSize"
-          @pagination="getList"
-      />
+      <!-- 翻页组件 -->
+        <pagination v-show="total > 0" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" :total="total" @pagination="getList" />
     </el-card>
     <!-- 添加或修改${functionName}对话框 -->
-    <detail-form ref="detailFormRef" @success="getList" apped-to-body/>
+    <detail-form ref="detailFormRef" apped-to-body @success="getList" />
   </div>
 </template>
 
 <script setup name="${BusinessName}" lang="ts">
 /** 模块导入 */
-import { list${BusinessName}, del${BusinessName}} from '@/api/${moduleName}/${businessName}';
-import { ${BusinessName}VO} from '@/api/${moduleName}/${businessName}/types';
+import { list${BusinessName}, del${BusinessName} } from '@/api/${moduleName}/${businessName}';
+import { ${BusinessName}VO } from '@/api/${moduleName}/${businessName}/types';
 import DetailForm from './DetailForm.vue';
 
 defineOptions({ name: '${BusinessName}' })
@@ -197,7 +191,7 @@ const columns = ref<FieldOption[]>([
     #set($comment=$column.columnComment)
 #end
     ##数组下标$foreach.index
-    { key: $arrayIndex, label: `$comment`, visible: true, children: [] },
+  { key: $arrayIndex, label: `$comment`, visible: true, children: [] },
     #set($arrayIndex = $arrayIndex + 1)
 #end
 #end
@@ -205,23 +199,23 @@ const columns = ref<FieldOption[]>([
 
 // 查询参数
 const queryParams = reactive({
-    pageNum: 1,
-    pageSize: 10,
+  pageNum: 1,
+  pageSize: 10,
 #foreach ($column in $columns)
 #if($column.query)
 #if($column.htmlType == "checkbox")
-    $column.javaField: []#if($foreach.count != $columns.size()),#end
+  $column.javaField: []#if($foreach.count != $columns.size()),#end
 #elseif($column.javaType == "String")
-    $column.javaField: ''#if($foreach.count != $columns.size()),#end
+  $column.javaField: ''#if($foreach.count != $columns.size()),#end
 #elseif($column.javaType == "Integer" || $column.javaType == "Long")
-    $column.javaField: 0#if($foreach.count != $columns.size()),#end
+  $column.javaField: 0#if($foreach.count != $columns.size()),#end
 #else
-    $column.javaField: undefined#if($foreach.count != $columns.size()),#end
+  $column.javaField: undefined#if($foreach.count != $columns.size()),#end
 #end
 #end
 #end
-    params: {}
-})
+  params: {}
+});
 
 /** 查询${functionName}列表 */
 const getList = async () => {
@@ -242,14 +236,14 @@ const getList = async () => {
   ${businessName}List.value = res.rows;
   total.value = res.total;
   loading.value = false;
-}
+};
 
 
 /** 搜索按钮操作 */
 const handleQuery = () => {
   queryParams.pageNum = 1;
   getList();
-}
+};
 
 /** 重置按钮操作 */
 const resetQuery = () => {
@@ -261,14 +255,14 @@ const resetQuery = () => {
 #end
   queryFormRef.value?.resetFields();
   handleQuery();
-}
+};
 
 /** 多选框选中数据 */
 const handleSelectionChange = (selection: ${BusinessName}VO[]) => {
-  ids.value = selection.map(item => item.${pkColumn.javaField});
+  ids.value = selection.map((item) => item.${pkColumn.javaField});
   single.value = selection.length != 1;
   multiple.value = !selection.length;
-}
+};
 
 /** 删除按钮操作 */
 const handleDelete = async (row?: ${BusinessName}VO) => {
@@ -276,21 +270,24 @@ const handleDelete = async (row?: ${BusinessName}VO) => {
   await proxy?.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + _${pkColumn.javaField}s + '"的数据项?').finally(() => loading.value = false);
   await del${BusinessName}(_${pkColumn.javaField}s);
   await getList();
-  proxy?.#[[$modal]]#.msgSuccess("删除成功");
-}
+  proxy?.#[[$modal]]#.msgSuccess('删除成功');
+};
 
 /** 导出按钮操作 */
 const handleExport = () => {
-  proxy?.download('${moduleName}/${businessName}/export', {
-    ...queryParams
-  }, `${businessName}_#[[${new Date().getTime()}]]#.xlsx`)
-}
+  proxy?.download(
+    '${moduleName}/${businessName}/export',
+    {
+       ...queryParams
+    },
+    `${businessName}_#[[${new Date().getTime()}]]#.xlsx`)
+};
 /** 弹出框(增加、修改) */
 const detailFormRef = ref();
 const openForm = (type: string, row?: ${BusinessName}VO) => {
-    const id = row?.${pkColumn.javaField} || ids.value[0];
-    detailFormRef?.value.open(type, id)
-}
+  const id = row?.${pkColumn.javaField} || ids.value[0];
+  detailFormRef?.value.open(type, id)
+};
 onMounted(() => {
   getList();
 });