修修改改,缝缝补补

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-option label="汇总" value="汇总" />
</el-select> </el-select>
</el-form-item> </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-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button> <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> <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
@ -46,20 +51,24 @@
<!-- 列表 --> <!-- 列表 -->
<ContentWrap> <ContentWrap>
<el-table <el-card>
v-loading="loading" <el-table
:data="list" v-loading="loading"
:stripe="true" :data="treeTableData"
:show-overflow-tooltip="true" style="width: 100%"
:header-cell-style="{ background: 'rgb(235, 241, 250)', height: '56px', color: '#333333' }" row-key="id"
:row-style="{ height: '56px' }" border
@row-click="handleRowClick" default-expand-all
> :tree-props="{ children: 'children' }"
<el-table-column label="主键" align="center" prop="id" v-if="false" /> @row-click="handleRowClick"
<el-table-column label="模板名称" align="center" prop="contentName" /> :header-cell-style="{ background: 'rgb(235, 241, 250)', height: '56px', color: '#333333' }"
<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> <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 <Pagination
:total="total" :total="total"
@ -80,7 +89,9 @@ const { t } = useI18n() // 国际化
const loading = ref(true) // const loading = ref(true) //
const list = ref<TemplateVO[]>([]) // const list = ref<TemplateVO[]>([]) //
const treeTableData = ref<any[]>([]) //
const total = ref(0) // const total = ref(0) //
const categoryOptions = ref<any[]>([]) //
const queryParams = reactive({ const queryParams = reactive({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
@ -89,7 +100,8 @@ const queryParams = reactive({
status: undefined, status: undefined,
content: undefined, content: undefined,
orderNum: undefined, orderNum: undefined,
contentName: undefined contentName: undefined,
category: undefined
}) })
const queryFormRef = ref() // const queryFormRef = ref() //
const exportLoading = ref(false) // const exportLoading = ref(false) //
@ -102,6 +114,8 @@ const getList = async () => {
const data = await TemplateApi.getTemplatePage(queryParams) const data = await TemplateApi.getTemplatePage(queryParams)
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
//
treeTableData.value = convertToTreeTableData(data.list)
} finally { } finally {
loading.value = false loading.value = false
} }
@ -145,23 +159,123 @@ watch(visible, (newVal) => {
if (newVal) { if (newVal) {
Type.value = props.templateType Type.value = props.templateType
getList() 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) => { const handleClose = (done) => {
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) => { const handleRowClick = (template) => {
//
if (!template.isLeaf) return
const templateData = template.originalData || template
ElMessageBox.confirm('确认要使用该模板吗?', '提示', { ElMessageBox.confirm('确认要使用该模板吗?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}) })
.then(() => { .then(() => {
emit('select-template', template.content) emit('select-template', templateData.content)
visible.value = false // visible.value = false //
ElMessage.success('模板应用成功') ElMessage.success('模板应用成功')
}) })

View File

@ -78,10 +78,12 @@
border border
default-expand-all default-expand-all
:tree-props="{ children: 'children' }" :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="type" label="模板类型" width="180" />
<el-table-column prop="category" label="模板类别" width="180" /> <el-table-column prop="category" label="模板类别" width="200" />
<el-table-column prop="contentName" label="模板名称" /> <el-table-column prop="contentName" label="模板名称" width="300" />
<el-table-column prop="content" label="模板内容" /> <el-table-column prop="content" label="模板内容" />
<el-table-column label="状态" align="center" width="100"> <el-table-column label="状态" align="center" width="100">
<template #default="scope"> <template #default="scope">