集成代码生成器模块
This commit is contained in:
parent
446eb72943
commit
394d19991f
|
|
@ -0,0 +1,20 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>net.maku</groupId>
|
||||
<artifactId>maku-boot-module</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>maku-module-generator</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.maku</groupId>
|
||||
<artifactId>maku-generator-boot-starter</artifactId>
|
||||
<version>2.0.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
auth:
|
||||
ignore_urls:
|
||||
- /maku-generator/**
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
"project": {
|
||||
"packageName": "net.maku",
|
||||
"version": "1.0.0",
|
||||
"backendPath": "D:\\generator\\maku-boot\\maku-server",
|
||||
"frontendPath": "D:\\generator\\maku-admin"
|
||||
},
|
||||
"developer": {
|
||||
"author": "阿沐",
|
||||
"email": "babamu@126.com"
|
||||
},
|
||||
"templates": [
|
||||
{
|
||||
"templateName": "java/Controller.java.ftl",
|
||||
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/controller/${ClassName}Controller.java"
|
||||
},
|
||||
{
|
||||
"templateName": "java/Service.java.ftl",
|
||||
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/service/${ClassName}Service.java"
|
||||
},
|
||||
{
|
||||
"templateName": "java/ServiceImpl.java.ftl",
|
||||
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/service/impl/${ClassName}ServiceImpl.java"
|
||||
},
|
||||
{
|
||||
"templateName": "java/Query.java.ftl",
|
||||
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/query/${ClassName}Query.java"
|
||||
},
|
||||
{
|
||||
"templateName": "java/Entity.java.ftl",
|
||||
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/entity/${ClassName}Entity.java"
|
||||
},
|
||||
{
|
||||
"templateName": "java/VO.java.ftl",
|
||||
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/vo/${ClassName}VO.java"
|
||||
},
|
||||
{
|
||||
"templateName": "java/Convert.java.ftl",
|
||||
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/convert/${ClassName}Convert.java"
|
||||
},
|
||||
{
|
||||
"templateName": "java/Dao.java.ftl",
|
||||
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/dao/${ClassName}Dao.java"
|
||||
},
|
||||
{
|
||||
"templateName": "xml/Dao.xml.ftl",
|
||||
"generatorPath": "${backendPath}/src/main/resources/mapper/${moduleName}/${ClassName}Dao.xml"
|
||||
},
|
||||
{
|
||||
"templateName": "sql/menu.sql.ftl",
|
||||
"generatorPath": "${backendPath}/menu/${functionName}_menu.sql"
|
||||
},
|
||||
{
|
||||
"templateName": "vue/api.ts.ftl",
|
||||
"generatorPath": "${frontendPath}/src/api/${moduleName}/${functionName}.ts"
|
||||
},
|
||||
{
|
||||
"templateName": "vue/index.vue.ftl",
|
||||
"generatorPath": "${frontendPath}/src/views/${moduleName}/${functionName}/index.vue"
|
||||
},
|
||||
{
|
||||
"templateName": "vue/add-or-update.vue.ftl",
|
||||
"generatorPath": "${frontendPath}/src/views/${moduleName}/${functionName}/add-or-update.vue"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
package ${package}.${moduleName}.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import ${package}.framework.common.page.PageResult;
|
||||
import ${package}.framework.common.utils.Result;
|
||||
import ${package}.${moduleName}.convert.${ClassName}Convert;
|
||||
import ${package}.${moduleName}.entity.${ClassName}Entity;
|
||||
import ${package}.${moduleName}.service.${ClassName}Service;
|
||||
import ${package}.${moduleName}.query.${ClassName}Query;
|
||||
import ${package}.${moduleName}.vo.${ClassName}VO;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${tableComment}
|
||||
*
|
||||
* @author ${author} ${email}
|
||||
* @since ${version} ${date}
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("${moduleName}/${functionName}")
|
||||
@Tag(name="${tableComment}")
|
||||
@AllArgsConstructor
|
||||
public class ${ClassName}Controller {
|
||||
private final ${ClassName}Service ${className}Service;
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
@PreAuthorize("hasAuthority('${moduleName}:${functionName}:page')")
|
||||
public Result<PageResult<${ClassName}VO>> page(@Valid ${ClassName}Query query){
|
||||
PageResult<${ClassName}VO> page = ${className}Service.page(query);
|
||||
|
||||
return Result.ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
@PreAuthorize("hasAuthority('${moduleName}:${functionName}:info')")
|
||||
public Result<${ClassName}VO> get(@PathVariable("id") Long id){
|
||||
${ClassName}Entity entity = ${className}Service.getById(id);
|
||||
|
||||
return Result.ok(${ClassName}Convert.INSTANCE.convert(entity));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
@PreAuthorize("hasAuthority('${moduleName}:${functionName}:save')")
|
||||
public Result<String> save(@RequestBody ${ClassName}VO vo){
|
||||
${className}Service.save(vo);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "修改")
|
||||
@PreAuthorize("hasAuthority('${moduleName}:${functionName}:update')")
|
||||
public Result<String> update(@RequestBody @Valid ${ClassName}VO vo){
|
||||
${className}Service.update(vo);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@Operation(summary = "删除")
|
||||
@PreAuthorize("hasAuthority('${moduleName}:${functionName}:delete')")
|
||||
public Result<String> delete(@RequestBody List<Long> idList){
|
||||
${className}Service.delete(idList);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package ${package}.${moduleName}.convert;
|
||||
|
||||
import ${package}.${moduleName}.entity.${ClassName}Entity;
|
||||
import ${package}.${moduleName}.vo.${ClassName}VO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${tableComment}
|
||||
*
|
||||
* @author ${author} ${email}
|
||||
* @since ${version} ${date}
|
||||
*/
|
||||
@Mapper
|
||||
public interface ${ClassName}Convert {
|
||||
${ClassName}Convert INSTANCE = Mappers.getMapper(${ClassName}Convert.class);
|
||||
|
||||
${ClassName}Entity convert(${ClassName}VO vo);
|
||||
|
||||
${ClassName}VO convert(${ClassName}Entity entity);
|
||||
|
||||
List<${ClassName}VO> convertList(List<${ClassName}Entity> list);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package ${package}.${moduleName}.dao;
|
||||
|
||||
import ${package}.framework.common.dao.BaseDao;
|
||||
import ${package}.${moduleName}.entity.${ClassName}Entity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* ${tableComment}
|
||||
*
|
||||
* @author ${author} ${email}
|
||||
* @since ${version} ${date}
|
||||
*/
|
||||
@Mapper
|
||||
public interface ${ClassName}Dao extends BaseDao<${ClassName}Entity> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package ${package}.${moduleName}.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
<#list importList as i>
|
||||
import ${i!};
|
||||
</#list>
|
||||
<#if baseClass??>
|
||||
import ${baseClass.packageName}.${baseClass.code};
|
||||
</#if>
|
||||
|
||||
/**
|
||||
* ${tableComment}
|
||||
*
|
||||
* @author ${author} ${email}
|
||||
* @since ${version} ${date}
|
||||
*/
|
||||
<#if baseClass??>@EqualsAndHashCode(callSuper=false)</#if>
|
||||
@Data
|
||||
@TableName("${tableName}")
|
||||
public class ${ClassName}Entity<#if baseClass??> extends ${baseClass.code}</#if> {
|
||||
<#list fieldList as field>
|
||||
<#if !field.baseField>
|
||||
<#if field.fieldComment!?length gt 0>
|
||||
/**
|
||||
* ${field.fieldComment}
|
||||
*/
|
||||
</#if>
|
||||
<#if field.autoFill == "INSERT">
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
</#if>
|
||||
<#if field.autoFill == "INSERT_UPDATE">
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
</#if>
|
||||
<#if field.autoFill == "UPDATE">
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
</#if>
|
||||
<#if field.primaryPk>
|
||||
@TableId
|
||||
</#if>
|
||||
private ${field.attrType} ${field.attrName};
|
||||
</#if>
|
||||
|
||||
</#list>
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package ${package}.${moduleName}.query;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import ${package}.framework.common.query.Query;
|
||||
|
||||
<#list importList as i>
|
||||
import ${i!};
|
||||
</#list>
|
||||
|
||||
/**
|
||||
* ${tableComment}查询
|
||||
*
|
||||
* @author ${author} ${email}
|
||||
* @since ${version} ${date}
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Schema(description = "${tableComment}查询")
|
||||
public class ${ClassName}Query extends Query {
|
||||
<#list queryList as field>
|
||||
<#if field.fieldComment!?length gt 0>
|
||||
@Schema(description = "${field.fieldComment}")
|
||||
</#if>
|
||||
private ${field.attrType} ${field.attrName};
|
||||
|
||||
</#list>
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package ${package}.${moduleName}.service;
|
||||
|
||||
import ${package}.framework.common.page.PageResult;
|
||||
import ${package}.framework.common.service.BaseService;
|
||||
import ${package}.${moduleName}.vo.${ClassName}VO;
|
||||
import ${package}.${moduleName}.query.${ClassName}Query;
|
||||
import ${package}.${moduleName}.entity.${ClassName}Entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${tableComment}
|
||||
*
|
||||
* @author ${author} ${email}
|
||||
* @since ${version} ${date}
|
||||
*/
|
||||
public interface ${ClassName}Service extends BaseService<${ClassName}Entity> {
|
||||
|
||||
PageResult<${ClassName}VO> page(${ClassName}Query query);
|
||||
|
||||
void save(${ClassName}VO vo);
|
||||
|
||||
void update(${ClassName}VO vo);
|
||||
|
||||
void delete(List<Long> idList);
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package ${package}.${moduleName}.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.AllArgsConstructor;
|
||||
import ${package}.framework.common.page.PageResult;
|
||||
import ${package}.framework.common.service.impl.BaseServiceImpl;
|
||||
import ${package}.${moduleName}.convert.${ClassName}Convert;
|
||||
import ${package}.${moduleName}.entity.${ClassName}Entity;
|
||||
import ${package}.${moduleName}.query.${ClassName}Query;
|
||||
import ${package}.${moduleName}.vo.${ClassName}VO;
|
||||
import ${package}.${moduleName}.dao.${ClassName}Dao;
|
||||
import ${package}.${moduleName}.service.${ClassName}Service;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${tableComment}
|
||||
*
|
||||
* @author ${author} ${email}
|
||||
* @since ${version} ${date}
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class ${ClassName}ServiceImpl extends BaseServiceImpl<${ClassName}Dao, ${ClassName}Entity> implements ${ClassName}Service {
|
||||
|
||||
@Override
|
||||
public PageResult<${ClassName}VO> page(${ClassName}Query query) {
|
||||
IPage<${ClassName}Entity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||
|
||||
return new PageResult<>(${ClassName}Convert.INSTANCE.convertList(page.getRecords()), page.getTotal());
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<${ClassName}Entity> getWrapper(${ClassName}Query query){
|
||||
LambdaQueryWrapper<${ClassName}Entity> wrapper = Wrappers.lambdaQuery();
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(${ClassName}VO vo) {
|
||||
${ClassName}Entity entity = ${ClassName}Convert.INSTANCE.convert(vo);
|
||||
|
||||
baseMapper.insert(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(${ClassName}VO vo) {
|
||||
${ClassName}Entity entity = ${ClassName}Convert.INSTANCE.convert(vo);
|
||||
|
||||
updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(List<Long> idList) {
|
||||
removeByIds(idList);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package ${package}.${moduleName}.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import ${package}.framework.common.utils.DateUtils;
|
||||
<#list importList as i>
|
||||
import ${i!};
|
||||
</#list>
|
||||
|
||||
/**
|
||||
* ${tableComment}
|
||||
*
|
||||
* @author ${author} ${email}
|
||||
* @since ${version} ${date}
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "${tableComment}")
|
||||
public class ${ClassName}VO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
<#list fieldList as field>
|
||||
<#if field.fieldComment!?length gt 0>
|
||||
@Schema(description = "${field.fieldComment}")
|
||||
</#if>
|
||||
<#if field.attrType == 'Date'>
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
</#if>
|
||||
private ${field.attrType} ${field.attrName};
|
||||
|
||||
</#list>
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<#assign dbTime = "now()">
|
||||
<#if dbType=="SQLServer">
|
||||
<#assign dbTime = "getDate()">
|
||||
</#if>
|
||||
|
||||
-- 初始化菜单
|
||||
INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES (1, '${tableComment!}', '${moduleName}/${functionName}/index', NULL, 0, 0, 'icon-menu', 0, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
|
||||
|
||||
-- 菜单ID
|
||||
<#if dbType=="SQLServer">
|
||||
DECLARE @menuId int
|
||||
</#if>
|
||||
set @menuId = @@identity;
|
||||
|
||||
INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES ((SELECT @menuId), '查看', '', '${moduleName}:${functionName}:page', 1, 0, '', 0, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
|
||||
INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES ((SELECT @menuId), '新增', '', '${moduleName}:${functionName}:save', 1, 0, '', 1, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
|
||||
INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES ((SELECT @menuId), '修改', '', '${moduleName}:${functionName}:update,${moduleName}:${functionName}:info', 1, 0, '', 2, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
|
||||
INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES ((SELECT @menuId), '删除', '', '${moduleName}:${functionName}:delete', 1, 0, '', 3, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
<template>
|
||||
<el-dialog v-model="visible" :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false">
|
||||
<el-form ref="dataFormRef" :model="dataForm" :rules="dataRules" label-width="100px" @keyup.enter="submitHandle()">
|
||||
<#list formList as field>
|
||||
<#if field.formType == 'text'>
|
||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
||||
<el-input v-model="dataForm.${field.attrName}" placeholder="${field.fieldComment!}"></el-input>
|
||||
</el-form-item>
|
||||
<#elseif field.formType == 'textarea'>
|
||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
||||
<el-input type="textarea" v-model="dataForm.${field.attrName}"></el-input>
|
||||
</el-form-item>
|
||||
<#elseif field.formType == 'editor'>
|
||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
||||
<el-input type="textarea" v-model="dataForm.${field.attrName}"></el-input>
|
||||
</el-form-item>
|
||||
<#elseif field.formType == 'select'>
|
||||
<#if field.dictName??>
|
||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
||||
<fast-select v-model="dataForm.${field.attrName}" dict-type="${field.dictName}" placeholder="${field.fieldComment!}"></fast-select>
|
||||
</el-form-item>
|
||||
<#else>
|
||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
||||
<el-select v-model="dataForm.${field.attrName}" placeholder="请选择">
|
||||
<el-option label="人人" value="0"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</#if>
|
||||
<#elseif field.formType == 'radio'>
|
||||
<#if field.dictName??>
|
||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
||||
<fast-radio-group v-model="dataForm.${field.attrName}" dict-type="${field.dictName}"></fast-radio-group>
|
||||
</el-form-item>
|
||||
<#else>
|
||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
||||
<el-radio-group v-model="dataForm.${field.attrName}">
|
||||
<el-radio :label="0">启用</el-radio>
|
||||
<el-radio :label="1">禁用</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</#if>
|
||||
<#elseif field.formType == 'checkbox'>
|
||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
||||
<el-checkbox-group v-model="dataForm.${field.attrName}">
|
||||
<el-checkbox label="启用" name="type"></el-checkbox>
|
||||
<el-checkbox label="禁用" name="type"></el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</el-form-item>
|
||||
<#elseif field.formType == 'date'>
|
||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
||||
<el-date-picker type="date" placeholder="${field.fieldComment!}" v-model="dataForm.${field.attrName}"></el-date-picker>
|
||||
</el-form-item>
|
||||
<#elseif field.formType == 'datetime'>
|
||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
||||
<el-date-picker type="datetime" placeholder="${field.fieldComment!}" v-model="dataForm.${field.attrName}"></el-date-picker>
|
||||
</el-form-item>
|
||||
<#else>
|
||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
||||
<el-input v-model="dataForm.${field.attrName}" placeholder="${field.fieldComment!}"></el-input>
|
||||
</el-form-item>
|
||||
</#if>
|
||||
</#list>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="visible = false">取消</el-button>
|
||||
<el-button type="primary" @click="submitHandle()">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus/es'
|
||||
import { use${FunctionName}Api, use${FunctionName}SubmitApi } from '@/api/${moduleName}/${functionName}'
|
||||
|
||||
const emit = defineEmits(['refreshDataList'])
|
||||
|
||||
const visible = ref(false)
|
||||
const dataFormRef = ref()
|
||||
|
||||
const dataForm = reactive({
|
||||
<#list formList as field>
|
||||
${field.attrName}: ''<#sep>,
|
||||
</#list>
|
||||
})
|
||||
|
||||
const init = (id?: number) => {
|
||||
visible.value = true
|
||||
dataForm.id = ''
|
||||
|
||||
// 重置表单数据
|
||||
if (dataFormRef.value) {
|
||||
dataFormRef.value.resetFields()
|
||||
}
|
||||
|
||||
if (id) {
|
||||
get${FunctionName}(id)
|
||||
}
|
||||
}
|
||||
|
||||
const get${FunctionName} = (id: number) => {
|
||||
use${FunctionName}Api(id).then(res => {
|
||||
Object.assign(dataForm, res.data)
|
||||
})
|
||||
}
|
||||
|
||||
const dataRules = ref({
|
||||
<#list formList as field>
|
||||
<#if field.formRequired>
|
||||
${field.attrName}: [{ required: true, message: '必填项不能为空', trigger: 'blur' }]<#sep>,
|
||||
</#if>
|
||||
</#list>
|
||||
})
|
||||
|
||||
// 表单提交
|
||||
const submitHandle = () => {
|
||||
dataFormRef.value.validate((valid: boolean) => {
|
||||
if (!valid) {
|
||||
return false
|
||||
}
|
||||
|
||||
use${FunctionName}SubmitApi(dataForm).then(() => {
|
||||
ElMessage.success({
|
||||
message: '操作成功',
|
||||
duration: 500,
|
||||
onClose: () => {
|
||||
visible.value = false
|
||||
emit('refreshDataList')
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
init
|
||||
})
|
||||
</script>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import service from '@/utils/request'
|
||||
|
||||
export const use${FunctionName}Api = (id: number) => {
|
||||
return service.get('/${moduleName}/${functionName}/' + id)
|
||||
}
|
||||
|
||||
export const use${FunctionName}SubmitApi = (dataForm: any) => {
|
||||
if (dataForm.id) {
|
||||
return service.put('/${moduleName}/${functionName}', dataForm)
|
||||
} else {
|
||||
return service.post('/${moduleName}/${functionName}', dataForm)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
<template>
|
||||
<el-card>
|
||||
<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
|
||||
<#list queryList as field>
|
||||
<el-form-item>
|
||||
<#if field.formType == 'text' || field.formType == 'textarea' || field.formType == 'editor'>
|
||||
<el-input v-model="state.queryForm.${field.attrName}"
|
||||
placeholder="${field.fieldComment!}"></el-input>
|
||||
<#elseif field.queryFormType == 'select'>
|
||||
<#if field.queryDict??>
|
||||
<fast-select v-model="state.queryForm.${field.attrName}" dict-type="${field.queryDict}"
|
||||
placeholder="${field.fieldComment!}" clearable></fast-select>
|
||||
<#else>
|
||||
<el-select v-model="state.queryForm.${field.attrName}" placeholder="${field.fieldComment!}">
|
||||
<el-option label="选择" value="0"></el-option>
|
||||
</el-select>
|
||||
</#if>
|
||||
<#elseif field.queryFormType == 'radio'>
|
||||
<#if field.queryDict??>
|
||||
<fast-radio-group v-model="state.queryForm.${field.attrName}"
|
||||
dict-type="${field.queryDict}"></fast-radio-group>
|
||||
<#else>
|
||||
<el-radio-group v-model="state.queryForm.${field.attrName}">
|
||||
<el-radio :label="0">单选</el-radio>
|
||||
</el-radio-group>
|
||||
</#if>
|
||||
<#elseif field.queryFormType == 'date'>
|
||||
<el-date-picker
|
||||
v-model="daterange"
|
||||
type="daterange"
|
||||
value-format="yyyy-MM-dd">
|
||||
</el-date-picker>
|
||||
<#elseif field.queryFormType == 'datetime'>
|
||||
<el-date-picker
|
||||
v-model="datetimerange"
|
||||
type="datetimerange"
|
||||
value-format="yyyy-MM-dd HH:mm:ss">
|
||||
</el-date-picker>
|
||||
<#else>
|
||||
<el-input v-model="state.queryForm.${field.attrName}"
|
||||
placeholder="${field.fieldComment!}"></el-input>
|
||||
</#if>
|
||||
</el-form-item>
|
||||
</#list>
|
||||
<el-form-item>
|
||||
<el-button @click="getDataList()">查询</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button v-auth="'${moduleName}:${functionName}:save'" type="primary" @click="addOrUpdateHandle()">
|
||||
新增
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button v-auth="'${moduleName}:${functionName}:delete'" type="danger" @click="deleteBatchHandle()">
|
||||
删除
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-table v-loading="state.dataListLoading" :data="state.dataList" border style="width: 100%"
|
||||
@selection-change="selectionChangeHandle">
|
||||
<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
|
||||
<#list gridList as field>
|
||||
<#if field.formDict??>
|
||||
<fast-table-column prop="${field.attrName}" label="${field.fieldComment!}"
|
||||
dict-type="${field.formDict}"></fast-table-column>
|
||||
<#else>
|
||||
<el-table-column prop="${field.attrName}" label="${field.fieldComment!}" header-align="center"
|
||||
align="center"></el-table-column>
|
||||
</#if>
|
||||
</#list>
|
||||
<el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
|
||||
<template #default="scope">
|
||||
<el-button v-auth="'${moduleName}:${functionName}:update'" type="primary" link
|
||||
@click="addOrUpdateHandle(scope.row.id)">修改
|
||||
</el-button>
|
||||
<el-button v-auth="'${moduleName}:${functionName}:delete'" type="primary" link
|
||||
@click="deleteBatchHandle(scope.row.id)">删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
:current-page="state.page"
|
||||
:page-sizes="state.pageSizes"
|
||||
:page-size="state.limit"
|
||||
:total="state.total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="sizeChangeHandle"
|
||||
@current-change="currentChangeHandle"
|
||||
>
|
||||
</el-pagination>
|
||||
|
||||
<!-- 弹窗, 新增 / 修改 -->
|
||||
<add-or-update ref="addOrUpdateRef" @refreshDataList="getDataList"></add-or-update>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="${ModuleName}${FunctionName}Index">
|
||||
import {useCrud} from '@/hooks'
|
||||
import {reactive, ref} from 'vue'
|
||||
import {IHooksOptions} from '@/hooks/interface'
|
||||
|
||||
const state: IHooksOptions = reactive({
|
||||
dataListUrl: '/${moduleName}/${functionName}/page',
|
||||
deleteUrl: '/${moduleName}/${functionName}',
|
||||
queryForm: {
|
||||
<#list queryList as field>
|
||||
<#if field.formType == 'date'>
|
||||
startDate: '',
|
||||
endDate: ''<#sep>, </#sep>
|
||||
<#elseif field.formType == 'datetime'>
|
||||
startDateTime: '',
|
||||
endDateTime: ''<#sep>, </#sep>
|
||||
<#else>
|
||||
${field.attrName}: ''<#sep>, </#sep>
|
||||
</#if>
|
||||
</#list>
|
||||
}
|
||||
})
|
||||
|
||||
const addOrUpdateRef = ref()
|
||||
const addOrUpdateHandle = (id
|
||||
? : number
|
||||
) =>
|
||||
{
|
||||
addOrUpdateRef.value.init(id)
|
||||
}
|
||||
|
||||
const {
|
||||
getDataList,
|
||||
selectionChangeHandle,
|
||||
sizeChangeHandle,
|
||||
currentChangeHandle,
|
||||
deleteBatchHandle
|
||||
} = useCrud(state)
|
||||
</script>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="${package}.${moduleName}.dao.${ClassName}Dao">
|
||||
|
||||
<resultMap type="${package}.${moduleName}.entity.${ClassName}Entity" id="${className}Map">
|
||||
<#list fieldList as field>
|
||||
<result property="${field.attrName}" column="${field.fieldName}"/>
|
||||
</#list>
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
<modules>
|
||||
<module>maku-module-quartz</module>
|
||||
<module>maku-module-message</module>
|
||||
<module>maku-module-generator</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<dependency>
|
||||
<groupId>net.maku</groupId>
|
||||
<artifactId>maku-boot-system</artifactId>
|
||||
<version>${revision}</version>
|
||||
|
|
@ -20,16 +20,21 @@
|
|||
<artifactId>maku-boot-new</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>net.maku</groupId>-->
|
||||
<!-- <artifactId>maku-module-quartz</artifactId>-->
|
||||
<!-- <version>${revision}</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>net.maku</groupId>-->
|
||||
<!-- <artifactId>maku-module-message</artifactId>-->
|
||||
<!-- <version>${revision}</version>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>net.maku</groupId>
|
||||
<artifactId>maku-module-quartz</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.maku</groupId>
|
||||
<artifactId>maku-module-generator</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.maku</groupId>
|
||||
<artifactId>maku-module-message</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-springdoc-ui</artifactId>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user