Files
pqs-9100_client/frontend/src/views/home/components/tree.vue

232 lines
5.4 KiB
Vue
Raw Normal View History

2024-08-23 13:19:20 +08:00
<template>
2024-10-11 08:49:31 +08:00
<div class='plan_tree'>
<div class='search_view'>
2024-08-27 18:37:46 +08:00
<el-input
2024-10-11 08:49:31 +08:00
placeholder='请输入计划名称'
2025-01-06 09:21:24 +08:00
clearable
2024-10-11 08:49:31 +08:00
v-model='searchForm.planName'
2024-08-27 18:37:46 +08:00
></el-input>
2025-02-13 15:40:13 +08:00
<el-tooltip content="检测计划列表" placement="top">
2024-10-11 08:49:31 +08:00
<Menu style='width: 26px;height: 26px; margin-left: 8px;cursor: pointer;color:var(--el-color-primary)'
@click.stop='detail()' />
2025-02-13 15:40:13 +08:00
</el-tooltip>
2024-08-27 18:37:46 +08:00
</div>
2024-10-11 08:49:31 +08:00
<div class='tree_container'>
2024-08-27 18:37:46 +08:00
<el-tree
2024-10-11 08:49:31 +08:00
:data='data'
ref='treeRef'
:filter-node-method='filterNode'
:props='defaultProps'
node-key='id'
2025-01-06 09:21:24 +08:00
class="filter-tree"
:highlight-current="true"
2024-08-27 18:37:46 +08:00
default-expand-all
2024-10-11 08:49:31 +08:00
:default-checked-keys='defaultChecked'
@node-click='handleNodeClick'
2024-08-27 18:37:46 +08:00
>
2024-10-11 08:49:31 +08:00
<template #default='{ node, data }'>
<span class='custom-tree-node' style='display: flex;align-items: center;'>
<Platform v-if='!data.pid' style='width:18px;height: 18px;margin-right:8px;'
2025-01-22 16:28:09 +08:00
:style="{color:node.label=='未检'?'#fac858':node.label=='检测中'?'#ee6666':'#91cc75'}" />
2024-08-27 15:40:58 +08:00
<span>{{ node.label }}</span>
2024-08-27 18:37:46 +08:00
<!-- <Menu v-if="data.pid" @click.stop="detail(data)" style="width: 12px;margin-left: 8px;"/> -->
2024-08-27 15:40:58 +08:00
</span>
</template>
</el-tree>
</div>
2024-08-23 13:19:20 +08:00
</div>
</template>
2024-10-11 08:49:31 +08:00
<script lang='ts' setup>
2024-12-13 16:35:27 +08:00
import { type Plan } from '@/api/plan/interface';
import { Menu, Platform, CircleCheck,Loading } from '@element-plus/icons-vue'
2025-01-06 09:21:24 +08:00
import { nextTick, onMounted, ref, watch } from 'vue';
2024-10-11 08:49:31 +08:00
import { useRouter } from 'vue-router'
2024-12-31 19:03:52 +08:00
import {useCheckStore} from "@/stores/modules/check";
2025-02-13 15:40:13 +08:00
import { ElTooltip } from 'element-plus';
2024-10-11 08:49:31 +08:00
const router = useRouter()
2024-12-31 19:03:52 +08:00
const checkStore = useCheckStore()
2025-01-06 09:21:24 +08:00
const filterText = ref('')
const treeRef = ref()
2024-10-11 08:49:31 +08:00
const data: any = ref([])
2024-08-23 13:19:20 +08:00
const defaultProps = {
2024-10-11 08:49:31 +08:00
children: 'children',
label: 'name',
pid: 'pid',
}
2024-08-23 13:19:20 +08:00
const searchForm = ref({
2024-10-11 08:49:31 +08:00
planName: '',
})
2025-01-03 11:27:36 +08:00
const defaultChecked = ref<string[]>([]) // 明确类型为 number[]
2025-02-11 10:32:09 +08:00
const tree = ref(false)//确保左侧树高凉只执行一次
2024-08-23 13:19:20 +08:00
const getTreeData = (val: any) => {
2025-02-11 10:32:09 +08:00
defaultChecked.value = [];
data.value = val;
2025-01-03 11:27:36 +08:00
2025-02-11 10:32:09 +08:00
for (let item of data.value) {
if (item.children.length > 0) {
let node = item.children[0];
defaultChecked.value.push(node.id);
checkStore.setPlan(node);
2025-02-11 10:32:09 +08:00
// 高亮显示第一个节点
// 使用 nextTick 确保在 DOM 更新后调用 setCurrentKey
nextTick(() => {
treeRef.value?.setCurrentKey(node.id);
idd.value = node.id;
});
// 找到第一个符合条件的 children 后跳出循环
break;
}
}
2024-10-11 08:49:31 +08:00
}
2025-01-06 09:21:24 +08:00
2025-01-16 14:24:55 +08:00
//点击表格后左侧树刷新,高亮显示对应节点
const clickTableToTree = (val: any,id:any) => {
2025-02-11 10:32:09 +08:00
2025-01-16 14:24:55 +08:00
defaultChecked.value = []
data.value = val
let node = ref('')
if (data.value.length > 0) {
for (let i = 0; i < data.value.length; i++){
for (let j = 0; j < data.value[i].children.length; j++) {
if (data.value[i].children[j].id == id) {
node.value = data.value[i].children[j].id
break;
}
}
}
// 使用 nextTick 确保在 DOM 更新后调用 setCurrentKey
nextTick(() => {
treeRef.value?.setCurrentKey(node.value);
idd.value = node.value
});
}
}
const {updateSelectedTreeNode} = defineProps<{
updateSelectedTreeNode:Function;
}>();
2024-08-23 13:19:20 +08:00
watch(
() => searchForm.value.planName,
(val) => {
2024-10-11 08:49:31 +08:00
treeRef.value!.filter(val)
2024-08-23 13:19:20 +08:00
},
{
deep: true,
2024-10-11 08:49:31 +08:00
},
)
2025-01-14 19:05:08 +08:00
const idd = ref('')
2024-12-13 16:35:27 +08:00
const handleNodeClick = (data: Plan.ResPlan) => {
2025-02-11 10:32:09 +08:00
if (data.name === '未检' || data.name === '检测中' || data.name === '检测完成') {
// 如果是父节点,不执行任何操作
//console.log('父节点不执行任何操作');
// 设置当前高亮节点
nextTick(() => {
treeRef.value?.setCurrentKey(idd.value);
});
2025-01-14 19:05:08 +08:00
return;
}
idd.value = data.id
checkStore.setPlan(data);
2024-12-13 16:35:27 +08:00
updateSelectedTreeNode(data.id)
2024-10-11 08:49:31 +08:00
}
2024-12-13 16:35:27 +08:00
const filterNode = (value: string, data: any) => {
2024-10-11 08:49:31 +08:00
if (!value) return true
2025-01-06 09:21:24 +08:00
return data.name.includes(value)
2024-10-11 08:49:31 +08:00
}
2025-01-06 09:21:24 +08:00
2024-08-27 15:40:58 +08:00
// 点击详情
2024-10-11 08:49:31 +08:00
const detail = () => {
2025-02-13 15:40:13 +08:00
router.push('/plan/planList')
2024-10-11 08:49:31 +08:00
}
2024-08-23 13:19:20 +08:00
onMounted(() => {
2024-11-14 18:26:34 +08:00
// console.log()
2024-10-11 08:49:31 +08:00
})
2025-01-16 14:24:55 +08:00
defineExpose({ getTreeData ,clickTableToTree})
2025-01-06 09:21:24 +08:00
2024-08-23 13:19:20 +08:00
</script>
2024-10-11 08:49:31 +08:00
<style lang='scss' scoped>
2024-08-23 13:19:20 +08:00
.plan_tree {
2024-12-04 21:36:12 +08:00
height: 100%;
display: flex;
flex-direction: column;
2025-01-06 14:07:21 +08:00
background-color: #fff;
2024-10-11 08:49:31 +08:00
2024-08-27 18:37:46 +08:00
.search_view {
width: 100%;
height: auto;
display: flex;
justify-content: space-between;
padding: 0 5px;
box-sizing: border-box;
align-items: center;
2024-10-11 08:49:31 +08:00
.el-input {
2024-08-27 18:37:46 +08:00
margin-top: 6px;
}
}
2024-10-11 08:49:31 +08:00
2024-08-23 13:19:20 +08:00
.el-input {
width: 100%;
margin: 0 10px 10px 0;
2024-08-23 13:19:20 +08:00
}
2024-08-27 15:40:58 +08:00
.tree_container {
2024-12-04 21:36:12 +08:00
height: 100%;
width: 100%;
flex: 1;
overflow-y: auto;
2024-12-04 21:36:12 +08:00
overflow-x: auto;
2024-08-27 15:40:58 +08:00
.el-tree {
2024-12-05 18:14:43 +08:00
// height: 100%;
2024-12-04 21:36:12 +08:00
width: auto;
}
2024-08-23 13:19:20 +08:00
}
}
2025-01-06 09:21:24 +08:00
2024-12-05 18:14:43 +08:00
.filter-tree {
// border: 1px solid #dcdfe6;
min-width: 100%;
2025-01-06 09:21:24 +08:00
height: 97%;
2024-12-05 18:14:43 +08:00
display: inline-block;
overflow: auto;
margin-top: 12px;
2025-01-06 14:07:21 +08:00
2024-12-05 18:14:43 +08:00
}
2024-12-05 21:33:52 +08:00
//.filter-tree span {
// font-size: 16px;
// display:block;
// overflow:hidden;
2024-12-05 18:14:43 +08:00
// word-break:keep-all;
// white-space:nowrap;
// text-overflow:ellipsis;
2024-12-05 21:33:52 +08:00
// padding-right: 12px;
//}
2024-12-05 18:14:43 +08:00
.leftBox {
// float: left;
// width: 20%;
height: 100%;
width: 100%;
}
.left {
height: calc(100% - 45px);
overflow: auto;
}
/* 设置滚动条宽度 */
:deep(.bodyTwo ::-webkit-scrollbar) {
width: 3px !important;
height: 6px !important;
}
2024-08-23 13:19:20 +08:00
</style>