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