修改树形展示
This commit is contained in:
parent
19c47c79a0
commit
ae8b5756c3
@ -1,45 +1,55 @@
|
|||||||
import request from '@/config/axios'
|
import request from '@/config/axios'
|
||||||
|
|
||||||
// 汇总模板 VO
|
// 汇总模板 VO
|
||||||
export interface TemplateVO {
|
export interface TemplateVO {
|
||||||
id: number // 主键id
|
id: number // 主键id
|
||||||
type: string // 类型
|
type: string // 类型
|
||||||
status: string // 状态
|
status: string // 状态
|
||||||
content: string // 模板内容
|
content: string // 模板内容
|
||||||
orderNum: number // 排序
|
orderNum: number // 排序
|
||||||
createId: string // 创建人
|
createId: string // 创建人
|
||||||
contentName: string // 模板名称
|
contentName: string // 模板名称
|
||||||
}
|
category: string // 模板类别
|
||||||
|
}
|
||||||
// 汇总模板 API
|
|
||||||
export const TemplateApi = {
|
// 汇总模板 API
|
||||||
// 查询汇总模板分页
|
export const TemplateApi = {
|
||||||
getTemplatePage: async (params: any) => {
|
// 查询汇总模板分页
|
||||||
return await request.get({ url: `/inspect/template/page`, params })
|
getTemplatePage: async (params: any) => {
|
||||||
},
|
return await request.get({ url: `/inspect/template/page`, params })
|
||||||
|
},
|
||||||
// 查询汇总模板详情
|
|
||||||
getTemplate: async (id: number) => {
|
// 查询汇总模板详情
|
||||||
return await request.get({ url: `/inspect/template/get?id=` + id })
|
getTemplate: async (id: number) => {
|
||||||
},
|
return await request.get({ url: `/inspect/template/get?id=` + id })
|
||||||
|
},
|
||||||
// 新增汇总模板
|
|
||||||
createTemplate: async (data: TemplateVO) => {
|
// 新增汇总模板
|
||||||
return await request.post({ url: `/inspect/template/create`, data })
|
createTemplate: async (data: TemplateVO) => {
|
||||||
},
|
return await request.post({ url: `/inspect/template/create`, data })
|
||||||
|
},
|
||||||
// 修改汇总模板
|
|
||||||
updateTemplate: async (data: TemplateVO) => {
|
// 修改汇总模板
|
||||||
return await request.put({ url: `/inspect/template/update`, data })
|
updateTemplate: async (data: TemplateVO) => {
|
||||||
},
|
return await request.put({ url: `/inspect/template/update`, data })
|
||||||
|
},
|
||||||
// 删除汇总模板
|
|
||||||
deleteTemplate: async (id: number) => {
|
// 删除汇总模板
|
||||||
return await request.delete({ url: `/inspect/template/delete?id=` + id })
|
deleteTemplate: async (id: number) => {
|
||||||
},
|
return await request.delete({ url: `/inspect/template/delete?id=` + id })
|
||||||
|
},
|
||||||
// 导出汇总模板 Excel
|
|
||||||
exportTemplate: async (params) => {
|
// 导出汇总模板 Excel
|
||||||
return await request.download({ url: `/inspect/template/export-excel`, params })
|
exportTemplate: async (params) => {
|
||||||
},
|
return await request.download({ url: `/inspect/template/export-excel`, params })
|
||||||
}
|
},
|
||||||
|
|
||||||
|
//根据模版类型获取所属模版类别
|
||||||
|
getCategory: async (type: string) => {
|
||||||
|
return await request.get({ url: `/inspect/template/getcategory?type=` + type })
|
||||||
|
},
|
||||||
|
// 获取所有模板类别
|
||||||
|
getAllCategories: async () => {
|
||||||
|
return await request.get({ url: `/inspect/template/getAllCategories` })
|
||||||
|
},
|
||||||
|
}
|
||||||
|
@ -7,11 +7,8 @@
|
|||||||
label-width="100px"
|
label-width="100px"
|
||||||
v-loading="formLoading"
|
v-loading="formLoading"
|
||||||
>
|
>
|
||||||
<el-form-item label="模板名称" prop="contentName">
|
<el-form-item label="模板类型" prop="type">
|
||||||
<el-input v-model="formData.contentName" placeholder="请输入模板名称" />
|
<el-select v-model="formData.type" placeholder="请选择模板类型" clearable>
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="模板类型" prop="type">
|
|
||||||
<el-select v-model="formData.type" placeholder="请选择模板类型">
|
|
||||||
<el-option label="一般检查" value="一般检查" />
|
<el-option label="一般检查" value="一般检查" />
|
||||||
<el-option label="超声" value="超声" />
|
<el-option label="超声" value="超声" />
|
||||||
<el-option label="心电图" value="心电图" />
|
<el-option label="心电图" value="心电图" />
|
||||||
@ -22,6 +19,15 @@
|
|||||||
<el-option label="汇总" value="汇总" />
|
<el-option label="汇总" value="汇总" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item label="模板类别" prop="category">
|
||||||
|
<el-select v-model="formData.category" placeholder="请选择模板类别" clearable :loading="loadingCategories">
|
||||||
|
<el-option v-for="item in categoryOptions" :key="item" :label="item" :value="item" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="模板名称" prop="contentName">
|
||||||
|
<el-input v-model="formData.contentName" placeholder="请输入模板名称" />
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item label="状态" prop="status">
|
<el-form-item label="状态" prop="status">
|
||||||
<el-radio-group v-model="formData.status">
|
<el-radio-group v-model="formData.status">
|
||||||
<el-radio-button label="启用" value="1" />
|
<el-radio-button label="启用" value="1" />
|
||||||
@ -48,6 +54,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { TemplateApi, TemplateVO } from '@/api/inspect/inspecttemplate'
|
import { TemplateApi, TemplateVO } from '@/api/inspect/inspecttemplate'
|
||||||
|
import { watch } from 'vue'
|
||||||
|
|
||||||
/** 汇总模板 表单 */
|
/** 汇总模板 表单 */
|
||||||
defineOptions({ name: 'TemplateForm' })
|
defineOptions({ name: 'TemplateForm' })
|
||||||
@ -67,22 +74,66 @@ const formData = ref({
|
|||||||
orderNum: undefined,
|
orderNum: undefined,
|
||||||
createId: undefined,
|
createId: undefined,
|
||||||
contentName: undefined,
|
contentName: undefined,
|
||||||
|
category: undefined,
|
||||||
})
|
})
|
||||||
const formRules = reactive({
|
const formRules = reactive({
|
||||||
})
|
})
|
||||||
const formRef = ref() // 表单 Ref
|
const formRef = ref() // 表单 Ref
|
||||||
|
|
||||||
|
// 类别选项列表
|
||||||
|
const categoryOptions = ref([])
|
||||||
|
// 是否正在加载类别选项
|
||||||
|
const loadingCategories = ref(false)
|
||||||
|
|
||||||
|
// 监听类型变化,获取对应的类别选项
|
||||||
|
watch(() => formData.value.type, async (newType) => {
|
||||||
|
if (newType) {
|
||||||
|
await loadCategoryOptions(newType)
|
||||||
|
} else {
|
||||||
|
// 如果类型被清空,也清空类别选项
|
||||||
|
categoryOptions.value = []
|
||||||
|
formData.value.category = undefined
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 根据类型加载类别选项的方法
|
||||||
|
const loadCategoryOptions = async (type) => {
|
||||||
|
if (!type) return
|
||||||
|
|
||||||
|
loadingCategories.value = true
|
||||||
|
// 不要在这里重置类别,这会导致编辑时的数据丢失
|
||||||
|
// formData.value.category = undefined
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 调用接口获取指定类型下的所有类别
|
||||||
|
categoryOptions.value = await TemplateApi.getCategory(type)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('加载类别选项失败', error)
|
||||||
|
message.error('加载类别选项失败')
|
||||||
|
categoryOptions.value = []
|
||||||
|
} finally {
|
||||||
|
loadingCategories.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** 打开弹窗 */
|
/** 打开弹窗 */
|
||||||
const open = async (type: string, id?: number) => {
|
const open = async (type: string, id?: number) => {
|
||||||
dialogVisible.value = true
|
dialogVisible.value = true
|
||||||
dialogTitle.value = t('action.' + type)
|
dialogTitle.value = t('action.' + type)
|
||||||
formType.value = type
|
formType.value = type
|
||||||
resetForm()
|
resetForm()
|
||||||
|
|
||||||
// 修改时,设置数据
|
// 修改时,设置数据
|
||||||
if (id) {
|
if (id) {
|
||||||
formLoading.value = true
|
formLoading.value = true
|
||||||
try {
|
try {
|
||||||
formData.value = await TemplateApi.getTemplate(id)
|
const templateData = await TemplateApi.getTemplate(id)
|
||||||
|
// 先加载该类型对应的类别选项,确保类别选项已加载
|
||||||
|
if (templateData.type) {
|
||||||
|
await loadCategoryOptions(templateData.type)
|
||||||
|
}
|
||||||
|
// 再设置表单数据
|
||||||
|
formData.value = templateData
|
||||||
} finally {
|
} finally {
|
||||||
formLoading.value = false
|
formLoading.value = false
|
||||||
}
|
}
|
||||||
@ -124,6 +175,7 @@ const resetForm = () => {
|
|||||||
orderNum: undefined,
|
orderNum: undefined,
|
||||||
createId: undefined,
|
createId: undefined,
|
||||||
contentName: undefined,
|
contentName: undefined,
|
||||||
|
category: undefined,
|
||||||
}
|
}
|
||||||
formRef.value?.resetFields()
|
formRef.value?.resetFields()
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,23 @@
|
|||||||
class="!w-240px"
|
class="!w-240px"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item label="模板类型" prop="type">
|
||||||
|
<el-select v-model="queryParams.type" placeholder="请选择模板类型" clearable class="!w-240px">
|
||||||
|
<el-option label="一般检查" value="一般检查" />
|
||||||
|
<el-option label="超声" value="超声" />
|
||||||
|
<el-option label="心电图" value="心电图" />
|
||||||
|
<el-option label="血常规" value="血常规" />
|
||||||
|
<el-option label="尿常规" value="尿常规" />
|
||||||
|
<el-option label="生化" value="生化" />
|
||||||
|
<el-option label="通用" value="通用" />
|
||||||
|
<el-option label="汇总" value="汇总" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="模板类别" prop="category">
|
||||||
|
<el-select v-model="queryParams.category" placeholder="请选择模板类别" clearable class="!w-240px">
|
||||||
|
<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
|
<el-button
|
||||||
type="primary"
|
type="primary"
|
||||||
@ -51,53 +68,50 @@
|
|||||||
</el-form>
|
</el-form>
|
||||||
</ContentWrap>
|
</ContentWrap>
|
||||||
|
|
||||||
<!-- 列表 -->
|
<!-- 树形结构展示 -->
|
||||||
<ContentWrap>
|
<ContentWrap>
|
||||||
<el-table
|
<el-card>
|
||||||
v-loading="loading"
|
<el-table
|
||||||
: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' }"
|
||||||
<el-table-column label="主键" align="center" prop="id" v-if="false" />
|
>
|
||||||
<el-table-column label="模板名称" align="center" prop="contentName" />
|
<el-table-column prop="type" label="模板类型" width="180" />
|
||||||
<el-table-column label="模板内容" align="center" prop="content" />
|
<el-table-column prop="category" label="模板类别" width="180" />
|
||||||
<el-table-column label="状态" align="center" prop="status">
|
<el-table-column prop="contentName" label="模板名称" />
|
||||||
<template #default="scope">
|
<el-table-column prop="content" label="模板内容" />
|
||||||
<el-tag :type="scope.row.status === '1' ? 'success' : 'danger'">
|
<el-table-column label="状态" align="center" width="100">
|
||||||
{{ scope.row.status === '1' ? '启用' : '禁用' }}
|
<template #default="scope">
|
||||||
</el-tag>
|
<el-tag v-if="scope.row.status" :type="scope.row.status === '1' ? 'success' : 'danger'">
|
||||||
</template>
|
{{ scope.row.status === '1' ? '启用' : '禁用' }}
|
||||||
</el-table-column>
|
</el-tag>
|
||||||
<el-table-column label="模板类型" align="center" prop="type" />
|
</template>
|
||||||
<el-table-column label="操作" align="center" min-width="120px">
|
</el-table-column>
|
||||||
<template #default="scope">
|
<el-table-column label="操作" align="center" width="150">
|
||||||
<el-button
|
<template #default="scope">
|
||||||
link
|
<el-button
|
||||||
type="primary"
|
v-if="scope.row.isLeaf"
|
||||||
@click="openForm('update', scope.row.id)"
|
link
|
||||||
>
|
type="primary"
|
||||||
编辑
|
@click="openForm('update', scope.row.id)"
|
||||||
</el-button>
|
>
|
||||||
<el-button
|
编辑
|
||||||
link
|
</el-button>
|
||||||
type="danger"
|
<el-button
|
||||||
@click="handleDelete(scope.row.id)"
|
v-if="scope.row.isLeaf"
|
||||||
>
|
link
|
||||||
删除
|
type="danger"
|
||||||
</el-button>
|
@click="handleDelete(scope.row.id)"
|
||||||
</template>
|
>
|
||||||
</el-table-column>
|
删除
|
||||||
</el-table>
|
</el-button>
|
||||||
<!-- 分页 -->
|
</template>
|
||||||
<Pagination
|
</el-table-column>
|
||||||
:total="total"
|
</el-table>
|
||||||
v-model:page="queryParams.pageNo"
|
</el-card>
|
||||||
v-model:limit="queryParams.pageSize"
|
|
||||||
@pagination="getList"
|
|
||||||
/>
|
|
||||||
</ContentWrap>
|
</ContentWrap>
|
||||||
|
|
||||||
<!-- 表单弹窗:添加/修改 -->
|
<!-- 表单弹窗:添加/修改 -->
|
||||||
@ -118,6 +132,7 @@ const { t } = useI18n() // 国际化
|
|||||||
const loading = ref(true) // 列表的加载中
|
const loading = ref(true) // 列表的加载中
|
||||||
const list = ref<TemplateVO[]>([]) // 列表的数据
|
const list = ref<TemplateVO[]>([]) // 列表的数据
|
||||||
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,
|
||||||
@ -127,10 +142,14 @@ const queryParams = reactive({
|
|||||||
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) // 导出的加载中
|
||||||
|
|
||||||
|
// 树形表格数据
|
||||||
|
const treeTableData = ref<any[]>([])
|
||||||
|
|
||||||
/** 查询列表 */
|
/** 查询列表 */
|
||||||
const getList = async () => {
|
const getList = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
@ -138,11 +157,27 @@ 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 获取所有模板类别 */
|
||||||
|
const getCategoryOptions = async () => {
|
||||||
|
try {
|
||||||
|
const categories = await TemplateApi.getAllCategories()
|
||||||
|
categoryOptions.value = categories.map(category => ({
|
||||||
|
label: category,
|
||||||
|
value: category
|
||||||
|
}))
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取模板类别失败:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** 搜索按钮操作 */
|
/** 搜索按钮操作 */
|
||||||
const handleQuery = () => {
|
const handleQuery = () => {
|
||||||
queryParams.pageNo = 1
|
queryParams.pageNo = 1
|
||||||
@ -189,8 +224,97 @@ const handleExport = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 转换列表数据为树形表格数据 */
|
||||||
|
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,
|
||||||
|
status: item.status,
|
||||||
|
isLeaf: true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// 转换为树形结构
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
/** 初始化 **/
|
/** 初始化 **/
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getList()
|
getList()
|
||||||
|
getCategoryOptions() // 获取所有模板类别
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.card-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
</style>
|
Loading…
Reference in New Issue
Block a user