Commit 7c48aaba8ab2a7540490c8394a6822bd00612bb8

Authored by zhijiantianya@gmail.com
1 parent 01bdb336

代码生成器:进一步完善 erp 生成模版

yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm
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> 1 <template>
  2 + <ContentWrap>
  3 + <!-- 搜索工作栏 -->
  4 + <el-form
  5 + class="-mb-15px"
  6 + :model="queryParams"
  7 + ref="queryFormRef"
  8 + :inline="true"
  9 + label-width="68px"
  10 + >
  11 + #foreach($column in $columns)
  12 + #if ($column.listOperation)
  13 + #set ($dictType = $column.dictType)
  14 + #set ($javaField = $column.javaField)
  15 + #set ($javaType = $column.javaType)
  16 + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  17 + #set ($comment = $column.columnComment)
  18 + #set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法
  19 + #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
  20 + #set ($dictMethod = "getIntDictOptions")
  21 + #elseif ($javaType == "String")
  22 + #set ($dictMethod = "getStrDictOptions")
  23 + #elseif ($javaType == "Boolean")
  24 + #set ($dictMethod = "getBoolDictOptions")
  25 + #end
  26 + #if ($column.htmlType == "input")
  27 + <el-form-item label="${comment}" prop="${javaField}">
  28 + <el-input
  29 + v-model="queryParams.${javaField}"
  30 + placeholder="请输入${comment}"
  31 + clearable
  32 + @keyup.enter="handleQuery"
  33 + class="!w-240px"
  34 + />
  35 + </el-form-item>
  36 + #elseif ($column.htmlType == "select" || $column.htmlType == "radio")
  37 + <el-form-item label="${comment}" prop="${javaField}">
  38 + <el-select
  39 + v-model="queryParams.${javaField}"
  40 + placeholder="请选择${comment}"
  41 + clearable
  42 + class="!w-240px"
  43 + >
  44 + #if ("" != $dictType)## 设置了 dictType 数据字典的情况
  45 + <el-option
  46 + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
  47 + :key="dict.value"
  48 + :label="dict.label"
  49 + :value="dict.value"
  50 + />
  51 + #else## 未设置 dictType 数据字典的情况
  52 + <el-option label="请选择字典生成" value="" />
  53 + #end
  54 + </el-select>
  55 + </el-form-item>
  56 + #elseif($column.htmlType == "datetime")
  57 + #if ($column.listOperationCondition != "BETWEEN")## 非范围
  58 + <el-form-item label="${comment}" prop="${javaField}">
  59 + <el-date-picker
  60 + v-model="queryParams.${javaField}"
  61 + value-format="YYYY-MM-DD"
  62 + type="date"
  63 + placeholder="选择${comment}"
  64 + clearable
  65 + class="!w-240px"
  66 + />
  67 + </el-form-item>
  68 + #else## 范围
  69 + <el-form-item label="${comment}" prop="${javaField}">
  70 + <el-date-picker
  71 + v-model="queryParams.${javaField}"
  72 + value-format="YYYY-MM-DD HH:mm:ss"
  73 + type="daterange"
  74 + start-placeholder="开始日期"
  75 + end-placeholder="结束日期"
  76 + :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  77 + class="!w-240px"
  78 + />
  79 + </el-form-item>
  80 + #end
  81 + #end
  82 + #end
  83 + #end
  84 + <el-form-item>
  85 + <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  86 + <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  87 + <el-button
  88 + type="primary"
  89 + plain
  90 + @click="openForm('create')"
  91 + v-hasPermi="['${permissionPrefix}:create']"
  92 + >
  93 + <Icon icon="ep:plus" class="mr-5px" /> 新增
  94 + </el-button>
  95 + <el-button
  96 + type="success"
  97 + plain
  98 + @click="handleExport"
  99 + :loading="exportLoading"
  100 + v-hasPermi="['${permissionPrefix}:export']"
  101 + >
  102 + <Icon icon="ep:download" class="mr-5px" /> 导出
  103 + </el-button>
  104 + </el-form-item>
  105 + </el-form>
  106 + </ContentWrap>
  107 +
8 <!-- 列表 --> 108 <!-- 列表 -->
9 <ContentWrap> 109 <ContentWrap>
10 - <el-button  
11 - type="primary"  
12 - plain  
13 - @click="openForm('create')"  
14 - v-hasPermi="['${permissionPrefix}:create']" 110 +## 特殊:主子表专属逻辑
  111 +#if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
  112 + <el-table
  113 + v-loading="loading"
  114 + :data="list"
  115 + :stripe="true"
  116 + :show-overflow-tooltip="true"
  117 + highlight-current-row
  118 + @current-change="handleCurrentChange"
