2026-06-26 20b96473f2520590a0dca6b775b81e3ea06a77a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#set ($subTable = $subTables.get($subIndex))##当前表
#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($subIndex))
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
<script lang="ts" setup>
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${table.businessName}';
import type { VxeTableInstance } from '#/adapter/vxe-table';
 
import { reactive, ref, h, nextTick, watch, onMounted } from 'vue';
 
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
 
import { DictTag } from '#/components/dict-tag';
import { getRangePickerDefaultProps } from '#/utils/rangePickerProps';
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
import { formatDateTime } from '@vben/utils';
 
#if ($table.templateType == 11) ## erp
import { useVbenModal } from '@vben/common-ui';
import { useTableToolbar, VbenVxeTableToolbar } from '@vben/plugins/vxe-table';
import ${subSimpleClassName}Form from './${subSimpleClassName_strikeCase}-form.vue'
import { Tinymce as RichTextarea } from '#/components/tinymce';
import { ImageUpload, FileUpload } from "#/components/upload";
import { message, Button, Card, Tabs, Pagination, Form, Input, Textarea, Select, RadioGroup, Radio, CheckboxGroup, Checkbox, RangePicker, DatePicker, TreeSelect } from 'ant-design-vue';
import { Plus, Trash2 } from '@vben/icons';
import { $t } from '#/locales';
#end
 
#if ($table.templateType == 11) ## erp
import { delete${subSimpleClassName},#if ($deleteBatchEnable) delete${subSimpleClassName}List,#end get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}';
import { isEmpty, cloneDeep } from '@vben/utils';
#else
#if ($subTable.subJoinMany) ## 一对多
import { get${subSimpleClassName}ListBy${SubJoinColumnName} } from '#/api/${table.moduleName}/${table.businessName}';
#else
import { get${subSimpleClassName}By${SubJoinColumnName} } from '#/api/${table.moduleName}/${table.businessName}';
#end
#end
 
const props = defineProps<{
  ${subJoinColumn.javaField}?: number // ${subJoinColumn.columnComment}(主表的关联字段)
}>()
 
#if ($table.templateType == 11) ## erp
const [FormModal, formModalApi] = useVbenModal({
  connectedComponent: ${subSimpleClassName}Form,
  destroyOnClose: true,
});
 
/** 创建${subTable.classComment} */
function handleCreate() {
  if (!props.${subJoinColumn.javaField}){
    message.warning("请先选择一个${table.classComment}!")
    return
  }
  formModalApi.setData({${subJoinColumn.javaField}: props.${subJoinColumn.javaField}}).open();
}
 
/** 编辑${subTable.classComment} */
function handleEdit(row: ${simpleClassName}Api.${subSimpleClassName}) {
  formModalApi.setData(row).open();
}
 
/** 删除${subTable.classComment} */
async function handleDelete(row: ${simpleClassName}Api.${subSimpleClassName}) {
  const hideLoading = message.loading({
    content: $t('ui.actionMessage.deleting', [row.id]),
    duration: 0,
  });
  try {
    await delete${subSimpleClassName}(row.id!);
    message.success($t('ui.actionMessage.deleteSuccess', [row.id]));
    await getList();
  } finally {
    hideLoading();
  }
}
 
#if ($deleteBatchEnable)
/** 批量删除${subTable.classComment} */
async function handleDeleteBatch() {
  const hideLoading = message.loading({
    content: $t('ui.actionMessage.deleting'),
    duration: 0,
  });
  try {
    await delete${subSimpleClassName}List(checkedIds.value);
    checkedIds.value = [];
    message.success($t('ui.actionMessage.deleteSuccess'));
    await getList();
  } finally {
    hideLoading();
  }
}
 
const checkedIds = ref<number[]>([])
function handleRowCheckboxChange({
  records,
}: {
  records: ${simpleClassName}Api.${subSimpleClassName}[];
}) {
  checkedIds.value = records.map((item) => item.id!);
}
#end
#end
 
const loading = ref(true) // 列表的加载中
const list = ref<${simpleClassName}Api.${subSimpleClassName}[]>([]) // 列表的数据
#if ($table.templateType == 11) ## erp
const total = ref(0) // 列表的总页数
#end
#if ($table.templateType == 11) ## erp
const queryFormRef = ref() // 搜索的表单
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  #foreach ($column in $subColumns)
    #if ($column.listOperation)
      #if ($column.listOperationCondition != 'BETWEEN')
            $column.javaField: undefined,
      #end
      #if ($column.htmlType == "datetime" || $column.listOperationCondition == "BETWEEN")
            $column.javaField: undefined,
      #end
    #end
  #end
})
 
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.pageNo = 1
  getList()
}
 
