浏览代码

代码生成器调整

bing 1 年之前
父节点
当前提交
fdf49b4871

+ 2 - 0
ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/constant/GenConstants.java

@@ -40,6 +40,8 @@ public interface GenConstants {
      * 上级菜单名称字段
      */
     String PARENT_MENU_NAME = "parentMenuName";
+    String webPrefix = "webPrefix";
+    String apiPrefix = "apiPrefix";
 
     /**
      * 数据库字符串类型

+ 6 - 0
ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/domain/GenTable.java

@@ -134,6 +134,12 @@ public class GenTable extends BaseEntity {
      */
     private String remark;
 
+    @TableField(exist = false)
+    private String webPrefix;
+
+    @TableField(exist = false)
+    private String apiPrefix;
+
     /**
      * 树编码字段
      */

+ 4 - 0
ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/service/GenTableServiceImpl.java

@@ -439,12 +439,16 @@ public class GenTableServiceImpl implements IGenTableService {
             String treeName = paramsObj.getStr(GenConstants.TREE_NAME);
             String parentMenuId = paramsObj.getStr(GenConstants.PARENT_MENU_ID);
             String parentMenuName = paramsObj.getStr(GenConstants.PARENT_MENU_NAME);
+            String webPrefix = paramsObj.getStr(GenConstants.webPrefix);
+            String apiPrefix = paramsObj.getStr(GenConstants.apiPrefix);
 
             genTable.setTreeCode(treeCode);
             genTable.setTreeParentCode(treeParentCode);
             genTable.setTreeName(treeName);
             genTable.setParentMenuId(parentMenuId);
             genTable.setParentMenuName(parentMenuName);
+            genTable.setWebPrefix(webPrefix);
+            genTable.setApiPrefix(apiPrefix);
         }
     }
 

+ 26 - 0
ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/util/VelocityUtils.java

@@ -82,6 +82,12 @@ public class VelocityUtils {
         Dict paramsObj = JsonUtils.parseMap(options);
         String parentMenuId = getParentMenuId(paramsObj);
         context.put("parentMenuId", parentMenuId);
+        String apiPrefix = getApiPrefix(paramsObj);
+        context.put("apiPrefix", apiPrefix);
+        genTable.setApiPrefix(apiPrefix);
+        String webPrefix = getWebPrefix(paramsObj);
+        context.put("webPrefix", webPrefix);
+        genTable.setWebPrefix(webPrefix);
     }
 
     public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) {
@@ -146,6 +152,10 @@ public class VelocityUtils {
         String packageName = genTable.getPackageName();
         // 模块名
         String moduleName = genTable.getModuleName();
+
+        if(StringUtils.isNotBlank(genTable.getWebPrefix())){
+            moduleName = genTable.getWebPrefix()+"/"+moduleName;
+        }
         // 大写类名
         String className = genTable.getClassName();
         // 业务名称
@@ -275,6 +285,22 @@ public class VelocityUtils {
         return DEFAULT_PARENT_MENU_ID;
     }
 
+    public static String getWebPrefix(Dict paramsObj) {
+        if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.webPrefix)
+            && StringUtils.isNotEmpty(paramsObj.getStr(GenConstants.webPrefix))) {
+            return paramsObj.getStr(GenConstants.webPrefix);
+        }
+        return "";
+    }
+
+    public static String getApiPrefix(Dict paramsObj) {
+        if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.apiPrefix)
+            && StringUtils.isNotEmpty(paramsObj.getStr(GenConstants.apiPrefix))) {
+            return paramsObj.getStr(GenConstants.apiPrefix);
+        }
+        return "";
+    }
+
     /**
      * 获取树编码
      *

+ 9 - 6
ruoyi-modules/ruoyi-gen/src/main/resources/vm/ts/api.ts.vm

@@ -2,15 +2,18 @@ import request from '@/utils/request';
 import { AxiosPromise } from 'axios';
 import { ${BusinessName}VO, ${BusinessName}Form, ${BusinessName}Query } from '@/api/${moduleName}/${businessName}/types';
 
+#set($prefix = '')
+#if(${apiPrefix} != '')
+    #set($prefix = '/'+ ${apiPrefix})
+#end
 /**
  * 查询${functionName}列表
  * @param query
  * @returns {*}
  */