15 > 119 >
16 - <Icon icon="ep:plus" class="mr-5px" /> 新增  
17 - </el-button> 120 +#else
18 <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> 121 <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
19 - #foreach($column in $subColumns) 122 +#end
  123 +## 特殊:主子表专属逻辑
  124 +#if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 )
  125 + <!-- 子表的列表 -->
  126 + <el-table-column type="expand">
  127 + <template #default="scope">
  128 + <el-tabs model-value="$subClassNameVars.get(0)">
  129 + #foreach ($subTable in $subTables)
  130 + #set ($index = $foreach.count - 1)
  131 + #set ($subClassNameVar = $subClassNameVars.get($index))
  132 + #set ($subSimpleClassName = $subSimpleClassNames.get($index))
  133 + #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
  134 + <el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
  135 + <${subSimpleClassName}List :${subJoinColumn_strikeCase}="scope.row.id" />
  136 + </el-tab-pane>
  137 + #end
  138 + </el-tabs>
  139 + </template>
  140 + </el-table-column>
  141 +#end
  142 + #foreach($column in $columns)
20 #if ($column.listOperationResult) 143 #if ($column.listOperationResult)
21 #set ($dictType=$column.dictType) 144 #set ($dictType=$column.dictType)
22 #set ($javaField = $column.javaField) 145 #set ($javaField = $column.javaField)
@@ -41,7 +164,6 @@ @@ -41,7 +164,6 @@
41 #end 164 #end
42 #end 165 #end
43 #end 166 #end
44 - #if ($table.templateType == 11)  
45 <el-table-column label="操作" align="center"> 167 <el-table-column label="操作" align="center">
46 <template #default="scope"> 168 <template #default="scope">
47 <el-button 169 <el-button
@@ -62,9 +184,7 @@ @@ -62,9 +184,7 @@
62 </el-button> 184 </el-button>
63 </template> 185 </template>
64 </el-table-column> 186 </el-table-column>
65 - #end  
66 </el-table> 187 </el-table>
67 - #if ($table.templateType == 11)  
68 <!-- 分页 --> 188 <!-- 分页 -->
69 <Pagination 189 <Pagination
70 :total="total" 190 :total="total"
@@ -72,64 +192,72 @@ @@ -72,64 +192,72 @@
72 v-model:limit="queryParams.pageSize" 192 v-model:limit="queryParams.pageSize"
73 @pagination="getList" 193 @pagination="getList"
74 /> 194 />
75 - #end  
76 </ContentWrap> 195 </ContentWrap>
77 196
78 - <!-- 表单弹窗:添加/修改 -->  
79 - <${subSimpleClassName}Form ref="formRef" @success="getList" /> 197 + <!-- 表单弹窗:添加/修改 -->
  198 + <${simpleClassName}Form ref="formRef" @success="getList" />
  199 +## 特殊:主子表专属逻辑
  200 +#if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
  201 + <!-- 子表的列表 -->
  202 + <ContentWrap>
  203 + <el-tabs model-value="$subClassNameVars.get(0)">
  204 + #foreach ($subTable in $subTables)
  205 + #set ($index = $foreach.count - 1)
  206 + #set ($subClassNameVar = $subClassNameVars.get($index))
  207 + #set ($subSimpleClassName = $subSimpleClassNames.get($index))
  208 + #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
  209 + <el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
  210 + <${subSimpleClassName}List :${subJoinColumn_strikeCase}="currentRow.id" />
  211 + </el-tab-pane>
  212 + #end
  213 + </el-tabs>
  214 + </ContentWrap>
  215 +#end
80 </template> 216 </template>
81 217
82 <script setup lang="ts"> 218 <script setup lang="ts">
83 import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict' 219 import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
  220 +import { dateFormatter } from '@/utils/formatTime'
  221 +import download from '@/utils/download'
84 import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}' 222 import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
85 -import ${subSimpleClassName}Form from './${subSimpleClassName}Form.vue' 223 +import ${simpleClassName}Form from './${simpleClassName}Form.vue'
  224 +## 特殊:主子表专属逻辑
  225 +#foreach ($subSimpleClassName in $subSimpleClassNames)
  226 +import ${subSimpleClassName}List from './components/${subSimpleClassName}List.vue'
  227 +#end
  228 +
  229 +defineOptions({ name: '${table.className}' })
86 230
87 -const { t } = useI18n() // 国际化  
88 const message = useMessage() // 消息弹窗 231 const message = useMessage() // 消息弹窗
  232 +const { t } = useI18n() // 国际化
89 233
90 -const props = defineProps<{  
91 - ${subJoinColumn.javaField}: undefined // ${subJoinColumn.columnComment}(主表的关联字段)  
92 -}>()  
93 -const loading = ref(false) // 列表的加载中  
94 -const list = ref([]) // 列表的数据  
95 -#if ($table.templateType == 11) 234 +const loading = ref(true) // 列表的加载中
96 const total = ref(0) // 列表的总页数 235 const total = ref(0) // 列表的总页数
  236 +const list = ref([]) // 列表的数据
