修修改改,缝缝补补
This commit is contained in:
parent
ae8b5756c3
commit
1371f42ef3
@ -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-card>
|
||||||
<el-table
|
<el-table
|
||||||
v-loading="loading"
|
v-loading="loading"
|
||||||
:data="list"
|
:data="treeTableData"
|
||||||
:stripe="true"
|
style="width: 100%"
|
||||||
:show-overflow-tooltip="true"
|
row-key="id"
|
||||||
:header-cell-style="{ background: 'rgb(235, 241, 250)', height: '56px', color: '#333333' }"
|
border
|
||||||
:row-style="{ height: '56px' }"
|
default-expand-all
|
||||||
|
:tree-props="{ children: 'children' }"
|
||||||
@row-click="handleRowClick"
|
@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 prop="type" label="模板类型" width="180" />
|
||||||
<el-table-column label="模板名称" align="center" prop="contentName" />
|
<el-table-column prop="category" label="模板类别" width="180" />
|
||||||
<el-table-column label="模板内容" align="center" prop="content" />
|
<el-table-column prop="contentName" label="模板名称" />
|
||||||
<el-table-column label="模板类型" align="center" prop="type" />
|
<el-table-column prop="content" label="模板内容" />
|
||||||
</el-table>
|
</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('模板应用成功')
|
||||||
})
|
})
|
||||||
|
@ -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">
|
||||||
|
Loading…
Reference in New Issue
Block a user