perf: vben 2.0 codegen

This commit is contained in:
xingyu 2023-08-12 17:31:33 +08:00
parent ebf4ac1d5a
commit b55c1b942d
3 changed files with 83 additions and 83 deletions

View File

@ -15,7 +15,7 @@ export const columns: BasicColumn[] = [
width: 180, width: 180,
customRender: ({ text }) => { customRender: ({ text }) => {
return useRender.renderDate(text) return useRender.renderDate(text)
} },
}, },
#elseif("" != $column.dictType)## 数据字典 #elseif("" != $column.dictType)## 数据字典
{ {
@ -24,7 +24,7 @@ export const columns: BasicColumn[] = [
width: 180, width: 180,
customRender: ({ text }) => { customRender: ({ text }) => {
return useRender.renderDict(text, DICT_TYPE.$dictType.toUpperCase()) return useRender.renderDict(text, DICT_TYPE.$dictType.toUpperCase())
} },
}, },
#else #else
{ {
@ -53,9 +53,9 @@ export const searchFormSchema: FormSchema[] = [
component: 'Select', component: 'Select',
componentProps: { componentProps: {
#if ("" != $dictType)## 设置了 dictType 数据字典的情况 #if ("" != $dictType)## 设置了 dictType 数据字典的情况
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase()) options: getDictOptions(DICT_TYPE.$dictType.toUpperCase()),
#else## 未设置 dictType 数据字典的情况 #else## 未设置 dictType 数据字典的情况
options: [] options: [],
#end #end
}, },
#elseif($column.htmlType == "datetime") #elseif($column.htmlType == "datetime")
@ -88,52 +88,52 @@ export const createFormSchema: FormSchema[] = [
required: true, required: true,
#end #end
#if ($column.htmlType == "input") #if ($column.htmlType == "input")
component: 'Input' component: 'Input',
#elseif($column.htmlType == "imageUpload")## 图片上传 #elseif($column.htmlType == "imageUpload")## 图片上传
component: 'FileUpload', component: 'FileUpload',
componentProps: { componentProps: {
fileType: 'file', fileType: 'file',
maxCount: 1 maxCount: 1,
} },
#elseif($column.htmlType == "fileUpload")## 文件上传 #elseif($column.htmlType == "fileUpload")## 文件上传
component: 'FileUpload', component: 'FileUpload',
componentProps: { componentProps: {
fileType: 'image', fileType: 'image',
maxCount: 1 maxCount: 1,
} },
#elseif($column.htmlType == "editor")## 文本编辑器 #elseif($column.htmlType == "editor")## 文本编辑器
component: 'Editor' component: 'Editor',
#elseif($column.htmlType == "select")## 下拉框 #elseif($column.htmlType == "select")## 下拉框
component: 'Select', component: 'Select',
componentProps: { componentProps: {
#if ("" != $dictType)## 有数据字典 #if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number') options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'),
#else##没数据字典 #else##没数据字典
options:[] options:[],
#end #end
} },
#elseif($column.htmlType == "checkbox")## 多选框 #elseif($column.htmlType == "checkbox")## 多选框
component: 'Checkbox', component: 'Checkbox',
componentProps: { componentProps: {
#if ("" != $dictType)## 有数据字典 #if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number') options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'),
#else##没数据字典 #else##没数据字典
options:[] options:[],
#end #end
} },
#elseif($column.htmlType == "radio")## 单选框 #elseif($column.htmlType == "radio")## 单选框
component: 'RadioButtonGroup', component: 'RadioButtonGroup',
componentProps: { componentProps: {
#if ("" != $dictType)## 有数据字典 #if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number') options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'),
#else##没数据字典 #else##没数据字典
options:[] options:[],
#end #end
} },
#elseif($column.htmlType == "datetime")## 时间框 #elseif($column.htmlType == "datetime")## 时间框
component: 'DatePicker' component: 'DatePicker',
#elseif($column.htmlType == "textarea")## 文本域 #elseif($column.htmlType == "textarea")## 文本域
component: 'InputTextArea' component: 'InputTextArea',
#end #end
}, },
#end #end
@ -162,44 +162,44 @@ export const updateFormSchema: FormSchema[] = [
required: true, required: true,
#end #end
#if ($column.htmlType == "input") #if ($column.htmlType == "input")
component: 'Input' component: 'Input',
#elseif($column.htmlType == "imageUpload")## 图片上传 #elseif($column.htmlType == "imageUpload")## 图片上传
component: 'Upload' component: 'Upload',
#elseif($column.htmlType == "fileUpload")## 文件上传 #elseif($column.htmlType == "fileUpload")## 文件上传
component: 'Upload' component: 'Upload',
#elseif($column.htmlType == "editor")## 文本编辑器 #elseif($column.htmlType == "editor")## 文本编辑器
component: 'Editor' component: 'Editor',
#elseif($column.htmlType == "select")## 下拉框 #elseif($column.htmlType == "select")## 下拉框
component: 'Select', component: 'Select',
componentProps: { componentProps: {
#if ("" != $dictType)## 有数据字典 #if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number') options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'),
#else##没数据字典 #else##没数据字典
options:[] options:[],
#end #end
} },
#elseif($column.htmlType == "checkbox")## 多选框 #elseif($column.htmlType == "checkbox")## 多选框
component: 'Checkbox', component: 'Checkbox',
componentProps: { componentProps: {
#if ("" != $dictType)## 有数据字典 #if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number') options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'),
#else##没数据字典 #else##没数据字典
options:[] options:[],
#end #end
} },
#elseif($column.htmlType == "radio")## 单选框 #elseif($column.htmlType == "radio")## 单选框
component: 'RadioButtonGroup', component: 'RadioButtonGroup',
componentProps: { componentProps: {
#if ("" != $dictType)## 有数据字典 #if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number') options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'),
#else##没数据字典 #else##没数据字典
options:[] options:[],
#end #end
} },
#elseif($column.htmlType == "datetime")## 时间框 #elseif($column.htmlType == "datetime")## 时间框
component: 'DatePicker' component: 'DatePicker',
#elseif($column.htmlType == "textarea")## 文本域 #elseif($column.htmlType == "textarea")## 文本域
component: 'InputTextArea' component: 'InputTextArea',
#end #end
}, },
#end #end

View File

@ -1,15 +1,10 @@
<template>
<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> <script lang="ts" setup>
import { ref, unref } from 'vue' import { ref, unref } from 'vue'
import { createFormSchema, updateFormSchema } from './${classNameVar}.data'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage' import { useMessage } from '@/hooks/web/useMessage'
import { BasicForm, useForm } from '@/components/Form' import { BasicForm, useForm } from '@/components/Form'
import { BasicModal, useModalInner } from '@/components/Modal' import { BasicModal, useModalInner } from '@/components/Modal'
import { createFormSchema, updateFormSchema } from './${classNameVar}.data'
import { create${simpleClassName}, get${simpleClassName}, update${simpleClassName} } from '@/api/${table.moduleName}/${classNameVar}' import { create${simpleClassName}, get${simpleClassName}, update${simpleClassName} } from '@/api/${table.moduleName}/${classNameVar}'
defineOptions({ name: '${table.className}Modal' }) defineOptions({ name: '${table.className}Modal' })
@ -24,7 +19,7 @@ const [registerForm, { setFieldsValue, resetFields, resetSchema, validate }] = u
baseColProps: { span: 24 }, baseColProps: { span: 24 },
schemas: createFormSchema, schemas: createFormSchema,
showActionButtonGroup: false, showActionButtonGroup: false,
actionColOptions: { span: 23 } actionColOptions: { span: 23 },
}) })
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
@ -55,3 +50,8 @@ async function handleSubmit() {
} }
} }
</script> </script>
<template>
<BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? t('action.edit') : t('action.create')" @ok="handleSubmit">
<BasicForm @register="registerForm" />
</BasicModal>
</template>