/** 重置按钮操作 */
function resetQuery() {
  queryFormRef.value.resetFields()
  handleQuery()
}
#end
  /** 查询列表 */
async function getList() {
  loading.value = true
  try {
    if (!props.${subJoinColumn.javaField}){
      return []
    }
      ## 特殊:树表专属逻辑(树不需要分页接口)
      #if ($table.templateType == 11) ## erp
        const params = cloneDeep(queryParams) as any;
          #foreach ($column in $columns)
              #if ($column.listOperation)
                  #if ($column.htmlType == "datetime" || $column.listOperationCondition == "BETWEEN")
                    if (params.${column.javaField} && Array.isArray(params.${column.javaField})) {
                      params.${column.javaField} = (params.${column.javaField} as string[]).join(',');
                    }
                  #end
              #end
          #end
        params.${subJoinColumn.javaField} = props.${subJoinColumn.javaField};
        const data = await get${subSimpleClassName}Page(params)
        list.value = data.list
        total.value = data.total
      #else
          #if ($subTable.subJoinMany) ## 一对多
           list.value = await get${subSimpleClassName}ListBy${SubJoinColumnName}(props.${subJoinColumn.javaField}!);
          #else
           list.value = [await get${subSimpleClassName}By${SubJoinColumnName}(props.${subJoinColumn.javaField}!)];
          #end
      #end
  } finally {
    loading.value = false
  }
}
 
/** 监听主表的关联字段的变化,加载对应的子表数据 */
watch(
  () => props.${subJoinColumn.javaField},
  async (val) => {
    if (!val) {
      return;
    }
    await nextTick();
    await getList()
  },
  { immediate: true },
);
 
#if ($table.templateType == 11) ## erp
/** 初始化 */
const { hiddenSearchBar, tableToolbarRef, tableRef } = useTableToolbar();
onMounted(() => {
  getList();
});
#end
</script>
 
