This commit is contained in:
2025-05-22 10:27:57 +08:00
parent 9139457203
commit bfbde8a0f5
229 changed files with 11846 additions and 3588 deletions
@@ -20,33 +20,38 @@ import java.util.Map;
* @author WebSoft
* @since 2021-09-05 00:31:14
*/
public class VivoGenerator {
public class LawGenerator {
// 输出位置
private static final String OUTPUT_LOCATION = System.getProperty("user.dir");
// private static final String OUTPUT_LOCATION = ""; // 不想生成到项目中可以写磁盘路径
//private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径
// 输出目录
private static final String OUTPUT_DIR = "/src/main/java";
// Vue文件输出位置
private static final String OUTPUT_LOCATION_VUE = "/Users/liangxin/Project/Html/web/law-admin";
// Vue文件输出目录
private static final String OUTPUT_DIR_VUE = "/src";
// 作者名称
private static final String AUTHOR = "科技小王子";
private static final String AUTHOR = "LX";
// 是否在xml中添加二级缓存配置
private static final boolean ENABLE_CACHE = false;
// 数据库连接配置
private static final String DB_URL = "jdbc:mysql://127.0.0.1:3306/vivo?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";
private static final String DB_URL = "jdbc:mysql://127.0.0.1:3306/law?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 = "root";
private static final String DB_PASSWORD = "root";
// 包名
private static final String PACKAGE_NAME = "com.gxwebsoft";
// 模块名
private static final String MODULE_NAME = "vivo";
private static final String MODULE_NAME = "law";
// 需要生成的表
private static final String[] TABLE_NAMES = new String[]{
"vivo_pay_code",
"law_notary_config",
"law_notary_list",
};
// 需要去除的表前缀
private static final String[] TABLE_PREFIX = new String[]{
"sys_",
"tb_"
""
};
// 不需要作为查询参数的字段
private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{
@@ -68,9 +73,9 @@ public class VivoGenerator {
"BigDecimal"
};
// 是否添加权限注解
private static final boolean AUTH_ANNOTATION = true;
private static final boolean AUTH_ANNOTATION = false;
// 是否添加日志注解
private static final boolean LOG_ANNOTATION = true;
private static final boolean LOG_ANNOTATION = false;
// controller的mapping前缀
private static final String CONTROLLER_MAPPING_PREFIX = "/api";
// 模板所在位置
@@ -157,6 +162,63 @@ public class VivoGenerator {
+ tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA;
}
});
/**
* 以下是生成VUE项目代码
* 生成文件的路径 /api/shop/goods/index.ts
*/
templatePath = TEMPLATES_DIR + "/index.ts.btl";
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
+ "/api/" + pc.getModuleName() + "/"
+ tableInfo.getEntityPath() + "/" + "index.ts";
}
});
// 生成TS文件 (/api/shop/goods/model/index.ts)
templatePath = TEMPLATES_DIR + "/model.ts.btl";
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
+ "/api/" + pc.getModuleName() + "/"
+ tableInfo.getEntityPath() + "/model/" + "index.ts";
}
});
// 生成Vue文件(/views/shop/goods/index.vue)
templatePath = TEMPLATES_DIR + "/index.vue.btl";
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
+ "/views/" + pc.getModuleName() + "/"
+ tableInfo.getEntityPath() + "/" + "index.vue";
}
});
// 生成components文件(/views/shop/goods/components/edit.vue)
templatePath = TEMPLATES_DIR + "/components.edit.vue.btl";
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
+ "/views/" + pc.getModuleName() + "/"
+ tableInfo.getEntityPath() + "/components/" + tableInfo.getEntityPath() + "Edit.vue";
}
});
// 生成components文件(/views/shop/goods/components/search.vue)
templatePath = TEMPLATES_DIR + "/components.search.vue.btl";
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
+ "/views/" + pc.getModuleName() + "/"
+ tableInfo.getEntityPath() + "/components/" + "search.vue";
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
@@ -26,36 +26,30 @@ public class SysGenerator {
//private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径
// 输出目录
private static final String OUTPUT_DIR = "/src/main/java";
// Vue文件输出位置
private static final String OUTPUT_LOCATION_VUE = "/Users/liangxin/Project/Html/web/law-admin";
// Vue文件输出目录
private static final String OUTPUT_DIR_VUE = "/src";
// 作者名称
private static final String AUTHOR = "科技小王子";
private static final String AUTHOR = "LX";
// 是否在xml中添加二级缓存配置
private static final boolean ENABLE_CACHE = false;
// 数据库连接配置
private static final String DB_URL = "jdbc:mysql://127.0.0.1:3306/vivo?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";
private static final String DB_URL = "jdbc:mysql://127.0.0.1:3306/law?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 = "root";
private static final String DB_PASSWORD = "root";
// 包名
private static final String PACKAGE_NAME = "com.gxwebsoft";
// 模块名
private static final String MODULE_NAME = "common.system";
private static final String MODULE_NAME = "sys";
// 需要生成的表
private static final String[] TABLE_NAMES = new String[]{
// "sys_user",
// "sys_tenant",
// "sys_setting"
// "sys_access_key"
// "sys_company",
// "sys_industry"
// "sys_plug",
"sys_area"
"sys_swiper",
};
// 需要去除的表前缀
private static final String[] TABLE_PREFIX = new String[]{
"sys_",
"tb_"
""
};
// 不需要作为查询参数的字段
private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{
@@ -77,9 +71,9 @@ public class SysGenerator {
"BigDecimal"
};
// 是否添加权限注解
private static final boolean AUTH_ANNOTATION = true;
private static final boolean AUTH_ANNOTATION = false;
// 是否添加日志注解
private static final boolean LOG_ANNOTATION = true;
private static final boolean LOG_ANNOTATION = false;
// controller的mapping前缀
private static final String CONTROLLER_MAPPING_PREFIX = "/api";
// 模板所在位置
@@ -166,6 +160,63 @@ public class SysGenerator {
+ tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA;
}
});
/**
* 以下是生成VUE项目代码
* 生成文件的路径 /api/shop/goods/index.ts
*/
templatePath = TEMPLATES_DIR + "/index.ts.btl";
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
+ "/api/" + pc.getModuleName() + "/"
+ tableInfo.getEntityPath() + "/" + "index.ts";
}
});
// 生成TS文件 (/api/shop/goods/model/index.ts)
templatePath = TEMPLATES_DIR + "/model.ts.btl";
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
+ "/api/" + pc.getModuleName() + "/"
+ tableInfo.getEntityPath() + "/model/" + "index.ts";
}
});
// 生成Vue文件(/views/shop/goods/index.vue)
templatePath = TEMPLATES_DIR + "/index.vue.btl";
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
+ "/views/" + pc.getModuleName() + "/"
+ tableInfo.getEntityPath() + "/" + "index.vue";
}
});
// 生成components文件(/views/shop/goods/components/edit.vue)
templatePath = TEMPLATES_DIR + "/components.edit.vue.btl";
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
+ "/views/" + pc.getModuleName() + "/"
+ tableInfo.getEntityPath() + "/components/" + tableInfo.getEntityPath() + "Edit.vue";
}
});
// 生成components文件(/views/shop/goods/components/search.vue)
templatePath = TEMPLATES_DIR + "/components.search.vue.btl";
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
+ "/views/" + pc.getModuleName() + "/"
+ tableInfo.getEntityPath() + "/components/" + "search.vue";
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
@@ -0,0 +1,185 @@
<!-- 编辑弹窗 -->
<template>
<ele-modal
:width="800"
:visible="visible"
:maskClosable="false"
:maxable="maxable"
:title="isUpdate ? '编辑${table.comment!}' : '添加${table.comment!}'"
: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' }
"
>
<% for(field in table.fields) { %>
<% if(field.propertyName == 'comments'){ %>
<a-form-item label="${field.comment!}" name="${field.propertyName}">
<a-textarea
:rows="4"
:maxlength="200"
placeholder="请输入描述"
v-model:value="form.${field.propertyName}"
/>
</a-form-item>
<% } %>
<% else if(field.propertyName == 'sortNumber'){ %>
<a-form-item label="${field.comment!}" name="${field.propertyName}">
<a-input-number
:min="0"
:max="9999"
class="ele-fluid"
placeholder="请输入排序号"
v-model:value="form.${field.propertyName}"
/>
</a-form-item>
<% } %>
<% else if(field.propertyName == 'status'){ %>
<a-form-item label="${field.comment!}" name="${field.propertyName}">
<a-radio-group v-model:value="form.status">
<a-radio :value="1">显示</a-radio>
<a-radio :value="0">隐藏</a-radio>
</a-radio-group>
</a-form-item>
<% } %>
<% else if(field.propertyName == 'image'){ %>
<a-form-item
label="${field.comment!}"
name="${field.propertyName}">
<SelectFile
:placeholder="`请选择图片`"
:limit="1"
:data="images"
@done="chooseImage"
@del="onDeleteItem"
/>
</a-form-item>
<% } %>
<% else if(field.keyFlag){ %>
<% } %>
<% else if(field.propertyName == 'tenantId'){ %>
<% } %>
<% else if(field.propertyName == 'createTime'){ %>
<% } %>
<% else { %>
<a-form-item label="${field.comment!}" name="${field.propertyName}">
<a-input
allow-clear
placeholder="请输入${field.comment!}"
v-model:value="form.${field.propertyName}"
/>
</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, uuid } from 'ele-admin-pro';
import { add${entity}, update${entity} } from '@/api/${package.ModuleName}/${table.entityPath}';
import { ${entity} } from '@/api/${package.ModuleName}/${table.entityPath}/model';
import { useThemeStore } from '@/store/modules/theme';
import { storeToRefs } from 'pinia';
import { FormInstance } from 'ant-design-vue/es/form';
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?: ${entity} | null;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
// 提交状态
const loading = ref(false);
// 是否显示最大化切换按钮
const maxable = ref(true);
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
// 用户信息
const form = reactive<${entity}>({
<% for(field in table.fields) { %>
${field.propertyName}: undefined,
<% } %>
});
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
// 表单验证规则
const rules = reactive({
});
const { resetFields } = useForm(form, rules);
/* 保存编辑 */
const save = () => {
if (!formRef.value) {
return;
}
formRef.value
.validate()
.then(() => {
loading.value = true;
const formData = {
...form
};
const saveOrUpdate = isUpdate.value ? update${entity} : add${entity};
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);
isUpdate.value = true;
} else {
isUpdate.value = false;
}
} else {
resetFields();
}
},
{ immediate: true }
);
</script>
@@ -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>
@@ -14,7 +14,6 @@ package ${package.Controller};
<% if(isNotEmpty(superControllerClassPackage)) { %>
import ${superControllerClassPackage};
<% } %>
import ${cfg.packageName!}.common.system.entity.User;
import ${cfg.packageName!}.${package.ModuleName}.service.${entity}Service;
import ${cfg.packageName!}.${package.ModuleName}.entity.${entity};
import ${cfg.packageName!}.${package.ModuleName}.param.${entity}Param;
@@ -23,6 +22,7 @@ import ${cfg.packageName!}.common.core.web.PageResult;
import ${cfg.packageName!}.common.core.web.PageParam;
import ${cfg.packageName!}.common.core.web.BatchParam;
import ${cfg.packageName!}.common.core.annotation.OperationLog;
import ${cfg.packageName!}.common.system.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -67,9 +67,6 @@ public class ${table.controllerName} {
<% if(cfg.authAnnotation) { %>
@PreAuthorize("hasAuthority('${authPre}:list')")
<% } %>
<% if(cfg.logAnnotation) { %>
@OperationLog
<% } %>
<% if(swagger2) { %>
@ApiOperation("分页查询${table.comment!}")
<% } %>
@@ -78,11 +75,8 @@ public class ${table.controllerName} {
<% } %>
@GetMapping("/page")
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) { %>
@@ -93,9 +87,6 @@ public class ${table.controllerName} {
<% if(cfg.authAnnotation) { %>
@PreAuthorize("hasAuthority('${authPre}:list')")
<% } %>
<% if(cfg.logAnnotation) { %>
@OperationLog
<% } %>
<% if(swagger2) { %>
@ApiOperation("查询全部${table.comment!}")
<% } %>
@@ -104,11 +95,8 @@ public class ${table.controllerName} {
<% } %>
@GetMapping()
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) { %>
@@ -117,13 +105,11 @@ public class ${table.controllerName} {
*/
<% } %>
@PreAuthorize("hasAuthority('${authPre}:list')")
@OperationLog
@ApiOperation("根据id查询${table.comment!}")
@GetMapping("/{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) { %>
@@ -148,7 +134,7 @@ public class ${table.controllerName} {
// 记录当前登录用户id
User loginUser = getLoginUser();
if (loginUser != null) {
${table.entityPath}.setUserId(loginUser.getUserId());
${table.entityPath}.setUserId(loginUser.getUserId());
}
if (${serviceIns}.save(${table.entityPath})) {
return success("添加成功");
@@ -249,7 +235,7 @@ public class ${table.controllerName} {
@ResponseBody
<% } %>
@PutMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody BatchParam<${entity}> batchParam) {
public ApiResult<?> updateBatch(@RequestBody BatchParam<${entity}> batchParam) {
if (batchParam.update(${serviceIns}, "${idFieldName!}")) {
return success("修改成功");
}
@@ -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 + '/${package.ModuleName}/${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 + '/${package.ModuleName}/${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 + '/${package.ModuleName}/${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 + '/${package.ModuleName}/${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 + '/${package.ModuleName}/${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 + '/${package.ModuleName}/${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 + '/${package.ModuleName}/${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,217 @@
<template>
<div class="page">
<div class="ele-body">
<a-card :bordered="false" :body-style="{ padding: '16px' }">
<ele-pro-table
ref="tableRef"
row-key="id"
: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 === 'image'">
<a-image :src="record.image" :width="50" />
</template>
<template v-if="column.key === 'status'">
<a-tag v-if="record.status === 1" color="green">显示</a-tag>
<a-tag v-if="record.status === 0" 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>
<!-- 编辑弹窗 -->
<${entity}Edit 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 { toDateString } from 'ele-admin-pro';
import type {
DatasourceFunction,
ColumnItem
} from 'ele-admin-pro/es/ele-pro-table/types';
import Search from './components/search.vue';
import ${entity}Edit from './components/${table.entityPath}Edit.vue';
import { page${entity}, remove${entity}, removeBatch${entity} } from '@/api/${package.ModuleName}/${table.entityPath}';
import type { ${entity}, ${entity}Param } from '@/api/${package.ModuleName}/${table.entityPath}/model';
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格选中数据
const selection = ref<${entity}[]>([]);
// 当前编辑数据
const current = ref<${entity} | null>(null);
// 是否显示编辑弹窗
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 page${entity}({
...where,
...orders,
page,
limit
});
};
// 表格列配置
const columns = ref<ColumnItem[]>([
<% for(field in table.fields) { %>
<% if(field.propertyName != 'tenantId'){ %>
{
title: '${field.comment}',
dataIndex: '${field.propertyName}',
key: '${field.propertyName}',
align: 'center',
<% if(field.keyFlag){ %>
width: 90,
<% } %>
<% if(field.propertyName == 'createTime'){ %>
sorter: true,
ellipsis: true,
customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd')
<% } %>
},
<% } %>
<% } %>
{
title: '操作',
key: 'action',
width: 180,
fixed: 'right',
align: 'center',
hideInSetting: true
}
]);
/* 搜索 */
const reload = (where?: ${entity}Param) => {
selection.value = [];
tableRef?.value?.reload({ where: where });
};
/* 打开编辑弹窗 */
const openEdit = (row?: ${entity}) => {
current.value = row ?? null;
showEdit.value = true;
};
/* 打开批量移动弹窗 */
const openMove = () => {
showMove.value = true;
};
/* 删除单个 */
const remove = (row: ${entity}) => {
const hide = message.loading('请求中..', 0);
remove${entity}(row.id)
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
};
/* 批量删除 */
const removeBatch = () => {
if (!selection.value.length) {
message.error('请至少选择一条数据');
return;
}
Modal.confirm({
title: '提示',
content: '确定要删除选中的记录吗?',
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeBatch${entity}(selection.value.map((d) => d.id))
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
}
});
};
/* 查询 */
const query = () => {
loading.value = true;
};
/* 自定义行属性 */
const customRow = (record: ${entity}) => {
return {
// 行点击事件
onClick: () => {
// console.log(record);
},
// 行双击事件
onDblclick: () => {
openEdit(record);
}
};
};
query();
</script>
<script lang="ts">
export default {
name: '${entity}'
};
</script>
<style lang="less" scoped></style>
@@ -80,6 +80,10 @@
</if>
<% } %>
<% } %>
<if test="param.keywords != null">
AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
)
</if>
</where>
</sql>
@@ -0,0 +1,43 @@
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.comment}
${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;
}
@@ -1,5 +1,6 @@
package ${cfg.packageName!}.${package.ModuleName}.param;
import java.math.BigDecimal;
import ${cfg.packageName!}.common.core.annotation.QueryField;
import ${cfg.packageName!}.common.core.annotation.QueryType;
import ${cfg.packageName!}.common.core.web.BaseParam;
@@ -37,7 +37,7 @@ public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.m
@Override
public PageResult<${entity}> pageRel(${entity}Param 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);
return new PageResult<>(list, page.getTotal());
}
@@ -47,7 +47,7 @@ public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.m
List<${entity}> list = baseMapper.selectListRel(param);
// 排序
PageParam<${entity}, ${entity}Param> page = new PageParam<>();
//page.setDefaultOrder("create_time desc");
page.setDefaultOrder("sort_number asc, create_time desc");
return page.sortRecords(list);
}