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}详情
export function get${simpleClassName}(id: number) {
return defHttp.get({ url: '${baseURL}/get?id=' + id })
return defHttp.get({ url: `${baseURL}/get?id=${id}` })
}
// 新增${table.classComment}
@ -23,7 +23,7 @@ export function update${simpleClassName}(data) {
// 删除${table.classComment}
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

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

View File

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