Commit df69fecbb4a7fbd3b671dd22b72e17258dc3c82c

Authored by puhui999
1 parent d2aee55e

代码生成:重构 vue2 模版,适配树表和主子表(80%)

sql/mysql/ruoyi-vue-pro.sql
@@ -450,6 +450,11 @@ CREATE TABLE `infra_codegen_table` ( @@ -450,6 +450,11 @@ CREATE TABLE `infra_codegen_table` (
450 `template_type` tinyint NOT NULL DEFAULT 1 COMMENT '模板类型', 450 `template_type` tinyint NOT NULL DEFAULT 1 COMMENT '模板类型',
451 `front_type` tinyint NOT NULL COMMENT '前端类型', 451 `front_type` tinyint NOT NULL COMMENT '前端类型',
452 `parent_menu_id` bigint NULL DEFAULT NULL COMMENT '父菜单编号', 452 `parent_menu_id` bigint NULL DEFAULT NULL COMMENT '父菜单编号',
  453 + `master_table_id` bigint NULL DEFAULT NULL COMMENT '主表的编号',
  454 + `sub_join_column_id` bigint NULL DEFAULT NULL COMMENT '【自己】子表关联主表的字段编号',
  455 + `sub_join_many` bit(1) NULL DEFAULT NULL COMMENT '主表与子表是否一对多',
  456 + `tree_parent_column_id` bigint NULL DEFAULT NULL COMMENT '树表的父字段编号',
  457 + `tree_name_column_id` bigint NULL DEFAULT NULL COMMENT '树表的名字字段编号',
453 `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', 458 `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
454 `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', 459 `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
455 `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', 460 `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/api/api.js.vm
@@ -35,21 +35,113 @@ export function get${simpleClassName}(id) { @@ -35,21 +35,113 @@ export function get${simpleClassName}(id) {
35 }) 35 })
36 } 36 }
37 37
  38 +#if ( $table.templateType != 2 )
38 // 获得${table.classComment}分页 39 // 获得${table.classComment}分页
39 -export function get${simpleClassName}Page(query) { 40 +export function get${simpleClassName}Page(params) {
40 return request({ 41 return request({
41 url: '${baseURL}/page', 42 url: '${baseURL}/page',
42 method: 'get', 43 method: 'get',
43 - params: query 44 + params
44 }) 45 })
45 } 46 }
46 - 47 +#else
  48 +// 获得${table.classComment}列表
  49 +export function get${simpleClassName}List(params) {
  50 + return request({
  51 + url: '${baseURL}/list',
  52 + method: 'get',
  53 + params
  54 + })
  55 +}
  56 +#end
47 // 导出${table.classComment} Excel 57 // 导出${table.classComment} Excel
48 -export function export${simpleClassName}Excel(query) { 58 +export function export${simpleClassName}Excel(params) {
49 return request({ 59 return request({
50 url: '${baseURL}/export-excel', 60 url: '${baseURL}/export-excel',
51 method: 'get', 61 method: 'get',
52 - params: query, 62 + params,
53 responseType: 'blob' 63 responseType: 'blob'
54 }) 64 })
55 } 65 }
  66 +## 特殊:主子表专属逻辑
  67 +#foreach ($subTable in $subTables)
  68 + #set ($index = $foreach.count - 1)
  69 + #set ($subSimpleClassName = $subSimpleClassNames.get($index))
  70 + #set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段
  71 + #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
  72 + #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
  73 + #set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index))
  74 + #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
  75 + #set ($subClassNameVar = $subClassNameVars.get($index))
  76 +
  77 +// ==================== 子表($subTable.classComment) ====================
  78 + ## 情况一:MASTER_ERP 时,需要分查询页子表
  79 + #if ( $table.templateType == 11 )
  80 +
  81 + // 获得${subTable.classComment}分页
  82 + export function get${simpleClassName}Page(params) {
  83 + return request({
  84 + url: '${baseURL}/${subSimpleClassName_strikeCase}/page',
  85 + method: 'get',
  86 + params
  87 + })
  88 + }
  89 + ## 情况二:非 MASTER_ERP 时,需要列表查询子表
  90 + #else
  91 + #if ( $subTable.subJoinMany )
  92 +
  93 + // 获得${subTable.classComment}列表
  94 + export function get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaField}) {
  95 + return request({
  96 + url: `${baseURL}/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=` + ${subJoinColumn.javaField},
  97 + method: 'get'
  98 + })
  99 + }
  100 + #else
  101 +
  102 + // 获得${subTable.classComment}
  103 + export function get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}) {
  104 + return request({
  105 + url: `${baseURL}/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=` + ${subJoinColumn.javaField},
  106 + method: 'get'
  107 + })
  108 + }
  109 + #end
  110 + #end
  111 + ## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作
  112 + #if ( $table.templateType == 11 )
  113 + // 新增${subTable.classComment}
  114 + export function create${subSimpleClassName}(data) {
  115 + return request({
  116 + url: `${baseURL}/${subSimpleClassName_strikeCase}/create`,
  117 + method: 'post',
  118 + data
  119 + })
  120 + }
  121 +
  122 + // 修改${subTable.classComment}
  123 + export function update${subSimpleClassName}(data) {
  124 + return request({
  125 + url: `${baseURL}/${subSimpleClassName_strikeCase}/update`,
  126 + method: 'post',
  127 + data
  128 + })
  129 + }
  130 +
  131 + // 删除${subTable.classComment}
  132 + export function delete${subSimpleClassName}(id) {
  133 + return request({
  134 + url: `${baseURL}/${subSimpleClassName_strikeCase}/delete?id=` + id,
  135 + method: 'delete'
  136 + })
  137 + }
  138 +
  139 + // 获得${subTable.classComment}
  140 + export function get${subSimpleClassName}(id) {
  141 + return request({
  142 + url: `${baseURL}/${subSimpleClassName_strikeCase}/get?id=` + id,
  143 + method: 'get'
  144 + })
  145 + }
  146 + #end
  147 +#end