-
 export const list${BusinessName} = (query?: ${BusinessName}Query): AxiosPromise<${BusinessName}VO[]> => {
   return request({
-    url: '/${moduleName}/${businessName}/list',
+    url: '$prefix/${moduleName}/${businessName}/list',
     method: 'get',
     params: query
   });
@@ -22,7 +25,7 @@ export const list${BusinessName} = (query?: ${BusinessName}Query): AxiosPromise<
  */
 export const get${BusinessName} = (${pkColumn.javaField}: string | number): AxiosPromise<${BusinessName}VO> => {
   return request({
-    url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
+    url: '$prefix/${moduleName}/${businessName}/' + ${pkColumn.javaField},
     method: 'get'
   });
 };
@@ -33,7 +36,7 @@ export const get${BusinessName} = (${pkColumn.javaField}: string | number): Axio
  */
 export const add${BusinessName} = (data: ${BusinessName}Form) => {
   return request({
-    url: '/${moduleName}/${businessName}',
+    url: '$prefix/${moduleName}/${businessName}',
     method: 'post',
     data: data
   });
@@ -45,7 +48,7 @@ export const add${BusinessName} = (data: ${BusinessName}Form) => {
  */
 export const update${BusinessName} = (data: ${BusinessName}Form) => {
   return request({
-    url: '/${moduleName}/${businessName}',
+    url: '$prefix/${moduleName}/${businessName}',
     method: 'put',
     data: data
   });
@@ -57,7 +60,7 @@ export const update${BusinessName} = (data: ${BusinessName}Form) => {
  */
 export const del${BusinessName} = (${pkColumn.javaField}: string | number | Array<string | number>) => {
   return request({
-    url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
+    url: '$prefix/${moduleName}/${businessName}/' + ${pkColumn.javaField},
     method: 'delete'
   });
 };

+ 5 - 0
ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/DetailForm.vue.vm

@@ -110,8 +110,13 @@
 </template>
 
 <script setup name="${BusinessName}Form" lang="ts">
+#if(${webPrefix} != '')
+import * as ${BusinessName}Api from '@/api/${webPrefix}/${moduleName}/${businessName}';
+import { ${BusinessName}Form } from '@/api/${webPrefix}/${moduleName}/${businessName}/types';
+#else
 import * as ${BusinessName}Api from '@/api/${moduleName}/${businessName}';
 import { ${BusinessName}Form } from '@/api/${moduleName}/${businessName}/types';
+#end
 import { useI18n } from 'vue-i18n';
 
 defineOptions({ name: '${BusinessName}Form' });

+ 6 - 1
ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm

@@ -146,8 +146,13 @@
 
 <script setup name="${BusinessName}" lang="ts">
 /** 模块导入 */
+#if(${webPrefix} != '')
+import { list${BusinessName}, del${BusinessName} } from '@/api/${webPrefix}/${moduleName}/${businessName}';
+import { ${BusinessName}VO } from '@/api/${webPrefix}/${moduleName}/${businessName}/types';
+#else
 import { list${BusinessName}, del${BusinessName} } from '@/api/${moduleName}/${businessName}';
 import { ${BusinessName}VO } from '@/api/${moduleName}/${businessName}/types';
+#end
 import DetailForm from './DetailForm.vue';
 
 defineOptions({ name: '${BusinessName}' });
@@ -278,7 +283,7 @@ const handleDelete = async (row?: ${BusinessName}VO) => {
 /** 导出按钮操作 */
 const handleExport = () => {
   proxy?.download(
-    '${moduleName}/${businessName}/export',
+    '${apiPrefix}/${moduleName}/${businessName}/export',
     {
       ...queryParams
     },