perf: vben codegen

This commit is contained in:
xingyu 2023-09-11 12:41:48 +08:00
parent 5e9e41c045
commit 092e48b9d5
4 changed files with 60 additions and 41 deletions

View File

@ -8,7 +8,7 @@ export function get${simpleClassName}Page(params) {
// 查询${table.classComment}详情 // 查询${table.classComment}详情
export function get${simpleClassName}(id: number) { export function get${simpleClassName}(id: number) {
return defHttp.get({ url: '${baseURL}/get?id=' + id }) return defHttp.get({ url: `${baseURL}/get?id=${id}` })
} }
// 新增${table.classComment} // 新增${table.classComment}
@ -23,7 +23,7 @@ export function update${simpleClassName}(data) {
// 删除${table.classComment} // 删除${table.classComment}
export function delete${simpleClassName}(id: number) { export function delete${simpleClassName}(id: number) {
return defHttp.delete({ url: '${baseURL}/delete?id=' + id }) return defHttp.delete({ url: `${baseURL}/delete?id=${id}` })
} }
// 导出${table.classComment} Excel // 导出${table.classComment} Excel

View File

@ -1,4 +1,5 @@
import { BasicColumn, FormSchema, useRender } from '@/components/Table' import type { BasicColumn, FormSchema } from '@/components/Table'
import { useRender } from '@/components/Table'
import { DICT_TYPE, getDictOptions } from '@/utils/dict' import { DICT_TYPE, getDictOptions } from '@/utils/dict'
export const columns: BasicColumn[] = [ export const columns: BasicColumn[] = [
@ -92,13 +93,13 @@ export const createFormSchema: FormSchema[] = [
#elseif($column.htmlType == "imageUpload")## 图片上传 #elseif($column.htmlType == "imageUpload")## 图片上传
component: 'FileUpload', component: 'FileUpload',
componentProps: { componentProps: {
fileType: 'file', fileType: 'image',
maxCount: 1, maxCount: 1,
}, },
#elseif($column.htmlType == "fileUpload")## 文件上传 #elseif($column.htmlType == "fileUpload")## 文件上传
component: 'FileUpload', component: 'FileUpload',
componentProps: { componentProps: {
fileType: 'image', fileType: 'file',
maxCount: 1, maxCount: 1,
}, },
#elseif($column.htmlType == "editor")## 文本编辑器 #elseif($column.htmlType == "editor")## 文本编辑器
@ -132,6 +133,11 @@ export const createFormSchema: FormSchema[] = [
}, },
#elseif($column.htmlType == "datetime")## 时间框 #elseif($column.htmlType == "datetime")## 时间框
component: 'DatePicker', component: 'DatePicker',
componentProps: {
showTime: true,
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'x',
},
#elseif($column.htmlType == "textarea")## 文本域 #elseif($column.htmlType == "textarea")## 文本域
component: 'InputTextArea', component: 'InputTextArea',
#end #end
@ -164,11 +170,18 @@ export const updateFormSchema: FormSchema[] = [
#if ($column.htmlType == "input") #if ($column.htmlType == "input")
component: 'Input', component: 'Input',
#elseif($column.htmlType == "imageUpload")## 图片上传 #elseif($column.htmlType == "imageUpload")## 图片上传
component: 'Upload', component: 'FileUpload',
componentProps: {
fileType: 'image',
maxCount: 1,
},
#elseif($column.htmlType == "fileUpload")## 文件上传 #elseif($column.htmlType == "fileUpload")## 文件上传
component: 'Upload', component: 'FileUpload',
#elseif($column.htmlType == "editor")## 文本编辑器 componentProps: {
component: 'Editor', fileType: 'file',
maxCount: 1,
},
#elseif($column.htmlType == "editor")## 文本编辑器component: 'Editor',
#elseif($column.htmlType == "select")## 下拉框 #elseif($column.htmlType == "select")## 下拉框
component: 'Select', component: 'Select',
componentProps: { componentProps: {
@ -198,6 +211,11 @@ export const updateFormSchema: FormSchema[] = [
}, },
#elseif($column.htmlType == "datetime")## 时间框 #elseif($column.htmlType == "datetime")## 时间框
component: 'DatePicker', component: 'DatePicker',
componentProps: {
showTime: true,
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'x',
},
#elseif($column.htmlType == "textarea")## 文本域 #elseif($column.htmlType == "textarea")## 文本域
component: 'InputTextArea', component: 'InputTextArea',
#end #end

View File

@ -9,9 +9,10 @@ import { create${simpleClassName}, get${simpleClassName}, update${simpleClassNam
defineOptions({ name: '${table.className}Modal' }) defineOptions({ name: '${table.className}Modal' })
const emit = defineEmits(['success', 'register'])
const { t } = useI18n() const { t } = useI18n()
const { createMessage } = useMessage() const { createMessage } = useMessage()
const emit = defineEmits(['success', 'register'])
const isUpdate = ref(true) const isUpdate = ref(true)
const [registerForm, { setFieldsValue, resetFields, resetSchema, validate }] = useForm({ const [registerForm, { setFieldsValue, resetFields, resetSchema, validate }] = useForm({
@ -37,11 +38,11 @@ async function handleSubmit() {
try { try {
const values = await validate() const values = await validate()
setModalProps({ confirmLoading: true }) setModalProps({ confirmLoading: true })
if (unref(isUpdate)) { if (unref(isUpdate))
await update${simpleClassName}(values) await update${simpleClassName}(values)
} else { else
await create${simpleClassName}(values) await create${simpleClassName}(values)
}
closeModal() closeModal()
emit('success') emit('success')
createMessage.success(t('common.saveSuccessText')) createMessage.success(t('common.saveSuccessText'))
@ -51,7 +52,7 @@ async function handleSubmit() {
} }
</script> </script>
<template> <template>
<BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? t('action.edit') : t('action.create')" @ok="handleSubmit"> <BasicModal v-bind="$attrs" :title="isUpdate ? t('action.edit') : t('action.create')" @register="registerModal" @ok="handleSubmit">
<BasicForm @register="registerForm" /> <BasicForm @register="registerForm" />
</BasicModal> </BasicModal>
</template> </template>