Commit 1df0fd1bf8e3e9fd00f8d03625926defdd347ba5
1 parent
28f4456b
fix: vue3 vben 代码生成支持创建和更新两种表单
Showing
2 changed files
with
77 additions
and
4 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben/views/data.ts.vm
| ... | ... | @@ -74,7 +74,7 @@ export const searchFormSchema: FormSchema[] = [ |
| 74 | 74 | #end |
| 75 | 75 | ] |
| 76 | 76 | |
| 77 | -export const formSchema: FormSchema[] = [ | |
| 77 | +export const createFormSchema: FormSchema[] = [ | |
| 78 | 78 | { |
| 79 | 79 | label: '编号', |
| 80 | 80 | field: 'id', |
| ... | ... | @@ -82,7 +82,7 @@ export const formSchema: FormSchema[] = [ |
| 82 | 82 | component: 'Input' |
| 83 | 83 | }, |
| 84 | 84 | #foreach($column in $columns) |
| 85 | -#if ($column.createOperation || $column.updateOperation) | |
| 85 | +#if ($column.createOperation) | |
| 86 | 86 | #set ($dictType = $column.dictType) |
| 87 | 87 | #set ($javaField = $column.javaField) |
| 88 | 88 | #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) |
| ... | ... | @@ -146,3 +146,76 @@ export const formSchema: FormSchema[] = [ |
| 146 | 146 | #end |
| 147 | 147 | #end |
| 148 | 148 | ] |
| 149 | + | |
| 150 | +export const updateFormSchema: FormSchema[] = [ | |
| 151 | + { | |
| 152 | + label: '编号', | |
| 153 | + field: 'id', | |
| 154 | + show: false, | |
| 155 | + component: 'Input' | |
| 156 | + }, | |
| 157 | + #foreach($column in $columns) | |
| 158 | + #if ($column.updateOperation) | |
| 159 | + #set ($dictType = $column.dictType) | |
| 160 | + #set ($javaField = $column.javaField) | |
| 161 | + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 162 | + #set ($comment = $column.columnComment) | |
| 163 | + #if (!$column.primaryKey)## 忽略主键,不用在表单里 | |
| 164 | + { | |
| 165 | + label: '${comment}', | |
| 166 | + field: '${javaField}', | |
| 167 | + #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键 | |
| 168 | + required: true, | |
| 169 | + #end | |
| 170 | + #if ($column.htmlType == "input") | |
| 171 | + component: 'Input' | |
| 172 | + #elseif($column.htmlType == "imageUpload")## 图片上传 | |
| 173 | + component: 'Upload' | |
| 174 | + #elseif($column.htmlType == "fileUpload")## 文件上传 | |
| 175 | + component: 'Upload' | |
| 176 | + #elseif($column.htmlType == "editor")## 文本编辑器 | |
| 177 | + component: 'InputTextArea' | |
| 178 | + #elseif($column.htmlType == "select")## 下拉框 | |
| 179 | + component: 'Select', | |
| 180 | + componentProps: { | |
| 181 | + #if ("" != $dictType)## 有数据字典 | |
| 182 | + #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short") | |
| 183 | + #set ($dictMethod = "getIntDictOptions") | |
| 184 | + #elseif ($javaType == "String") | |
| 185 | + #set ($dictMethod = "getStrDictOptions") | |
| 186 | + #elseif ($javaType == "Boolean") | |
| 187 | + #set ($dictMethod = "getBoolDictOptions") | |
| 188 | + #end | |
| 189 | + options: $dictMethod(DICT_TYPE.$dictType.toUpperCase()) | |
| 190 | + #else##没数据字典 | |
| 191 | + options:[] | |
| 192 | + #end | |
| 193 | + } | |
| 194 | + #elseif($column.htmlType == "checkbox")## 多选框 | |
| 195 | + component: 'Checkbox', | |
| 196 | + componentProps: { | |
| 197 | + #if ("" != $dictType)## 有数据字典 | |
| 198 | + options: getIntDictOptions(DICT_TYPE.COMMON_STATUS) | |
| 199 | + #else##没数据字典 | |
| 200 | + options:[] | |
| 201 | + #end | |
| 202 | + } | |
| 203 | + #elseif($column.htmlType == "radio")## 单选框 | |
| 204 | + component: 'Radio', | |
| 205 | + componentProps: { | |
| 206 | + #if ("" != $dictType)## 有数据字典 | |
| 207 | + options: getIntDictOptions(DICT_TYPE.COMMON_STATUS) | |
| 208 | + #else##没数据字典 | |
| 209 | + options:[] | |
| 210 | + #end | |
| 211 | + } | |
| 212 | + #elseif($column.htmlType == "datetime")## 时间框 | |
| 213 | + component: 'DatePicker' | |
| 214 | + #elseif($column.htmlType == "textarea")## 文本域 | |
| 215 | + component: 'InputTextArea' | |
| 216 | + #end | |
| 217 | + }, | |
| 218 | + #end | |
| 219 | + #end | |
| 220 | + #end | |
| 221 | +] | |
| 149 | 222 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben/views/form.vue.vm
| ... | ... | @@ -9,7 +9,7 @@ import { useI18n } from '@/hooks/web/useI18n' |
| 9 | 9 | import { useMessage } from '@/hooks/web/useMessage' |
| 10 | 10 | import { BasicForm, useForm } from '@/components/Form' |
| 11 | 11 | import { BasicModal, useModalInner } from '@/components/Modal' |
| 12 | -import { formSchema } from './${classNameVar}.data' | |
| 12 | +import { createFormSchema, updateFormSchema } from './${classNameVar}.data' | |
| 13 | 13 | import { create${simpleClassName}, get${simpleClassName}, update${simpleClassName} } from '@/api/${table.moduleName}/${classNameVar}' |
| 14 | 14 | |
| 15 | 15 | const { t } = useI18n() |
| ... | ... | @@ -20,7 +20,7 @@ const isUpdate = ref(true) |
| 20 | 20 | const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({ |
| 21 | 21 | labelWidth: 120, |
| 22 | 22 | baseColProps: { span: 24 }, |
| 23 | - schemas: formSchema, | |
| 23 | + schemas: isUpdate? updateFormSchema : createFormSchema, | |
| 24 | 24 | showActionButtonGroup: false, |
| 25 | 25 | actionColOptions: { span: 23 } |
| 26 | 26 | }) | ... | ... |