56 \ No newline at end of file 148 \ No newline at end of file
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/components/form_sub_erp.vue.vm 0 → 100644
  1 +#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
  2 +#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
  3 +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
  4 +<template>
  5 + <Dialog :title="dialogTitle" :visible.sync="dialogVisible">
  6 + <el-form
  7 + ref="formRef"
  8 + :model="formData"
  9 + :rules="formRules"
  10 + label-width="100px"
  11 + v-loading="formLoading"
  12 + >
  13 +#foreach($column in $subColumns)
  14 + #if ($column.createOperation || $column.updateOperation)
  15 + #set ($dictType = $column.dictType)
  16 + #set ($javaField = $column.javaField)
  17 + #set ($javaType = $column.javaType)
  18 + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  19 + #set ($comment = $column.columnComment)
  20 + #set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法
  21 + #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
  22 + #set ($dictMethod = "getIntDictOptions")
  23 + #elseif ($javaType == "String")
  24 + #set ($dictMethod = "getStrDictOptions")
  25 + #elseif ($javaType == "Boolean")
  26 + #set ($dictMethod = "getBoolDictOptions")
  27 + #end
  28 + #if ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里 TODO 芋艿:这里要忽略下 join 字段;
  29 + <el-form-item label="${comment}" prop="${javaField}">
  30 + <el-input v-model="formData.${javaField}" placeholder="请输入${comment}" />
  31 + </el-form-item>
  32 + #elseif($column.htmlType == "imageUpload")## 图片上传
  33 + <el-form-item label="${comment}" prop="${javaField}">
  34 + <UploadImg v-model="formData.${javaField}" />
  35 + </el-form-item>
  36 + #elseif($column.htmlType == "fileUpload")## 文件上传
  37 + <el-form-item label="${comment}" prop="${javaField}">
  38 + <UploadFile v-model="formData.${javaField}" />
  39 + </el-form-item>
  40 + #elseif($column.htmlType == "editor")## 文本编辑器
  41 + <el-form-item label="${comment}" prop="${javaField}">
  42 + <Editor v-model="formData.${javaField}" height="150px" />
  43 + </el-form-item>
  44 + #elseif($column.htmlType == "select")## 下拉框
  45 + <el-form-item label="${comment}" prop="${javaField}">
  46 + <el-select v-model="formData.${javaField}" placeholder="请选择${comment}">
  47 + #if ("" != $dictType)## 有数据字典
  48 + <el-option
  49 + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
  50 + :key="dict.value"
  51 + :label="dict.label"
  52 + :value="dict.value"
  53 + />
  54 + #else##没数据字典
  55 + <el-option label="请选择字典生成" value="" />
  56 + #end
  57 + </el-select>
  58 + </el-form-item>
  59 + #elseif($column.htmlType == "checkbox")## 多选框
  60 + <el-form-item label="${comment}" prop="${javaField}">
  61 + <el-checkbox-group v-model="formData.${javaField}">
  62 + #if ("" != $dictType)## 有数据字典
  63 + <el-checkbox
  64 + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
  65 + :key="dict.value"
  66 + :label="dict.value"
  67 + >
  68 + {{ dict.label }}
  69 + </el-checkbox>
  70 + #else##没数据字典
  71 + <el-checkbox>请选择字典生成</el-checkbox>
  72 + #end
  73 + </el-checkbox-group>
  74 + </el-form-item>
  75 + #elseif($column.htmlType == "radio")## 单选框
  76 + <el-form-item label="${comment}" prop="${javaField}">
  77 + <el-radio-group v-model="formData.${javaField}">
  78 + #if ("" != $dictType)## 有数据字典
  79 + <el-radio
  80 + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
  81 + :key="dict.value"
  82 + :label="dict.value"
  83 + >
  84 + {{ dict.label }}
  85 + </el-radio>
  86 + #else##没数据字典
  87 + <el-radio label="1">请选择字典生成</el-radio>
  88 + #end
  89 + </el-radio-group>
  90 + </el-form-item>
  91 + #elseif($column.htmlType == "datetime")## 时间框
  92 + <el-form-item label="${comment}" prop="${javaField}">
  93 + <el-date-picker
  94 + v-model="formData.${javaField}"
  95 + type="date"
  96 + value-format="x"
  97 + placeholder="选择${comment}"
  98 + />
  99 + </el-form-item>
  100 + #elseif($column.htmlType == "textarea")## 文本框
  101 + <el-form-item label="${comment}" prop="${javaField}">
  102 + <el-input v-model="formData.${javaField}" type="textarea" placeholder="请输入${comment}" />
  103 + </el-form-item>
  104 + #end
  105 + #end
  106 +#end
  107 + </el-form>
  108 + <template v-slot:footer>
  109 + <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
  110 + <el-button @click="dialogVisible = false">取 消</el-button>
  111 + </template>
  112 + </Dialog>
  113 +</template>
  114 +<script setup lang="ts">
  115 +import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
  116 +import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
  117 +
  118 +const { t } = useI18n() // 国际化
  119 +const message = useMessage() // 消息弹窗
  120 +
  121 +const dialogVisible = ref(false) // 弹窗的是否展示
  122 +const dialogTitle = ref('') // 弹窗的标题
  123 +const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  124 +const formType = ref('') // 表单的类型:create - 新增;update - 修改
  125 +const formData = ref({
  126 +#foreach ($column in $subColumns)
  127 + #if ($column.createOperation || $column.updateOperation)
  128 + #if ($column.htmlType == "checkbox")
  129 + $column.javaField: [],
  130 + #else
  131 + $column.javaField: undefined,
  132 + #end
  133 + #end
  134 +#end
  135 +})
  136 +const formRules = reactive({
  137 +#foreach ($column in $subColumns)
  138 + #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
  139 + #set($comment=$column.columnComment)
  140 + $column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == 'select')'change'#else'blur'#end }],
  141 + #end
  142 +#end
  143 +})
  144 +const formRef = ref() // 表单 Ref
  145 +
  146 +/** 打开弹窗 */
  147 +const open = async (type: string, id?: number, ${subJoinColumn.javaField}: number) => {
  148 + dialogVisible.value = true
  149 + dialogTitle.value = t('action.' + type)
  150 + formType.value = type
  151 + resetForm()
  152 + formData.value.${subJoinColumn.javaField} = ${subJoinColumn.javaField}
  153 + // 修改时,设置数据
  154 + if (id) {
  155 + formLoading.value = true
  156 + try {
  157 + formData.value = await ${simpleClassName}Api.get${subSimpleClassName}(id)
  158 + } finally {
  159 + formLoading.value = false
  160 + }
  161 + }
  162 +}
  163 +defineExpose({ open }) // 提供 open 方法,用于打开弹窗
  164 +
  165 +/** 提交表单 */
  166 +const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  167 +const submitForm = async () => {
  168 + // 校验表单
  169 + await formRef.value.validate()
  170 + // 提交请求
  171 + formLoading.value = true
  172 + try {
  173 + const data = formData.value
  174 + if (formType.value === 'create') {
  175 + await ${simpleClassName}Api.create${subSimpleClassName}(data)
  176 + message.success(t('common.createSuccess'))
  177 + } else {
  178 + await ${simpleClassName}Api.update${subSimpleClassName}(data)
  179 + message.success(t('common.updateSuccess'))
  180 + }
  181 + dialogVisible.value = false
  182 + // 发送操作成功的事件
  183 + emit('success')
  184 + } finally {
  185 + formLoading.value = false
  186 + }
  187 +}
  188 +
  189 +/** 重置表单 */
  190 +const resetForm = () => {
  191 + formData.value = {
  192 +#foreach ($column in $subColumns)
  193 + #if ($column.createOperation || $column.updateOperation)
  194 + #if ($column.htmlType == "checkbox")
  195 + $column.javaField: [],
  196 + #else
  197 + $column.javaField: undefined,
  198 + #end
  199 + #end
  200 +#end
  201 + }
  202 + formRef.value?.resetFields()
  203 +}
  204 +</script>
0 \ No newline at end of file 205 \ No newline at end of file
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/components/form_sub_inner.vue.vm 0 → 100644
  1 +## 主表的 normal 和 inner 使用相同的 form 表单
  2 +#parse("codegen/vue3/views/components/form_sub_normal.vue.vm")
