!513 优化代码生成

This commit is contained in:
YunaiV 2023-06-17 12:22:12 +08:00
parent 5f8129d65b
commit eb44015b74
10 changed files with 206 additions and 107 deletions

View File

@ -34,7 +34,7 @@
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<!-- 看看咋放到 bom 里 -->
<lombok.version>1.18.26</lombok.version>
<spring.boot.version>2.7.11</spring.boot.version>
<spring.boot.version>2.7.12</spring.boot.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

View File

@ -16,7 +16,7 @@
<properties>
<revision>1.7.3-snapshot</revision>
<!-- 统一依赖管理 -->
<spring.boot.version>2.7.11</spring.boot.version>
<spring.boot.version>2.7.12</spring.boot.version>
<spring.cloud.version>2021.0.5</spring.cloud.version>
<spring.cloud.alibaba.version>2021.0.4.0</spring.cloud.alibaba.version>
<!-- Web 相关 -->
@ -76,7 +76,7 @@
<minio.version>8.5.2</minio.version>
<aliyun-java-sdk-core.version>4.6.3</aliyun-java-sdk-core.version>
<aliyun-java-sdk-dysmsapi.version>2.2.1</aliyun-java-sdk-dysmsapi.version>
<tencentcloud-sdk-java.version>3.1.715</tencentcloud-sdk-java.version>
<tencentcloud-sdk-java.version>3.1.758</tencentcloud-sdk-java.version>
<justauth.version>1.4.0</justauth.version>
<jimureport.version>1.5.6</jimureport.version>
<xercesImpl.version>2.12.2</xercesImpl.version>

View File

