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

93 lines
2.0 KiB
Vue
Raw Normal View History

2024-08-23 13:19:20 +08:00
<template>
<div class="plan_tree">
2024-08-27 15:40:58 +08:00
<el-input placeholder="请输入计划名称" v-model="searchForm.planName"></el-input>
<div class="tree_container">
2024-08-27 15:40:58 +08:00
<el-tree :data="data" ref="treeRef" :filter-node-method="filterNode" :props="defaultProps" node-key="id"
default-expand-all :default-checked-keys="defaultChecked" @node-click="handleNodeClick">
<template #default="{ node, data }">
<span class="custom-tree-node">
<span>{{ node.label }}</span>
<Menu v-if="data.pid" @click.stop="detail(data)" style="width: 12px;margin-left: 8px;"/>
</span>
</template>
</el-tree>
</div>
2024-08-23 13:19:20 +08:00
</div>
</template>
<script lang="ts" setup>
import { ref, onMounted, defineExpose, watch } from "vue";
2024-08-27 15:40:58 +08:00
import {
Menu
} from '@element-plus/icons-vue'
const emit = defineEmits(['jump'])
2024-08-23 13:19:20 +08:00
const data: any = ref([]);
const defaultProps = {
children: "children",
label: "name",
2024-08-27 15:40:58 +08:00
pid: "pid",
2024-08-23 13:19:20 +08:00
};
const searchForm = ref({
planName: "",
});
2024-08-27 15:40:58 +08:00
const defaultChecked = ref([])
2024-08-23 13:19:20 +08:00
const getTreeData = (val: any) => {
2024-08-27 15:40:58 +08:00
defaultChecked.value = []
2024-08-23 13:19:20 +08:00
data.value = val;
2024-08-27 14:01:26 +08:00
defaultChecked.value.push(data.value[0].children[0].id)
2024-08-23 13:19:20 +08:00
};
const filterText = ref("");
const treeRef = ref();
watch(
() => searchForm.value.planName,
(val) => {
treeRef.value!.filter(val);
},
{
deep: true,
}
);
const handleNodeClick = (data) => {
console.log(data);
};
const filterNode = (value: string, data) => {
if (!value) return true;
return data.name.includes(value);
};
2024-08-27 15:40:58 +08:00
// 点击详情
const detail=(e:any) => {
emit('jump',e)
}
2024-08-23 13:19:20 +08:00
onMounted(() => {
console.log();
});
defineExpose({ getTreeData });
</script>
<style lang="scss" scoped>
.plan_tree {
width: 200px;
height: 100%;
display: flex;
flex-direction: column;
2024-08-23 13:19:20 +08:00
padding: 5px;
height: calc(100% - 70px);
2024-08-27 14:01:26 +08:00
background-color: #fff;
2024-08-27 15:40:58 +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 {
flex: 1;
overflow-y: auto;
2024-08-27 15:40:58 +08:00
.el-tree {
height: 100%;
}
2024-08-23 13:19:20 +08:00
}
}
</style>