View File

@ -1,3 +1,60 @@
<script lang="ts" setup>
import ${simpleClassName}Modal from './${simpleClassName}Modal.vue'
import { columns, searchFormSchema } from './${classNameVar}.data'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useModal } from '@/components/Modal'
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}'
defineOptions({ name: '${table.className}' })
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'))
},
})
}
async function handleDelete(record: Recordable) {
await delete${simpleClassName}(record.id)
createMessage.success(t('common.delSuccessText'))
reload()
}
</script>
<template> <template>
<div> <div>
<BasicTable @register="registerTable"> <BasicTable @register="registerTable">
@ -22,9 +79,9 @@
popConfirm: { popConfirm: {
title: t('common.delMessage'), title: t('common.delMessage'),
placement: 'left', placement: 'left',
confirm: handleDelete.bind(null, record) confirm: handleDelete.bind(null, record),
} },
} },
]" ]"
/> />
</template> </template>
@ -33,60 +90,3 @@
<${simpleClassName}Modal @register="registerModal" @success="reload()" /> <${simpleClassName}Modal @register="registerModal" @success="reload()" />
</div> </div>
</template> </template>
<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'
defineOptions({ name: '${table.className}' })
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'))
}
})
}
async function handleDelete(record: Recordable) {
await delete${simpleClassName}(record.id)
createMessage.success(t('common.delSuccessText'))
reload()
}
</script>