修改代码生成器
This commit is contained in:
@@ -58,7 +58,7 @@ public class CmsGenerator {
|
|||||||
// "cms_website_field",
|
// "cms_website_field",
|
||||||
// "cms_form",
|
// "cms_form",
|
||||||
// "cms_form_record",
|
// "cms_form_record",
|
||||||
"cms_domain"
|
// "cms_domain"
|
||||||
|
|
||||||
};
|
};
|
||||||
// 需要去除的表前缀
|
// 需要去除的表前缀
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ public class OaGenerator {
|
|||||||
// "oa_company_field",
|
// "oa_company_field",
|
||||||
// "oa_company_user",
|
// "oa_company_user",
|
||||||
// "oa_order",
|
// "oa_order",
|
||||||
"oa_goods",
|
// "oa_goods",
|
||||||
"oa_goods_category"
|
// "oa_goods_category"
|
||||||
};
|
};
|
||||||
// 需要去除的表前缀
|
// 需要去除的表前缀
|
||||||
private static final String[] TABLE_PREFIX = new String[]{
|
private static final String[] TABLE_PREFIX = new String[]{
|
||||||
|
|||||||
@@ -0,0 +1,176 @@
|
|||||||
|
package com.gxwebsoft.generator;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||||
|
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||||
|
import com.baomidou.mybatisplus.generator.InjectionConfig;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.*;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||||
|
import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成工具
|
||||||
|
*
|
||||||
|
* @author WebSoft
|
||||||
|
* @since 2021-09-05 00:31:14
|
||||||
|
*/
|
||||||
|
public class ShopGenerator {
|
||||||
|
// 输出位置
|
||||||
|
private static final String OUTPUT_LOCATION = System.getProperty("user.dir");
|
||||||
|
//private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径
|
||||||
|
// 输出目录
|
||||||
|
private static final String OUTPUT_DIR = "/src/main/java";
|
||||||
|
// 作者名称
|
||||||
|
private static final String AUTHOR = "科技小王子";
|
||||||
|
// 是否在xml中添加二级缓存配置
|
||||||
|
private static final boolean ENABLE_CACHE = false;
|
||||||
|
// 数据库连接配置
|
||||||
|
private static final String DB_URL = "jdbc:mysql://47.119.165.234:3308/modules?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";
|
||||||
|
private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
|
||||||
|
private static final String DB_USERNAME = "modules";
|
||||||
|
private static final String DB_PASSWORD = "FYJGx7s8yt7K8xDH";
|
||||||
|
// 包名
|
||||||
|
private static final String PACKAGE_NAME = "com.gxwebsoft";
|
||||||
|
// 模块名
|
||||||
|
private static final String MODULE_NAME = "shop";
|
||||||
|
// 需要生成的表
|
||||||
|
private static final String[] TABLE_NAMES = new String[]{
|
||||||
|
"shop_goods",
|
||||||
|
"shop_goods_attr",
|
||||||
|
"shop_goods_attr_result",
|
||||||
|
"shop_goods_attr_value",
|
||||||
|
"shop_goods_category",
|
||||||
|
"shop_goods_coupon",
|
||||||
|
"shop_goods_description",
|
||||||
|
"shop_goods_log",
|
||||||
|
"shop_goods_relation",
|
||||||
|
"shop_goods_comment",
|
||||||
|
"shop_goods_rule"
|
||||||
|
};
|
||||||
|
// 需要去除的表前缀
|
||||||
|
private static final String[] TABLE_PREFIX = new String[]{
|
||||||
|
"shop_",
|
||||||
|
"tb_"
|
||||||
|
};
|
||||||
|
// 不需要作为查询参数的字段
|
||||||
|
private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{
|
||||||
|
"tenant_id",
|
||||||
|
"create_time",
|
||||||
|
"update_time"
|
||||||
|
};
|
||||||
|
// 查询参数使用String的类型
|
||||||
|
private static final String[] PARAM_TO_STRING_TYPE = new String[]{
|
||||||
|
"Date",
|
||||||
|
"LocalDate",
|
||||||
|
"LocalTime",
|
||||||
|
"LocalDateTime"
|
||||||
|
};
|
||||||
|
// 查询参数使用EQ的类型
|
||||||
|
private static final String[] PARAM_EQ_TYPE = new String[]{
|
||||||
|
"Integer",
|
||||||
|
"Boolean",
|
||||||
|
"BigDecimal"
|
||||||
|
};
|
||||||
|
// 是否添加权限注解
|
||||||
|
private static final boolean AUTH_ANNOTATION = true;
|
||||||
|
// 是否添加日志注解
|
||||||
|
private static final boolean LOG_ANNOTATION = true;
|
||||||
|
// controller的mapping前缀
|
||||||
|
private static final String CONTROLLER_MAPPING_PREFIX = "/api";
|
||||||
|
// 模板所在位置
|
||||||
|
private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// 代码生成器
|
||||||
|
AutoGenerator mpg = new AutoGenerator();
|
||||||
|
|
||||||
|
// 全局配置
|
||||||
|
GlobalConfig gc = new GlobalConfig();
|
||||||
|
gc.setOutputDir(OUTPUT_LOCATION + OUTPUT_DIR);
|
||||||
|
gc.setAuthor(AUTHOR);
|
||||||
|
gc.setOpen(false);
|
||||||
|
gc.setFileOverride(true);
|
||||||
|
gc.setEnableCache(ENABLE_CACHE);
|
||||||
|
gc.setSwagger2(true);
|
||||||
|
gc.setIdType(IdType.AUTO);
|
||||||
|
gc.setServiceName("%sService");
|
||||||
|
mpg.setGlobalConfig(gc);
|
||||||
|
|
||||||
|
// 数据源配置
|
||||||
|
DataSourceConfig dsc = new DataSourceConfig();
|
||||||
|
dsc.setUrl(DB_URL);
|
||||||
|
// dsc.setSchemaName("public");
|
||||||
|
dsc.setDriverName(DB_DRIVER);
|
||||||
|
dsc.setUsername(DB_USERNAME);
|
||||||
|
dsc.setPassword(DB_PASSWORD);
|
||||||
|
mpg.setDataSource(dsc);
|
||||||
|
|
||||||
|
// 包配置
|
||||||
|
PackageConfig pc = new PackageConfig();
|
||||||
|
pc.setModuleName(MODULE_NAME);
|
||||||
|
pc.setParent(PACKAGE_NAME);
|
||||||
|
mpg.setPackageInfo(pc);
|
||||||
|
|
||||||
|
// 策略配置
|
||||||
|
StrategyConfig strategy = new StrategyConfig();
|
||||||
|
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||||
|
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
||||||
|
strategy.setInclude(TABLE_NAMES);
|
||||||
|
strategy.setTablePrefix(TABLE_PREFIX);
|
||||||
|
strategy.setSuperControllerClass(PACKAGE_NAME + ".common.core.web.BaseController");
|
||||||
|
strategy.setEntityLombokModel(true);
|
||||||
|
strategy.setRestControllerStyle(true);
|
||||||
|
strategy.setControllerMappingHyphenStyle(true);
|
||||||
|
strategy.setLogicDeleteFieldName("deleted");
|
||||||
|
mpg.setStrategy(strategy);
|
||||||
|
|
||||||
|
// 模板配置
|
||||||
|
TemplateConfig templateConfig = new TemplateConfig();
|
||||||
|
templateConfig.setController(TEMPLATES_DIR + "/controller.java");
|
||||||
|
templateConfig.setEntity(TEMPLATES_DIR + "/entity.java");
|
||||||
|
templateConfig.setMapper(TEMPLATES_DIR + "/mapper.java");
|
||||||
|
templateConfig.setXml(TEMPLATES_DIR + "/mapper.xml");
|
||||||
|
templateConfig.setService(TEMPLATES_DIR + "/service.java");
|
||||||
|
templateConfig.setServiceImpl(TEMPLATES_DIR + "/serviceImpl.java");
|
||||||
|
mpg.setTemplate(templateConfig);
|
||||||
|
mpg.setTemplateEngine(new BeetlTemplateEnginePlus());
|
||||||
|
|
||||||
|
// 自定义模板配置
|
||||||
|
InjectionConfig cfg = new InjectionConfig() {
|
||||||
|
@Override
|
||||||
|
public void initMap() {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("packageName", PACKAGE_NAME);
|
||||||
|
map.put("paramExcludeFields", PARAM_EXCLUDE_FIELDS);
|
||||||
|
map.put("paramToStringType", PARAM_TO_STRING_TYPE);
|
||||||
|
map.put("paramEqType", PARAM_EQ_TYPE);
|
||||||
|
map.put("authAnnotation", AUTH_ANNOTATION);
|
||||||
|
map.put("logAnnotation", LOG_ANNOTATION);
|
||||||
|
map.put("controllerMappingPrefix", CONTROLLER_MAPPING_PREFIX);
|
||||||
|
this.setMap(map);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
String templatePath = TEMPLATES_DIR + "/param.java.btl";
|
||||||
|
List<FileOutConfig> focList = new ArrayList<>();
|
||||||
|
focList.add(new FileOutConfig(templatePath) {
|
||||||
|
@Override
|
||||||
|
public String outputFile(TableInfo tableInfo) {
|
||||||
|
return OUTPUT_LOCATION + OUTPUT_DIR + "/"
|
||||||
|
+ PACKAGE_NAME.replace(".", "/")
|
||||||
|
+ "/" + pc.getModuleName() + "/param/"
|
||||||
|
+ tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
cfg.setFileOutConfigList(focList);
|
||||||
|
mpg.setCfg(cfg);
|
||||||
|
|
||||||
|
mpg.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -71,11 +71,8 @@ public class ${table.controllerName} {
|
|||||||
<% } %>
|
<% } %>
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
public ApiResult<PageResult<${entity}>> page(${entity}Param param) {
|
public ApiResult<PageResult<${entity}>> page(${entity}Param param) {
|
||||||
PageParam<${entity}, ${entity}Param> page = new PageParam<>(param);
|
|
||||||
page.setDefaultOrder("create_time desc");
|
|
||||||
return success(${serviceIns}.page(page, page.getWrapper()));
|
|
||||||
// 使用关联查询
|
// 使用关联查询
|
||||||
//return success(${serviceIns}.pageRel(param));
|
return success(${serviceIns}.pageRel(param));
|
||||||
}
|
}
|
||||||
|
|
||||||
<% if(!swagger2) { %>
|
<% if(!swagger2) { %>
|
||||||
@@ -91,11 +88,8 @@ public class ${table.controllerName} {
|
|||||||
<% } %>
|
<% } %>
|
||||||
@GetMapping()
|
@GetMapping()
|
||||||
public ApiResult<List<${entity}>> list(${entity}Param param) {
|
public ApiResult<List<${entity}>> list(${entity}Param param) {
|
||||||
PageParam<${entity}, ${entity}Param> page = new PageParam<>(param);
|
|
||||||
page.setDefaultOrder("create_time desc");
|
|
||||||
return success(${serviceIns}.list(page.getOrderWrapper()));
|
|
||||||
// 使用关联查询
|
// 使用关联查询
|
||||||
//return success(${serviceIns}.listRel(param));
|
return success(${serviceIns}.listRel(param));
|
||||||
}
|
}
|
||||||
|
|
||||||
<% if(!swagger2) { %>
|
<% if(!swagger2) { %>
|
||||||
@@ -106,9 +100,8 @@ public class ${table.controllerName} {
|
|||||||
@ApiOperation("根据id查询${table.comment!}")
|
@ApiOperation("根据id查询${table.comment!}")
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public ApiResult<${entity}> get(@PathVariable("id") Integer id) {
|
public ApiResult<${entity}> get(@PathVariable("id") Integer id) {
|
||||||
return success(${serviceIns}.getById(id));
|
|
||||||
// 使用关联查询
|
// 使用关联查询
|
||||||
//return success(${serviceIns}.getByIdRel(id));
|
return success(${serviceIns}.getByIdRel(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
<% if(!swagger2) { %>
|
<% if(!swagger2) { %>
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.m
|
|||||||
@Override
|
@Override
|
||||||
public PageResult<${entity}> pageRel(${entity}Param param) {
|
public PageResult<${entity}> pageRel(${entity}Param param) {
|
||||||
PageParam<${entity}, ${entity}Param> page = new PageParam<>(param);
|
PageParam<${entity}, ${entity}Param> page = new PageParam<>(param);
|
||||||
//page.setDefaultOrder("create_time desc");
|
page.setDefaultOrder("sort_number asc, create_time desc");
|
||||||
List<${entity}> list = baseMapper.selectPageRel(page, param);
|
List<${entity}> list = baseMapper.selectPageRel(page, param);
|
||||||
return new PageResult<>(list, page.getTotal());
|
return new PageResult<>(list, page.getTotal());
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.m
|
|||||||
List<${entity}> list = baseMapper.selectListRel(param);
|
List<${entity}> list = baseMapper.selectListRel(param);
|
||||||
// 排序
|
// 排序
|
||||||
PageParam<${entity}, ${entity}Param> page = new PageParam<>();
|
PageParam<${entity}, ${entity}Param> page = new PageParam<>();
|
||||||
//page.setDefaultOrder("create_time desc");
|
page.setDefaultOrder("sort_number asc, create_time desc");
|
||||||
return page.sortRecords(list);
|
return page.sortRecords(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,185 @@
|
|||||||
|
package com.gxwebsoft.generatorVue;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||||
|
import com.baomidou.mybatisplus.generator.InjectionConfig;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.*;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||||
|
import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成工具
|
||||||
|
*
|
||||||
|
* @author WebSoft
|
||||||
|
* @since 2021-09-05 00:31:14
|
||||||
|
*/
|
||||||
|
public class ShopVueGenerator {
|
||||||
|
// 输出位置
|
||||||
|
// private static final String OUTPUT_LOCATION = System.getProperty("user.dir");
|
||||||
|
private static final String OUTPUT_LOCATION = "/Users/gxwebsoft/VUE/com.gxwebsoft.core-web"; // 不想生成到项目中可以写磁盘路径
|
||||||
|
// 输出目录
|
||||||
|
private static final String OUTPUT_DIR = "/generator";
|
||||||
|
// 作者名称
|
||||||
|
private static final String AUTHOR = "科技小王子";
|
||||||
|
// 是否在xml中添加二级缓存配置
|
||||||
|
private static final boolean ENABLE_CACHE = false;
|
||||||
|
// 数据库连接配置
|
||||||
|
private static final String DB_URL = "jdbc:mysql://47.119.165.234:3308/modules?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";
|
||||||
|
private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
|
||||||
|
private static final String DB_USERNAME = "modules";
|
||||||
|
private static final String DB_PASSWORD = "FYJGx7s8yt7K8xDH";
|
||||||
|
// 包名
|
||||||
|
private static final String PACKAGE_NAME = "";
|
||||||
|
// 模块名
|
||||||
|
private static final String MODULE_NAME = "shop";
|
||||||
|
// 需要生成的表
|
||||||
|
private static final String[] TABLE_NAMES = new String[]{
|
||||||
|
"shop_goods",
|
||||||
|
// "shop_goods_attr",
|
||||||
|
// "shop_goods_attr_result",
|
||||||
|
// "shop_goods_attr_value",
|
||||||
|
// "shop_goods_category",
|
||||||
|
// "shop_goods_coupon",
|
||||||
|
// "shop_goods_description",
|
||||||
|
// "shop_goods_log",
|
||||||
|
// "shop_goods_relation",
|
||||||
|
// "shop_goods_comment",
|
||||||
|
"shop_goods_rule"
|
||||||
|
};
|
||||||
|
// 需要去除的表前缀
|
||||||
|
private static final String[] TABLE_PREFIX = new String[]{
|
||||||
|
"shop_",
|
||||||
|
"tb_"
|
||||||
|
};
|
||||||
|
// 不需要作为查询参数的字段
|
||||||
|
private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{
|
||||||
|
"tenant_id",
|
||||||
|
"create_time",
|
||||||
|
"update_time"
|
||||||
|
};
|
||||||
|
// 查询参数使用String的类型
|
||||||
|
private static final String[] PARAM_TO_STRING_TYPE = new String[]{
|
||||||
|
"Date",
|
||||||
|
"LocalDate",
|
||||||
|
"LocalTime",
|
||||||
|
"LocalDateTime"
|
||||||
|
};
|
||||||
|
// 查询参数使用EQ的类型
|
||||||
|
private static final String[] PARAM_EQ_TYPE = new String[]{
|
||||||
|
"Integer",
|
||||||
|
"Boolean",
|
||||||
|
"BigDecimal"
|
||||||
|
};
|
||||||
|
// 是否添加权限注解
|
||||||
|
private static final boolean AUTH_ANNOTATION = true;
|
||||||
|
// 是否添加日志注解
|
||||||
|
private static final boolean LOG_ANNOTATION = true;
|
||||||
|
// controller的mapping前缀
|
||||||
|
private static final String CONTROLLER_MAPPING_PREFIX = "/api";
|
||||||
|
// 模板所在位置
|
||||||
|
private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generatorVue/templates";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// 代码生成器
|
||||||
|
AutoGenerator mpg = new AutoGenerator();
|
||||||
|
|
||||||
|
// 全局配置
|
||||||
|
GlobalConfig gc = new GlobalConfig();
|
||||||
|
gc.setOutputDir(OUTPUT_LOCATION + OUTPUT_DIR);
|
||||||
|
gc.setAuthor(AUTHOR);
|
||||||
|
gc.setOpen(false);
|
||||||
|
gc.setFileOverride(true);
|
||||||
|
gc.setEnableCache(ENABLE_CACHE);
|
||||||
|
gc.setSwagger2(true);
|
||||||
|
gc.setIdType(IdType.AUTO);
|
||||||
|
gc.setServiceName("%sService");
|
||||||
|
mpg.setGlobalConfig(gc);
|
||||||
|
|
||||||
|
// 数据源配置
|
||||||
|
DataSourceConfig dsc = new DataSourceConfig();
|
||||||
|
dsc.setUrl(DB_URL);
|
||||||
|
// dsc.setSchemaName("public");
|
||||||
|
dsc.setDriverName(DB_DRIVER);
|
||||||
|
dsc.setUsername(DB_USERNAME);
|
||||||
|
dsc.setPassword(DB_PASSWORD);
|
||||||
|
mpg.setDataSource(dsc);
|
||||||
|
|
||||||
|
// 包配置
|
||||||
|
PackageConfig pc = new PackageConfig();
|
||||||
|
pc.setModuleName(MODULE_NAME);
|
||||||
|
pc.setParent(PACKAGE_NAME);
|
||||||
|
mpg.setPackageInfo(pc);
|
||||||
|
|
||||||
|
// 策略配置
|
||||||
|
StrategyConfig strategy = new StrategyConfig();
|
||||||
|
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||||
|
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
||||||
|
strategy.setInclude(TABLE_NAMES);
|
||||||
|
strategy.setTablePrefix(TABLE_PREFIX);
|
||||||
|
strategy.setSuperControllerClass(PACKAGE_NAME + ".common.core.web.BaseController");
|
||||||
|
strategy.setEntityLombokModel(true);
|
||||||
|
strategy.setRestControllerStyle(true);
|
||||||
|
strategy.setControllerMappingHyphenStyle(true);
|
||||||
|
strategy.setLogicDeleteFieldName("deleted");
|
||||||
|
mpg.setStrategy(strategy);
|
||||||
|
|
||||||
|
// 模板配置
|
||||||
|
TemplateConfig templateConfig = new TemplateConfig();
|
||||||
|
// templateConfig.setController(TEMPLATES_DIR + "/index.ts");
|
||||||
|
// templateConfig.setEntity(TEMPLATES_DIR + "/model.ts");
|
||||||
|
// templateConfig.setMapper(TEMPLATES_DIR + "/search.vue");
|
||||||
|
// templateConfig.setXml(TEMPLATES_DIR + "/search.vue");
|
||||||
|
// templateConfig.setService(TEMPLATES_DIR + "/index.vue");
|
||||||
|
// templateConfig.setServiceImpl(TEMPLATES_DIR + "/components.edit.vue");
|
||||||
|
mpg.setTemplate(templateConfig);
|
||||||
|
mpg.setTemplateEngine(new BeetlTemplateEnginePlus());
|
||||||
|
|
||||||
|
// 自定义模板配置
|
||||||
|
InjectionConfig cfg = new InjectionConfig() {
|
||||||
|
@Override
|
||||||
|
public void initMap() {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("packageName", PACKAGE_NAME);
|
||||||
|
map.put("paramExcludeFields", PARAM_EXCLUDE_FIELDS);
|
||||||
|
map.put("paramToStringType", PARAM_TO_STRING_TYPE);
|
||||||
|
map.put("paramEqType", PARAM_EQ_TYPE);
|
||||||
|
map.put("authAnnotation", AUTH_ANNOTATION);
|
||||||
|
map.put("logAnnotation", LOG_ANNOTATION);
|
||||||
|
map.put("controllerMappingPrefix", CONTROLLER_MAPPING_PREFIX);
|
||||||
|
this.setMap(map);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
String templatePath = TEMPLATES_DIR + "/index.ts.btl";
|
||||||
|
List<FileOutConfig> focList = new ArrayList<>();
|
||||||
|
focList.add(new FileOutConfig(templatePath) {
|
||||||
|
@Override
|
||||||
|
public String outputFile(TableInfo tableInfo) {
|
||||||
|
return OUTPUT_LOCATION + OUTPUT_DIR + "/"
|
||||||
|
+ PACKAGE_NAME.replace(".", "/")
|
||||||
|
+ "/" + pc.getModuleName() + "/api/"
|
||||||
|
+ tableInfo.getEntityPath() + '/' + "index.ts";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
templatePath = TEMPLATES_DIR + "/model.ts.btl";
|
||||||
|
focList.add(new FileOutConfig(templatePath) {
|
||||||
|
@Override
|
||||||
|
public String outputFile(TableInfo tableInfo) {
|
||||||
|
return OUTPUT_LOCATION + OUTPUT_DIR + "/"
|
||||||
|
+ PACKAGE_NAME.replace(".", "/")
|
||||||
|
+ "/" + pc.getModuleName() + "/api/"
|
||||||
|
+ tableInfo.getEntityPath() + "/model/" + "index.ts";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
cfg.setFileOutConfigList(focList);
|
||||||
|
mpg.setCfg(cfg);
|
||||||
|
|
||||||
|
mpg.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.gxwebsoft.generatorVue.engine;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
|
||||||
|
import com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine;
|
||||||
|
import org.beetl.core.Configuration;
|
||||||
|
import org.beetl.core.GroupTemplate;
|
||||||
|
import org.beetl.core.Template;
|
||||||
|
import org.beetl.core.resource.FileResourceLoader;
|
||||||
|
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Beetl模板引擎实现文件输出
|
||||||
|
*
|
||||||
|
* @author WebSoft
|
||||||
|
* @since 2021-09-05 00:30:28
|
||||||
|
*/
|
||||||
|
public class BeetlTemplateEnginePlus extends AbstractTemplateEngine {
|
||||||
|
private GroupTemplate groupTemplate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractTemplateEngine init(ConfigBuilder configBuilder) {
|
||||||
|
super.init(configBuilder);
|
||||||
|
try {
|
||||||
|
Configuration cfg = Configuration.defaultConfiguration();
|
||||||
|
groupTemplate = new GroupTemplate(new FileResourceLoader(), cfg);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writer(Map<String, Object> objectMap, String templatePath, String outputFile) throws Exception {
|
||||||
|
Template template = groupTemplate.getTemplate(templatePath);
|
||||||
|
try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile)) {
|
||||||
|
template.binding(objectMap);
|
||||||
|
template.renderTo(fileOutputStream);
|
||||||
|
}
|
||||||
|
logger.debug("模板:" + templatePath + "; 文件:" + outputFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String templateFilePath(String filePath) {
|
||||||
|
return filePath + ".btl";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,361 @@
|
|||||||
|
<!-- 编辑弹窗 -->
|
||||||
|
<template>
|
||||||
|
<ele-modal
|
||||||
|
:width="800"
|
||||||
|
:visible="visible"
|
||||||
|
:maskClosable="false"
|
||||||
|
:maxable="maxable"
|
||||||
|
:title="isUpdate ? '编辑广告' : '添加广告'"
|
||||||
|
:body-style="{ paddingBottom: '28px' }"
|
||||||
|
@update:visible="updateVisible"
|
||||||
|
@ok="save"
|
||||||
|
>
|
||||||
|
<a-form
|
||||||
|
ref="formRef"
|
||||||
|
:model="form"
|
||||||
|
:rules="rules"
|
||||||
|
:label-col="styleResponsive ? { md: 4, sm: 5, xs: 24 } : { flex: '90px' }"
|
||||||
|
:wrapper-col="
|
||||||
|
styleResponsive ? { md: 19, sm: 19, xs: 24 } : { flex: '1' }
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<a-form-item label="广告位类型" name="adType">
|
||||||
|
<a-select
|
||||||
|
ref="select"
|
||||||
|
v-model:value="form.adType"
|
||||||
|
style="width: 120px"
|
||||||
|
>
|
||||||
|
<a-select-option value="图片广告">图片广告</a-select-option>
|
||||||
|
<a-select-option value="幻灯片">幻灯片</a-select-option>
|
||||||
|
<a-select-option value="视频广告">视频广告</a-select-option>
|
||||||
|
</a-select>
|
||||||
|
</a-form-item>
|
||||||
|
<template v-if="form.adType == '幻灯片'">
|
||||||
|
<a-form-item label="广告图片" name="images" extra="请上传广告图片,最多可上传9张图">
|
||||||
|
<SelectFile
|
||||||
|
:placeholder="`请选择图片`"
|
||||||
|
:limit="9"
|
||||||
|
:data="images"
|
||||||
|
@done="chooseFile"
|
||||||
|
@del="onDeleteItem"
|
||||||
|
/>
|
||||||
|
<!-- <ele-image-upload-->
|
||||||
|
<!-- v-model:value="images"-->
|
||||||
|
<!-- :limit="9"-->
|
||||||
|
<!-- :drag="true"-->
|
||||||
|
<!-- :accept="'image/png,image/jpeg'"-->
|
||||||
|
<!-- :item-style="{ maxWidth: '160px', maxHeight: '160px' }"-->
|
||||||
|
<!-- :upload-handler="uploadHandler"-->
|
||||||
|
<!-- @upload="onUpload"-->
|
||||||
|
<!-- />-->
|
||||||
|
</a-form-item>
|
||||||
|
</template>
|
||||||
|
<template v-if="form.adType == '图片广告'">
|
||||||
|
<a-form-item label="广告图片" name="images" extra="请上传广告图片">
|
||||||
|
<SelectFile
|
||||||
|
:placeholder="`请选择图片`"
|
||||||
|
:limit="1"
|
||||||
|
:data="images"
|
||||||
|
@done="chooseFile"
|
||||||
|
@del="onDeleteItem"
|
||||||
|
/>
|
||||||
|
<!-- <ele-image-upload-->
|
||||||
|
<!-- v-model:value="images"-->
|
||||||
|
<!-- :limit="1"-->
|
||||||
|
<!-- :accept="'image/png,image/jpeg'"-->
|
||||||
|
<!-- :drag="true"-->
|
||||||
|
<!-- :item-style="{ maxWidth: '160px', maxHeight: '160px' }"-->
|
||||||
|
<!-- :upload-handler="uploadHandler"-->
|
||||||
|
<!-- @upload="onUpload"-->
|
||||||
|
<!-- />-->
|
||||||
|
</a-form-item>
|
||||||
|
</template>
|
||||||
|
<template v-if="form.adType == '视频广告'">
|
||||||
|
<a-form-item label="上传视频" name="images" extra="请上传视频文件,仅支持mp4格式,大小200M以内">
|
||||||
|
<SelectFile
|
||||||
|
:placeholder="`请选择视频文件`"
|
||||||
|
:limit="1"
|
||||||
|
:data="images"
|
||||||
|
@done="chooseFile"
|
||||||
|
@del="onDeleteItem"
|
||||||
|
/>
|
||||||
|
<!-- <ele-image-upload-->
|
||||||
|
<!-- v-model:value="images"-->
|
||||||
|
<!-- :limit="1"-->
|
||||||
|
<!-- :accept="'video/mp4'"-->
|
||||||
|
<!-- :drag="true"-->
|
||||||
|
<!-- :item-style="{ maxWidth: '160px', maxHeight: '160px' }"-->
|
||||||
|
<!-- :upload-handler="uploadHandler"-->
|
||||||
|
<!-- @upload="onUpload"-->
|
||||||
|
<!-- />-->
|
||||||
|
</a-form-item>
|
||||||
|
</template>
|
||||||
|
<a-form-item label="广告位名称" name="name">
|
||||||
|
<a-input
|
||||||
|
allow-clear
|
||||||
|
:maxlength="100"
|
||||||
|
placeholder="请输入广告位名称"
|
||||||
|
v-model:value="form.name"
|
||||||
|
/>
|
||||||
|
</a-form-item>
|
||||||
|
<a-form-item label="广告位描述" name="comments">
|
||||||
|
<a-textarea
|
||||||
|
:rows="4"
|
||||||
|
:maxlength="200"
|
||||||
|
placeholder="请输入广告位描述"
|
||||||
|
v-model:value="form.comments"
|
||||||
|
/>
|
||||||
|
</a-form-item>
|
||||||
|
<a-form-item label="路由/链接地址" name="path">
|
||||||
|
<a-input
|
||||||
|
allow-clear
|
||||||
|
:maxlength="100"
|
||||||
|
placeholder="请输入路由/链接地址"
|
||||||
|
v-model:value="form.path"
|
||||||
|
/>
|
||||||
|
</a-form-item>
|
||||||
|
<a-form-item label="排序号" name="sortNumber">
|
||||||
|
<a-input-number
|
||||||
|
:min="0"
|
||||||
|
:max="9999"
|
||||||
|
class="ele-fluid"
|
||||||
|
placeholder="请输入排序号"
|
||||||
|
v-model:value="form.sortNumber"
|
||||||
|
/>
|
||||||
|
</a-form-item>
|
||||||
|
<a-form-item label="状态" name="status">
|
||||||
|
<a-radio-group v-model:value="form.status">
|
||||||
|
<a-radio :value="0">开启</a-radio>
|
||||||
|
<a-radio :value="1">关闭</a-radio>
|
||||||
|
</a-radio-group>
|
||||||
|
</a-form-item>
|
||||||
|
</a-form>
|
||||||
|
</ele-modal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref, reactive, watch } from 'vue';
|
||||||
|
import { Form, message } from 'ant-design-vue';
|
||||||
|
import {assignObject, isChinese} from 'ele-admin-pro';
|
||||||
|
import { addAd, updateAd } from '@/api/cms/ad';
|
||||||
|
import { Ad } from '@/api/cms/ad/model';
|
||||||
|
import { useThemeStore } from '@/store/modules/theme';
|
||||||
|
import { storeToRefs } from 'pinia';
|
||||||
|
import {FormInstance, RuleObject} from 'ant-design-vue/es/form';
|
||||||
|
import { ItemType } from 'ele-admin-pro/es/ele-image-upload/types';
|
||||||
|
import { uploadFile } from '@/api/system/file';
|
||||||
|
import {FileRecord} from "@/api/system/file/model";
|
||||||
|
|
||||||
|
// 是否是修改
|
||||||
|
const isUpdate = ref(false);
|
||||||
|
const useForm = Form.useForm;
|
||||||
|
// 是否开启响应式布局
|
||||||
|
const themeStore = useThemeStore();
|
||||||
|
const { styleResponsive } = storeToRefs(themeStore);
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
// 弹窗是否打开
|
||||||
|
visible: boolean;
|
||||||
|
// 修改回显的数据
|
||||||
|
data?: Ad | null;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'done'): void;
|
||||||
|
(e: 'update:visible', visible: boolean): void;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
// 提交状态
|
||||||
|
const loading = ref(false);
|
||||||
|
// 已上传数据
|
||||||
|
const images = ref<ItemType[]>([]);
|
||||||
|
// 是否显示最大化切换按钮
|
||||||
|
const maxable = ref(true);
|
||||||
|
// 表格选中数据
|
||||||
|
const formRef = ref<FormInstance | null>(null);
|
||||||
|
|
||||||
|
// 用户信息
|
||||||
|
const form = reactive<Ad>({
|
||||||
|
adId: undefined,
|
||||||
|
name: '',
|
||||||
|
adType: '图片广告',
|
||||||
|
images: '',
|
||||||
|
width: '',
|
||||||
|
height: '',
|
||||||
|
path: '',
|
||||||
|
type: '',
|
||||||
|
status: 0,
|
||||||
|
comments: '',
|
||||||
|
sortNumber: 100
|
||||||
|
});
|
||||||
|
|
||||||
|
/* 更新visible */
|
||||||
|
const updateVisible = (value: boolean) => {
|
||||||
|
emit('update:visible', value);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 表单验证规则
|
||||||
|
const rules = reactive({
|
||||||
|
name: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
type: 'string',
|
||||||
|
message: '请填写广告位名称',
|
||||||
|
trigger: 'blur'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
adType: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
type: 'string',
|
||||||
|
message: '请选择广告类型',
|
||||||
|
trigger: 'blur'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
images: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
type: 'string',
|
||||||
|
message: '请上传图片或视频',
|
||||||
|
trigger: 'blur',
|
||||||
|
validator: async (_rule: RuleObject, value: string) => {
|
||||||
|
if (images.value.length == 0) {
|
||||||
|
return Promise.reject('请上传图片或视频');
|
||||||
|
}
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
const { resetFields } = useForm(form, rules);
|
||||||
|
|
||||||
|
/* 上传事件 */
|
||||||
|
const uploadHandler = (file: File) => {
|
||||||
|
const item: ItemType = {
|
||||||
|
file,
|
||||||
|
uid: (file as any).uid,
|
||||||
|
name: file.name
|
||||||
|
};
|
||||||
|
if (file.type.startsWith('video')) {
|
||||||
|
if (file.size / 1024 / 1024 > 200) {
|
||||||
|
message.error('大小不能超过 200MB');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (file.type.startsWith('image')) {
|
||||||
|
if (file.size / 1024 / 1024 > 5) {
|
||||||
|
message.error('大小不能超过 5MB');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onUpload(item);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 上传文件
|
||||||
|
const onUpload = (item: any) => {
|
||||||
|
const { file } = item;
|
||||||
|
uploadFile(file)
|
||||||
|
.then((data) => {
|
||||||
|
images.value.push({
|
||||||
|
uid: data.id,
|
||||||
|
url: file.type == 'video/mp4' ? 'https://oss.wsdns.cn/20240301/6e4e32cb808245d4be336b9486961145.png' : data.path,
|
||||||
|
status: 'done'
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
message.error(e.message);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const chooseFile = (data: FileRecord) => {
|
||||||
|
images.value.push({
|
||||||
|
uid: data.id,
|
||||||
|
url: data.path,
|
||||||
|
status: 'done'
|
||||||
|
});
|
||||||
|
form.images = data.path;
|
||||||
|
}
|
||||||
|
|
||||||
|
const onDeleteItem = (index: number) => {
|
||||||
|
images.value.splice(index,1)
|
||||||
|
form.images = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 保存编辑 */
|
||||||
|
const save = () => {
|
||||||
|
if (!formRef.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
formRef.value
|
||||||
|
.validate()
|
||||||
|
.then(() => {
|
||||||
|
loading.value = true;
|
||||||
|
const formData = {
|
||||||
|
...form,
|
||||||
|
images: JSON.stringify(images.value)
|
||||||
|
};
|
||||||
|
const saveOrUpdate = isUpdate.value ? updateAd : addAd;
|
||||||
|
saveOrUpdate(formData)
|
||||||
|
.then((msg) => {
|
||||||
|
loading.value = false;
|
||||||
|
message.success(msg);
|
||||||
|
updateVisible(false);
|
||||||
|
emit('done');
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
loading.value = false;
|
||||||
|
message.error(e.message);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
|
};
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.visible,
|
||||||
|
(visible) => {
|
||||||
|
if (visible) {
|
||||||
|
if (props.data) {
|
||||||
|
assignObject(form, props.data);
|
||||||
|
images.value = [];
|
||||||
|
if (props.data.images) {
|
||||||
|
const arr = JSON.parse(props.data.images);
|
||||||
|
arr.map((d) => {
|
||||||
|
images.value.push({
|
||||||
|
uid: d.uid,
|
||||||
|
url: d.url,
|
||||||
|
status: 'done'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
isUpdate.value = true;
|
||||||
|
} else {
|
||||||
|
images.value = [];
|
||||||
|
isUpdate.value = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
resetFields();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
<style lang="less">
|
||||||
|
.tab-pane {
|
||||||
|
min-height: 300px;
|
||||||
|
}
|
||||||
|
.ml-10 {
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
.upload-text {
|
||||||
|
margin-right: 70px;
|
||||||
|
}
|
||||||
|
.icon-bg {
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
display: block;
|
||||||
|
border-radius: 50px;
|
||||||
|
background: url('data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20version%3D%221.1%22%3E%3Cdefs%3E%3ClinearGradient%20id%3D%221%22%20x1%3D%220%22%20x2%3D%221%22%20y1%3D%220%22%20y2%3D%220%22%20gradientTransform%3D%22matrix(6.123233995736766e-17%2C%201%2C%20-0.024693877551020406%2C%206.123233995736766e-17%2C%200.5%2C%200)%22%3E%3Cstop%20stop-color%3D%22%230a060d%22%20stop-opacity%3D%221%22%20offset%3D%220%22%3E%3C%2Fstop%3E%3Cstop%20stop-color%3D%22%23660061%22%20stop-opacity%3D%221%22%20offset%3D%220.95%22%3E%3C%2Fstop%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22url(%231)%22%3E%3C%2Frect%3E%3C%2Fsvg%3E');
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
import request from '@/utils/request';
|
||||||
|
import type { ApiResult, PageResult } from '@/api';
|
||||||
|
import type { ${entity}, ${entity}Param } from './model';
|
||||||
|
import { MODULES_API_URL } from '@/config/setting';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询${table.comment!}
|
||||||
|
*/
|
||||||
|
export async function page${entity}(params: ${entity}Param) {
|
||||||
|
const res = await request.get<ApiResult<PageResult<${entity}>>>(
|
||||||
|
MODULES_API_URL + '/shop/${controllerMappingHyphen}/page',
|
||||||
|
{
|
||||||
|
params
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (res.data.code === 0) {
|
||||||
|
return res.data.data;
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error(res.data.message));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询${table.comment!}列表
|
||||||
|
*/
|
||||||
|
export async function list${entity}(params?: ${entity}Param) {
|
||||||
|
const res = await request.get<ApiResult<${entity}[]>>(
|
||||||
|
MODULES_API_URL + '/shop/${controllerMappingHyphen}',
|
||||||
|
{
|
||||||
|
params
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (res.data.code === 0 && res.data.data) {
|
||||||
|
return res.data.data;
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error(res.data.message));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加${table.comment!}
|
||||||
|
*/
|
||||||
|
export async function add${entity}(data: ${entity}) {
|
||||||
|
const res = await request.post<ApiResult<unknown>>(
|
||||||
|
MODULES_API_URL + '/shop/${controllerMappingHyphen}',
|
||||||
|
data
|
||||||
|
);
|
||||||
|
if (res.data.code === 0) {
|
||||||
|
return res.data.message;
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error(res.data.message));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改${table.comment!}
|
||||||
|
*/
|
||||||
|
export async function update${entity}(data: ${entity}) {
|
||||||
|
const res = await request.put<ApiResult<unknown>>(
|
||||||
|
MODULES_API_URL + '/shop/${controllerMappingHyphen}',
|
||||||
|
data
|
||||||
|
);
|
||||||
|
if (res.data.code === 0) {
|
||||||
|
return res.data.message;
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error(res.data.message));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除${table.comment!}
|
||||||
|
*/
|
||||||
|
export async function remove${entity}(id?: number) {
|
||||||
|
const res = await request.delete<ApiResult<unknown>>(
|
||||||
|
MODULES_API_URL + '/shop/${controllerMappingHyphen}/' + id
|
||||||
|
);
|
||||||
|
if (res.data.code === 0) {
|
||||||
|
return res.data.message;
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error(res.data.message));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除${table.comment!}
|
||||||
|
*/
|
||||||
|
export async function removeBatch${entity}(data: (number | undefined)[]) {
|
||||||
|
const res = await request.delete<ApiResult<unknown>>(
|
||||||
|
MODULES_API_URL + '/shop/${controllerMappingHyphen}/batch',
|
||||||
|
{
|
||||||
|
data
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (res.data.code === 0) {
|
||||||
|
return res.data.message;
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error(res.data.message));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询${table.comment!}
|
||||||
|
*/
|
||||||
|
export async function get${entity}(id: number) {
|
||||||
|
const res = await request.get<ApiResult<${entity}>>(
|
||||||
|
MODULES_API_URL + '/shop/${controllerMappingHyphen}/' + id
|
||||||
|
);
|
||||||
|
if (res.data.code === 0 && res.data.data) {
|
||||||
|
return res.data.data;
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error(res.data.message));
|
||||||
|
}
|
||||||
@@ -0,0 +1,242 @@
|
|||||||
|
<template>
|
||||||
|
<div class="page">
|
||||||
|
<div class="ele-body">
|
||||||
|
<a-card :bordered="false" :body-style="{ padding: '16px' }">
|
||||||
|
<ele-pro-table
|
||||||
|
ref="tableRef"
|
||||||
|
row-key="adId"
|
||||||
|
:columns="columns"
|
||||||
|
:datasource="datasource"
|
||||||
|
:customRow="customRow"
|
||||||
|
tool-class="ele-toolbar-form"
|
||||||
|
class="sys-org-table"
|
||||||
|
>
|
||||||
|
<template #toolbar>
|
||||||
|
<search
|
||||||
|
@search="reload"
|
||||||
|
:selection="selection"
|
||||||
|
@add="openEdit"
|
||||||
|
@remove="removeBatch"
|
||||||
|
@batchMove="openMove"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<template #bodyCell="{ column, record }">
|
||||||
|
<template v-if="column.key === 'images'">
|
||||||
|
<template v-for="(item,index) in JSON.parse(record.images)" :key="index">
|
||||||
|
<a-image :src="item.url" :width="80"></a-image>
|
||||||
|
</template>
|
||||||
|
<span></span>
|
||||||
|
</template>
|
||||||
|
<template v-if="column.key === 'status'">
|
||||||
|
<a-tag v-if="record.status === 0" color="green">开启</a-tag>
|
||||||
|
<a-tag v-if="record.status === 1" color="red">关闭</a-tag>
|
||||||
|
</template>
|
||||||
|
<template v-if="column.key === 'action'">
|
||||||
|
<a-space>
|
||||||
|
<a @click="openEdit(record)">修改</a>
|
||||||
|
<a-divider type="vertical" />
|
||||||
|
<a-popconfirm
|
||||||
|
title="确定要删除此记录吗?"
|
||||||
|
@confirm="remove(record)"
|
||||||
|
>
|
||||||
|
<a class="ele-text-danger">删除</a>
|
||||||
|
</a-popconfirm>
|
||||||
|
</a-space>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
</ele-pro-table>
|
||||||
|
</a-card>
|
||||||
|
|
||||||
|
<!-- 编辑弹窗 -->
|
||||||
|
<AdEdit v-model:visible="showEdit" :data="current" @done="reload" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { createVNode, ref } from 'vue';
|
||||||
|
import { message, Modal } from 'ant-design-vue';
|
||||||
|
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
|
||||||
|
import type { EleProTable } from 'ele-admin-pro';
|
||||||
|
import type {
|
||||||
|
DatasourceFunction,
|
||||||
|
ColumnItem
|
||||||
|
} from 'ele-admin-pro/es/ele-pro-table/types';
|
||||||
|
import Search from './components/search.vue';
|
||||||
|
import AdEdit from './components/ad-edit.vue';
|
||||||
|
import { pageAd, removeAd, removeBatchAd } from '@/api/cms/ad';
|
||||||
|
import type { Ad, AdParam } from '@/api/cms/ad/model';
|
||||||
|
|
||||||
|
// 表格实例
|
||||||
|
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
|
||||||
|
|
||||||
|
// 表格选中数据
|
||||||
|
const selection = ref<Ad[]>([]);
|
||||||
|
// 当前编辑数据
|
||||||
|
const current = ref<Ad | null>(null);
|
||||||
|
// 是否显示资产详情
|
||||||
|
const showInfo = ref(false);
|
||||||
|
// 是否显示编辑弹窗
|
||||||
|
const showEdit = ref(false);
|
||||||
|
// 是否显示批量移动弹窗
|
||||||
|
const showMove = ref(false);
|
||||||
|
// 加载状态
|
||||||
|
const loading = ref(true);
|
||||||
|
|
||||||
|
// 表格数据源
|
||||||
|
const datasource: DatasourceFunction = ({
|
||||||
|
page,
|
||||||
|
limit,
|
||||||
|
where,
|
||||||
|
orders,
|
||||||
|
filters
|
||||||
|
}) => {
|
||||||
|
if (filters) {
|
||||||
|
where.status = filters.status;
|
||||||
|
}
|
||||||
|
return pageAd({
|
||||||
|
...where,
|
||||||
|
...orders,
|
||||||
|
page,
|
||||||
|
limit
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 表格列配置
|
||||||
|
const columns = ref<ColumnItem[]>([
|
||||||
|
{
|
||||||
|
title: 'ID',
|
||||||
|
width: 90,
|
||||||
|
dataIndex: 'adId'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '类型',
|
||||||
|
dataIndex: 'adType',
|
||||||
|
key: 'adType'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '广告位名称',
|
||||||
|
dataIndex: 'name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '广告图片',
|
||||||
|
dataIndex: 'images',
|
||||||
|
key: 'images'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
key: 'status'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
key: 'action',
|
||||||
|
width: 120,
|
||||||
|
fixed: 'right',
|
||||||
|
align: 'center',
|
||||||
|
hideInSetting: true
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
/* 搜索 */
|
||||||
|
const reload = (where?: AdParam) => {
|
||||||
|
console.log(where);
|
||||||
|
selection.value = [];
|
||||||
|
tableRef?.value?.reload({ where: where });
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 打开编辑弹窗 */
|
||||||
|
const openEdit = (row?: Ad) => {
|
||||||
|
current.value = row ?? null;
|
||||||
|
showEdit.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 打开批量移动弹窗 */
|
||||||
|
const openMove = () => {
|
||||||
|
showMove.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 打开用户详情弹窗 */
|
||||||
|
const openInfo = (row?: Ad) => {
|
||||||
|
current.value = row ?? null;
|
||||||
|
showInfo.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 删除单个 */
|
||||||
|
const remove = (row: Ad) => {
|
||||||
|
const hide = message.loading('请求中..', 0);
|
||||||
|
removeAd(row.adId)
|
||||||
|
.then((msg) => {
|
||||||
|
hide();
|
||||||
|
message.success(msg);
|
||||||
|
reload();
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
hide();
|
||||||
|
message.error(e.message);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 批量转移 */
|
||||||
|
const batchMove = (userId) => {
|
||||||
|
console.log(userId, '批量转移0000');
|
||||||
|
console.log(selection.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 批量删除 */
|
||||||
|
const removeBatch = () => {
|
||||||
|
if (!selection.value.length) {
|
||||||
|
message.error('请至少选择一条数据');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Modal.confirm({
|
||||||
|
title: '提示',
|
||||||
|
content: '确定要删除选中的记录吗?',
|
||||||
|
icon: createVNode(ExclamationCircleOutlined),
|
||||||
|
maskClosable: true,
|
||||||
|
onOk: () => {
|
||||||
|
const hide = message.loading('请求中..', 0);
|
||||||
|
removeBatchAd(selection.value.map((d) => d.adId))
|
||||||
|
.then((msg) => {
|
||||||
|
hide();
|
||||||
|
message.success(msg);
|
||||||
|
reload();
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
hide();
|
||||||
|
message.error(e.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 查询 */
|
||||||
|
const query = () => {
|
||||||
|
loading.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 自定义行属性 */
|
||||||
|
const customRow = (record: Ad) => {
|
||||||
|
return {
|
||||||
|
// 行点击事件
|
||||||
|
onClick: () => {
|
||||||
|
// console.log(record);
|
||||||
|
},
|
||||||
|
// 行双击事件
|
||||||
|
onDblclick: () => {
|
||||||
|
openEdit(record);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
query();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
export default {
|
||||||
|
name: 'Ad'
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import type { PageParam } from '@/api';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${table.comment!}
|
||||||
|
*/
|
||||||
|
export interface ${entity} {
|
||||||
|
<% /** -----------BEGIN 字段循环遍历----------- **/ %>
|
||||||
|
<% for(field in table.fields) { %>
|
||||||
|
<%
|
||||||
|
var keyPropertyName;
|
||||||
|
if(field.keyFlag) {
|
||||||
|
keyPropertyName = field.propertyName;
|
||||||
|
}
|
||||||
|
%>
|
||||||
|
<% /* 主键 */ %>
|
||||||
|
<% if(field.keyFlag) { %>
|
||||||
|
<% /* 普通字段 */ %>
|
||||||
|
<% } else if(isNotEmpty(field.fill)) { %>
|
||||||
|
<% if(field.convert){ %>
|
||||||
|
@TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill})
|
||||||
|
<% }else{ %>
|
||||||
|
@TableField(fill = FieldFill.${field.fill})
|
||||||
|
<% } %>
|
||||||
|
<% } else if(field.convert) { %>
|
||||||
|
@TableField("${field.annotationColumnName}")
|
||||||
|
<% } %>
|
||||||
|
${field.propertyName}?: <% if(field.propertyType == 'Integer') { %>number<% }else{ %>string<% } %>;
|
||||||
|
<% } %>
|
||||||
|
<% /** -----------END 字段循环遍历----------- **/ %>
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${table.comment!}搜索条件
|
||||||
|
*/
|
||||||
|
export interface ${entity}Param extends PageParam {
|
||||||
|
<% for(field in table.fields) { %>
|
||||||
|
<% if(field.keyFlag) { %>
|
||||||
|
${field.propertyName}?: number;
|
||||||
|
<% } %>
|
||||||
|
<% } %>
|
||||||
|
keywords?: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<!-- 搜索表单 -->
|
||||||
|
<template>
|
||||||
|
<a-space :size="10" style="flex-wrap: wrap">
|
||||||
|
<a-button type="primary" class="ele-btn-icon" @click="add">
|
||||||
|
<template #icon>
|
||||||
|
<PlusOutlined />
|
||||||
|
</template>
|
||||||
|
<span>添加</span>
|
||||||
|
</a-button>
|
||||||
|
</a-space>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { PlusOutlined } from '@ant-design/icons-vue';
|
||||||
|
import type { GradeParam } from '@/api/user/grade/model';
|
||||||
|
import { watch } from 'vue';
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
// 选中的角色
|
||||||
|
selection?: [];
|
||||||
|
}>(),
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'search', where?: GradeParam): void;
|
||||||
|
(e: 'add'): void;
|
||||||
|
(e: 'remove'): void;
|
||||||
|
(e: 'batchMove'): void;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
// 新增
|
||||||
|
const add = () => {
|
||||||
|
emit('add');
|
||||||
|
};
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.selection,
|
||||||
|
() => {}
|
||||||
|
);
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user