0 \ No newline at end of file 3 \ No newline at end of file
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/components/form_sub_normal.vue.vm 0 → 100644
  1 +#set ($subTable = $subTables.get($subIndex))##当前表
  2 +#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
  3 +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
  4 +#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
  5 +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
  6 +#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
  7 +<template>
  8 +#if ( $subTable.subJoinMany )## 情况一:一对多,table + form
  9 + <el-form
  10 + ref="formRef"
  11 + :model="formData"
  12 + :rules="formRules"
  13 + v-loading="formLoading"
  14 + label-width="0px"
  15 + :inline-message="true"
  16 + >
  17 + <el-table :data="formData" class="-mt-10px">
  18 + <el-table-column label="序号" type="index" width="100" />
  19 +#foreach($column in $subColumns)
  20 + #if ($column.createOperation || $column.updateOperation)
  21 + #set ($dictType = $column.dictType)
  22 + #set ($javaField = $column.javaField)
  23 + #set ($javaType = $column.javaType)
  24 + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  25 + #set ($comment = $column.columnComment)
  26 + #set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法
  27 + #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
  28 + #set ($dictMethod = "getIntDictOptions")
  29 + #elseif ($javaType == "String")
  30 + #set ($dictMethod = "getStrDictOptions")
  31 + #elseif ($javaType == "Boolean")
  32 + #set ($dictMethod = "getBoolDictOptions")
  33 + #end
  34 + #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
  35 + #elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
  36 + <el-table-column label="${comment}" min-width="150">
  37 + <template #default="{ row, $index }">
  38 + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
  39 + <el-input v-model="row.${javaField}" placeholder="请输入${comment}" />
  40 + </el-form-item>
  41 + </template>
  42 + </el-table-column>
  43 + #elseif($column.htmlType == "imageUpload")## 图片上传
  44 + <el-table-column label="${comment}" min-width="200">
  45 + <template #default="{ row, $index }">
  46 + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
  47 + <UploadImg v-model="row.${javaField}" />
  48 + </el-form-item>
  49 + </template>
  50 + </el-table-column>
  51 + #elseif($column.htmlType == "fileUpload")## 文件上传
  52 + <el-table-column label="${comment}" min-width="200">
  53 + <template #default="{ row, $index }">
  54 + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
  55 + <UploadFile v-model="row.${javaField}" />
  56 + </el-form-item>
  57 + </template>
  58 + </el-table-column>
  59 + #elseif($column.htmlType == "editor")## 文本编辑器
  60 + <el-table-column label="${comment}" min-width="400">
  61 + <template #default="{ row, $index }">
  62 + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
  63 + <Editor v-model="row.${javaField}" height="150px" />
  64 + </el-form-item>
  65 + </template>
  66 + </el-table-column>
  67 + #elseif($column.htmlType == "select")## 下拉框
  68 + <el-table-column label="${comment}" min-width="150">
  69 + <template #default="{ row, $index }">
  70 + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
  71 + <el-select v-model="row.${javaField}" placeholder="请选择${comment}">
  72 + #if ("" != $dictType)## 有数据字典
  73 + <el-option
  74 + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
  75 + :key="dict.value"
  76 + :label="dict.label"
  77 + :value="dict.value"
  78 + />
  79 + #else##没数据字典
  80 + <el-option label="请选择字典生成" value="" />
  81 + #end
  82 + </el-select>
  83 + </el-form-item>
  84 + </template>
  85 + </el-table-column>
  86 + #elseif($column.htmlType == "checkbox")## 多选框
  87 + <el-table-column label="${comment}" min-width="150">
  88 + <template #default="{ row, $index }">
  89 + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
  90 + <el-checkbox-group v-model="row.${javaField}">
  91 + #if ("" != $dictType)## 有数据字典
  92 + <el-checkbox
  93 + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
  94 + :key="dict.value"
  95 + :label="dict.value"
  96 + >
  97 + {{ dict.label }}
  98 + </el-checkbox>
  99 + #else##没数据字典
  100 + <el-checkbox>请选择字典生成</el-checkbox>
  101 + #end
  102 + </el-checkbox-group>
  103 + </el-form-item>
  104 + </template>
  105 + </el-table-column>
  106 + #elseif($column.htmlType == "radio")## 单选框
  107 + <el-table-column label="${comment}" min-width="150">
  108 + <template #default="{ row, $index }">
  109 + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
  110 + <el-radio-group v-model="row.${javaField}">
  111 + #if ("" != $dictType)## 有数据字典
  112 + <el-radio
  113 + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
  114 + :key="dict.value"
  115 + :label="dict.value"
  116 + >
  117 + {{ dict.label }}
  118 + </el-radio>
  119 + #else##没数据字典
  120 + <el-radio label="1">请选择字典生成</el-radio>
  121 + #end
  122 + </el-radio-group>
  123 + </el-form-item>
  124 + </template>
  125 + </el-table-column>
  126 + #elseif($column.htmlType == "datetime")## 时间框
  127 + <el-table-column label="${comment}" min-width="150">
  128 + <template #default="{ row, $index }">
  129 + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
  130 + <el-date-picker
  131 + v-model="row.${javaField}"
  132 + type="date"
  133 + value-format="x"
  134 + placeholder="选择${comment}"
  135 + />
  136 + </el-form-item>
  137 + </template>
  138 + </el-table-column>
  139 + #elseif($column.htmlType == "textarea")## 文本框
  140 + <el-table-column label="${comment}" min-width="200">
  141 + <template #default="{ row, $index }">
  142 + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
  143 + <el-input v-model="row.${javaField}" type="textarea" placeholder="请输入${comment}" />
  144 + </el-form-item>
  145 + </template>
  146 + </el-table-column>
  147 + #end
  148 + #end
  149 +#end
  150 + <el-table-column align="center" fixed="right" label="操作" width="60">
  151 + <template #default="{ $index }">
  152 + <el-button @click="handleDelete($index)" link>—</el-button>
  153 + </template>
  154 + </el-table-column>
  155 + </el-table>
  156 + </el-form>
  157 + <el-row justify="center" class="mt-3">
  158 + <el-button @click="handleAdd" round>+ 添加${subTable.classComment}</el-button>
  159 + </el-row>
  160 +#else## 情况二:一对一,form
  161 + <el-form
  162 + ref="formRef"
  163 + :model="formData"
  164 + :rules="formRules"
  165 + label-width="100px"
  166 + v-loading="formLoading"
  167 + >
  168 +#foreach($column in $subColumns)
  169 + #if ($column.createOperation || $column.updateOperation)
  170 + #set ($dictType = $column.dictType)
  171 + #set ($javaField = $column.javaField)
  172 + #set ($javaType = $column.javaType)
  173 + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  174 + #set ($comment = $column.columnComment)
  175 + #set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法
  176 + #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
  177 + #set ($dictMethod = "getIntDictOptions")
  178 + #elseif ($javaType == "String")
  179 + #set ($dictMethod = "getStrDictOptions")
  180 + #elseif ($javaType == "Boolean")
  181 + #set ($dictMethod = "getBoolDictOptions")
  182 + #end
  183 + #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
  184 + #elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
  185 + <el-form-item label="${comment}" prop="${javaField}">
  186 + <el-input v-model="formData.${javaField}" placeholder="请输入${comment}" />
  187 + </el-form-item>
  188 + #elseif($column.htmlType == "imageUpload")## 图片上传
  189 + <el-form-item label="${comment}" prop="${javaField}">
  190 + <UploadImg v-model="formData.${javaField}" />
  191 + </el-form-item>
  192 + #elseif($column.htmlType == "fileUpload")## 文件上传
  193 + <el-form-item label="${comment}" prop="${javaField}">
  194 + <UploadFile v-model="formData.${javaField}" />
  195 + </el-form-item>
  196 + #elseif($column.htmlType == "editor")## 文本编辑器
  197 + <el-form-item label="${comment}" prop="${javaField}">
  198 + <Editor v-model="formData.${javaField}" height="150px" />
  199 + </el-form-item>
  200 + #elseif($column.htmlType == "select")## 下拉框
  201 + <el-form-item label="${comment}" prop="${javaField}">
  202 + <el-select v-model="formData.${javaField}" placeholder="请选择${comment}">
  203 + #if ("" != $dictType)## 有数据字典
  204 + <el-option
  205 + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
  206 + :key="dict.value"
  207 + :label="dict.label"
  208 + :value="dict.value"
  209 + />
  210 + #else##没数据字典
  211 + <el-option label="请选择字典生成" value="" />
  212 + #end
  213 + </el-select>
  214 + </el-form-item>
  215 + #elseif($column.htmlType == "checkbox")## 多选框
  216 + <el-form-item label="${comment}" prop="${javaField}">
  217 + <el-checkbox-group v-model="formData.${javaField}">
  218 + #if ("" != $dictType)## 有数据字典
  219 + <el-checkbox
  220 + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
  221 + :key="dict.value"
  222 + :label="dict.value"
  223 + >
  224 + {{ dict.label }}
  225 + </el-checkbox>
  226 + #else##没数据字典
  227 + <el-checkbox>请选择字典生成</el-checkbox>
  228 + #end
  229 + </el-checkbox-group>
  230 + </el-form-item>
  231 + #elseif($column.htmlType == "radio")## 单选框
  232 + <el-form-item label="${comment}" prop="${javaField}">
  233 + <el-radio-group v-model="formData.${javaField}">
  234 + #if ("" != $dictType)## 有数据字典
  235 + <el-radio
  236 + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
  237 + :key="dict.value"
  238 + :label="dict.value"
  239 + >
  240 + {{ dict.label }}
  241 + </el-radio>
  242 + #else##没数据字典
  243 + <el-radio label="1">请选择字典生成</el-radio>
  244 + #end
  245 + </el-radio-group>
  246 + </el-form-item>
  247 + #elseif($column.htmlType == "datetime")## 时间框
  248 + <el-form-item label="${comment}" prop="${javaField}">
  249 + <el-date-picker
  250 + v-model="formData.${javaField}"
  251 + type="date"
  252 + value-format="x"
  253 + placeholder="选择${comment}"
  254 + />
  255 + </el-form-item>
  256 + #elseif($column.htmlType == "textarea")## 文本框
  257 + <el-form-item label="${comment}" prop="${javaField}">
  258 + <el-input v-model="formData.${javaField}" type="textarea" placeholder="请输入${comment}" />
  259 + </el-form-item>
  260 + #end
  261 + #end
  262 +#end
  263 + </el-form>
  264 +#end
  265 +</template>
  266 +<script setup lang="ts">
  267 +import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
  268 +import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
  269 +
  270 +const props = defineProps<{
  271 + ${subJoinColumn.javaField}: undefined // ${subJoinColumn.columnComment}(主表的关联字段)
  272 +}>()
  273 +const formLoading = ref(false) // 表单的加载中
  274 +const formData = ref([])
  275 +const formRules = reactive({
  276 +#foreach ($column in $subColumns)
  277 + #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
  278 + #set($comment=$column.columnComment)
  279 + $column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == 'select')'change'#else'blur'#end }],
  280 + #end
  281 +#end
  282 +})
  283 +const formRef = ref() // 表单 Ref
  284 +
  285 +/** 监听主表的关联字段的变化,加载对应的子表数据 */
  286 +watch(
  287 + () => props.${subJoinColumn.javaField},
  288 + async (val) => {
  289 + // 1. 重置表单
  290 +#if ( $subTable.subJoinMany )
  291 + formData.value = []
  292 +#else
  293 + formData.value = {
  294 + #foreach ($column in $subColumns)
  295 + #if ($column.createOperation || $column.updateOperation)
  296 + #if ($column.htmlType == "checkbox")
  297 + $column.javaField: [],
  298 + #else
  299 + $column.javaField: undefined,
  300 + #end
  301 + #end
  302 + #end
  303 + }
  304 +#end
  305 + // 2. val 非空,则加载数据
  306 + if (!val) {
  307 + return;
  308 + }
  309 + try {
  310 + formLoading.value = true
  311 +#if ( $subTable.subJoinMany )
  312 + formData.value = await ${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(val)
  313 +#else
  314 + const data = await ${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(val)
  315 + if (!data) {
  316 + return
  317 + }
  318 + formData.value = data
  319 +#end
  320 + } finally {
  321 + formLoading.value = false
  322 + }
  323 + },
  324 + { immediate: true }
  325 +)
  326 +#if ( $subTable.subJoinMany )
  327 +
  328 +/** 新增按钮操作 */
  329 +const handleAdd = () => {
  330 + const row = {
  331 +#foreach ($column in $subColumns)
  332 + #if ($column.createOperation || $column.updateOperation)
  333 + #if ($column.htmlType == "checkbox")
  334 + $column.javaField: [],
  335 + #else
  336 + $column.javaField: undefined,
  337 + #end
  338 + #end
  339 +#end
  340 + }
  341 + row.${subJoinColumn.javaField} = props.${subJoinColumn.javaField}
  342 + formData.value.push(row)
  343 +}
  344 +
  345 +/** 删除按钮操作 */
  346 +const handleDelete = (index) => {
  347 + formData.value.splice(index, 1)
  348 +}
  349 +#end
  350 +
  351 +/** 表单校验 */
  352 +const validate = () => {
  353 + return formRef.value.validate()
  354 +}
  355 +
  356 +/** 表单值 */
  357 +const getData = () => {
  358 + return formData.value
  359 +}
  360 +
  361 +defineExpose({ validate, getData })
  362 +</script>
0 \ No newline at end of file 363 \ No newline at end of file
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/components/list_sub_erp.vue.vm 0 → 100644
  1 +#set ($subTable = $subTables.get($subIndex))##当前表
  2 +#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
  3 +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
  4 +#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
  5 +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
  6 +#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
  7 +<template>
  8 + <!-- 列表 -->
  9 + <ContentWrap>
  10 +#if ($table.templateType == 11)
  11 + <el-button
  12 + type="primary"
  13 + plain
  14 + @click="openForm('create')"
  15 + v-hasPermi="['${permissionPrefix}:create']"
  16 + >
  17 + <Icon icon="ep:plus" class="mr-5px" /> 新增
  18 + </el-button>
  19 +#end
  20 + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  21 + #foreach($column in $subColumns)
  22 + #if ($column.listOperationResult)
  23 + #set ($dictType=$column.dictType)
  24 + #set ($javaField = $column.javaField)
  25 + #set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  26 + #set ($comment=$column.columnComment)
  27 + #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
  28 + #elseif ($column.javaType == "LocalDateTime")## 时间类型
  29 + <el-table-column
  30 + label="${comment}"
  31 + align="center"
  32 + prop="${javaField}"
  33 + :formatter="dateFormatter"
  34 + width="180px"
  35 + />
  36 + #elseif($column.dictType && "" != $column.dictType)## 数据字典
  37 + <el-table-column label="${comment}" align="center" prop="${javaField}">
  38 + <template #default="scope">
  39 + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.${column.javaField}" />
  40 + </template>
  41 + </el-table-column>
  42 + #else
  43 + <el-table-column label="${comment}" align="center" prop="${javaField}" />
  44 + #end
  45 + #end
  46 + #end
  47 + #if ($table.templateType == 11)
  48 + <el-table-column label="操作" align="center">
  49 + <template #default="scope">
  50 + <el-button
  51 + link
  52 + type="primary"
  53 + @click="openForm('update', scope.row.id)"
  54 + v-hasPermi="['${permissionPrefix}:update']"
  55 + >
  56 + 编辑
  57 + </el-button>
  58 + <el-button
  59 + link
  60 + type="danger"
  61 + @click="handleDelete(scope.row.id)"
  62 + v-hasPermi="['${permissionPrefix}:delete']"
  63 + >
  64 + 删除
  65 + </el-button>
  66 + </template>
  67 + </el-table-column>
  68 + #end
  69 + </el-table>
  70 + #if ($table.templateType == 11)
  71 + <!-- 分页 -->
  72 + <Pagination
  73 + :total="total"
  74 + v-model:page="queryParams.pageNo"
  75 + v-model:limit="queryParams.pageSize"
  76 + @pagination="getList"
  77 + />
  78 + #end
  79 + </ContentWrap>
  80 +#if ($table.templateType == 11)
  81 + <!-- 表单弹窗:添加/修改 -->
  82 + <${subSimpleClassName}Form ref="formRef" @success="getList" />
  83 +#end
  84 +</template>
  85 +<script setup lang="ts">
  86 +import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
  87 +import { dateFormatter } from '@/utils/formatTime'
  88 +import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
  89 +#if ($table.templateType == 11)
  90 +import ${subSimpleClassName}Form from './${subSimpleClassName}Form.vue'
  91 +#end
  92 +
  93 +const { t } = useI18n() // 国际化
  94 +const message = useMessage() // 消息弹窗
  95 +
  96 +const props = defineProps<{
  97 + ${subJoinColumn.javaField}: undefined // ${subJoinColumn.columnComment}(主表的关联字段)
  98 +}>()
  99 +const loading = ref(false) // 列表的加载中
  100 +const list = ref([]) // 列表的数据
  101 +#if ($table.templateType == 11)
  102 +const total = ref(0) // 列表的总页数
  103 +const queryParams = reactive({
  104 + pageNo: 1,
  105 + pageSize: 10,
  106 + ${subJoinColumn.javaField}: undefined
  107 +})
  108 +
  109 +/** 监听主表的关联字段的变化,加载对应的子表数据 */
  110 +watch(
  111 + () => props.${subJoinColumn.javaField},
  112 + (val) => {
  113 + queryParams.${subJoinColumn.javaField} = val
  114 + handleQuery()
  115 + },
  116 + { immediate: false }
  117 +)
  118 +#end
  119 +
  120 +/** 查询列表 */
  121 +const getList = async () => {
  122 + loading.value = true
  123 + try {
  124 +#if ($table.templateType == 11)
  125 + const data = await ${simpleClassName}Api.get${subSimpleClassName}Page(queryParams)
  126 + list.value = data.list
  127 + total.value = data.total
  128 +#else
  129 + #if ( $subTable.subJoinMany )
  130 + list.value = await ${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(props.${subJoinColumn.javaField})
  131 + #else
  132 + const data = await ${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(props.${subJoinColumn.javaField})
  133 + if (!data) {
  134 + return
  135 + }
  136 + list.value.push(data)
  137 + #end
  138 +#end
  139 + } finally {
  140 + loading.value = false
  141 + }
  142 +}
  143 +
  144 +/** 搜索按钮操作 */
  145 +const handleQuery = () => {
  146 + queryParams.pageNo = 1
  147 + getList()
  148 +}
  149 +#if ($table.templateType == 11)
  150 +
  151 +/** 添加/修改操作 */
  152 +const formRef = ref()
  153 +const openForm = (type: string, id?: number) => {
  154 + if (!props.${subJoinColumn.javaField}) {
  155 + message.error('请选择一个${table.classComment}')
  156 + return
  157 + }
  158 + formRef.value.open(type, id, props.${subJoinColumn.javaField})
  159 +}
  160 +
  161 +/** 删除按钮操作 */
  162 +const handleDelete = async (id: number) => {
  163 + try {
  164 + // 删除的二次确认
  165 + await message.delConfirm()
  166 + // 发起删除
  167 + await ${simpleClassName}Api.delete${subSimpleClassName}(id)
  168 + message.success(t('common.delSuccess'))
  169 + // 刷新列表
  170 + await getList()
  171 + } catch {}
  172 +}
  173 +#end
  174 +#if ($table.templateType != 11)
  175 +
  176 +/** 初始化 **/
  177 +onMounted(() => {
  178 + getList()
  179 +})
  180 +#end
  181 +</script>
0 \ No newline at end of file 182 \ No newline at end of file
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/components/list_sub_inner.vue.vm 0 → 100644
  1 +## 子表的 erp 和 inner 使用相似的 list 列表,差异主要两点:
  2 +## 1)inner 使用 list 不分页,erp 使用 page 分页
  3 +## 2)erp 支持单个子表的新增、修改、删除,inner 不支持
  4 +#parse("codegen/vue3/views/components/list_sub_erp.vue.vm")
0 \ No newline at end of file 5 \ No newline at end of file
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/form.vue.vm 0 → 100644
  1 +<template>
  2 + <div class="app-container">
  3 + <!-- 对话框(添加 / 修改) -->
  4 + <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="500px" v-dialogDrag append-to-body>
  5 + <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="80px">
  6 + #foreach($column in $columns)
  7 + #if ($column.createOperation || $column.updateOperation)
  8 + #set ($dictType = $column.dictType)
  9 + #set ($javaField = $column.javaField)
  10 + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  11 + #set ($comment = $column.columnComment)
  12 + #if ( $table.templateType == 2 && $column.id == $treeParentColumn.id )
  13 + <el-form-item label="${comment}" prop="${javaField}">
  14 + <treeselect
  15 + v-model="formData.${javaField}"
  16 + :options="${classNameVar}Tree"
  17 + :normalizer="normalizer"
  18 + placeholder="请选择${comment}"
  19 + />
  20 + </el-form-item>
  21 + #elseif ($column.htmlType == "input" && !$column.primaryKey)
  22 + #if (!$column.primaryKey)## 忽略主键,不用在表单里
  23 + <el-form-item label="${comment}" prop="${javaField}">
  24 + <el-input v-model="form.${javaField}" placeholder="请输入${comment}" />
  25 + </el-form-item>
  26 + #end
  27 + #elseif($column.htmlType == "imageUpload")## 图片上传
  28 + #set ($hasImageUploadColumn = true)
  29 + <el-form-item label="${comment}">
  30 + <imageUpload v-model="form.${javaField}"/>
  31 + </el-form-item>
  32 + #elseif($column.htmlType == "fileUpload")## 文件上传
  33 + #set ($hasFileUploadColumn = true)
  34 + <el-form-item label="${comment}">
  35 + <fileUpload v-model="form.${javaField}"/>
  36 + </el-form-item>
  37 + #elseif($column.htmlType == "editor")## 文本编辑器
  38 + #set ($hasEditorColumn = true)
  39 + <el-form-item label="${comment}">
  40 + <editor v-model="form.${javaField}" :min-height="192"/>
  41 + </el-form-item>
  42 + #elseif($column.htmlType == "select")## 下拉框
  43 + <el-form-item label="${comment}" prop="${javaField}">
  44 + <el-select v-model="form.${javaField}" placeholder="请选择${comment}">
  45 + #if ("" != $dictType)## 有数据字典
  46 + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
  47 + :key="dict.value" :label="dict.label" #if ($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end />
  48 + #else##没数据字典
  49 + <el-option label="请选择字典生成" value="" />
  50 + #end
  51 + </el-select>
  52 + </el-form-item>
  53 + #elseif($column.htmlType == "checkbox")## 多选框
  54 + <el-form-item label="${comment}" prop="${javaField}">
  55 + <el-checkbox-group v-model="form.${javaField}">
  56 + #if ("" != $dictType)## 有数据字典
  57 + <el-checkbox v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
  58 + :key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end>{{dict.label}}</el-checkbox>
  59 + #else##没数据字典
  60 + <el-checkbox>请选择字典生成</el-checkbox>
  61 + #end
  62 + </el-checkbox-group>
  63 + </el-form-item>
  64 + #elseif($column.htmlType == "radio")## 单选框
  65 + <el-form-item label="${comment}" prop="${javaField}">
  66 + <el-radio-group v-model="form.${javaField}">
  67 + #if ("" != $dictType)## 有数据字典
  68 + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
  69 + :key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"
  70 + #else:label="dict.value"#end>{{dict.label}}</el-radio>
  71 + #else##没数据字典
  72 + <el-radio label="1">请选择字典生成</el-radio>
  73 + #end
  74 + </el-radio-group>
  75 + </el-form-item>
  76 + #elseif($column.htmlType == "datetime")## 时间框
  77 + <el-form-item label="${comment}" prop="${javaField}">
  78 + <el-date-picker clearable v-model="form.${javaField}" type="date" value-format="timestamp" placeholder="选择${comment}" />
  79 + </el-form-item>
  80 + #elseif($column.htmlType == "textarea")## 文本框
  81 + <el-form-item label="${comment}" prop="${javaField}">
  82 + <el-input v-model="form.${javaField}" type="textarea" placeholder="请输入内容" />
  83 + </el-form-item>
  84 + #end
  85 + #end
  86 + #end
  87 + </el-form>
  88 + ## 特殊:主子表专属逻辑
  89 + #if ( $subTables && $subTables.size() > 0 )
  90 + <!-- 子表的表单 -->
  91 + <el-tabs v-model="subTabsName">
  92 + #foreach ($subTable in $subTables)
  93 + #set ($index = $foreach.count - 1)
  94 + #set ($subClassNameVar = $subClassNameVars.get($index))
  95 + #set ($subSimpleClassName = $subSimpleClassNames.get($index))
  96 + #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
  97 + <el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
  98 + <${subSimpleClassName}Form ref="${subClassNameVar}FormRef" :${subJoinColumn_strikeCase}="formData.id" />
  99 + </el-tab-pane>
  100 + #end
  101 + </el-tabs>
  102 + #end
  103 + <div slot="footer" class="dialog-footer">
  104 + <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button>
  105 + <el-button @click="dialogVisible = false">取 消</el-button>
  106 + </div>
  107 + </el-dialog>
  108 + </div>
  109 +</template>
  110 +
  111 +<script>
  112 + import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
  113 + #if ($hasImageUploadColumn)
  114 + import ImageUpload from '@/components/ImageUpload';
  115 + #end
  116 + #if ($hasFileUploadColumn)
  117 + import FileUpload from '@/components/FileUpload';
  118 + #end
  119 + #if ($hasEditorColumn)
  120 + import Editor from '@/components/Editor';
  121 + #end
  122 + ## 特殊:树表专属逻辑
  123 + #if ( $table.templateType == 2 )
  124 + import Treeselect from "@riophae/vue-treeselect";
  125 + import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  126 + #end
  127 + ## 特殊:主子表专属逻辑
  128 + #if ( $subTables && $subTables.size() > 0 )
  129 + #foreach ($subSimpleClassName in $subSimpleClassNames)
  130 + import ${subSimpleClassName}Form from './components/${subSimpleClassName}Form.vue'
  131 + #end
  132 + #end
  133 + export default {
  134 + name: "${simpleClassName}",
  135 + components: {
  136 + #if ($hasImageUploadColumn)
  137 + ImageUpload,
  138 + #end
  139 + #if ($hasFileUploadColumn)
  140 + FileUpload,
  141 + #end
  142 + #if ($hasEditorColumn)
  143 + Editor,
  144 + #end
  145 + ## 特殊:树表专属逻辑
  146 + #if ( $table.templateType == 2 )
  147 + Treeselect,
  148 + #end
  149 + ## 特殊:主子表专属逻辑
  150 + #if ( $subTables && $subTables.size() > 0 )
  151 + #foreach ($subSimpleClassName in $subSimpleClassNames)
  152 + ${subSimpleClassName}Form,
  153 + #end
  154 + #end
  155 + },
  156 + data() {
  157 + return {
  158 + // 弹出层标题
  159 + dialogTitle: "",
  160 + // 是否显示弹出层
  161 + dialogVisible: false,
  162 + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  163 + formLoading: false,
  164 + // 表单参数
  165 + formData: {
  166 + #foreach ($column in $columns)
  167 + #if ($column.createOperation || $column.updateOperation)
  168 + #if ($column.htmlType == "checkbox")
  169 + $column.javaField: [],
  170 + #else
  171 + $column.javaField: undefined,
  172 + #end
  173 + #end
  174 + #end
  175 + },
  176 + // 表单校验
  177 + formRules: {
  178 + #foreach ($column in $columns)
  179 + #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
  180 + #set($comment=$column.columnComment)
  181 + $column.javaField: [{ required: true, message: "${comment}不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }],
  182 + #end
  183 + #end
  184 + },
  185 + ## 特殊:树表专属逻辑
  186 + #if ( $table.templateType == 2 )
  187 + ${classNameVar}Tree: [], // 树形结构
  188 + #end
  189 + ## 特殊:主子表专属逻辑
  190 + #if ( $subTables && $subTables.size() > 0 )
  191 + /** 子表的表单 */
  192 + subTabsName: '$subClassNameVars.get(0)'
  193 + #end
  194 + };
  195 + },
  196 + methods: {
  197 + ## 特殊:树表专属逻辑
  198 + #if ( $table.templateType == 2 )
  199 + /** 转换${table.classComment}数据结构 */
  200 + normalizer(node) {
  201 + if (node.children && !node.children.length) {
  202 + delete node.children;
  203 + }
  204 + return {
  205 + id: node.id,
  206 + label: node.name,
  207 + children: node.children
  208 + };
  209 + },
  210 + #end
  211 + /** 表单重置 */
  212 + reset() {
  213 + this.formData = {
  214 + #foreach ($column in $columns)
  215 + #if ($column.createOperation || $column.updateOperation)
  216 + #if ($column.htmlType == "checkbox")
  217 + $column.javaField: [],
  218 + #else
  219 + $column.javaField: undefined,
  220 + #end
  221 + #end
  222 + #end
  223 + };
  224 + this.resetForm("formRef");
  225 + },
  226 + /** 打开弹窗 */
  227 + open(id) {
  228 + this.dialogVisible = true;
  229 + this.reset();
  230 + const that = this;
  231 + // 修改时,设置数据
  232 + if (id) {
  233 + this.formLoading = true;
  234 + try {
  235 + ${simpleClassName}Api.get${simpleClassName}(id).then(res=>{
  236 + that.formData = res.data;
  237 + that.title = "修改${table.classComment}";
  238 + })
  239 + } finally {
  240 + this.formLoading = false;
  241 + }
  242 + }
  243 + this.title = "新增${table.classComment}";
  244 + ## 特殊:树表专属逻辑
  245 + #if ( $table.templateType == 2 )
  246 + this.get${simpleClassName}Tree()
  247 + #end
  248 + },
  249 + ## 特殊:树表专属逻辑
  250 + #if ( $table.templateType == 2 )
  251 + /** 获得${table.classComment}树 */
  252 + get${simpleClassName}Tree() {
  253 + const that = this;
  254 + that.${classNameVar}Tree = [];
  255 + ${simpleClassName}Api.get${simpleClassName}List().then(res=>{
  256 + const root = { id: 0, name: '顶级${table.classComment}', children: [] };
  257 + root.children = this.handleTree(res.data, 'id', '${treeParentColumn.javaField}')
  258 + that.${classNameVar}Tree.push(root)
  259 + });
  260 + },
  261 + #end
  262 +
  263 + /** 提交按钮 */
  264 + submitForm() {
  265 + this.formLoading = true;
  266 + try {
  267 + let data = this.formData;
  268 +## 特殊:主子表专属逻辑
  269 +#if ( $subTables && $subTables.size() > 0 )
  270 + // 需要校验的表单 ref
  271 + const validFormRefArr = [
  272 + #foreach ($subTable in $subTables)
  273 + #set ($index = $foreach.count - 1)
  274 + #set ($subClassNameVar = $subClassNameVars.get($index))
  275 + "${subClassNameVar}FormRef",
  276 + #end
  277 + ];
  278 +
  279 + const validArr = []; // 校验
  280 + const that = this;
  281 + validFormRefArr.forEach((item, index) => {
  282 + validArr.push(new Promise((resolve, reject) => {
  283 + that.getRef(item).validate(valid => {
  284 + if (valid){ // 校验成功
  285 + resolve()
  286 + }else {
  287 + reject(item.replace("FormRef","")) // 校验失败返回对应的表单
  288 + }
  289 + })
  290 + }))})
  291 + Promise.all(validArr).then(() => {
  292 + // 全部校验通过-拼接子表的数据
  293 + // 拼接子表的数据
  294 + #foreach ($subTable in $subTables)
  295 + #set ($index = $foreach.count - 1)
  296 + #set ($subClassNameVar = $subClassNameVars.get($index))
  297 + data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = that.getRef(${subClassNameVar}FormRef).getData()
  298 + #end
  299 + }).catch((err)=>{
  300 + that.subTabsName = err
  301 + })
  302 +#end
  303 +
  304 + this.getRef("formRef").validate(valid => {
  305 + if (!valid) {
  306 + return;
  307 + }
  308 + // 修改的提交
  309 + if (data.${primaryColumn.javaField}) {
  310 + ${simpleClassName}Api.update${simpleClassName}(data).then(response => {
  311 + this.#[[$modal]]#.msgSuccess("修改成功");
  312 + this.dialogVisible = false;
  313 + this.#[[$]]#emit('success');
  314 + });
  315 + return;
  316 + }
  317 + // 添加的提交
  318 + ${simpleClassName}Api.create${simpleClassName}(data).then(response => {
  319 + this.#[[$modal]]#.msgSuccess("新增成功");
  320 + this.dialogVisible = false;
  321 + this.#[[$]]#emit('success');
  322 + });
  323 + });
  324 + }finally {
  325 + this.formLoading = false
  326 + }
  327 + },
  328 + getRef(refName){
  329 + this.#[[$]]#refs[refName]
  330 + }
  331 + }
  332 + };
  333 +</script>
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/index.vue.vm
@@ -47,18 +47,67 @@ @@ -47,18 +47,67 @@
47 <!-- 操作工具栏 --> 47 <!-- 操作工具栏 -->
48 <el-row :gutter="10" class="mb8"> 48 <el-row :gutter="10" class="mb8">
49 <el-col :span="1.5"> 49 <el-col :span="1.5">
50 - <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" 50 + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)"
51 v-hasPermi="['${permissionPrefix}:create']">新增</el-button> 51 v-hasPermi="['${permissionPrefix}:create']">新增</el-button>
52 </el-col> 52 </el-col>
53 <el-col :span="1.5"> 53 <el-col :span="1.5">
54 <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading" 54 <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
55 v-hasPermi="['${permissionPrefix}:export']">导出</el-button> 55 v-hasPermi="['${permissionPrefix}:export']">导出</el-button>
56 </el-col> 56 </el-col>
  57 + #if ( $table.templateType == 2 )
  58 + <el-col :span="1.5">
  59 + <el-button type="danger" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll">
  60 + 展开/折叠
  61 + </el-button>
  62 + </el-col>
  63 + #end
57 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> 64 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
58 </el-row> 65 </el-row>
59 66
60 - <!-- 列表 -->  
61 - <el-table v-loading="loading" :data="list"> 67 + ## 特殊:主子表专属逻辑 TODO puhui999: 普通模式
  68 + #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
  69 + <el-table
  70 + v-loading="loading"
  71 + :data="list"
  72 + :stripe="true"
  73 + :highlight-current-row="true"
  74 + :show-overflow-tooltip="true"
  75 + @current-change="handleCurrentChange"
  76 + >
  77 + ## 特殊:树表专属逻辑
  78 + #elseif ( $table.templateType == 2 )
  79 + <el-table
  80 + v-loading="loading"
  81 + :data="list"
  82 + :stripe="true"
  83 + :show-overflow-tooltip="true"
  84 + v-if="refreshTable"
  85 + row-key="id"
  86 + :default-expand-all="isExpandAll"
  87 + :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  88 + >
  89 + #else
  90 + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  91 + #end
  92 + ## 特殊:主子表专属逻辑 TODO puhui999: 内嵌模式
  93 + #if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 )
  94 + <!-- 子表的列表 -->
  95 + <el-table-column type="expand">
  96 + <template #default="scope">
  97 + <el-tabs value="$subClassNameVars.get(0)">
  98 + #foreach ($subTable in $subTables)
  99 + #set ($index = $foreach.count - 1)
  100 + #set ($subClassNameVar = $subClassNameVars.get($index))
  101 + #set ($subSimpleClassName = $subSimpleClassNames.get($index))
  102 + #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
  103 + <el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
  104 + <${subSimpleClassName}List :${subJoinColumn_strikeCase}="scope.row.id" />
  105 + </el-tab-pane>
  106 + #end
  107 + </el-tabs>
  108 + </template>
  109 + </el-table-column>
  110 + #end
62 #foreach($column in $columns) 111 #foreach($column in $columns)
63 #if ($column.listOperationResult) 112 #if ($column.listOperationResult)
64 #set ($dictType=$column.dictType) 113 #set ($dictType=$column.dictType)
@@ -84,7 +133,7 @@ @@ -84,7 +133,7 @@
84 #end 133 #end
85 <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> 134 <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
86 <template v-slot="scope"> 135 <template v-slot="scope">
87 - <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" 136 + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.${primaryColumn.javaField})"
88 v-hasPermi="['${permissionPrefix}:update']">修改</el-button> 137 v-hasPermi="['${permissionPrefix}:update']">修改</el-button>
89 <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" 138 <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
90 v-hasPermi="['${permissionPrefix}:delete']">删除</el-button> 139 v-hasPermi="['${permissionPrefix}:delete']">删除</el-button>
@@ -96,90 +145,28 @@ @@ -96,90 +145,28 @@
96 @pagination="getList"/> 145 @pagination="getList"/>
97 146
98 <!-- 对话框(添加 / 修改) --> 147 <!-- 对话框(添加 / 修改) -->
99 - <el-dialog :title="title" :visible.sync="open" width="500px" v-dialogDrag append-to-body>  
100 - <el-form ref="form" :model="form" :rules="rules" label-width="80px">  
101 -#foreach($column in $columns)  
102 -#if ($column.createOperation || $column.updateOperation)  
103 - #set ($dictType = $column.dictType)  
104 - #set ($javaField = $column.javaField)  
105 - #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})  
106 - #set ($comment = $column.columnComment)  
107 -#if ($column.htmlType == "input")  
108 - #if (!$column.primaryKey)## 忽略主键,不用在表单里  
109 - <el-form-item label="${comment}" prop="${javaField}">  
110 - <el-input v-model="form.${javaField}" placeholder="请输入${comment}" />  
111 - </el-form-item> 148 + <${simpleClassName}Form ref="formRef" @success="getList" />
  149 + ## 特殊:主子表专属逻辑 TODO puhui999: ERP 模式
  150 + #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
  151 + <!-- 子表的列表 -->
  152 + <el-tabs model-value="$subClassNameVars.get(0)">
  153 + #foreach ($subTable in $subTables)
  154 + #set ($index = $foreach.count - 1)
  155 + #set ($subClassNameVar = $subClassNameVars.get($index))
  156 + #set ($subSimpleClassName = $subSimpleClassNames.get($index))
  157 + #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
  158 + <el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
  159 + <${subSimpleClassName}List :${subJoinColumn_strikeCase}="currentRow.id" />
  160 + </el-tab-pane>
  161 + #end
  162 + </el-tabs>
112 #end 163 #end
113 -#elseif($column.htmlType == "imageUpload")## 图片上传  
114 - #set ($hasImageUploadColumn = true)  
115 - <el-form-item label="${comment}">  
116 - <imageUpload v-model="form.${javaField}"/>  
117 - </el-form-item>  
118 -#elseif($column.htmlType == "fileUpload")## 文件上传  
119 - #set ($hasFileUploadColumn = true)  
120 - <el-form-item label="${comment}">  
121 - <fileUpload v-model="form.${javaField}"/>  
122 - </el-form-item>  
123 -#elseif($column.htmlType == "editor")## 文本编辑器  
124 - #set ($hasEditorColumn = true)  
125 - <el-form-item label="${comment}">  
126 - <editor v-model="form.${javaField}" :min-height="192"/>  
127 - </el-form-item>  
128 -#elseif($column.htmlType == "select")## 下拉框  
129 - <el-form-item label="${comment}" prop="${javaField}">  
130 - <el-select v-model="form.${javaField}" placeholder="请选择${comment}">  
131 - #if ("" != $dictType)## 有数据字典  
132 - <el-option v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"  
133 - :key="dict.value" :label="dict.label" #if ($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end />  
134 - #else##没数据字典  
135 - <el-option label="请选择字典生成" value="" />  
136 - #end  
137 - </el-select>  
138 - </el-form-item>  
139 -#elseif($column.htmlType == "checkbox")## 多选框  
140 - <el-form-item label="${comment}" prop="${javaField}">  
141 - <el-checkbox-group v-model="form.${javaField}">  
142 - #if ("" != $dictType)## 有数据字典  
143 - <el-checkbox v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"  
144 - :key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end>{{dict.label}}</el-checkbox>  
145 - #else##没数据字典  
146 - <el-checkbox>请选择字典生成</el-checkbox>  
147 - #end  
148 - </el-checkbox-group>  
149 - </el-form-item>  
150 -#elseif($column.htmlType == "radio")## 单选框  
151 - <el-form-item label="${comment}" prop="${javaField}">  
152 - <el-radio-group v-model="form.${javaField}">  
153 - #if ("" != $dictType)## 有数据字典  
154 - <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"  
155 - :key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end>{{dict.label}}</el-radio>  
156 - #else##没数据字典  
157 - <el-radio label="1">请选择字典生成</el-radio>  
158 - #end  
159 - </el-radio-group>  
160 - </el-form-item>  
161 -#elseif($column.htmlType == "datetime")## 时间框  
162 - <el-form-item label="${comment}" prop="${javaField}">  
163 - <el-date-picker clearable v-model="form.${javaField}" type="date" value-format="timestamp" placeholder="选择${comment}" />  
164 - </el-form-item>  
165 -#elseif($column.htmlType == "textarea")## 文本框  
166 - <el-form-item label="${comment}" prop="${javaField}">  
167 - <el-input v-model="form.${javaField}" type="textarea" placeholder="请输入内容" />  
168 - </el-form-item>  
169 -#end  
170 -#end  
171 -#end  
172 - </el-form>  
173 - <div slot="footer" class="dialog-footer">  
174 - <el-button type="primary" @click="submitForm">确 定</el-button>  
175 - <el-button @click="cancel">取 消</el-button>  
176 - </div>  
177 - </el-dialog>  
178 </div> 164 </div>
179 </template> 165 </template>
180 166
181 <script> 167 <script>
182 -import { create${simpleClassName}, update${simpleClassName}, delete${simpleClassName}, get${simpleClassName}, get${simpleClassName}Page, export${simpleClassName}Excel } from "@/api/${table.moduleName}/${classNameVar}"; 168 +import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}';
  169 +import ${simpleClassName}Form from './${simpleClassName}Form.vue';
183 #if ($hasImageUploadColumn) 170 #if ($hasImageUploadColumn)
184 import ImageUpload from '@/components/ImageUpload'; 171 import ImageUpload from '@/components/ImageUpload';
185 #end 172 #end
@@ -189,10 +176,22 @@ import FileUpload from &#39;@/components/FileUpload&#39;; @@ -189,10 +176,22 @@ import FileUpload from &#39;@/components/FileUpload&#39;;
189 #if ($hasEditorColumn) 176 #if ($hasEditorColumn)
190 import Editor from '@/components/Editor'; 177 import Editor from '@/components/Editor';
191 #end 178 #end
192 - 179 +## 特殊:主子表专属逻辑
  180 +#if ( $subTables && $subTables.size() > 0 )
  181 + #foreach ($subSimpleClassName in $subSimpleClassNames)
  182 + import ${subSimpleClassName}List from './components/${subSimpleClassName}List.vue'
  183 + #end
  184 +#end
193 export default { 185 export default {
194 name: "${simpleClassName}", 186 name: "${simpleClassName}",
195 components: { 187 components: {
  188 + ${simpleClassName}Form,
  189 +## 特殊:主子表专属逻辑
  190 +#if ( $subTables && $subTables.size() > 0 )
  191 + #foreach ($subSimpleClassName in $subSimpleClassNames)
  192 + ${subSimpleClassName}List,
  193 + #end
  194 +#end
196 #if ($hasImageUploadColumn) 195 #if ($hasImageUploadColumn)
197 ImageUpload, 196 ImageUpload,
198 #end 197 #end
@@ -212,17 +211,25 @@ export default { @@ -212,17 +211,25 @@ export default {
212 // 显示搜索条件 211 // 显示搜索条件
213 showSearch: true, 212 showSearch: true,
214 // 总条数 213 // 总条数
215 - total: 0, 214 + ## 特殊:树表专属逻辑(树不需要分页接口)
  215 + #if ( $table.templateType != 2 )
  216 + total: 0,
  217 + #end
216 // ${table.classComment}列表 218 // ${table.classComment}列表
217 list: [], 219 list: [],
218 - // 弹出层标题  
219 - title: "",  
220 - // 是否显示弹出层  
221 - open: false, 220 + // 是否展开,默认全部展开
  221 + isExpandAll: true,
  222 + // 重新渲染表格状态
  223 + refreshTable: true,
  224 + // 选中行
  225 + currentRow: {},
222 // 查询参数 226 // 查询参数
223 queryParams: { 227 queryParams: {
224 - pageNo: 1,  
225 - pageSize: 10, 228 + ## 特殊:树表专属逻辑(树不需要分页接口)
  229 + #if ( $table.templateType != 2 )
  230 + pageNo: 1,
  231 + pageSize: 10,
  232 + #end
226 #foreach ($column in $columns) 233 #foreach ($column in $columns)
227 #if ($column.listOperation) 234 #if ($column.listOperation)
228 #if ($column.listOperationCondition != 'BETWEEN') 235 #if ($column.listOperationCondition != 'BETWEEN')
@@ -233,17 +240,6 @@ export default { @@ -233,17 +240,6 @@ export default {
233 #end 240 #end
234 #end 241 #end
235 #end 242 #end
236 - },  
237 - // 表单参数  
238 - form: {},  
239 - // 表单校验  
240 - rules: {  
241 - #foreach ($column in $columns)  
242 - #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键  
243 - #set($comment=$column.columnComment)  
244 - $column.javaField: [{ required: true, message: "${comment}不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }],  
245 - #end  
246 - #end  
247 } 243 }
248 }; 244 };
249 }, 245 },
@@ -253,33 +249,22 @@ export default { @@ -253,33 +249,22 @@ export default {
253 methods: { 249 methods: {
254 /** 查询列表 */ 250 /** 查询列表 */
255 getList() { 251 getList() {
  252 + try {
256 this.loading = true; 253 this.loading = true;
257 - // 执行查询  
258 - get${simpleClassName}Page(this.queryParams).then(response => { 254 + ## 特殊:树表专属逻辑(树不需要分页接口)
  255 + #if ( $table.templateType == 2 )
  256 + ${simpleClassName}Api.get${simpleClassName}List(queryParams).then(response => {
  257 + this.list = this.handleTree(response.data, 'id', '${treeParentColumn.javaField}');
  258 + })
  259 + #else
  260 + ${simpleClassName}Api.get${simpleClassName}Page(this.queryParams).then(response => {
259 this.list = response.data.list; 261 this.list = response.data.list;
260 this.total = response.data.total; 262 this.total = response.data.total;
261 - this.loading = false;  
262 }); 263 });
263 - },  
264 - /** 取消按钮 */  
265 - cancel() {  
266 - this.open = false;  
267 - this.reset();  
268 - },  
269 - /** 表单重置 */  
270 - reset() {  
271 - this.form = {  
272 - #foreach ($column in $columns)  
273 - #if ($column.createOperation || $column.updateOperation)  
274 - #if ($column.htmlType == "checkbox")  
275 - $column.javaField: [],  
276 - #else  
277 - $column.javaField: undefined,  
278 - #end  
279 - #end  
280 - #end  
281 - };  
282 - this.resetForm("form"); 264 + #end
  265 + } finally {
  266 + this.loading = false;
  267 + }
283 }, 268 },
284 /** 搜索按钮操作 */ 269 /** 搜索按钮操作 */
285 handleQuery() { 270 handleQuery() {
@@ -291,79 +276,56 @@ export default { @@ -291,79 +276,56 @@ export default {
291 this.resetForm("queryForm"); 276 this.resetForm("queryForm");
292 this.handleQuery(); 277 this.handleQuery();
293 }, 278 },
294 - /** 新增按钮操作 */  
295 - handleAdd() {  
296 - this.reset();  
297 - this.open = true;  
298 - this.title = "添加${table.classComment}";  
299 - },  
300 - /** 修改按钮操作 */  
301 - handleUpdate(row) {  
302 - this.reset();  
303 - const ${primaryColumn.javaField} = row.${primaryColumn.javaField};  
304 - get${simpleClassName}(${primaryColumn.javaField}).then(response => {  
305 - this.form = response.data;  
306 - #foreach ($column in $columns)  
307 - #if($column.htmlType == "checkbox")## checkbox 特殊处理  
308 - this.form.$column.javaField = this.form.${column.javaField}.split(",");  
309 - #end  
310 - #end  
311 - this.open = true;  
312 - this.title = "修改${table.classComment}";  
313 - });  
314 - },  
315 - /** 提交按钮 */  
316 - submitForm() {  
317 - this.#[[$]]#refs["form"].validate(valid => {  
318 - if (!valid) {  
319 - return;  
320 - }  
321 - #foreach ($column in $columns)  
322 - #if($column.htmlType == "checkbox")  
323 - this.form.$column.javaField = this.form.${column.javaField}.join(",");  
324 - #end  
325 - #end  
326 - // 修改的提交  
327 - if (this.form.${primaryColumn.javaField} != null) {  
328 - update${simpleClassName}(this.form).then(response => {  
329 - this.#[[$modal]]#.msgSuccess("修改成功");  
330 - this.open = false;  
331 - this.getList();  
332 - });  
333 - return;  
334 - }  
335 - // 添加的提交  
336 - create${simpleClassName}(this.form).then(response => {  
337 - this.#[[$modal]]#.msgSuccess("新增成功");  
338 - this.open = false;  
339 - this.getList();  
340 - });  
341 - }); 279 + /** 添加/修改操作 */
  280 + openForm(id) {
  281 + this.#[[$]]#refs["formRef"].open(id)
342 }, 282 },
343 /** 删除按钮操作 */ 283 /** 删除按钮操作 */
344 handleDelete(row) { 284 handleDelete(row) {
  285 + const that = this;
  286 + try {
345 const ${primaryColumn.javaField} = row.${primaryColumn.javaField}; 287 const ${primaryColumn.javaField} = row.${primaryColumn.javaField};
346 - this.#[[$modal]]#.confirm('是否确认删除${table.classComment}编号为"' + ${primaryColumn.javaField} + '"的数据项?').then(function() {  
347 - return delete${simpleClassName}(${primaryColumn.javaField}); 288 + this.#[[$modal]]#.confirm('是否确认删除${table.classComment}编号为"' + ${primaryColumn.javaField} + '"的数据项?').then(()=>{
  289 + return ${simpleClassName}Api.delete${simpleClassName}(${primaryColumn.javaField});
348 }).then(() => { 290 }).then(() => {
349 - this.getList();  
350 - this.#[[$modal]]#.msgSuccess("删除成功"); 291 + that.getList();
  292 + that.#[[$modal]]#.msgSuccess("删除成功");
351 }).catch(() => {}); 293 }).catch(() => {});
  294 + } catch {}
352 }, 295 },
353 /** 导出按钮操作 */ 296 /** 导出按钮操作 */
354 handleExport() { 297 handleExport() {
355 - // 处理查询参数  
356 - let params = {...this.queryParams};  
357 - params.pageNo = undefined;  
358 - params.pageSize = undefined;  
359 - this.#[[$modal]]#.confirm('是否确认导出所有${table.classComment}数据项?').then(() => {  
360 - this.exportLoading = true;  
361 - return export${simpleClassName}Excel(params);  
362 - }).then(response => {  
363 - this.#[[$]]#download.excel(response, '${table.classComment}.xls');  
364 - this.exportLoading = false;  
365 - }).catch(() => {});  
366 - } 298 + const that = this;
  299 + try {
  300 + this.#[[$modal]]#.confirm('是否确认导出所有${table.classComment}数据项?').then(() => {
  301 + that.exportLoading = true;
  302 + return ${simpleClassName}Api.export${simpleClassName}Excel(params);
  303 + }).then(response => {
  304 + that.#[[$]]#download.excel(response, '${table.classComment}.xls');
  305 + }));
  306 + } catch {
  307 + } finally {
  308 + that.exportLoading = false;
  309 + }
  310 + },
  311 + ## 特殊:主子表专属逻辑
  312 + #if ( $subTables && $subTables.size() > 0 )
  313 + /** 选中行操作 */
  314 + handleCurrentChange(row) {
  315 + this.currentRow = row
  316 + },
  317 + #end
  318 + ## 特殊:树表专属逻辑
  319 + #if ( $table.templateType == 2 )
  320 + /** 展开/折叠操作 */
  321 + toggleExpandAll() {
  322 + this.refreshTable = false
  323 + this.isExpandAll = !this.isExpandAll
  324 + this.$nextTick(function () {
  325 + this.refreshTable = true
  326 + })
  327 + }
  328 + #end
367 } 329 }
368 }; 330 };
369 </script> 331 </script>
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm
@@ -146,9 +146,11 @@ import * as ${simpleClassName}Api from &#39;@/api/${table.moduleName}/${table.busine @@ -146,9 +146,11 @@ import * as ${simpleClassName}Api from &#39;@/api/${table.moduleName}/${table.busine
146 import { defaultProps, handleTree } from '@/utils/tree' 146 import { defaultProps, handleTree } from '@/utils/tree'
147 #end 147 #end
148 ## 特殊:主子表专属逻辑 148 ## 特殊:主子表专属逻辑
  149 +#if ( $subTables && $subTables.size() > 0 )
149 #foreach ($subSimpleClassName in $subSimpleClassNames) 150 #foreach ($subSimpleClassName in $subSimpleClassNames)
150 import ${subSimpleClassName}Form from './components/${subSimpleClassName}Form.vue' 151 import ${subSimpleClassName}Form from './components/${subSimpleClassName}Form.vue'
151 #end 152 #end
  153 +#end
152 154
153 const { t } = useI18n() // 国际化 155 const { t } = useI18n() // 国际化
154 const message = useMessage() // 消息弹窗 156 const message = useMessage() // 消息弹窗
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm
@@ -113,7 +113,7 @@ @@ -113,7 +113,7 @@
113 113
114 <!-- 列表 --> 114 <!-- 列表 -->
115 <ContentWrap> 115 <ContentWrap>
116 -## 特殊:主子表专属逻辑 116 +## 特殊:主子表专属逻辑 TODO puhui999: 普通模式
117 #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 ) 117 #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
118 <el-table 118 <el-table
119 v-loading="loading" 119 v-loading="loading"
@@ -137,7 +137,7 @@ @@ -137,7 +137,7 @@
137 #else 137 #else
138 <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> 138 <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
139 #end 139 #end
140 -## 特殊:主子表专属逻辑 140 +## 特殊:主子表专属逻辑 TODO puhui999: 内嵌模式
141 #if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 ) 141 #if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 )
142 <!-- 子表的列表 --> 142 <!-- 子表的列表 -->
143 <el-table-column type="expand"> 143 <el-table-column type="expand">
@@ -213,7 +213,7 @@ @@ -213,7 +213,7 @@
213 213
214 <!-- 表单弹窗:添加/修改 --> 214 <!-- 表单弹窗:添加/修改 -->
215 <${simpleClassName}Form ref="formRef" @success="getList" /> 215 <${simpleClassName}Form ref="formRef" @success="getList" />
216 -## 特殊:主子表专属逻辑 216 +## 特殊:主子表专属逻辑 TODO puhui999: ERP 模式
217 #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 ) 217 #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
218 <!-- 子表的列表 --> 218 <!-- 子表的列表 -->
219 <ContentWrap> 219 <ContentWrap>
@@ -243,7 +243,7 @@ import download from &#39;@/utils/download&#39; @@ -243,7 +243,7 @@ import download from &#39;@/utils/download&#39;
243 import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}' 243 import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
244 import ${simpleClassName}Form from './${simpleClassName}Form.vue' 244 import ${simpleClassName}Form from './${simpleClassName}Form.vue'
245 ## 特殊:主子表专属逻辑 245 ## 特殊:主子表专属逻辑
246 -#if ( $table.templateType != 10 ) 246 +#if ( $subTables && $subTables.size() > 0 )
247 #foreach ($subSimpleClassName in $subSimpleClassNames) 247 #foreach ($subSimpleClassName in $subSimpleClassNames)
248 import ${subSimpleClassName}List from './components/${subSimpleClassName}List.vue' 248 import ${subSimpleClassName}List from './components/${subSimpleClassName}List.vue'
249 #end 249 #end
@@ -343,9 +343,9 @@ const handleExport = async () =&gt; { @@ -343,9 +343,9 @@ const handleExport = async () =&gt; {
343 exportLoading.value = false 343 exportLoading.value = false
344 } 344 }
345 } 345 }
346 -## 特殊:主子表专属逻辑  
347 -#if ( $table.templateType == 11 )  
348 346
  347 +## 特殊:主子表专属逻辑
  348 +#if ( $subTables && $subTables.size() > 0 )
