修修改改,缝缝补补

This commit is contained in:
Euni4U 2025-03-28 17:12:23 +08:00
parent ae8b5756c3
commit 1371f42ef3
2 changed files with 134 additions and 18 deletions

View File

@ -37,6 +37,11 @@
<el-option label="汇总" value="汇总" />
</el-select>
</el-form-item>
<el-form-item label="模板类别" prop="category" class="w-200px">
<el-select v-model="queryParams.category" placeholder="请选择模板类别" clearable>
<el-option v-for="item in categoryOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
@ -46,20 +51,24 @@
<!-- 列表 -->
<ContentWrap>
<el-card>
<el-table
v-loading="loading"
:data="list"
:stripe="true"
:show-overflow-tooltip="true"
:header-cell-style="{ background: 'rgb(235, 241, 250)', height: '56px', color: '#333333' }"
:row-style="{ height: '56px' }"
:data="treeTableData"
style="width: 100%"
row-key="id"
border
default-expand-all
:tree-props="{ children: 'children' }"
@row-click="handleRowClick"
:header-cell-style="{ background: 'rgb(235, 241, 250)', height: '56px', color: '#333333' }"
>
<el-table-column label="主键" align="center" prop="id" v-if="false" />
<el-table-column label="模板名称" align="center" prop="contentName" />
<el-table-column label="模板内容" align="center" prop="content" />
<el-table-column label="模板类型" align="center" prop="type" />
<el-table-column prop="type" label="模板类型" width="180" />
<el-table-column prop="category" label="模板类别" width="180" />
<el-table-column prop="contentName" label="模板名称" />
<el-table-column prop="content" label="模板内容" />
</el-table>
</el-card>
<!-- 分页 -->
<Pagination
:total="total"
@ -80,7 +89,9 @@ const { t } = useI18n() // 国际化
const loading = ref(true) //
const list = ref<TemplateVO[]>([]) //
const treeTableData = ref<any[]>([]) //
const total = ref(0) //
const categoryOptions = ref<any[]>([]) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
@ -89,7 +100,8 @@ const queryParams = reactive({
status: undefined,
content: undefined,
orderNum: undefined,
contentName: undefined
contentName: undefined,
category: undefined
})
const queryFormRef = ref() //
const exportLoading = ref(false) //
@ -102,6 +114,8 @@ const getList = async () => {
const data = await TemplateApi.getTemplatePage(queryParams)
list.value = data.list
total.value = data.total
//
treeTableData.value = convertToTreeTableData(data.list)
} finally {
loading.value = false
}
@ -145,23 +159,123 @@ watch(visible, (newVal) => {
if (newVal) {
Type.value = props.templateType
getList()
getCategoryOptions() //
}
})
/** 获取所有模板类别 */
const getCategoryOptions = async () => {
try {
const categories = await TemplateApi.getAllCategories()
categoryOptions.value = categories.map(category => ({
label: category,
value: category
}))
} catch (error) {
console.error('获取模板类别失败:', error)
}
}
//
const handleClose = (done) => {
done()
}
/** 转换列表数据为树形表格数据 */
const convertToTreeTableData = (listData: TemplateVO[]) => {
const typeMap = new Map()
let uniqueId = 1000 // ID
//
listData.forEach(item => {
if (!typeMap.has(item.type)) {
typeMap.set(item.type, {
id: uniqueId++,
type: item.type,
category: '',
contentName: '',
content: '',
children: new Map(),
isLeaf: false
})
}
const typeNode = typeMap.get(item.type)
const categoryMap = typeNode.children
//
if (!categoryMap.has(item.category)) {
categoryMap.set(item.category, {
id: uniqueId++,
type: '',
category: item.category,
contentName: '',
content: '',
children: [],
isLeaf: false
})
}
//
categoryMap.get(item.category).children.push({
id: item.id,
type: '',
category: '',
contentName: item.contentName,
content: item.content,
isLeaf: true,
//
originalData: item
})
})
//
const result: any[] = []
typeMap.forEach(typeNode => {
const typeItem = {
id: typeNode.id,
type: typeNode.type,
category: typeNode.category,
contentName: typeNode.contentName,
content: typeNode.content,
isLeaf: typeNode.isLeaf,
children: [] as any[]
}
typeNode.children.forEach(categoryNode => {
const categoryItem = {
id: categoryNode.id,
type: categoryNode.type,
category: categoryNode.category,
contentName: categoryNode.contentName,
content: categoryNode.content,
isLeaf: categoryNode.isLeaf,
children: categoryNode.children
}
typeItem.children.push(categoryItem)
})
result.push(typeItem)
})
return result
}
//
const handleRowClick = (template) => {
//
if (!template.isLeaf) return
const templateData = template.originalData || template
ElMessageBox.confirm('确认要使用该模板吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(() => {
emit('select-template', template.content)
emit('select-template', templateData.content)
visible.value = false //
ElMessage.success('模板应用成功')
})

View File

@ -78,10 +78,12 @@
border
default-expand-all
:tree-props="{ children: 'children' }"
:header-cell-style="{ background: 'rgb(235, 241, 250)', height: '56px', color: '#333333' }"
:resizable="false"
>
<el-table-column prop="type" label="模板类型" width="180" />
<el-table-column prop="category" label="模板类别" width="180" />
<el-table-column prop="contentName" label="模板名称" />
<el-table-column prop="category" label="模板类别" width="200" />
<el-table-column prop="contentName" label="模板名称" width="300" />
<el-table-column prop="content" label="模板内容" />
<el-table-column label="状态" align="center" width="100">
<template #default="scope">