Commit 092e48b9d57fbb6bd4bb473aa7510ca69f4e4f89
1 parent
5e9e41c0
perf: vben codegen
Showing
4 changed files
with
60 additions
and
41 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben/api/api.ts.vm
| @@ -3,27 +3,27 @@ import { defHttp } from '@/utils/http/axios' | @@ -3,27 +3,27 @@ import { defHttp } from '@/utils/http/axios' | ||
| 3 | 3 | ||
| 4 | // 查询${table.classComment}列表 | 4 | // 查询${table.classComment}列表 |
| 5 | export function get${simpleClassName}Page(params) { | 5 | export function get${simpleClassName}Page(params) { |
| 6 | - return defHttp.get({ url: '${baseURL}/page', params }) | 6 | + return defHttp.get({ url: '${baseURL}/page', params }) |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | // 查询${table.classComment}详情 | 9 | // 查询${table.classComment}详情 |
| 10 | export function get${simpleClassName}(id: number) { | 10 | export function get${simpleClassName}(id: number) { |
| 11 | - return defHttp.get({ url: '${baseURL}/get?id=' + id }) | 11 | + return defHttp.get({ url: `${baseURL}/get?id=${id}` }) |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | // 新增${table.classComment} | 14 | // 新增${table.classComment} |
| 15 | export function create${simpleClassName}(data) { | 15 | export function create${simpleClassName}(data) { |
| 16 | - return defHttp.post({ url: '${baseURL}/create', data }) | 16 | + return defHttp.post({ url: '${baseURL}/create', data }) |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | // 修改${table.classComment} | 19 | // 修改${table.classComment} |
| 20 | export function update${simpleClassName}(data) { | 20 | export function update${simpleClassName}(data) { |
| 21 | - return defHttp.put({ url: '${baseURL}/update', data }) | 21 | + return defHttp.put({ url: '${baseURL}/update', data }) |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | // 删除${table.classComment} | 24 | // 删除${table.classComment} |
| 25 | export function delete${simpleClassName}(id: number) { | 25 | export function delete${simpleClassName}(id: number) { |
| 26 | - return defHttp.delete({ url: '${baseURL}/delete?id=' + id }) | 26 | + return defHttp.delete({ url: `${baseURL}/delete?id=${id}` }) |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | // 导出${table.classComment} Excel | 29 | // 导出${table.classComment} Excel |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben/views/data.ts.vm
| 1 | -import { BasicColumn, FormSchema, useRender } from '@/components/Table' | 1 | +import type { BasicColumn, FormSchema } from '@/components/Table' |
| 2 | +import { useRender } from '@/components/Table' | ||
| 2 | import { DICT_TYPE, getDictOptions } from '@/utils/dict' | 3 | import { DICT_TYPE, getDictOptions } from '@/utils/dict' |
| 3 | 4 | ||
| 4 | export const columns: BasicColumn[] = [ | 5 | export const columns: BasicColumn[] = [ |
| @@ -92,13 +93,13 @@ export const createFormSchema: FormSchema[] = [ | @@ -92,13 +93,13 @@ export const createFormSchema: FormSchema[] = [ | ||
| 92 | #elseif($column.htmlType == "imageUpload")## 图片上传 | 93 | #elseif($column.htmlType == "imageUpload")## 图片上传 |
| 93 | component: 'FileUpload', | 94 | component: 'FileUpload', |
| 94 | componentProps: { | 95 | componentProps: { |
| 95 | - fileType: 'file', | 96 | + fileType: 'image', |
| 96 | maxCount: 1, | 97 | maxCount: 1, |
| 97 | }, | 98 | }, |
| 98 | #elseif($column.htmlType == "fileUpload")## 文件上传 | 99 | #elseif($column.htmlType == "fileUpload")## 文件上传 |
| 99 | component: 'FileUpload', | 100 | component: 'FileUpload', |
| 100 | componentProps: { | 101 | componentProps: { |
| 101 | - fileType: 'image', | 102 | + fileType: 'file', |
| 102 | maxCount: 1, | 103 | maxCount: 1, |
| 103 | }, | 104 | }, |
| 104 | #elseif($column.htmlType == "editor")## 文本编辑器 | 105 | #elseif($column.htmlType == "editor")## 文本编辑器 |
| @@ -132,6 +133,11 @@ export const createFormSchema: FormSchema[] = [ | @@ -132,6 +133,11 @@ export const createFormSchema: FormSchema[] = [ | ||
| 132 | }, | 133 | }, |
| 133 | #elseif($column.htmlType == "datetime")## 时间框 | 134 | #elseif($column.htmlType == "datetime")## 时间框 |
| 134 | component: 'DatePicker', | 135 | component: 'DatePicker', |
| 136 | + componentProps: { | ||
| 137 | + showTime: true, | ||
| 138 | + format: 'YYYY-MM-DD HH:mm:ss', | ||
| 139 | + valueFormat: 'x', | ||
| 140 | + }, | ||
| 135 | #elseif($column.htmlType == "textarea")## 文本域 | 141 | #elseif($column.htmlType == "textarea")## 文本域 |
| 136 | component: 'InputTextArea', | 142 | component: 'InputTextArea', |
| 137 | #end | 143 | #end |
| @@ -154,7 +160,7 @@ export const updateFormSchema: FormSchema[] = [ | @@ -154,7 +160,7 @@ export const updateFormSchema: FormSchema[] = [ | ||
| 154 | #set ($javaField = $column.javaField) | 160 | #set ($javaField = $column.javaField) |
| 155 | #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | 161 | #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) |
| 156 | #set ($comment = $column.columnComment) | 162 | #set ($comment = $column.columnComment) |
| 157 | -#if (!$column.primaryKey)## 忽略主键,不用在表单里 | 163 | + #if (!$column.primaryKey)## 忽略主键,不用在表单里 |
| 158 | { | 164 | { |
| 159 | label: '${comment}', | 165 | label: '${comment}', |
| 160 | field: '${javaField}', | 166 | field: '${javaField}', |
| @@ -164,45 +170,57 @@ export const updateFormSchema: FormSchema[] = [ | @@ -164,45 +170,57 @@ export const updateFormSchema: FormSchema[] = [ | ||
| 164 | #if ($column.htmlType == "input") | 170 | #if ($column.htmlType == "input") |
| 165 | component: 'Input', | 171 | component: 'Input', |
| 166 | #elseif($column.htmlType == "imageUpload")## 图片上传 | 172 | #elseif($column.htmlType == "imageUpload")## 图片上传 |
| 167 | - component: 'Upload', | 173 | + component: 'FileUpload', |
| 174 | + componentProps: { | ||
| 175 | + fileType: 'image', | ||
| 176 | + maxCount: 1, | ||
| 177 | + }, | ||
| 168 | #elseif($column.htmlType == "fileUpload")## 文件上传 | 178 | #elseif($column.htmlType == "fileUpload")## 文件上传 |
| 169 | - component: 'Upload', | ||
| 170 | - #elseif($column.htmlType == "editor")## 文本编辑器 | ||
| 171 | - component: 'Editor', | 179 | + component: 'FileUpload', |
| 180 | + componentProps: { | ||
| 181 | + fileType: 'file', | ||
| 182 | + maxCount: 1, | ||
| 183 | + }, | ||
| 184 | + #elseif($column.htmlType == "editor")## 文本编辑器component: 'Editor', | ||
| 172 | #elseif($column.htmlType == "select")## 下拉框 | 185 | #elseif($column.htmlType == "select")## 下拉框 |
| 173 | component: 'Select', | 186 | component: 'Select', |
| 174 | componentProps: { | 187 | componentProps: { |
| 175 | #if ("" != $dictType)## 有数据字典 | 188 | #if ("" != $dictType)## 有数据字典 |
| 176 | - options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'), | 189 | + options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'), |
| 177 | #else##没数据字典 | 190 | #else##没数据字典 |
| 178 | - options:[], | 191 | + options:[], |
| 179 | #end | 192 | #end |
| 180 | }, | 193 | }, |
| 181 | #elseif($column.htmlType == "checkbox")## 多选框 | 194 | #elseif($column.htmlType == "checkbox")## 多选框 |
| 182 | component: 'Checkbox', | 195 | component: 'Checkbox', |
| 183 | componentProps: { | 196 | componentProps: { |
| 184 | #if ("" != $dictType)## 有数据字典 | 197 | #if ("" != $dictType)## 有数据字典 |
| 185 | - options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'), | 198 | + options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'), |
| 186 | #else##没数据字典 | 199 | #else##没数据字典 |
| 187 | - options:[], | 200 | + options:[], |
| 188 | #end | 201 | #end |
| 189 | }, | 202 | }, |
| 190 | #elseif($column.htmlType == "radio")## 单选框 | 203 | #elseif($column.htmlType == "radio")## 单选框 |
| 191 | component: 'RadioButtonGroup', | 204 | component: 'RadioButtonGroup', |
| 192 | componentProps: { | 205 | componentProps: { |
| 193 | #if ("" != $dictType)## 有数据字典 | 206 | #if ("" != $dictType)## 有数据字典 |
| 194 | - options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'), | 207 | + options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'), |
| 195 | #else##没数据字典 | 208 | #else##没数据字典 |
| 196 | - options:[], | 209 | + options:[], |
| 197 | #end | 210 | #end |
| 198 | }, | 211 | }, |
| 199 | #elseif($column.htmlType == "datetime")## 时间框 | 212 | #elseif($column.htmlType == "datetime")## 时间框 |
| 200 | component: 'DatePicker', | 213 | component: 'DatePicker', |
| 214 | + componentProps: { | ||
| 215 | + showTime: true, | ||
| 216 | + format: 'YYYY-MM-DD HH:mm:ss', | ||
| 217 | + valueFormat: 'x', | ||
| 218 | + }, | ||
| 201 | #elseif($column.htmlType == "textarea")## 文本域 | 219 | #elseif($column.htmlType == "textarea")## 文本域 |
| 202 | component: 'InputTextArea', | 220 | component: 'InputTextArea', |
| 203 | #end | 221 | #end |
| 204 | }, | 222 | }, |
| 205 | -#end | 223 | + #end |
| 206 | #end | 224 | #end |
| 207 | #end | 225 | #end |
| 208 | ] | 226 | ] |
| 209 | \ No newline at end of file | 227 | \ No newline at end of file |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben/views/form.vue.vm
| @@ -9,9 +9,10 @@ import { create${simpleClassName}, get${simpleClassName}, update${simpleClassNam | @@ -9,9 +9,10 @@ import { create${simpleClassName}, get${simpleClassName}, update${simpleClassNam | ||
| 9 | 9 | ||
| 10 | defineOptions({ name: '${table.className}Modal' }) | 10 | defineOptions({ name: '${table.className}Modal' }) |
| 11 | 11 | ||
| 12 | +const emit = defineEmits(['success', 'register']) | ||
| 13 | + | ||
| 12 | const { t } = useI18n() | 14 | const { t } = useI18n() |
| 13 | const { createMessage } = useMessage() | 15 | const { createMessage } = useMessage() |
| 14 | -const emit = defineEmits(['success', 'register']) | ||
| 15 | const isUpdate = ref(true) | 16 | const isUpdate = ref(true) |
| 16 | 17 | ||
| 17 | const [registerForm, { setFieldsValue, resetFields, resetSchema, validate }] = useForm({ | 18 | const [registerForm, { setFieldsValue, resetFields, resetSchema, validate }] = useForm({ |
| @@ -37,11 +38,11 @@ async function handleSubmit() { | @@ -37,11 +38,11 @@ async function handleSubmit() { | ||
| 37 | try { | 38 | try { |
| 38 | const values = await validate() | 39 | const values = await validate() |
| 39 | setModalProps({ confirmLoading: true }) | 40 | setModalProps({ confirmLoading: true }) |
| 40 | - if (unref(isUpdate)) { | 41 | + if (unref(isUpdate)) |
| 41 | await update${simpleClassName}(values) | 42 | await update${simpleClassName}(values) |
| 42 | - } else { | 43 | + else |
| 43 | await create${simpleClassName}(values) | 44 | await create${simpleClassName}(values) |
| 44 | - } | 45 | + |
| 45 | closeModal() | 46 | closeModal() |
| 46 | emit('success') | 47 | emit('success') |
| 47 | createMessage.success(t('common.saveSuccessText')) | 48 | createMessage.success(t('common.saveSuccessText')) |
| @@ -51,7 +52,7 @@ async function handleSubmit() { | @@ -51,7 +52,7 @@ async function handleSubmit() { | ||
| 51 | } | 52 | } |
| 52 | </script> | 53 | </script> |
| 53 | <template> | 54 | <template> |
| 54 | - <BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? t('action.edit') : t('action.create')" @ok="handleSubmit"> | 55 | + <BasicModal v-bind="$attrs" :title="isUpdate ? t('action.edit') : t('action.create')" @register="registerModal" @ok="handleSubmit"> |
| 55 | <BasicForm @register="registerForm" /> | 56 | <BasicForm @register="registerForm" /> |
| 56 | </BasicModal> | 57 | </BasicModal> |
| 57 | </template> | 58 | </template> |
| 58 | \ No newline at end of file | 59 | \ No newline at end of file |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben/views/index.vue.vm
| 1 | <script lang="ts" setup> | 1 | <script lang="ts" setup> |
| 2 | -import ${simpleClassName}Modal from './${simpleClassName}Modal.vue' | 2 | +import ${ simpleClassName }Modal from './${simpleClassName}Modal.vue' |
| 3 | import { columns, searchFormSchema } from './${classNameVar}.data' | 3 | import { columns, searchFormSchema } from './${classNameVar}.data' |
| 4 | import { useI18n } from '@/hooks/web/useI18n' | 4 | import { useI18n } from '@/hooks/web/useI18n' |
| 5 | import { useMessage } from '@/hooks/web/useMessage' | 5 | import { useMessage } from '@/hooks/web/useMessage' |
| 6 | import { useModal } from '@/components/Modal' | 6 | import { useModal } from '@/components/Modal' |
| 7 | import { IconEnum } from '@/enums/appEnum' | 7 | import { IconEnum } from '@/enums/appEnum' |
| 8 | import { BasicTable, useTable, TableAction } from '@/components/Table' | 8 | import { BasicTable, useTable, TableAction } from '@/components/Table' |
| 9 | -import { delete${simpleClassName}, export${simpleClassName}, get${simpleClassName}Page } from '@/api/${table.moduleName}/${classNameVar}' | 9 | +import { delete${ simpleClassName }, export${ simpleClassName }, get${ simpleClassName } Page } from '@/api/${table.moduleName}/${classNameVar}' |
| 10 | 10 | ||
| 11 | defineOptions({ name: '${table.className}' }) | 11 | defineOptions({ name: '${table.className}' }) |
| 12 | 12 | ||
| @@ -16,17 +16,17 @@ const [registerModal, { openModal }] = useModal() | @@ -16,17 +16,17 @@ const [registerModal, { openModal }] = useModal() | ||
| 16 | 16 | ||
| 17 | const [registerTable, { getForm, reload }] = useTable({ | 17 | const [registerTable, { getForm, reload }] = useTable({ |
| 18 | title: '${table.classComment}列表', | 18 | title: '${table.classComment}列表', |
| 19 | - api: get${simpleClassName}Page, | ||
| 20 | - columns, | ||
| 21 | - formConfig: { labelWidth: 120, schemas: searchFormSchema }, | ||
| 22 | - useSearchForm: true, | ||
| 23 | - showTableSetting: true, | ||
| 24 | - actionColumn: { | ||
| 25 | - width: 140, | ||
| 26 | - title: t('common.action'), | ||
| 27 | - dataIndex: 'action', | ||
| 28 | - fixed: 'right', | ||
| 29 | - }, | 19 | + api: get${ simpleClassName }Page, |
| 20 | + columns, | ||
| 21 | + formConfig: { labelWidth: 120, schemas: searchFormSchema }, | ||
| 22 | +useSearchForm: true, | ||
| 23 | + showTableSetting: true, | ||
| 24 | + actionColumn: { | ||
| 25 | + width: 140, | ||
| 26 | + title: t('common.action'), | ||
| 27 | + dataIndex: 'action', | ||
| 28 | + fixed: 'right', | ||
| 29 | +}, | ||
| 30 | }) | 30 | }) |
| 31 | 31 | ||
| 32 | function handleCreate() { | 32 | function handleCreate() { |
| @@ -43,14 +43,14 @@ async function handleExport() { | @@ -43,14 +43,14 @@ async function handleExport() { | ||
| 43 | iconType: 'warning', | 43 | iconType: 'warning', |
| 44 | content: t('common.exportMessage'), | 44 | content: t('common.exportMessage'), |
| 45 | async onOk() { | 45 | async onOk() { |
| 46 | - await export${simpleClassName}(getForm().getFieldsValue()) | 46 | + await export${ simpleClassName } (getForm().getFieldsValue()) |
| 47 | createMessage.success(t('common.exportSuccessText')) | 47 | createMessage.success(t('common.exportSuccessText')) |
| 48 | }, | 48 | }, |
| 49 | }) | 49 | }) |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | async function handleDelete(record: Recordable) { | 52 | async function handleDelete(record: Recordable) { |
| 53 | - await delete${simpleClassName}(record.id) | 53 | + await delete${ simpleClassName } (record.id) |
| 54 | createMessage.success(t('common.delSuccessText')) | 54 | createMessage.success(t('common.delSuccessText')) |
| 55 | reload() | 55 | reload() |
| 56 | } | 56 | } |
| @@ -89,4 +89,4 @@ async function handleDelete(record: Recordable) { | @@ -89,4 +89,4 @@ async function handleDelete(record: Recordable) { | ||
| 89 | </BasicTable> | 89 | </BasicTable> |
| 90 | <${simpleClassName}Modal @register="registerModal" @success="reload()" /> | 90 | <${simpleClassName}Modal @register="registerModal" @success="reload()" /> |
| 91 | </div> | 91 | </div> |
| 92 | -</template> | ||
| 93 | \ No newline at end of file | 92 | \ No newline at end of file |
| 93 | +</template> |