349 /** 选中行操作 */ 349 /** 选中行操作 */
350 const currentRow = ref({}) // 选中行 350 const currentRow = ref({}) // 选中行
351 const handleCurrentChange = (row) => { 351 const handleCurrentChange = (row) => {
yudao-server/src/main/resources/application-local.yaml
@@ -48,7 +48,7 @@ spring: @@ -48,7 +48,7 @@ spring:
48 primary: master 48 primary: master
49 datasource: 49 datasource:
50 master: 50 master:
51 - name: ruoyi-vue-pro 51 + name: ruoyi-vue-pro4
52 url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 52 url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
53 # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 53 # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例
54 # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.master.name} # PostgreSQL 连接的示例 54 # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.master.name} # PostgreSQL 连接的示例
@@ -62,7 +62,7 @@ spring: @@ -62,7 +62,7 @@ spring:
62 # username: SYSDBA # DM 连接的示例 62 # username: SYSDBA # DM 连接的示例
63 # password: SYSDBA # DM 连接的示例 63 # password: SYSDBA # DM 连接的示例
64 slave: # 模拟从库,可根据自己需要修改 64 slave: # 模拟从库,可根据自己需要修改
65 - name: ruoyi-vue-pro 65 + name: ruoyi-vue-pro4
66 lazy: true # 开启懒加载,保证启动速度 66 lazy: true # 开启懒加载,保证启动速度
67 url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 67 url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
68 # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 68 # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例
@@ -78,8 +78,8 @@ spring: @@ -78,8 +78,8 @@ spring:
78 redis: 78 redis:
79 host: 127.0.0.1 # 地址 79 host: 127.0.0.1 # 地址
80 port: 6379 # 端口 80 port: 6379 # 端口
81 - database: 0 # 数据库索引  
82 -# password: dev # 密码,建议生产环境开启 81 + database: 4 # 数据库索引
  82 + password: 123456 # 密码,建议生产环境开启
83 83
84 --- #################### 定时任务相关配置 #################### 84 --- #################### 定时任务相关配置 ####################
85 85