feat: 代码生成 Beta 公测版本
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
### 代码生成器配置
|
||||
# 代码生成器配置
|
||||
generator:
|
||||
defaultConfig:
|
||||
author: youlaitech
|
||||
backendAppName: youlai-boot
|
||||
frontendAppName: vue3-element-admin
|
||||
## 模板配置
|
||||
templateConfigs:
|
||||
Controller:
|
||||
@@ -18,6 +22,9 @@ generator:
|
||||
templatePath: generator/mapper.xml.vm
|
||||
packageName: mapper
|
||||
extension: .xml
|
||||
Converter:
|
||||
templatePath: generator/converter.java.vm
|
||||
packageName: converter
|
||||
Query:
|
||||
templatePath: generator/query.java.vm
|
||||
packageName: model.query
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<mapper namespace="com.youlai.system.mapper.DatabaseMapper">
|
||||
|
||||
<!-- 查询数据库表分页 -->
|
||||
<select id="getTablePage" resultType="com.youlai.system.model.bo.TableMetaData">
|
||||
<select id="getTablePage" resultType="com.youlai.system.model.vo.TablePageVO">
|
||||
SELECT
|
||||
TABLE_NAME ,
|
||||
TABLE_COMMENT ,
|
||||
|
||||
@@ -4,25 +4,4 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.youlai.system.mapper.GenFieldConfigMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.youlai.system.model.entity.GenFieldConfig">
|
||||
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||
<result property="configId" column="config_id" jdbcType="BIGINT"/>
|
||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||
<result property="type" column="type" jdbcType="VARCHAR"/>
|
||||
<result property="description" column="description" jdbcType="VARCHAR"/>
|
||||
<result property="showInList" column="show_in_list" jdbcType="TINYINT"/>
|
||||
<result property="showInForm" column="show_in_form" jdbcType="TINYINT"/>
|
||||
<result property="showInQuery" column="show_in_query" jdbcType="TINYINT"/>
|
||||
<result property="formType" column="form_type" jdbcType="VARCHAR"/>
|
||||
<result property="queryMethod" column="query_method" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,config_id,name,
|
||||
type,description,show_in_list,
|
||||
show_in_form,show_in_query,form_type,
|
||||
query_method,create_time,update_time
|
||||
</sql>
|
||||
</mapper>
|
||||
|
||||
@@ -1,121 +1,93 @@
|
||||
import request from "@/utils/request";
|
||||
|
||||
const ${className.toUpperCase()}_BASE_URL = "/api/v1/${className.toLowerCase()}s";
|
||||
const ${entityName.toUpperCase()}_BASE_URL = "/api/v1/${entityName.toLowerCase()}s";
|
||||
|
||||
class ${className}API {
|
||||
/** 获取${className}分页数据 */
|
||||
static getPage(queryParams?: ${className}PageQuery) {
|
||||
return request<any, PageResult<${className}PageVO[]>>({
|
||||
url: `${${className.toUpperCase()}_BASE_URL}/page`,
|
||||
class ${entityName}API {
|
||||
/** 获取${businessName}分页数据 */
|
||||
static getPage(queryParams?: ${entityName}PageQuery) {
|
||||
return request<any, PageResult<${entityName}PageVO[]>>({
|
||||
url: `${${entityName.toUpperCase()}_BASE_URL}/page`,
|
||||
method: "get",
|
||||
params: queryParams,
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取${className}下拉数据源 */
|
||||
static getOptions() {
|
||||
return request<any, OptionType[]>({
|
||||
url: `${${className.toUpperCase()}_BASE_URL}/options`,
|
||||
method: "get",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取${className}的菜单ID集合
|
||||
* 获取${businessName}表单数据
|
||||
*
|
||||
* @param ${className.toLowerCase()}Id ${className}ID
|
||||
* @returns ${className}的菜单ID集合
|
||||
*/
|
||||
static get${className}MenuIds(${className.toLowerCase()}Id: number) {
|
||||
return request<any, number[]>({
|
||||
url: `${${className.toUpperCase()}_BASE_URL}/${${className.toLowerCase()}Id}/menuIds`,
|
||||
method: "get",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 分配菜单权限
|
||||
*
|
||||
* @param ${className.toLowerCase()}Id ${className}ID
|
||||
* @param data 菜单ID集合
|
||||
*/
|
||||
static update${className}Menus(${className.toLowerCase()}Id: number, data: number[]) {
|
||||
return request({
|
||||
url: `${${className.toUpperCase()}_BASE_URL}/${${className.toLowerCase()}Id}/menus`,
|
||||
method: "put",
|
||||
data: data,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取${className}表单数据
|
||||
*
|
||||
* @param id ${className}ID
|
||||
* @returns ${className}表单数据
|
||||
* @param id ${entityName}ID
|
||||
* @returns ${entityName}表单数据
|
||||
*/
|
||||
static getFormData(id: number) {
|
||||
return request<any, ${className}Form>({
|
||||
url: `${${className.toUpperCase()}_BASE_URL}/${id}/form`,
|
||||
return request<any, ${entityName}Form>({
|
||||
url: `${${entityName.toUpperCase()}_BASE_URL}/${id}/form`,
|
||||
method: "get",
|
||||
});
|
||||
}
|
||||
|
||||
/** 添加${className} */
|
||||
static add(data: ${className}Form) {
|
||||
/** 添加${businessName}*/
|
||||
static add(data: ${entityName}Form) {
|
||||
return request({
|
||||
url: `${${className.toUpperCase()}_BASE_URL}`,
|
||||
url: `${${entityName.toUpperCase()}_BASE_URL}`,
|
||||
method: "post",
|
||||
data: data,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新${className}
|
||||
* 更新${businessName}
|
||||
*
|
||||
* @param id ${className}ID
|
||||
* @param data ${className}表单数据
|
||||
* @param id ${entityName}ID
|
||||
* @param data ${entityName}表单数据
|
||||
*/
|
||||
static update(id: number, data: ${className}Form) {
|
||||
static update(id: number, data: ${entityName}Form) {
|
||||
return request({
|
||||
url: `${${className.toUpperCase()}_BASE_URL}/${id}`,
|
||||
url: `${${entityName.toUpperCase()}_BASE_URL}/${id}`,
|
||||
method: "put",
|
||||
data: data,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除${className},多个以英文逗号(,)分割
|
||||
* 批量删除${businessName},多个以英文逗号(,)分割
|
||||
*
|
||||
* @param ids ${className}ID字符串,多个以英文逗号(,)分割
|
||||
* @param ids ${businessName}ID字符串,多个以英文逗号(,)分割
|
||||
*/
|
||||
static deleteByIds(ids: string) {
|
||||
return request({
|
||||
url: `${${className.toUpperCase()}_BASE_URL}/${ids}`,
|
||||
url: `${${entityName.toUpperCase()}_BASE_URL}/${ids}`,
|
||||
method: "delete",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default ${className}API;
|
||||
export default ${entityName}API;
|
||||
|
||||
/** ${className}分页查询参数 */
|
||||
export interface ${className}PageQuery extends PageQuery {
|
||||
/** $${businessName}分页查询参数 */
|
||||
export interface ${entityName}PageQuery extends PageQuery {
|
||||
/** 搜索关键字 */
|
||||
keywords?: string;
|
||||
}
|
||||
|
||||
/** ${className}分页对象 */
|
||||
export interface ${className}PageVO {
|
||||
#foreach($field in $fields)
|
||||
/** ${field.comment} */
|
||||
${field.name}?: ${field.type};
|
||||
/** ${businessName}表单对象 */
|
||||
export interface ${entityName}Form {
|
||||
#foreach($fieldConfig in $fieldConfigs)
|
||||
#if($fieldConfig.isShowInForm)
|
||||
#if("$!fieldConfig.fieldComment" != "")
|
||||
/** ${fieldConfig.fieldComment} */
|
||||
#end
|
||||
${fieldConfig.fieldName}?: ${fieldConfig.tsType};
|
||||
#end
|
||||
#end
|
||||
}
|
||||
|
||||
/** ${className}表单对象 */
|
||||
export interface ${className}Form {
|
||||
#foreach($field in $fields)
|
||||
/** ${field.comment} */
|
||||
${field.name}?: ${field.type};
|
||||
/** ${businessName}分页对象 */
|
||||
export interface ${entityName}PageVO {
|
||||
#foreach($fieldConfig in $fieldConfigs)
|
||||
#if($fieldConfig.isShowInList)
|
||||
#if("$!fieldConfig.fieldComment" != "")
|
||||
/** ${fieldConfig.fieldComment} */
|
||||
#end
|
||||
${fieldConfig.fieldName}?: ${fieldConfig.tsType};
|
||||
#end
|
||||
#end
|
||||
}
|
||||
|
||||
@@ -17,12 +17,12 @@ import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
* $!{tableComment}前端控制层
|
||||
* $!{businessName}前端控制层
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Tag(name = "${tableComment}接口")
|
||||
@Tag(name = "${businessName}接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/${lowerFirstEntityName}s")
|
||||
@RequiredArgsConstructor
|
||||
@@ -30,41 +30,41 @@ public class ${entityName}Controller {
|
||||
|
||||
private final ${entityName}Serivie ${lowerFirstEntityName}Service;
|
||||
|
||||
@Operation(summary = "$!{tableComment}分页列表")
|
||||
@Operation(summary = "$!{businessName}分页列表")
|
||||
@GetMapping("/page")
|
||||
public PageResult<${entityName}PageVO> get${entityName}Page(${entityName}PageQuery queryParams ) {
|
||||
IPage<${entityName}PageVO> result = ${lowerFirstEntityName}Service.get${entityName}Page(queryParams);
|
||||
return PageResult.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "新增$!{tableComment}")
|
||||
@Operation(summary = "新增${businessName}")
|
||||
@PostMapping
|
||||
public Result save${entityName}(@RequestBody @Valid ${entityName}Form formData ) {
|
||||
boolean result = ${lowerFirstEntityName}Service.save${entityName}(formData);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取$!{tableComment}表单数据")
|
||||
@Operation(summary = "获取${businessName}表单数据")
|
||||
@GetMapping("/{id}/form")
|
||||
public Result<${entityName}Form> get${entityName}Form(
|
||||
@Parameter(description = "$!{tableComment}ID") @PathVariable Long id
|
||||
@Parameter(description = "$!{businessName}ID") @PathVariable Long id
|
||||
) {
|
||||
${entityName}Form formData = ${lowerFirstEntityName}Service.get${entityName}FormData(id);
|
||||
return Result.success(formData);
|
||||
}
|
||||
|
||||
@Operation(summary = "修改$!{tableComment}")
|
||||
@Operation(summary = "修改${businessName}")
|
||||
@PutMapping(value = "/{id}")
|
||||
public Result update${entityName}(@Parameter(description = "$!{tableComment}ID") @PathVariable Long id,
|
||||
public Result update${entityName}(@Parameter(description = "$!{businessName}ID") @PathVariable Long id,
|
||||
@RequestBody @Validated ${entityName}Form formData) {
|
||||
boolean result = ${lowerFirstEntityName}Service.update${entityName}(id, formData);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除$!{tableComment}")
|
||||
@Operation(summary = "删除${businessName}")
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result delete${entityName}s(
|
||||
@Parameter(description = "$!{tableComment}ID,多个以英文逗号(,)分割") @PathVariable String ids
|
||||
@Parameter(description = "$!{businessName}ID,多个以英文逗号(,)分割") @PathVariable String ids
|
||||
) {
|
||||
boolean result = ${lowerFirstEntityName}Service.delete${entityName}s(ids);
|
||||
return Result.judge(result);
|
||||
|
||||
@@ -6,7 +6,7 @@ import ${package}.model.entity.${entityName};
|
||||
import ${package}.model.form.${entityName}Form;
|
||||
|
||||
/**
|
||||
* $!{tableComment}对象转换器
|
||||
* $!{businessName}对象转换器
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
|
||||
@@ -12,7 +12,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.youlai.system.common.base.BaseEntity;
|
||||
|
||||
/**
|
||||
* $!{tableComment}实体对象
|
||||
* $!{businessName}实体对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
|
||||
@@ -16,14 +16,14 @@ import jakarta.validation.constraints.*;
|
||||
#end
|
||||
|
||||
/**
|
||||
* $!{tableComment}表单对象
|
||||
* $!{businessName}表单对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "$!{tableComment}表单对象")
|
||||
@Schema(description = "$!{businessName}表单对象")
|
||||
public class ${entityName}Form implements Serializable {
|
||||
|
||||
@Serial
|
||||
@@ -32,7 +32,7 @@ public class ${entityName}Form implements Serializable {
|
||||
## ---------- BEGIN 字段循环遍历 ----------
|
||||
#if($fieldConfigs)
|
||||
#foreach($fieldConfig in ${fieldConfigs})
|
||||
#if($fieldConfig.showInForm)
|
||||
#if($fieldConfig.isShowInForm)
|
||||
#if($fieldConfig.isRequired)
|
||||
#if($fieldConfig.fieldType == 'String')
|
||||
@NotBlank(message = "$fieldConfig.fieldComment不能为空")
|
||||
|
||||
@@ -2,114 +2,127 @@
|
||||
<div class="app-container">
|
||||
<div class="search-container">
|
||||
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
||||
<el-form-item prop="keywords" label="关键字">
|
||||
<el-input
|
||||
v-model="queryParams.keywords"
|
||||
placeholder="${className}名称"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
#foreach($fieldConfig in $fieldConfigs)
|
||||
#if($fieldConfig.isShowInQuery == 1)
|
||||
<el-form-item :label="$fieldConfig.fieldComment" :key="$fieldConfig.fieldName">
|
||||
#if($fieldConfig.formType == "INPUT")
|
||||
<el-input v-model="queryParams.$fieldConfig.fieldName" :placeholder="$fieldConfig.fieldComment" clearable @keyup.enter="handleQuery" />
|
||||
#elseif($fieldConfig.formType == "SELECT")
|
||||
<el-select v-model="queryParams.$fieldConfig.fieldName" :placeholder="$fieldConfig.fieldComment" clearable>
|
||||
<!-- 这里可以根据具体需求生成select options -->
|
||||
<el-option v-for="option in $fieldConfig.options" :key="option.value" :label="option.label" :value="option.value"></el-option>
|
||||
</el-select>
|
||||
#elseif($fieldConfig.formType == "RADIO")
|
||||
<el-radio-group v-model="queryParams.$fieldConfig.fieldName">
|
||||
<el-radio v-for="option in $fieldConfig.options" :key="option.value" :label="option.value">{{ option.label }}</el-radio>
|
||||
</el-radio-group>
|
||||
#elseif($fieldConfig.formType == "CHECK_BOX")
|
||||
<el-checkbox-group v-model="queryParams.$fieldConfig.fieldName">
|
||||
<el-checkbox v-for="option in $fieldConfig.options" :key="option.value" :label="option.value">{{ option.label }}</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
#elseif($fieldConfig.formType == "INPUT_NUMBER")
|
||||
<el-input-number v-model="queryParams.$fieldConfig.fieldName" :placeholder="$fieldConfig.fieldComment" />
|
||||
#elseif($fieldConfig.formType == "SWITCH")
|
||||
<el-switch v-model="queryParams.$fieldConfig.fieldName" />
|
||||
#elseif($fieldConfig.formType == "TEXT_AREA")
|
||||
<el-input type="textarea" v-model="queryParams.$fieldConfig.fieldName" :placeholder="$fieldConfig.fieldComment" />
|
||||
#elseif($fieldConfig.formType == "DATE_TIME")
|
||||
<el-date-picker v-model="queryParams.$fieldConfig.fieldName" type="datetime" :placeholder="$fieldConfig.fieldComment" />
|
||||
#elseif($fieldConfig.formType == "DATE")
|
||||
<el-date-picker v-model="queryParams.$fieldConfig.fieldName" type="date" :placeholder="$fieldConfig.fieldComment" />
|
||||
#end
|
||||
</el-form-item>
|
||||
#end
|
||||
#end
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleQuery">
|
||||
<i-ep-search />
|
||||
搜索
|
||||
</el-button>
|
||||
<el-button @click="handleResetQuery">
|
||||
<i-ep-refresh />
|
||||
重置
|
||||
</el-button>
|
||||
<el-button type="primary" @click="handleQuery"><i-ep-search />搜索</el-button>
|
||||
<el-button @click="handleResetQuery"><i-ep-refresh />重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<el-card shadow="never" class="table-container">
|
||||
<template #header>
|
||||
<el-button type="success" @click="handleOpenDialog()">
|
||||
<i-ep-plus />
|
||||
新增
|
||||
</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
:disabled="ids.length === 0"
|
||||
@click="handleDelete()"
|
||||
>
|
||||
<i-ep-delete />
|
||||
删除
|
||||
</el-button>
|
||||
<el-button type="success" @click="handleOpenDialog"><i-ep-plus />新增</el-button>
|
||||
<el-button type="danger" :disabled="ids.length === 0" @click="handleDelete"><i-ep-delete />删除</el-button>
|
||||
</template>
|
||||
|
||||
<el-table
|
||||
ref="dataTableRef"
|
||||
v-loading="loading"
|
||||
:data="${className.toLowerCase()}List"
|
||||
highlight-current-row
|
||||
border
|
||||
@selection-change="handleSelectionChange"
|
||||
ref="dataTableRef"
|
||||
v-loading="loading"
|
||||
:data="pageData"
|
||||
highlight-current-row
|
||||
border
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
#foreach($field in $fields)
|
||||
<el-table-column label="${field.comment}" prop="${field.name}" min-width="100" />
|
||||
#foreach($fieldConfig in $fieldConfigs)
|
||||
#if($fieldConfig.isShowInList == 1)
|
||||
<el-table-column
|
||||
:key="$fieldConfig.fieldName"
|
||||
:label="$fieldConfig.fieldComment"
|
||||
:prop="$fieldConfig.fieldName"
|
||||
min-width="100"
|
||||
/>
|
||||
#end
|
||||
|
||||
#end
|
||||
<el-table-column fixed="right" label="操作" width="220">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
type="primary"
|
||||
size="small"
|
||||
link
|
||||
@click="handleOpenDialog(scope.row.id)"
|
||||
>
|
||||
<i-ep-edit />
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
size="small"
|
||||
link
|
||||
@click="handleDelete(scope.row.id)"
|
||||
>
|
||||
<i-ep-delete />
|
||||
删除
|
||||
</el-button>
|
||||
<el-button type="primary" size="small" link @click="handleOpenDialog(scope.row.id)"><i-ep-edit />编辑</el-button>
|
||||
<el-button type="danger" size="small" link @click="handleDelete(scope.row.id)"><i-ep-delete />删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-if="total > 0"
|
||||
v-model:total="total"
|
||||
v-model:page="queryParams.pageNum"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="handleQuery"
|
||||
v-if="total > 0"
|
||||
v-model:total="total"
|
||||
v-model:page="queryParams.pageNum"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="handleQuery"
|
||||
/>
|
||||
</el-card>
|
||||
|
||||
<!-- ${className}表单弹窗 -->
|
||||
<el-dialog
|
||||
v-model="dialog.visible"
|
||||
:title="dialog.title"
|
||||
width="500px"
|
||||
@close="handleCloseDialog"
|
||||
>
|
||||
<el-form
|
||||
ref="${className.toLowerCase()}FormRef"
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
label-width="100px"
|
||||
>
|
||||
#foreach($field in $fields)
|
||||
<el-form-item label="${field.comment}" prop="${field.name}">
|
||||
<el-input v-model="formData.${field.name}" placeholder="请输入${field.comment}" />
|
||||
</el-form-item>
|
||||
<!-- $!{businessName}表单弹窗 -->
|
||||
<el-dialog v-model="dialog.visible" :title="dialog.title" width="500px" @close="handleCloseDialog">
|
||||
<el-form ref="dataFormRef" :model="formData" :rules="rules" label-width="100px">
|
||||
#foreach($fieldConfig in $fieldConfigs)
|
||||
#if($fieldConfig.isShowInForm == 1)
|
||||
<el-form-item :label="$fieldConfig.fieldComment" :key="$fieldConfig.fieldName">
|
||||
#if($fieldConfig.formType == "INPUT")
|
||||
<el-input v-model="formData.$fieldConfig.fieldName" :placeholder="'请输入$fieldConfig.fieldComment" />
|
||||
#elseif($fieldConfig.formType == "SELECT")
|
||||
<el-select v-model="formData.$fieldConfig.fieldName" :placeholder="'请选择$fieldConfig.fieldComment">
|
||||
<!-- 这里可以根据具体需求生成select options -->
|
||||
<el-option v-for="option in $fieldConfig.options" :key="option.value" :label="option.label" :value="option.value"></el-option>
|
||||
</el-select>
|
||||
#elseif($fieldConfig.formType == "RADIO")
|
||||
<el-radio-group v-model="formData.$fieldConfig.fieldName">
|
||||
<el-radio v-for="option in $fieldConfig.options" :key="option.value" :label="option.value">{{ option.label }}</el-radio>
|
||||
</el-radio-group>
|
||||
#elseif($fieldConfig.formType == "CHECK_BOX")
|
||||
<el-checkbox-group v-model="formData.$fieldConfig.fieldName">
|
||||
<el-checkbox v-for="option in $fieldConfig.options" :key="option.value" :label="option.value">{{ option.label }}</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
#elseif($fieldConfig.formType == "INPUT_NUMBER")
|
||||
<el-input-number v-model="formData.$fieldConfig.fieldName" :placeholder="'请输入$fieldConfig.fieldComment" />
|
||||
#elseif($fieldConfig.formType == "SWITCH")
|
||||
<el-switch v-model="formData.$fieldConfig.fieldName" />
|
||||
#elseif($fieldConfig.formType == "TEXT_AREA")
|
||||
<el-input type="textarea" v-model="formData.$fieldConfig.fieldName" :placeholder="'请输入$fieldConfig.fieldComment" />
|
||||
#elseif($fieldConfig.formType == "DATE_TIME")
|
||||
<el-date-picker v-model="formData.$fieldConfig.fieldName" type="datetime" :placeholder="'请选择$fieldConfig.fieldComment" />
|
||||
#elseif($fieldConfig.formType == "DATE")
|
||||
<el-date-picker v-model="formData.$fieldConfig.fieldName" type="date" :placeholder="'请选择$fieldConfig.fieldComment" />
|
||||
#end
|
||||
</el-form-item>
|
||||
#end
|
||||
#end
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button type="primary" @click="handleSubmit">确 定</el-button>
|
||||
<el-button @click="handleCloseDialog">取 消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit">确定</el-button>
|
||||
<el-button @click="handleCloseDialog">取消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
@@ -118,55 +131,60 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
defineOptions({
|
||||
name: "${className}",
|
||||
name: "${entityName}",
|
||||
inheritAttrs: false,
|
||||
});
|
||||
|
||||
import ${className}API, { ${className}PageVO, ${className}Form, ${className}PageQuery } from "@/api/${className.toLowerCase()}";
|
||||
import ${entityName}API, { ${entityName}PageVO, ${entityName}Form, ${entityName}PageQuery } from "@/api/${lowerFirstEntityName}";
|
||||
|
||||
const queryFormRef = ref(ElForm);
|
||||
const ${className.toLowerCase()}FormRef = ref(ElForm);
|
||||
const queryFormRef = ref(null);
|
||||
const dataFormRef = ref(null);
|
||||
|
||||
const loading = ref(false);
|
||||
const ids = ref<number[]>([]);
|
||||
const total = ref(0);
|
||||
|
||||
const queryParams = reactive<${className}PageQuery>({
|
||||
const queryParams = reactive<RolePageQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
keywords: '',
|
||||
name: '',
|
||||
code: '',
|
||||
});
|
||||
|
||||
// ${className}表格数据
|
||||
const ${className.toLowerCase()}List = ref<${className}PageVO[]>();
|
||||
// $!{businessName}表格数据
|
||||
const pageData = ref<RolePageVO[]>([]);
|
||||
|
||||
// 弹窗
|
||||
const dialog = reactive({
|
||||
title: "",
|
||||
visible: false,
|
||||
});
|
||||
// ${className}表单
|
||||
const formData = reactive<${className}Form>({});
|
||||
|
||||
const rules = reactive({
|
||||
#foreach($field in $fields)
|
||||
${field.name}: [{ required: true, message: "请输入${field.comment}", trigger: "blur" }],
|
||||
#end
|
||||
// $!{businessName}表单
|
||||
const formData = reactive<RoleForm>({
|
||||
keywords: '',
|
||||
name: '',
|
||||
code: '',
|
||||
});
|
||||
|
||||
/** 查询 */
|
||||
const rules = reactive({
|
||||
name: [{ required: true, message: "请输入$!{businessName}名称", trigger: "blur" }],
|
||||
code: [{ required: true, message: "请输入$!{businessName}编码", trigger: "blur" }],
|
||||
});
|
||||
|
||||
/** 查询$!{businessName} */
|
||||
function handleQuery() {
|
||||
loading.value = true;
|
||||
${className}API.getPage(queryParams)
|
||||
.then((data) => {
|
||||
${className.toLowerCase()}List.value = data.list;
|
||||
total.value = data.total;
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
${entityName}API.getPage(queryParams)
|
||||
.then((data) => {
|
||||
pageData.value = data.list;
|
||||
total.value = data.total;
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
/** 重置查询 */
|
||||
/** 重置$!{businessName}查询 */
|
||||
function handleResetQuery() {
|
||||
queryFormRef.value.resetFields();
|
||||
queryParams.pageNum = 1;
|
||||
@@ -175,4 +193,86 @@
|
||||
|
||||
/** 行复选框选中记录选中ID集合 */
|
||||
function handleSelectionChange(selection: any) {
|
||||
ids.value = selection.map((item: any
|
||||
ids.value = selection.map((item: any) => item.id);
|
||||
}
|
||||
|
||||
/** 打开$!{businessName}弹窗 */
|
||||
function handleOpenDialog(id?: number) {
|
||||
dialog.visible = true;
|
||||
if (id) {
|
||||
dialog.title = "修改$!{businessName}";
|
||||
${entityName}API.getFormData(id).then((data) => {
|
||||
Object.assign(formData, data);
|
||||
});
|
||||
} else {
|
||||
dialog.title = "新增$!{businessName}";
|
||||
}
|
||||
}
|
||||
|
||||
/** 提交$!{businessName}表单 */
|
||||
function handleSubmit() {
|
||||
dataFormRef.value.validate((valid: any) => {
|
||||
if (valid) {
|
||||
loading.value = true;
|
||||
const id = formData.id;
|
||||
if (id) {
|
||||
${entityName}API.update(id, formData)
|
||||
.then(() => {
|
||||
ElMessage.success("修改成功");
|
||||
handleCloseDialog();
|
||||
handleResetQuery();
|
||||
})
|
||||
.finally(() => (loading.value = false));
|
||||
} else {
|
||||
${entityName}API.add(formData)
|
||||
.then(() => {
|
||||
ElMessage.success("新增成功");
|
||||
handleCloseDialog();
|
||||
handleResetQuery();
|
||||
})
|
||||
.finally(() => (loading.value = false));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** 关闭$!{businessName}弹窗 */
|
||||
function handleCloseDialog() {
|
||||
dialog.visible = false;
|
||||
dataFormRef.value.resetFields();
|
||||
dataFormRef.value.clearValidate();
|
||||
formData.id = undefined;
|
||||
}
|
||||
|
||||
/** 删除$!{businessName} */
|
||||
function handleDelete(id?: number) {
|
||||
const ids = [id || ids.value].join(",");
|
||||
if (!ids) {
|
||||
ElMessage.warning("请勾选删除项");
|
||||
return;
|
||||
}
|
||||
|
||||
ElMessageBox.confirm("确认删除已选中的数据项?", "警告", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning",
|
||||
}).then(
|
||||
() => {
|
||||
loading.value = true;
|
||||
${entityName}API.deleteByIds(ids)
|
||||
.then(() => {
|
||||
ElMessage.success("删除成功");
|
||||
handleResetQuery();
|
||||
})
|
||||
.finally(() => (loading.value = false));
|
||||
},
|
||||
() => {
|
||||
ElMessage.info("已取消删除");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
handleQuery();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -7,7 +7,7 @@ import ${package}.model.query.${entityName}Query;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* $!{tableComment}Mapper接口
|
||||
* $!{businessName}Mapper接口
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
@@ -16,7 +16,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
public interface ${entityName}Mapper extends BaseMapper<${entityName}> {
|
||||
|
||||
/**
|
||||
* 获取$!{tableComment}分页数据
|
||||
* 获取${businessName}分页数据
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param queryParams 查询参数
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="${package}.mapper.${entityName}Mapper">
|
||||
|
||||
<!-- 获取${tableComment}分页列表 -->
|
||||
<!-- 获取${businessName}分页列表 -->
|
||||
<select id="get${entityName}Page" resultType="${package}.model.vo.${entityName}VO">
|
||||
SELECT
|
||||
*
|
||||
|
||||
@@ -12,12 +12,12 @@ import java.math.BigDecimal;
|
||||
#end
|
||||
|
||||
/**
|
||||
* $!{tableComment}分页查询对象
|
||||
* $!{businessName}分页查询对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Schema(description ="$!{tableComment}分页查询对象")
|
||||
@Schema(description ="$!{businessName}查询对象")
|
||||
@Getter
|
||||
@Setter
|
||||
public class ${entityName}Query extends BasePageQuery {
|
||||
@@ -25,9 +25,9 @@ public class ${entityName}Query extends BasePageQuery {
|
||||
private static final long serialVersionUID = 1L;
|
||||
#if($fieldConfigs)
|
||||
#foreach($fieldConfig in ${fieldConfigs})
|
||||
#if($fieldConfig.showInQuery)
|
||||
#if($fieldConfig.isShowInQuery)
|
||||
#if("$!fieldConfig.fieldComment" != "")
|
||||
@Schema(description = "${field.fieldComment}")
|
||||
@Schema(description = "${fieldConfig.fieldComment}")
|
||||
#end
|
||||
private ${fieldConfig.fieldType} ${fieldConfig.fieldName};
|
||||
#end
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* $!{tableComment}服务类
|
||||
* $!{businessName}服务类
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
@@ -16,41 +16,41 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
public interface ${entityName}Service extends IService<${entityName}> {
|
||||
|
||||
/**
|
||||
*$!{tableComment}分页列表
|
||||
*$!{businessName}分页列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams);
|
||||
|
||||
/**
|
||||
* 获取$!{tableComment}表单数据
|
||||
* 获取${businessName}表单数据
|
||||
*
|
||||
* @param id $!{tableComment}ID
|
||||
* @param id $!{businessName}ID
|
||||
* @return
|
||||
*/
|
||||
${entityName}Form get${entityName}FormData(Long id);
|
||||
|
||||
/**
|
||||
* 新增$!{tableComment}
|
||||
* 新增${businessName}
|
||||
*
|
||||
* @param formData $!{tableComment}表单对象
|
||||
* @param formData $!{businessName}表单对象
|
||||
* @return
|
||||
*/
|
||||
boolean save${entityName}(${entityName}Form formData);
|
||||
|
||||
/**
|
||||
* 修改$!{tableComment}
|
||||
* 修改${businessName}
|
||||
*
|
||||
* @param id $!{tableComment}ID
|
||||
* @param formData $!{tableComment}表单对象
|
||||
* @param id $!{businessName}ID
|
||||
* @param formData $!{businessName}表单对象
|
||||
* @return
|
||||
*/
|
||||
boolean update${entityName}(Long id, ${entityName}Form formData);
|
||||
|
||||
/**
|
||||
* 删除$!{tableComment}
|
||||
* 删除${businessName}
|
||||
*
|
||||
* @param ids $!{tableComment}ID,多个以英文逗号(,)分割
|
||||
* @param ids $!{businessName}ID,多个以英文逗号(,)分割
|
||||
* @return
|
||||
*/
|
||||
boolean delete${entityName}s(String ids);
|
||||
|
||||
@@ -21,7 +21,7 @@ import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* $!{tableComment}服务实现类
|
||||
* $!{businessName}服务实现类
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
@@ -33,10 +33,10 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $
|
||||
private final ${entityName}Converter ${lowerFirstEntityName}Converter;
|
||||
|
||||
/**
|
||||
* 获取$!{tableComment}分页列表
|
||||
* 获取${businessName}分页列表
|
||||
*
|
||||
* @param queryParams 查询参数
|
||||
* @return {@link IPage<${entityName}PageVO>} $!{tableComment}分页列表
|
||||
* @return {@link IPage<${entityName}PageVO>} $!{businessName}分页列表
|
||||
*/
|
||||
@Override
|
||||
public IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams) {
|
||||
@@ -48,9 +48,9 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取$!{tableComment}表单数据
|
||||
* 获取${businessName}表单数据
|
||||
*
|
||||
* @param id $!{tableComment}ID
|
||||
* @param id $!{businessName}ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@@ -60,9 +60,9 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增$!{tableComment}
|
||||
* 新增${businessName}
|
||||
*
|
||||
* @param formData $!{tableComment}表单对象
|
||||
* @param formData $!{businessName}表单对象
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@@ -72,10 +72,10 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新$!{tableComment}
|
||||
* 更新${businessName}
|
||||
*
|
||||
* @param id $!{tableComment}ID
|
||||
* @param formData $!{tableComment}表单对象
|
||||
* @param id $!{businessName}ID
|
||||
* @param formData $!{businessName}表单对象
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@@ -85,14 +85,14 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除$!{tableComment}
|
||||
* 删除${businessName}
|
||||
*
|
||||
* @param ids $!{tableComment}ID,多个以英文逗号(,)分割
|
||||
* @param ids $!{businessName}ID,多个以英文逗号(,)分割
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean delete${entityName}s(String ids) {
|
||||
Assert.isTrue(StrUtil.isNotBlank(ids), "删除的$!{tableComment}数据为空");
|
||||
Assert.isTrue(StrUtil.isNotBlank(ids), "删除的${businessName}数据为空");
|
||||
// 逻辑删除
|
||||
List<Long> idList = Arrays.stream(ids.split(","))
|
||||
.map(Long::parseLong)
|
||||
|
||||
@@ -14,14 +14,14 @@ import java.math.BigDecimal;
|
||||
#end
|
||||
|
||||
/**
|
||||
* $!{tableComment}视图对象
|
||||
* $!{businessName}视图对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema( description = "$!{tableComment}视图对象")
|
||||
@Schema( description = "$!{businessName}视图对象")
|
||||
public class ${entityName}VO implements Serializable {
|
||||
|
||||
@Serial
|
||||
@@ -29,10 +29,12 @@ public class ${entityName}VO implements Serializable {
|
||||
|
||||
#if($fieldConfigs)
|
||||
#foreach($fieldConfig in ${fieldConfigs})
|
||||
#if("$!fieldConfig.fieldComment" != "")
|
||||
#if($fieldConfig.isShowInList)
|
||||
#if("$!fieldConfig.fieldComment" != "")
|
||||
@Schema(description = "${fieldConfig.fieldComment}")
|
||||
#end
|
||||
#end
|
||||
private ${fieldConfig.fieldType} ${fieldConfig.fieldName};
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user