hi-ucs/front/src/views/instructionManual/components/abilityDocTree.vue

148 lines
2.9 KiB
Vue
Raw Normal View History

2022-07-13 09:19:03 +08:00
<template>
2022-07-14 17:02:42 +08:00
<div class="list-box">
2022-08-03 13:36:43 +08:00
<div class="list-item" v-for="(item, i) in newDataList" :key="i" @click.stop="showChildren(item)">
2022-07-14 17:02:42 +08:00
<a-tooltip placement="top" :title="item.title" arrow-point-at-center>
2022-08-03 13:36:43 +08:00
<div :class="[
newClickData.title === item.title ? 'select' : '',
level === 1 ? 'parent' : '',
judgeLeaf(item) ? 'leaf' : '',
]" class="list-text">
2022-07-14 17:02:42 +08:00
{{ item.title }}
<DownOutlined v-show="!item.show && !judgeLeaf(item)" />
<UpOutlined v-show="item.show && !judgeLeaf(item)" />
2022-07-13 09:19:03 +08:00
</div>
2022-07-14 17:02:42 +08:00
</a-tooltip>
<div style="margin-left: 10px" v-if="!judgeLeaf(item) && item.show">
2022-08-03 13:36:43 +08:00
<abilityDocTree :dataList="item.children" @tree-click="handleTreeItem" :clickData="newClickData"
:level="newLevel + 1"></abilityDocTree>
2022-07-14 17:02:42 +08:00
</div>
2022-07-13 09:19:03 +08:00
</div>
2022-07-14 17:02:42 +08:00
</div>
2022-07-13 09:19:03 +08:00
</template>
<script setup>
2022-08-03 13:36:43 +08:00
import {
defineComponent,
onMounted,
ref,
watch,
defineProps,
2022-09-13 18:03:55 +08:00
defineEmits,
2022-08-03 13:36:43 +08:00
} from 'vue'
import { getDevelopDocTree } from '@/api/home'
import { message } from 'ant-design-vue'
import { UpOutlined, DownOutlined } from '@ant-design/icons-vue'
2022-07-13 09:19:03 +08:00
2022-08-03 13:36:43 +08:00
const props = defineProps({
dataList: {
type: Array,
default: () => [],
},
level: {
type: Number,
default: 1,
},
clickData: {
type: Object,
default: () => {
''
2022-07-13 09:19:03 +08:00
},
2022-08-03 13:36:43 +08:00
},
})
2022-07-13 09:19:03 +08:00
2022-08-03 13:36:43 +08:00
// 数组
const newDataList = ref(props.dataList)
// 级别
const newLevel = ref(props.level)
2022-07-13 09:19:03 +08:00
2022-08-03 13:36:43 +08:00
const newClickData = ref(props.clickData)
2022-07-13 09:19:03 +08:00
2022-08-03 13:36:43 +08:00
// 判断是不是叶子节点
const judgeLeaf = (item) => {
if (item.children && item.children.length > 0) {
return false
} else {
return true
2022-07-14 17:02:42 +08:00
}
2022-08-03 13:36:43 +08:00
}
2022-07-13 09:19:03 +08:00
2022-08-03 13:36:43 +08:00
const showChildren = (item) => {
if (!(item.children && item.children.length > 0)) {
if (newClickData.value.title !== '') {
handleTreeItem(item)
} else {
handleTreeItem({ title: '' })
2022-07-13 09:19:03 +08:00
}
2022-07-14 17:02:42 +08:00
}
2022-08-03 13:36:43 +08:00
if (item.children && item.children.length > 0) {
item.show = !item.show
}
}
2022-07-13 09:19:03 +08:00
2022-08-03 13:36:43 +08:00
watch(
() => props.dataList,
(val) => {
if (val) {
newDataList.value = val
2022-07-13 17:46:57 +08:00
}
2022-08-03 13:36:43 +08:00
}
)
2022-07-13 17:46:57 +08:00
2022-08-03 13:36:43 +08:00
watch(
() => props.clickData,
(val) => {
if (val) {
newClickData.value = val
2022-07-13 17:46:57 +08:00
}
2022-07-14 17:02:42 +08:00
}
2022-08-03 13:36:43 +08:00
)
const emit = defineEmits(['treeClick'])
const handleTreeItem = (item) => {
emit('tree-click', item)
}
2022-07-13 09:19:03 +08:00
</script>
<style lang="less" scoped>
2022-08-03 13:36:43 +08:00
.list-text {
font-size: 16px;
color: #333;
padding: 10px 0;
cursor: pointer;
padding-left: 10px;
border-bottom: 1px solid #ccc;
overflow: hidden;
/*文本不会换行*/
white-space: nowrap;
/*当文本溢出包含元素时,以省略号表示超出的文本*/
text-overflow: ellipsis;
2022-07-13 15:04:12 +08:00
2022-08-03 13:36:43 +08:00
&:hover {
color: #0058e1;
cursor: pointer;
2022-07-14 17:02:42 +08:00
}
2022-08-03 13:36:43 +08:00
}
2022-07-13 09:19:03 +08:00
2022-08-03 13:36:43 +08:00
.parent {
margin-bottom: 10px;
background: rgba(0, 135, 225, 0.1);
color: #333;
2022-07-13 17:46:57 +08:00
2022-08-03 13:36:43 +08:00
&:hover {
color: #fff;
background: #0058e1;
2022-07-14 14:16:49 +08:00
cursor: pointer;
2022-07-14 17:02:42 +08:00
}
2022-08-03 13:36:43 +08:00
}
2022-07-13 17:46:57 +08:00
2022-08-03 13:36:43 +08:00
.leaf {
font-size: 14px;
color: #555;
cursor: pointer;
}
.select {
color: #0058e1;
font-weight: 600;
cursor: pointer;
}
2022-07-13 09:19:03 +08:00
</style>