代码生成:重构 vue2 模版,适配树表和主子表
parent
737ea4635c
commit
80db28ee5b
@ -1,181 +1,164 @@
|
|||||||
#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 ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
|
||||||
<template>
|
<template>
|
||||||
<!-- 列表 -->
|
<div class="app-container">
|
||||||
<ContentWrap>
|
|
||||||
#if ($table.templateType == 11)
|
#if ($table.templateType == 11)
|
||||||
<el-button
|
<!-- 操作工具栏 -->
|
||||||
type="primary"
|
<el-row :gutter="10" class="mb8">
|
||||||
plain
|
<el-col :span="1.5">
|
||||||
@click="openForm('create')"
|
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)"
|
||||||
v-hasPermi="['${permissionPrefix}:create']"
|
v-hasPermi="['${permissionPrefix}:create']">新增</el-button>
|
||||||
>
|
</el-col>
|
||||||
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
</el-row>
|
||||||
</el-button>
|
|
||||||
#end
|
#end
|
||||||
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
|
## 列表
|
||||||
#foreach($column in $subColumns)
|
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
|
||||||
#if ($column.listOperationResult)
|
#foreach($column in $subColumns)
|
||||||
#set ($dictType=$column.dictType)
|
#if ($column.listOperationResult)
|
||||||
#set ($javaField = $column.javaField)
|
#set ($dictType=$column.dictType)
|
||||||
#set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
#set ($javaField = $column.javaField)
|
||||||
#set ($comment=$column.columnComment)
|
#set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
#if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
|
#set ($comment=$column.columnComment)
|
||||||
#elseif ($column.javaType == "LocalDateTime")## 时间类型
|
#if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
|
||||||
<el-table-column
|
#elseif ($column.javaType == "LocalDateTime")## 时间类型
|
||||||
label="${comment}"
|
<el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
|
||||||
align="center"
|
<template v-slot="scope">
|
||||||
prop="${javaField}"
|
<span>{{ parseTime(scope.row.${javaField}) }}</span>
|
||||||
:formatter="dateFormatter"
|
</template>
|
||||||
width="180px"
|
</el-table-column>
|
||||||
/>
|
#elseif($column.dictType && "" != $column.dictType)## 数据字典
|
||||||
#elseif($column.dictType && "" != $column.dictType)## 数据字典
|
<el-table-column label="${comment}" align="center" prop="${javaField}">
|
||||||
<el-table-column label="${comment}" align="center" prop="${javaField}">
|
<template v-slot="scope">
|
||||||
<template #default="scope">
|
<dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.${column.javaField}" />
|
||||||
<dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.${column.javaField}" />
|
</template>
|
||||||
</template>
|
</el-table-column>
|
||||||
</el-table-column>
|
#else
|
||||||
#else
|
<el-table-column label="${comment}" align="center" prop="${javaField}" />
|
||||||
<el-table-column label="${comment}" align="center" prop="${javaField}" />
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
#if ($table.templateType == 11)
|
<template v-slot="scope">
|
||||||
<el-table-column label="操作" align="center">
|
<el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.${primaryColumn.javaField})"
|
||||||
<template #default="scope">
|
v-hasPermi="['${permissionPrefix}:update']">修改</el-button>
|
||||||
<el-button
|
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
|
||||||
link
|
v-hasPermi="['${permissionPrefix}:delete']">删除</el-button>
|
||||||
type="primary"
|
</template>
|
||||||
@click="openForm('update', scope.row.id)"
|
</el-table-column>
|
||||||
v-hasPermi="['${permissionPrefix}:update']"
|
</el-table>
|
||||||
>
|
|
||||||
编辑
|
|
||||||
</el-button>
|
|
||||||
<el-button
|
|
||||||
link
|
|
||||||
type="danger"
|
|
||||||
@click="handleDelete(scope.row.id)"
|
|
||||||
v-hasPermi="['${permissionPrefix}:delete']"
|
|
||||||
>
|
|
||||||
删除
|
|
||||||
</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
#end
|
|
||||||
</el-table>
|
|
||||||
#if ($table.templateType == 11)
|
|
||||||
<!-- 分页 -->
|
|
||||||
<Pagination
|
|
||||||
:total="total"
|
|
||||||
v-model:page="queryParams.pageNo"
|
|
||||||
v-model:limit="queryParams.pageSize"
|
|
||||||
@pagination="getList"
|
|
||||||
/>
|
|
||||||
#end
|
|
||||||
</ContentWrap>
|
|
||||||
#if ($table.templateType == 11)
|
#if ($table.templateType == 11)
|
||||||
<!-- 表单弹窗:添加/修改 -->
|
<!-- 分页组件 -->
|
||||||
<${subSimpleClassName}Form ref="formRef" @success="getList" />
|
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
|
||||||
|
@pagination="getList"/>
|
||||||
|
<!-- 对话框(添加 / 修改) -->
|
||||||
|
<${subSimpleClassName}Form ref="formRef" @success="getList" />
|
||||||
#end
|
#end
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
|
||||||
import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
|
|
||||||
import { dateFormatter } from '@/utils/formatTime'
|
|
||||||
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
|
|
||||||
#if ($table.templateType == 11)
|
|
||||||
import ${subSimpleClassName}Form from './${subSimpleClassName}Form.vue'
|
|
||||||
#end
|
|
||||||
|
|
||||||
const { t } = useI18n() // 国际化
|
|
||||||
const message = useMessage() // 消息弹窗
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
${subJoinColumn.javaField}: undefined // ${subJoinColumn.columnComment}(主表的关联字段)
|
|
||||||
}>()
|
|
||||||
const loading = ref(false) // 列表的加载中
|
|
||||||
const list = ref([]) // 列表的数据
|
|
||||||
#if ($table.templateType == 11)
|
|
||||||
const total = ref(0) // 列表的总页数
|
|
||||||
const queryParams = reactive({
|
|
||||||
pageNo: 1,
|
|
||||||
pageSize: 10,
|
|
||||||
${subJoinColumn.javaField}: undefined
|
|
||||||
})
|
|
||||||
|
|
||||||
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
<script>
|
||||||
watch(
|
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
|
||||||
() => props.${subJoinColumn.javaField},
|
#if ($table.templateType == 11)
|
||||||
(val) => {
|
import ${subSimpleClassName}Form from './${subSimpleClassName}Form.vue'
|
||||||
queryParams.${subJoinColumn.javaField} = val
|
|
||||||
handleQuery()
|
|
||||||
},
|
|
||||||
{ immediate: false }
|
|
||||||
)
|
|
||||||
#end
|
|
||||||
|
|
||||||
/** 查询列表 */
|
|
||||||
const getList = async () => {
|
|
||||||
loading.value = true
|
|
||||||
try {
|
|
||||||
#if ($table.templateType == 11)
|
|
||||||
const data = await ${simpleClassName}Api.get${subSimpleClassName}Page(queryParams)
|
|
||||||
list.value = data.list
|
|
||||||
total.value = data.total
|
|
||||||
#else
|
|
||||||
#if ( $subTable.subJoinMany )
|
|
||||||
list.value = await ${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(props.${subJoinColumn.javaField})
|
|
||||||
#else
|
|
||||||
const data = await ${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(props.${subJoinColumn.javaField})
|
|
||||||
if (!data) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
list.value.push(data)
|
|
||||||
#end
|
#end
|
||||||
|
export default {
|
||||||
|
name: "${subSimpleClassName}List",
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
components: {
|
||||||
|
${subSimpleClassName}Form
|
||||||
|
},
|
||||||
#end
|
#end
|
||||||
} finally {
|
props:[
|
||||||
loading.value = false
|
'${subJoinColumn.javaField}'
|
||||||
}
|
],// ${subJoinColumn.columnComment}(主表的关联字段)
|
||||||
}
|
data() {
|
||||||
|
return {
|
||||||
/** 搜索按钮操作 */
|
// 遮罩层
|
||||||
const handleQuery = () => {
|
loading: true,
|
||||||
queryParams.pageNo = 1
|
// 列表的数据
|
||||||
getList()
|
list: [],
|
||||||
}
|
|
||||||
#if ($table.templateType == 11)
|
#if ($table.templateType == 11)
|
||||||
|
// 列表的总页数
|
||||||
/** 添加/修改操作 */
|
total: 0,
|
||||||
const formRef = ref()
|
// 查询参数
|
||||||
const openForm = (type: string, id?: number) => {
|
queryParams: {
|
||||||
if (!props.${subJoinColumn.javaField}) {
|
pageNo: 1,
|
||||||
message.error('请选择一个${table.classComment}')
|
pageSize: 10,
|
||||||
return
|
${subJoinColumn.javaField}: undefined
|
||||||
}
|
}
|
||||||
formRef.value.open(type, id, props.${subJoinColumn.javaField})
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 删除按钮操作 */
|
|
||||||
const handleDelete = async (id: number) => {
|
|
||||||
try {
|
|
||||||
// 删除的二次确认
|
|
||||||
await message.delConfirm()
|
|
||||||
// 发起删除
|
|
||||||
await ${simpleClassName}Api.delete${subSimpleClassName}(id)
|
|
||||||
message.success(t('common.delSuccess'))
|
|
||||||
// 刷新列表
|
|
||||||
await getList()
|
|
||||||
} catch {}
|
|
||||||
}
|
|
||||||
#end
|
#end
|
||||||
|
};
|
||||||
|
},
|
||||||
#if ($table.templateType != 11)
|
#if ($table.templateType != 11)
|
||||||
|
created() {
|
||||||
/** 初始化 **/
|
this.getList();
|
||||||
onMounted(() => {
|
},
|
||||||
getList()
|
#end
|
||||||
})
|
watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
${subJoinColumn.javaField}:{
|
||||||
|
handler(val) {
|
||||||
|
this.queryParams.${subJoinColumn.javaField} = val
|
||||||
|
this.handleQuery()
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
/** 查询列表 */
|
||||||
|
getList() {
|
||||||
|
try {
|
||||||
|
this.loading = true;
|
||||||
|
const that = this;
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
${simpleClassName}Api.get${subSimpleClassName}Page(this.queryParams).then(response => {
|
||||||
|
that.list = response.data.list;
|
||||||
|
that.total = response.data.total;
|
||||||
|
});
|
||||||
|
#else
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(this.${subJoinColumn.javaField}).then(response=>{
|
||||||
|
that.list = response.data;
|
||||||
|
})
|
||||||
|
#else
|
||||||
|
${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(this.${subJoinColumn.javaField}).then(response=>{
|
||||||
|
const data = response.data;
|
||||||
|
if (!data) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
that.list.push(data)
|
||||||
|
})
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
handleQuery() {
|
||||||
|
this.queryParams.pageNo = 1;
|
||||||
|
this.getList();
|
||||||
|
},
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
/** 添加/修改操作 */
|
||||||
|
openForm(id) {
|
||||||
|
if (!this.${subJoinColumn.javaField}) {
|
||||||
|
that.#[[$modal]]#.msgError('请选择一个${table.classComment}');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.#[[$]]#refs["formRef"].open(id, this.${subJoinColumn.javaField});
|
||||||
|
},
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
handleDelete(row) {
|
||||||
|
const that = this;
|
||||||
|
try {
|
||||||
|
const ${primaryColumn.javaField} = row.${primaryColumn.javaField};
|
||||||
|
this.#[[$modal]]#.confirm('是否确认删除${table.classComment}编号为"' + ${primaryColumn.javaField} + '"的数据项?').then(()=>{
|
||||||
|
return ${simpleClassName}Api.delete${subSimpleClassName}(${primaryColumn.javaField});
|
||||||
|
}).then(() => {
|
||||||
|
that.getList();
|
||||||
|
that.#[[$modal]]#.msgSuccess("删除成功");
|
||||||
|
}).catch(() => {});
|
||||||
|
} catch {}
|
||||||
|
},
|
||||||
|
}
|
||||||
#end
|
#end
|
||||||
</script>
|
};
|
||||||
|
</script>
|
||||||
|
|||||||
Loading…
Reference in New Issue