@ -3,11 +3,15 @@ package cn.iocoder.yudao.framework.captcha.config;
import cn.hutool.core.util.ClassUtil;
import cn.iocoder.yudao.framework.captcha.core.enums.CaptchaRedisKeyConstants;
import cn.iocoder.yudao.framework.captcha.core.service.RedisCaptchaServiceImpl;
import com.xingyuv.captcha.properties.AjCaptchaProperties;
import com.xingyuv.captcha.service.CaptchaCacheService;
import com.xingyuv.captcha.service.impl.CaptchaServiceFactory;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.StringRedisTemplate;
import javax.annotation.Resource;
@AutoConfiguration
public class YudaoCaptchaConfiguration {
@ -17,9 +21,17 @@ public class YudaoCaptchaConfiguration {
ClassUtil.loadClass(CaptchaRedisKeyConstants.class.getName());
}
@Resource
private StringRedisTemplate stringRedisTemplate;
@Bean
public CaptchaCacheService captchaCacheService(StringRedisTemplate stringRedisTemplate) {
return new RedisCaptchaServiceImpl(stringRedisTemplate);
public CaptchaCacheService captchaCacheService(AjCaptchaProperties config) {
// 缓存类型 redis/local/....
CaptchaCacheService ret = CaptchaServiceFactory.getCache(config.getCacheType().name());
if (ret instanceof RedisCaptchaServiceImpl) {
((RedisCaptchaServiceImpl) ret).setStringRedisTemplate(stringRedisTemplate);
}
return ret;
}
}

View File

@ -20,6 +20,10 @@ public class RedisCaptchaServiceImpl implements CaptchaCacheService {
@Resource // 保证 aj-captcha SPI 创建时的注入
private StringRedisTemplate stringRedisTemplate;
public void setStringRedisTemplate(StringRedisTemplate stringRedisTemplate) {
this.stringRedisTemplate = stringRedisTemplate;
}
@Override
public String type() {
return "redis";

View File

@ -17,7 +17,7 @@ public class ${sceneEnum.prefixClass}${table.className}RespVO extends ${sceneEnu
#foreach ($column in $columns)
#if (${column.listOperationResult} && (!${column.createOperation} || !${column.updateOperation}))##不是通用字段
@Schema(description = "${column.columnComment}"#if (!${column.nullable}), required = true#end#if ("$!column.example" != ""), example = "${column.example}"#end)
@Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end)
private ${column.javaType} ${column.javaField};
#end

View File

@ -16,7 +16,7 @@ export interface ${simpleClassName}VO {
}
// 查询${table.classComment}列表
export const get${simpleClassName}Page = async (params: ${simpleClassName}PageReqVO) => {
export const get${simpleClassName}Page = async (params) => {
return await request.get({ url: `${baseURL}/page`, params })
}

View File

@ -16,7 +16,7 @@ export interface ${simpleClassName}VO {
}
// 查询${table.classComment}列表
export const get${simpleClassName}Page = async (params: ${simpleClassName}PageReqVO) => {
export const get${simpleClassName}Page = async (params) => {
return await request.get({ url: '${baseURL}/page', params })
}

View File

@ -1,5 +1,5 @@
import { BasicColumn, FormSchema, useRender } from '@/components/Table'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
export const columns: BasicColumn[] = [
#foreach($column in $columns)
@ -53,7 +53,7 @@ export const searchFormSchema: FormSchema[] = [
component: 'Select',
componentProps: {
#if ("" != $dictType)## 设置了 dictType 数据字典的情况
options: getIntDictOptions(DICT_TYPE.$dictType.toUpperCase())
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase())
#else## 未设置 dictType 数据字典的情况
options: []
#end
@ -67,7 +67,7 @@ export const searchFormSchema: FormSchema[] = [
#end
]
export const formSchema: FormSchema[] = [
export const createFormSchema: FormSchema[] = [
{
label: '编号',
field: 'id',
@ -75,7 +75,7 @@ export const formSchema: FormSchema[] = [
component: 'Input'
},
#foreach($column in $columns)
#if ($column.createOperation || $column.updateOperation)
#if ($column.createOperation)
#set ($dictType = $column.dictType)
#set ($javaField = $column.javaField)
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
@ -90,16 +90,24 @@ export const formSchema: FormSchema[] = [
#if ($column.htmlType == "input")
component: 'Input'
#elseif($column.htmlType == "imageUpload")## 图片上传
component: 'Upload'
component: 'FileUpload',
componentProps: {
fileType: 'file',
maxCount: 1
}
#elseif($column.htmlType == "fileUpload")## 文件上传
component: 'Upload'
component: 'FileUpload',
componentProps: {
fileType: 'image',
maxCount: 1
}
#elseif($column.htmlType == "editor")## 文本编辑器
component: 'InputTextArea'
component: 'Editor'
#elseif($column.htmlType == "select")## 下拉框
component: 'Select',
componentProps: {
#if ("" != $dictType)## 有数据字典
options: getIntDictOptions(DICT_TYPE.COMMON_STATUS)
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number')
#else##没数据字典
options:[]
#end
@ -108,16 +116,16 @@ export const formSchema: FormSchema[] = [
component: 'Checkbox',
componentProps: {
#if ("" != $dictType)## 有数据字典
options: getIntDictOptions(DICT_TYPE.COMMON_STATUS)
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number')
#else##没数据字典
options:[]
#end
}
#elseif($column.htmlType == "radio")## 单选框
component: 'Radio',
component: 'RadioButtonGroup',
componentProps: {
#if ("" != $dictType)## 有数据字典
options: getIntDictOptions(DICT_TYPE.COMMON_STATUS)
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number')
#else##没数据字典
options:[]
#end
@ -132,3 +140,69 @@ export const formSchema: FormSchema[] = [
#end
#end
]
export const updateFormSchema: FormSchema[] = [
{
label: '编号',
field: 'id',
show: false,
component: 'Input'
},
#foreach($column in $columns)
#if ($column.updateOperation)
#set ($dictType = $column.dictType)
#set ($javaField = $column.javaField)
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#set ($comment = $column.columnComment)
#if (!$column.primaryKey)## 忽略主键,不用在表单里
{
label: '${comment}',
field: '${javaField}',
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
required: true,
#end
#if ($column.htmlType == "input")
component: 'Input'
#elseif($column.htmlType == "imageUpload")## 图片上传
component: 'Upload'
#elseif($column.htmlType == "fileUpload")## 文件上传
component: 'Upload'
#elseif($column.htmlType == "editor")## 文本编辑器
component: 'Editor'
#elseif($column.htmlType == "select")## 下拉框
component: 'Select',
componentProps: {
#if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number')
#else##没数据字典
options:[]
#end
}
#elseif($column.htmlType == "checkbox")## 多选框
component: 'Checkbox',
componentProps: {
#if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number')
#else##没数据字典
options:[]
#end
}
#elseif($column.htmlType == "radio")## 单选框
component: 'RadioButtonGroup',
componentProps: {
#if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number')
#else##没数据字典
options:[]
#end
}
#elseif($column.htmlType == "datetime")## 时间框
component: 'DatePicker'
#elseif($column.htmlType == "textarea")## 文本域
component: 'InputTextArea'
#end
},
#end
#end
#end
]

View File

@ -1,49 +1,56 @@
<template>
<BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? '编辑' : '新增'" @ok="handleSubmit">
<BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? t('action.edit') : t('action.create')" @ok="handleSubmit">
<BasicForm @register="registerForm" />
</BasicModal>
</template>
<script lang="ts" setup name="${table.className}Modal">
import { ref, unref } from 'vue'
import { BasicModal, useModalInner } from '@/components/Modal'
import { BasicForm, useForm } from '@/components/Form'
import { formSchema } from './${classNameVar}.data'
import { create${simpleClassName}, get${simpleClassName}, update${simpleClassName} } from '@/api/${table.moduleName}/${classNameVar}'
<script lang="ts" setup>
import { ref, unref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { BasicForm, useForm } from '@/components/Form'
import { BasicModal, useModalInner } from '@/components/Modal'
import { createFormSchema, updateFormSchema } from './${classNameVar}.data'
import { create${simpleClassName}, get${simpleClassName}, update${simpleClassName} } from '@/api/${table.moduleName}/${classNameVar}'
const emit = defineEmits(['success', 'register'])
const isUpdate = ref(true)
defineOptions({ name: '${table.className}Modal' })
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
labelWidth: 120,
baseColProps: { span: 24 },
schemas: formSchema,
showActionButtonGroup: false,
actionColOptions: { span: 23 }
})
const { t } = useI18n()
const { createMessage } = useMessage()
const emit = defineEmits(['success', 'register'])
const isUpdate = ref(true)
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
resetFields()
setModalProps({ confirmLoading: false })
isUpdate.value = !!data?.isUpdate
if (unref(isUpdate)) {
const res = await get${simpleClassName}(data.record.id)
setFieldsValue({ ...res })
}
})
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
labelWidth: 120,
baseColProps: { span: 24 },
schemas: isUpdate? updateFormSchema : createFormSchema,
showActionButtonGroup: false,
actionColOptions: { span: 23 }
})
async function handleSubmit() {
try {
const values = await validate()
setModalProps({ confirmLoading: true })
if (unref(isUpdate)) {
await update${simpleClassName}(values)
} else {
await create${simpleClassName}(values)
}
closeModal()
emit('success')
} finally {
setModalProps({ confirmLoading: false })
}
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
resetFields()
setModalProps({ confirmLoading: false })
isUpdate.value = !!data?.isUpdate
if (unref(isUpdate)) {
const res = await get${simpleClassName}(data.record.id)
setFieldsValue({ ...res })
}
})
async function handleSubmit() {
try {
const values = await validate()
setModalProps({ confirmLoading: true })
if (unref(isUpdate)) {
await update${simpleClassName}(values)
} else {
await create${simpleClassName}(values)
}
closeModal()
emit('success')
createMessage.success(t('common.saveSuccessText'))
} finally {
setModalProps({ confirmLoading: false })
}
}
</script>

View File

@ -33,58 +33,60 @@
<${simpleClassName}Modal @register="registerModal" @success="reload()" />
</div>
</template>
<script lang="ts" setup name="${table.className}">
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useModal } from '@/components/Modal'
import ${simpleClassName}Modal from './${simpleClassName}Modal.vue'
import { IconEnum } from '@/enums/appEnum'
import { BasicTable, useTable, TableAction } from '@/components/Table'
import { delete${simpleClassName}, export${simpleClassName}, get${simpleClassName}Page } from '@/api/${table.moduleName}/${classNameVar}'
import { columns, searchFormSchema } from './${classNameVar}.data'
<script lang="ts" setup>
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useModal } from '@/components/Modal'
import ${simpleClassName}Modal from './${simpleClassName}Modal.vue'
import { IconEnum } from '@/enums/appEnum'
import { BasicTable, useTable, TableAction } from '@/components/Table'
import { delete${simpleClassName}, export${simpleClassName}, get${simpleClassName}Page } from '@/api/${table.moduleName}/${classNameVar}'
import { columns, searchFormSchema } from './${classNameVar}.data'
const { t } = useI18n()
const { createConfirm, createMessage } = useMessage()
const [registerModal, { openModal }] = useModal()
defineOptions({ name: '${table.className}' })
const [registerTable, { getForm, reload }] = useTable({
title: '${table.classComment}列表',
api: get${simpleClassName}Page,
columns,
formConfig: { labelWidth: 120, schemas: searchFormSchema },
useSearchForm: true,
showTableSetting: true,
actionColumn: {
width: 140,
title: t('common.action'),
dataIndex: 'action',
fixed: 'right'
const { t } = useI18n()
const { createConfirm, createMessage } = useMessage()
const [registerModal, { openModal }] = useModal()
const [registerTable, { getForm, reload }] = useTable({
title: '${table.classComment}列表',
api: get${simpleClassName}Page,
columns,
formConfig: { labelWidth: 120, schemas: searchFormSchema },
useSearchForm: true,
showTableSetting: true,
actionColumn: {
width: 140,
title: t('common.action'),
dataIndex: 'action',
fixed: 'right'
}
})
function handleCreate() {
openModal(true, { isUpdate: false })
}
function handleEdit(record: Recordable) {
openModal(true, { record, isUpdate: true })
}
async function handleExport() {
createConfirm({
title: t('common.exportTitle'),
iconType: 'warning',
content: t('common.exportMessage'),
async onOk() {
await export${simpleClassName}(getForm().getFieldsValue())
createMessage.success(t('common.exportSuccessText'))
}
})
}
function handleCreate() {
openModal(true, { isUpdate: false })
}
function handleEdit(record: Recordable) {
openModal(true, { record, isUpdate: true })
}
async function handleExport() {
createConfirm({
title: t('common.exportTitle'),
iconType: 'warning',
content: t('common.exportMessage'),
async onOk() {
await export${simpleClassName}(getForm().getFieldsValue())
createMessage.success(t('common.exportSuccessText'))
}
})
}
async function handleDelete(record: Recordable) {
await delete${simpleClassName}(record.id)
createMessage.success(t('common.delSuccessText'))
reload()
}
async function handleDelete(record: Recordable) {
await delete${simpleClassName}(record.id)
createMessage.success(t('common.delSuccessText'))
reload()
}
</script>