Commit c6582b2a61f4ecc27c843a165927cfe74093d3e5

Authored by puhui999
1 parent 515cbbb2

【功能完善】INFRA:代码生成 vben5 antd 主子表 erp 模版

yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/general/views/index.vue.vm
... ... @@ -38,6 +38,9 @@ import { downloadByData } from '#/utils/download';
38 38 const subTabsName = ref('$subClassNameVars.get(0)')
39 39 #if ($table.templateType == 11)
40 40 const select${simpleClassName} = ref<${simpleClassName}Api.${simpleClassName}>();
  41 +async function onCellClick({ row }: { row: ${simpleClassName}Api.${simpleClassName} }) {
  42 + select${simpleClassName}.value = row
  43 +}
41 44 #end
42 45 #end
43 46  
... ... @@ -323,7 +326,15 @@ onMounted(async () =&gt; {
323 326 expandAll: true,
324 327 reserve: true,
325 328 }"
326   - #end
  329 + #end
  330 +#if ($table.templateType == 11) ## erp情况
  331 + @cell-click="onCellClick"
  332 + :row-config="{
  333 + keyField: 'id',
  334 + isHover: true,
  335 + isCurrent: true,
  336 + }"
  337 +#end
327 338 show-overflow
328 339 :loading="loading"
329 340 >
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/general/views/modules/form_sub_erp.vue.vm
... ... @@ -4,49 +4,54 @@
4 4 #set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
5 5 <script lang="ts" setup>
6 6 import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
  7 + import type { Rule } from 'ant-design-vue/es/form';
7 8  
8 9 import { useVbenModal } from '@vben/common-ui';
9   - import { message } from 'ant-design-vue';
  10 + import { Tinymce as RichTextarea } from '#/components/tinymce';
  11 + import { ImageUpload, FileUpload } from "#/components/upload";
  12 + import { message, Tabs, Form, Input, Textarea, Select, RadioGroup, Radio, CheckboxGroup, Checkbox, DatePicker, TreeSelect } from 'ant-design-vue';
  13 + import { DICT_TYPE, getDictOptions } from '#/utils/dict';