97 const queryParams = reactive({ 237 const queryParams = reactive({
98 pageNo: 1, 238 pageNo: 1,
99 pageSize: 10, 239 pageSize: 10,
100 - ${subJoinColumn.javaField}: undefined 240 + #foreach ($column in $columns)
  241 + #if ($column.listOperation)
  242 + #if ($column.listOperationCondition != 'BETWEEN')
  243 + $column.javaField: null,
  244 + #end
  245 + #if ($column.htmlType == "datetime" || $column.listOperationCondition == "BETWEEN")
  246 + $column.javaField: [],
  247 + #end
  248 + #end
  249 + #end
101 }) 250 })
102 -  
103 -/** 监听主表的关联字段的变化,加载对应的子表数据 */  
104 -watch(  
105 - () => props.${subJoinColumn.javaField},  
106 - (val) => {  
107 - queryParams.${subJoinColumn.javaField} = val  
108 - handleQuery()  
109 - },  
110 - { immediate: false }  
111 -)  
112 -#end 251 +const queryFormRef = ref() // 搜索的表单
  252 +const exportLoading = ref(false) // 导出的加载中
113 253
114 /** 查询列表 */ 254 /** 查询列表 */
115 const getList = async () => { 255 const getList = async () => {
116 loading.value = true 256 loading.value = true
117 try { 257 try {
118 -#if ($table.templateType == 11)  
119 - const data = await ${simpleClassName}Api.get${subSimpleClassName}Page(queryParams) 258 + const data = await ${simpleClassName}Api.get${simpleClassName}Page(queryParams)
120 list.value = data.list 259 list.value = data.list
121 total.value = data.total 260 total.value = data.total
122 -#else  
123 - #if ( $subTable.subJoinMany )  
124 - list.value = await ${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(props.${subJoinColumn.javaField})  
125 - #else  
126 - const data = await ${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(props.${subJoinColumn.javaField})  
127 - if (!data) {  
128 - return  
129 - }  
130 - list.value.push(data)  
131 - #end  
132 -#end  
133 } finally { 261 } finally {
134 loading.value = false 262 loading.value = false
135 } 263 }
@@ -140,16 +268,17 @@ const handleQuery = () =&gt; { @@ -140,16 +268,17 @@ const handleQuery = () =&gt; {
140 queryParams.pageNo = 1 268 queryParams.pageNo = 1
141 getList() 269 getList()
142 } 270 }
143 -#if ($table.templateType == 11) 271 +
  272 +/** 重置按钮操作 */
  273 +const resetQuery = () => {
  274 + queryFormRef.value.resetFields()
  275 + handleQuery()
  276 +}
144 277
145 /** 添加/修改操作 */ 278 /** 添加/修改操作 */
146 const formRef = ref() 279 const formRef = ref()
147 const openForm = (type: string, id?: number) => { 280 const openForm = (type: string, id?: number) => {
148 - if (!props.${subJoinColumn.javaField}) {  
149 - message.error('请选择一个${table.classComment}')  
150 - return  
151 - }  
152 - formRef.value.open(type, id, props.${subJoinColumn.javaField}) 281 + formRef.value.open(type, id)
153 } 282 }
154 283
155 /** 删除按钮操作 */ 284 /** 删除按钮操作 */
@@ -158,18 +287,39 @@ const handleDelete = async (id: number) =&gt; { @@ -158,18 +287,39 @@ const handleDelete = async (id: number) =&gt; {
158 // 删除的二次确认 287 // 删除的二次确认
159 await message.delConfirm() 288 await message.delConfirm()
160 // 发起删除 289 // 发起删除
161 - await ${simpleClassName}Api.delete${subSimpleClassName}(id) 290 + await ${simpleClassName}Api.delete${simpleClassName}(id)
162 message.success(t('common.delSuccess')) 291 message.success(t('common.delSuccess'))
163 // 刷新列表 292 // 刷新列表
164 await getList() 293 await getList()
165 } catch {} 294 } catch {}
166 } 295 }
  296 +
  297 +/** 导出按钮操作 */
  298 +const handleExport = async () => {
  299 + try {
  300 + // 导出的二次确认
  301 + await message.exportConfirm()
  302 + // 发起导出
  303 + exportLoading.value = true
  304 + const data = await ${simpleClassName}Api.export${simpleClassName}(queryParams)
  305 + download.excel(data, '${table.classComment}.xls')
  306 + } catch {
  307 + } finally {
  308 + exportLoading.value = false
  309 + }
  310 +}
  311 +## 特殊:主子表专属逻辑
  312 +#if ( $table.templateType == 11 )
  313 +
  314 +/** 选中行操作 */
  315 +const currentRow = ref({}) // 选中行
  316 +const handleCurrentChange = (row) => {
  317 + currentRow.value = row
  318 +}
167 #end 319 #end
168 -#if ($table.templateType != 11)  
169 320
170 /** 初始化 **/ 321 /** 初始化 **/
171 onMounted(() => { 322 onMounted(() => {
172 getList() 323 getList()
173 }) 324 })
174 -#end  
175 </script> 325 </script>
176 \ No newline at end of file 326 \ No newline at end of file