2025-05-08 08:23:03 +00:00
|
|
|
<template>
|
2025-05-12 10:19:28 +00:00
|
|
|
<div>
|
|
|
|
|
<el-input
|
|
|
|
|
v-model="filterText"
|
|
|
|
|
:placeholder="$t('common.search')"
|
|
|
|
|
prefix-icon="Search"
|
|
|
|
|
clearable
|
2025-05-15 02:25:05 +00:00
|
|
|
class="p-8"
|
2025-05-12 10:19:28 +00:00
|
|
|
/>
|
2025-06-12 08:51:49 +00:00
|
|
|
<div
|
|
|
|
|
@click="handleSharedNodeClick"
|
|
|
|
|
v-if="isShared"
|
|
|
|
|
class="shared-knowledge"
|
|
|
|
|
:class="currentNodeKey === 'share' && 'active'"
|
|
|
|
|
>
|
2025-06-13 09:59:21 +00:00
|
|
|
<AppIcon iconName="app-folder-share-active" style="font-size: 18px"></AppIcon>
|
|
|
|
|
<span class="ml-8 lighter">{{ $t('views.system.share_knowledge') }}</span>
|
2025-06-12 08:51:49 +00:00
|
|
|
</div>
|
2025-05-12 10:19:28 +00:00
|
|
|
<el-tree
|
|
|
|
|
ref="treeRef"
|
|
|
|
|
:data="data"
|
|
|
|
|
:props="defaultProps"
|
|
|
|
|
@node-click="handleNodeClick"
|
|
|
|
|
:filter-node-method="filterNode"
|
|
|
|
|
:default-expanded-keys="[currentNodeKey]"
|
|
|
|
|
:current-node-key="currentNodeKey"
|
|
|
|
|
highlight-current
|
|
|
|
|
node-key="id"
|
|
|
|
|
>
|
|
|
|
|
<template #default="{ node, data }">
|
|
|
|
|
<div class="custom-tree-node flex align-center">
|
|
|
|
|
<AppIcon iconName="app-folder" style="font-size: 16px"></AppIcon>
|
2025-06-12 08:51:49 +00:00
|
|
|
<span class="ml-8">{{ node.label }}</span>
|
2025-05-12 10:19:28 +00:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</el-tree>
|
|
|
|
|
</div>
|
2025-05-08 08:23:03 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2025-05-12 10:19:28 +00:00
|
|
|
import { ref, watch } from 'vue'
|
|
|
|
|
import type { TreeInstance } from 'element-plus'
|
2025-06-12 08:51:49 +00:00
|
|
|
import { t } from '@/locales'
|
2025-05-08 08:23:03 +00:00
|
|
|
defineOptions({ name: 'FolderTree' })
|
2025-05-09 06:42:51 +00:00
|
|
|
const props = defineProps({
|
|
|
|
|
data: {
|
|
|
|
|
type: Array,
|
|
|
|
|
default: () => [],
|
|
|
|
|
},
|
2025-05-12 10:19:28 +00:00
|
|
|
currentNodeKey: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: 'root',
|
|
|
|
|
},
|
2025-06-12 08:51:49 +00:00
|
|
|
isShared: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false,
|
|
|
|
|
},
|
2025-05-09 06:42:51 +00:00
|
|
|
})
|
2025-05-08 08:23:03 +00:00
|
|
|
interface Tree {
|
2025-05-09 06:42:51 +00:00
|
|
|
name: string
|
2025-05-08 08:23:03 +00:00
|
|
|
children?: Tree[]
|
2025-06-12 08:51:49 +00:00
|
|
|
id?: string
|
2025-05-08 08:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
|
children: 'children',
|
2025-05-09 06:42:51 +00:00
|
|
|
label: 'name',
|
2025-05-08 08:23:03 +00:00
|
|
|
}
|
2025-05-12 10:19:28 +00:00
|
|
|
|
|
|
|
|
const emit = defineEmits(['handleNodeClick'])
|
|
|
|
|
|
|
|
|
|
const treeRef = ref<TreeInstance>()
|
|
|
|
|
const filterText = ref('')
|
|
|
|
|
|
|
|
|
|
watch(filterText, (val) => {
|
|
|
|
|
treeRef.value!.filter(val)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const filterNode = (value: string, data: Tree) => {
|
|
|
|
|
if (!value) return true
|
|
|
|
|
return data.name.includes(value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleNodeClick = (data: Tree) => {
|
|
|
|
|
emit('handleNodeClick', data)
|
|
|
|
|
}
|
2025-06-12 08:51:49 +00:00
|
|
|
|
|
|
|
|
const handleSharedNodeClick = () => {
|
2025-06-13 09:17:01 +00:00
|
|
|
treeRef.value?.setCurrentKey(undefined)
|
2025-06-12 08:51:49 +00:00
|
|
|
emit('handleNodeClick', { id: 'share', name: t('views.system.share_knowledge') })
|
|
|
|
|
}
|
2025-05-08 08:23:03 +00:00
|
|
|
</script>
|
2025-06-12 08:51:49 +00:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.shared-knowledge {
|
|
|
|
|
padding-left: 8px;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
height: 40px;
|
|
|
|
|
position: relative;
|
|
|
|
|
margin-bottom: 8px;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
background: var(--app-text-color-light-1);
|
|
|
|
|
color: var(--el-menu-text-color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&.active {
|
|
|
|
|
color: var(--el-color-primary);
|
|
|
|
|
background: var(--el-color-primary-light-9);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&::after {
|
|
|
|
|
content: '';
|
|
|
|
|
position: absolute;
|
|
|
|
|
bottom: -4px;
|
|
|
|
|
background-color: #1f232926;
|
|
|
|
|
left: 0;
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 1px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|