10 14  
11 15 import { computed, ref } from 'vue';
12 16 import { $t } from '#/locales';
13   - import { useVbenForm } from '#/adapter/form';
14   - import { get${subSimpleClassName}, create${subSimpleClassName}, update${subSimpleClassName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
15 17  
16   - import { use${subSimpleClassName}FormSchema } from '../data';
  18 + import { get${subSimpleClassName}, create${subSimpleClassName}, update${subSimpleClassName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}';
17 19  
18 20 const emit = defineEmits(['success']);
19   - const formData = ref<${simpleClassName}Api.${subSimpleClassName}>();
20 21 const getTitle = computed(() => {
21 22 return formData.value?.id
22 23 ? $t('ui.actionTitle.edit', ['${subTable.classComment}'])
23 24 : $t('ui.actionTitle.create', ['${subTable.classComment}']);
24 25 });
25 26  
26   - const [Form, formApi] = useVbenForm({
27   - commonConfig: {
28   - componentProps: {
29   - class: 'w-full',
30   - },
31   - formItemClass: 'col-span-2',
32   - labelWidth: 80,
33   - },
34   - layout: 'horizontal',
35   - schema: use${subSimpleClassName}FormSchema(),
36   - showDefaultActions: false
  27 + const formRef = ref();
  28 + const formData = ref<Partial<${simpleClassName}Api.${subSimpleClassName}>>({
  29 + #foreach ($column in $subColumns)
  30 + #if ($column.createOperation || $column.updateOperation)
  31 + #if ($column.htmlType == "checkbox")
  32 + $column.javaField: [],
  33 + #else
  34 + $column.javaField: undefined,
  35 + #end
  36 + #end
  37 + #end
37 38 });
  39 + const rules: Record<string, Rule[]> = {
  40 + #foreach ($column in $subColumns)
  41 + #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
  42 + #set($comment=$column.columnComment)
  43 + $column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == 'select')'change'#else'blur'#end }],
  44 + #end
  45 + #end
  46 + };
38 47  
39 48 const [Modal, modalApi] = useVbenModal({
40 49 async onConfirm() {
41   - const { valid } = await formApi.validate();
42   - if (!valid) {
43   - return;
44   - }
  50 + await formRef.value?.validate();
45 51  
46 52 modalApi.lock();
47 53 // 提交表单
48   - const data = (await formApi.getValues()) as ${simpleClassName}Api.${subSimpleClassName};
49   - data.${subJoinColumn.javaField} = formData.value?.${subJoinColumn.javaField};
  54 + const data = formData.value as ${simpleClassName}Api.${subSimpleClassName};
50 55 try {
51 56 await (formData.value?.id ? update${subSimpleClassName}(data) : create${subSimpleClassName}(data));
52 57 // 关闭并提示
... ... @@ -62,7 +67,7 @@
62 67 },
63 68 async onOpenChange(isOpen: boolean) {
64 69 if (!isOpen) {
65   - formData.value = undefined;
  70 + resetForm()
66 71 return;
67 72 }
68 73  
... ... @@ -81,13 +86,127 @@
81 86 }
82 87 // 设置到 values
83 88 formData.value = data;
84   - await formApi.setValues(formData.value);
85 89 },
86 90 });
  91 +
  92 + /** 重置表单 */
  93 + const resetForm = () => {
  94 + formData.value = {
  95 + #foreach ($column in $subColumns)
  96 + #if ($column.createOperation || $column.updateOperation)
  97 + #if ($column.htmlType == "checkbox")
  98 + $column.javaField: [],
  99 + #else
  100 + $column.javaField: undefined,
  101 + #end
  102 + #end
  103 + #end
  104 + };
  105 + formRef.value?.resetFields();
  106 + }
87 107 </script>
88 108  
89 109 <template>
90 110 <Modal :title="getTitle">
91   - <Form class="mx-4" />
  111 + <Form
  112 + ref="formRef"
  113 + :model="formData"
  114 + :rules="rules"
  115 + :label-col="{ span: 5 }"
  116 + :wrapper-col="{ span: 18 }"
  117 + >
  118 + #foreach($column in $subColumns)
  119 + #if ($column.createOperation || $column.updateOperation)
  120 + #set ($dictType = $column.dictType)
  121 + #set ($javaField = $column.javaField)
  122 + #set ($javaType = $column.javaType)
  123 + #set ($comment = $column.columnComment)
  124 + #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
  125 + #set ($dictMethod = "number")
  126 + #elseif ($javaType == "String")
  127 + #set ($dictMethod = "string")
  128 + #elseif ($javaType == "Boolean")
  129 + #set ($dictMethod = "boolean")
  130 + #end
  131 + #if ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
  132 + <Form.Item label="${comment}" name="${javaField}">
  133 + <Input v-model:value="formData.${javaField}" placeholder="请输入${comment}" />
  134 + </Form.Item>
  135 + #elseif($column.htmlType == "imageUpload")## 图片上传
  136 + <Form.Item label="${comment}" name="${javaField}">
  137 + <ImageUpload v-model:value="formData.${javaField}" />
  138 + </Form.Item>
  139 + #elseif($column.htmlType == "fileUpload")## 文件上传
  140 + <Form.Item label="${comment}" name="${javaField}">
  141 + <FileUpload v-model:value="formData.${javaField}" />
  142 + </Form.Item>
  143 + #elseif($column.htmlType == "editor")## 文本编辑器
  144 + <Form.Item label="${comment}" name="${javaField}">
  145 + <RichTextarea v-model="formData.${javaField}" height="500px" />
  146 + </Form.Item>
  147 + #elseif($column.htmlType == "select")## 下拉框
  148 + <Form.Item label="${comment}" name="${javaField}">
  149 + <Select v-model:value="formData.${javaField}" placeholder="请选择${comment}">
  150 + #if ("" != $dictType)## 有数据字典
  151 + <Select.Option
  152 + v-for="dict in getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod')"
  153 + :key="dict.value"
  154 + :value="dict.value"
  155 + >
  156 + {{ dict.label }}
  157 + </Select.Option>
  158 + #else##没数据字典
  159 + <Select.Option label="请选择字典生成" value="" />
  160 + #end
  161 + </Select>
  162 + </Form.Item>
  163 + #elseif($column.htmlType == "checkbox")## 多选框
  164 + <Form.Item label="${comment}" name="${javaField}">
  165 + <CheckboxGroup v-model:value="formData.${javaField}">
  166 + #if ("" != $dictType)## 有数据字典
  167 + <Checkbox
  168 + v-for="dict in getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod')"
  169 + :key="dict.value"
  170 + :value="dict.value"
  171 + >
  172 + {{ dict.label }}
  173 + </Checkbox>
  174 + #else##没数据字典
  175 + <Checkbox label="请选择字典生成" />
  176 + #end
  177 + </CheckboxGroup>
  178 + </Form.Item>
  179 + #elseif($column.htmlType == "radio")## 单选框
  180 + <Form.Item label="${comment}" name="${javaField}">
  181 + <RadioGroup v-model:value="formData.${javaField}">
  182 + #if ("" != $dictType)## 有数据字典
  183 + <Radio
  184 + v-for="dict in getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod')"
  185 + :key="dict.value"
  186 + :value="dict.value"
  187 + >
  188 + {{ dict.label }}
  189 + </Radio>
  190 + #else##没数据字典
  191 + <Radio value="1">请选择字典生成</Radio>
  192 + #end
  193 + </RadioGroup>
  194 + </Form.Item>
  195 + #elseif($column.htmlType == "datetime")## 时间框
  196 + <Form.Item label="${comment}" name="${javaField}">
  197 + <DatePicker
  198 + v-model:value="formData.${javaField}"
  199 + valueFormat="x"
  200 + placeholder="选择${comment}"
  201 + />
  202 + </Form.Item>
  203 + #elseif($column.htmlType == "textarea")## 文本框
  204 + <Form.Item label="${comment}" name="${javaField}">
  205 + <Textarea v-model:value="formData.${javaField}" placeholder="请输入${comment}" />
  206 + </Form.Item>
  207 + #end
  208 + #end
  209 + #end
  210 + </Form>
92 211 </Modal>
93 212 </template>
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/general/views/modules/list_sub_erp.vue.vm
... ... @@ -14,11 +14,15 @@
14 14 import { VxeColumn, VxeTable } from 'vxe-table';
15 15 import { reactive,ref, h, nextTick,watch,onMounted } from 'vue';
16 16 import { cloneDeep, formatDateTime } from '@vben/utils';
  17 + import { ContentWrap } from "#/components/content-wrap";
17 18  
18 19 #if ($table.templateType == 11) ## erp
19 20 import { useVbenModal } from '@vben/common-ui';
20 21 import ${subSimpleClassName}Form from './${subSimpleClassName_strikeCase}-form.vue'
21   - import { Button, message } from 'ant-design-vue';
  22 + import { Tinymce as RichTextarea } from '#/components/tinymce';
  23 + import { ImageUpload, FileUpload } from "#/components/upload";
  24 + import { message,Button, Tabs,Pagination, Form, Input, Textarea, Select, RadioGroup, Radio, CheckboxGroup, Checkbox,RangePicker, DatePicker, TreeSelect } from 'ant-design-vue';
  25 + import { DICT_TYPE, getDictOptions } from '#/utils/dict';
22 26 import { Plus } from '@vben/icons';
23 27 import { $t } from '#/locales';
24 28 import { TableToolbar } from '#/components/table-toolbar';
... ... @@ -99,8 +103,6 @@ async function onDelete(row: ${simpleClassName}Api.${subSimpleClassName}) {
99 103 #end
100 104 #end
101 105 #end
102   -
103   - ${subJoinColumn.javaField}: props.${subJoinColumn.javaField},
104 106 })
105 107  
106 108 /** 搜索按钮操作 */
... ... @@ -134,6 +136,7 @@ const resetQuery = () =&gt; {
134 136 #end
135 137 #end
136 138 #end
  139 + params.${subJoinColumn.javaField} = props.${subJoinColumn.javaField};
137 140 const data = await get${subSimpleClassName}Page(params)
138 141 list.value = data.list
139 142 total.value = data.total
... ...