diff --git a/docs/java/VelocityUtils.java b/docs/java/VelocityUtils.java index 8545a422..fb3aee36 100644 --- a/docs/java/VelocityUtils.java +++ b/docs/java/VelocityUtils.java @@ -1,3 +1,42 @@ + /** + * 设置模板变量信息 + * + * @return 模板列表 + */ + public static VelocityContext prepareContext(GenTable genTable) { + String moduleName = genTable.getModuleName(); + String businessName = genTable.getBusinessName(); + String packageName = genTable.getPackageName(); + String tplCategory = genTable.getTplCategory(); + String functionName = genTable.getFunctionName(); + + VelocityContext velocityContext = new VelocityContext(); + velocityContext.put("tplCategory", genTable.getTplCategory()); + velocityContext.put("tableName", genTable.getTableName()); + velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】"); + velocityContext.put("ClassName", genTable.getClassName()); + velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName())); + velocityContext.put("moduleName", genTable.getModuleName()); + velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName())); + velocityContext.put("businessName", genTable.getBusinessName()); + velocityContext.put("basePackage", getPackagePrefix(packageName)); + velocityContext.put("packageName", packageName); + velocityContext.put("author", genTable.getFunctionAuthor()); + velocityContext.put("datetime", DateUtils.getDate()); + velocityContext.put("pkColumn", genTable.getPkColumn()); + velocityContext.put("importList", getImportList(genTable)); + velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); + velocityContext.put("columns", genTable.getColumns()); + velocityContext.put("table", genTable); + velocityContext.put("dicts", getDicts(genTable)); + velocityContext.put("dictList", getDictList(genTable)); + setMenuVelocityContext(velocityContext, genTable); + if (GenConstants.TPL_TREE.equals(tplCategory)) { + setTreeVelocityContext(velocityContext, genTable); + } + return velocityContext; + } + /** * 获取模板信息 * @@ -26,6 +65,8 @@ templates.add("vm/ts/types.ts.vm"); templates.add("vm/soybean/typings/soy.api.d.ts.vm"); templates.add("vm/soybean/api/soy.api.ts.vm"); + templates.add("vm/soybean/modules/soy.search.vue.vm"); + templates.add("vm/soybean/modules/soy.operate-drawer.vue.vm"); if (GenConstants.TPL_CRUD.equals(tplCategory)) { templates.add("vm/vue/index.vue.vm"); templates.add("vm/soybean/soy.index.vue.vm"); @@ -69,6 +110,10 @@ fileName = StringUtils.format("soybean/typings/api/{}.d.ts", moduleName); } else if (template.contains("soy.api.ts.vm")) { fileName = StringUtils.format("soybean/api/{}/{}.ts", moduleName, businessName); + } else if (template.contains("soy.search.vue.vm")) { + fileName = StringUtils.format("soybean/views/{}/{}/modules/search.vue", moduleName, businessName); + } else if (template.contains("soy.operate-drawer.vue.vm")) { + fileName = StringUtils.format("soybean/views/{}/{}/modules/operate-drawer.vue", moduleName, businessName); } else if (template.contains("mapper.java.vm")) { fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); } else if (template.contains("service.java.vm")) { @@ -92,3 +137,36 @@ } return fileName; } + + /** + * 根据列类型获取字典组 + * + * @param genTable 业务表对象 + * @return 返回字典组 + */ + public static Set> getDictList(GenTable genTable) { + List columns = genTable.getColumns(); + Set> dicts = new HashSet<>(); + addDictList(dicts, columns); + return dicts; + } + + /** + * 添加字典列表 + * + * @param dicts 字典列表 + * @param columns 列集合 + */ + public static void addDictList(Set> dicts, List columns) { + for (GenTableColumn column : columns) { + if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny( + column.getHtmlType(), + new String[]{GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX})) { + Map dict = new HashMap<>(); + dict.put("type", column.getDictType()); + dict.put("name", StringUtils.toCamelCase(column.getDictType())); + dict.put("immediate", !column.isList()); + dicts.add(dict); + } + } + } diff --git a/docs/template/api/soy.api.ts.vm b/docs/template/api/soy.api.ts.vm index 3483a4f6..59119adf 100644 --- a/docs/template/api/soy.api.ts.vm +++ b/docs/template/api/soy.api.ts.vm @@ -1,7 +1,7 @@ import { request } from '@/service/request'; /** 获取${functionName}列表 */ -export function fetchGet${BusinessName}List(params?: Api.System.${BusinessName}SearchParams) { +export function fetchGet${BusinessName}List (params?: Api.System.${BusinessName}SearchParams) { return request({ url: '/${moduleName}/${businessName}/list', method: 'get', @@ -10,7 +10,7 @@ export function fetchGet${BusinessName}List(params?: Api.System.${BusinessName}S } /** 新增${functionName} */ -export function fetchCreate${BusinessName}(data: Api.${ModuleName}.${BusinessName}OperateParams) { +export function fetchCreate${BusinessName} (data: Api.${ModuleName}.${BusinessName}OperateParams) { return request({ url: '/${moduleName}/${businessName}', method: 'post', @@ -19,7 +19,7 @@ export function fetchCreate${BusinessName}(data: Api.${ModuleName}.${BusinessNam } /** 修改${functionName} */ -export function fetchUpdate${BusinessName}(data: Api.${ModuleName}.${BusinessName}OperateParams) { +export function fetchUpdate${BusinessName} (data: Api.${ModuleName}.${BusinessName}OperateParams) { return request({ url: '/${moduleName}/${businessName}', method: 'put', @@ -28,7 +28,7 @@ export function fetchUpdate${BusinessName}(data: Api.${ModuleName}.${BusinessNam } /** 批量删除${functionName} */ -export function fetchDelete${BusinessName}(${pkColumn.javaField}s: CommonType.IdType[]) { +export function fetchDelete${BusinessName} (${pkColumn.javaField}s: CommonType.IdType[]) { return request({ url: `/${moduleName}/${businessName}/${${pkColumn.javaField}s.join(',')}`, method: 'delete' diff --git a/docs/template/modules/soy.operate-drawer.vue.vm b/docs/template/modules/soy.operate-drawer.vue.vm new file mode 100644 index 00000000..1874fe87 --- /dev/null +++ b/docs/template/modules/soy.operate-drawer.vue.vm @@ -0,0 +1,195 @@ + + + + + diff --git a/docs/template/modules/soy.search.vue.vm b/docs/template/modules/soy.search.vue.vm new file mode 100644 index 00000000..c489ecf4 --- /dev/null +++ b/docs/template/modules/soy.search.vue.vm @@ -0,0 +1,137 @@ +#set($ModuleName=$moduleName.substring(0, 1).toUpperCase() + $moduleName.substring(1)) + + + + + diff --git a/docs/template/soy.index.vue.vm b/docs/template/soy.index.vue.vm index 591f62a0..5f5e7564 100644 --- a/docs/template/soy.index.vue.vm +++ b/docs/template/soy.index.vue.vm @@ -7,6 +7,10 @@ import { useTable, useTableOperate } from '@/hooks/common/table'; import ${BusinessName}OperateDrawer from './modules/${businessName}-operate-drawer.vue'; import ${BusinessName}Search from './modules/${businessName}-search.vue'; +defineOptions({ + name: '${BusinessName}List' +}); + const appStore = useAppStore(); const { @@ -113,7 +117,7 @@ async function edit(id: number) {