<template>
    #if ($table.templateType == 11) ## erp
      <FormModal @success="getList" />
      <div class="h-[600px]">
        <Card v-if="!hiddenSearchBar" class="mb-4">
          <!-- 搜索工作栏 -->
          <Form
              :model="queryParams"
              ref="queryFormRef"
              layout="inline"
          >
              #foreach($column in $subColumns)
                  #if ($column.listOperation)
                      #set ($dictType = $column.dictType)
                      #set ($javaField = $column.javaField)
                      #set ($javaType = $column.javaType)
                      #set ($comment = $column.columnComment)
                      #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
                          #set ($dictMethod = "number")
                      #elseif ($javaType == "String")
                          #set ($dictMethod = "string")
                      #elseif ($javaType == "Boolean")
                          #set ($dictMethod = "boolean")
                      #end
                      #if ($column.htmlType == "input")
                        <Form.Item label="${comment}" name="${javaField}">
                          <Input
                              v-model:value="queryParams.${javaField}"
                              placeholder="请输入${comment}"
                              allowClear
                              @pressEnter="handleQuery"
                              class="w-full"
                          />
                        </Form.Item>
                      #elseif ($column.htmlType == "select" || $column.htmlType == "radio" || $column.htmlType == "checkbox")
                        <Form.Item label="${comment}" name="${javaField}">
                          <Select
                              v-model:value="queryParams.${javaField}"
                              placeholder="请选择${comment}"
                              allowClear
                              class="w-full"
                          >
                              #if ("" != $dictType)## 设置了 dictType 数据字典的情况
                                <Select.Option
                                    v-for="dict in getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod')"
                                    :key="dict.value"
                                    :value="dict.value"
                                >
                                  {{ dict.label }}
                                </Select.Option>
                              #else## 未设置 dictType 数据字典的情况
                                <Select.Option label="请选择字典生成" value="" />
                              #end
                          </Select>
                        </Form.Item>
                      #elseif($column.htmlType == "datetime")
                          #if ($column.listOperationCondition != "BETWEEN")## 非范围
                            <Form.Item label="${comment}" name="${javaField}">
                              <DatePicker
                                  v-model:value="queryParams.${javaField}"
                                  valueFormat="YYYY-MM-DD"
                                  placeholder="选择${comment}"
                                  allowClear
                                  class="w-full"
                              />
                            </Form.Item>
                          #else## 范围
                            <Form.Item label="${comment}" name="${javaField}">
                              <RangePicker
                                  v-model:value="queryParams.${javaField}"
                                  v-bind="getRangePickerDefaultProps()"
                                  class="w-full"
                              />
                            </Form.Item>
                          #end
                      #end
                  #end
              #end
            <Form.Item>
              <Button class="ml-2" @click="resetQuery"> 重置 </Button>
              <Button class="ml-2" @click="handleQuery" type="primary">
                搜索
              </Button>
            </Form.Item>
          </Form>
        </Card>
 
        <!-- 列表 -->
        <Card title="${table.classComment}">
          <template #extra>
            <VbenVxeTableToolbar
                ref="tableToolbarRef"
                v-model:hidden-search="hiddenSearchBar"
            >
              <Button
                  class="ml-2"
                  :icon="h(Plus)"
                  type="primary"
                  @click="handleCreate"
                  v-access:code="['${permissionPrefix}:create']"
              >
                {{ $t('ui.actionTitle.create', ['${table.classComment}']) }}
              </Button>
                #if ($deleteBatchEnable)
                  <Button
                      :icon="h(Trash2)"
                      type="primary"
                      danger
                      class="ml-2"
                      :disabled="isEmpty(checkedIds)"
                      @click="handleDeleteBatch"
                      v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:delete']"
                  >
                    批量删除
                  </Button>
                #end
            </VbenVxeTableToolbar>
          </template>
          <VxeTable
              ref="tableRef"
              :data="list"
              show-overflow
              :loading="loading"
              #if ($deleteBatchEnable)
              @checkboxAll="handleRowCheckboxChange"
              @checkboxChange="handleRowCheckboxChange"
              #end
          >
              #if ($deleteBatchEnable)
                <VxeColumn type="checkbox" width="40" />
              #end
              #foreach($column in $subColumns)
                  #if ($column.listOperationResult)
                      #set ($dictType=$column.dictType)
                      #set ($javaField = $column.javaField)
                      #set ($comment=$column.columnComment)
                      #if ($column.javaType == "LocalDateTime")## 时间类型
                        <VxeColumn field="${javaField}" title="${comment}" align="center">
                          <template #default="{row}">
                            {{formatDateTime(row.${javaField})}}
                          </template>
                        </VxeColumn>
                      #elseif($column.dictType && "" != $column.dictType)## 数据字典
                        <VxeColumn field="${javaField}" title="${comment}" align="center">
                          <template #default="{row}">
                            <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="row.${javaField}" />
                          </template>
                        </VxeColumn>
                      #elseif ($table.templateType == 2 && $javaField == $treeNameColumn.javaField)
                        <VxeColumn field="${javaField}" title="${comment}" align="center"  tree-node/>
                      #else
                        <VxeColumn field="${javaField}" title="${comment}" align="center" />
                      #end
                  #end
              #end
            <VxeColumn field="operation" title="操作" align="center">
              <template #default="{row}">
                <Button
                    size="small"
                    type="link"
                    @click="handleEdit(row)"
                    v-access:code="['${permissionPrefix}:update']"
                >
                  {{ $t('ui.actionTitle.edit') }}
                </Button>
                <Button
                    size="small"
                    type="link"
                    danger
                    class="ml-2"
                    @click="handleDelete(row)"
                    v-access:code="['${permissionPrefix}:delete']"
                >
                  {{ $t('ui.actionTitle.delete') }}
                </Button>
              </template>
            </VxeColumn>
          </VxeTable>
          <!-- 分页 -->
          <div class="mt-2 flex justify-end">
            <Pagination
                :total="total"
                v-model:current="queryParams.pageNo"
                v-model:page-size="queryParams.pageSize"
                show-size-changer
                @change="getList"
            />
          </div>
        </Card>
      </div>
    #else
    <Card title="${subTable.classComment}列表">
      <VxeTable
          :data="list"
          show-overflow
          :loading="loading"
      >
          #foreach($column in $subColumns)
              #if ($column.listOperationResult)
                  #set ($dictType=$column.dictType)
                  #set ($javaField = $column.javaField)
                  #set ($comment=$column.columnComment)
                  #if ($column.javaType == "LocalDateTime")## 时间类型
                    <VxeColumn field="${javaField}" title="${comment}" align="center">
                      <template #default="{row}">
                        {{formatDateTime(row.${javaField})}}
                      </template>
                    </VxeColumn>
                  #elseif($column.dictType && "" != $column.dictType)## 数据字典
                    <VxeColumn field="${javaField}" title="${comment}" align="center">
                      <template #default="{row}">
                        <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="row.${javaField}" />
                      </template>
                    </VxeColumn>
                  #else
                    <VxeColumn field="${javaField}" title="${comment}" align="center" />
                  #end
              #end
          #end
      </VxeTable>
    </Card>
    #end
</template>