|
@@ -4,7 +4,8 @@ const props = withDefaults(
|
|
|
modelValue?: string | number
|
|
modelValue?: string | number
|
|
|
data?: any
|
|
data?: any
|
|
|
dataFun?: () => Promise<any>
|
|
dataFun?: () => Promise<any>
|
|
|
- showSearchInput?: boolean
|
|
|
|
|
|
|
+ initLoad?: boolean
|
|
|
|
|
+ search?: boolean
|
|
|
searchWords?: string
|
|
searchWords?: string
|
|
|
treeBoxClass?: string
|
|
treeBoxClass?: string
|
|
|
treeBoxStyle?: string
|
|
treeBoxStyle?: string
|
|
@@ -14,6 +15,8 @@ const props = withDefaults(
|
|
|
searchWords: "",
|
|
searchWords: "",
|
|
|
treeBoxClass: "h-100",
|
|
treeBoxClass: "h-100",
|
|
|
treeBoxStyle: "margin-top:15px;background: var(--bs-app-header-minimize-bg-color);",
|
|
treeBoxStyle: "margin-top:15px;background: var(--bs-app-header-minimize-bg-color);",
|
|
|
|
|
+ search: true,
|
|
|
|
|
+ initLoad: true,
|
|
|
props: () => {
|
|
props: () => {
|
|
|
return {
|
|
return {
|
|
|
children: "children",
|
|
children: "children",
|
|
@@ -28,7 +31,8 @@ const emits = defineEmits<{
|
|
|
(e: "nodeClick", v: any): void
|
|
(e: "nodeClick", v: any): void
|
|
|
}>()
|
|
}>()
|
|
|
|
|
|
|
|
-const { searchWords, data } = toRefs(props)
|
|
|
|
|
|
|
+const { data } = toRefs(props)
|
|
|
|
|
+const searchWords = ref(props.searchWords)
|
|
|
const treeRef = ref<any>()
|
|
const treeRef = ref<any>()
|
|
|
const treeData = ref<any>([])
|
|
const treeData = ref<any>([])
|
|
|
|
|
|
|
@@ -40,7 +44,7 @@ function handleNodeClick(data: any) {
|
|
|
emits("update:modelValue", data.id)
|
|
emits("update:modelValue", data.id)
|
|
|
emits("nodeClick", data)
|
|
emits("nodeClick", data)
|
|
|
}
|
|
}
|
|
|
-function loadTreeData() {
|
|
|
|
|
|
|
+function load() {
|
|
|
if (props.dataFun) {
|
|
if (props.dataFun) {
|
|
|
props.dataFun().then((res) => {
|
|
props.dataFun().then((res) => {
|
|
|
treeData.value = res.data
|
|
treeData.value = res.data
|
|
@@ -53,7 +57,6 @@ function loadTreeData() {
|
|
|
if (treeData.value.length > 0) {
|
|
if (treeData.value.length > 0) {
|
|
|
initDefaultKey(treeData.value[0].id)
|
|
initDefaultKey(treeData.value[0].id)
|
|
|
}
|
|
}
|
|
|
- console.log("----", data.value)
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
/** 初始化默认选中 */
|
|
/** 初始化默认选中 */
|
|
@@ -70,7 +73,9 @@ function setCurrentKey(id: any) {
|
|
|
initDefaultKey(id)
|
|
initDefaultKey(id)
|
|
|
}
|
|
}
|
|
|
function init() {
|
|
function init() {
|
|
|
- loadTreeData()
|
|
|
|
|
|
|
+ if (props.initLoad) {
|
|
|
|
|
+ load()
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
onMounted(init)
|
|
onMounted(init)
|
|
@@ -84,17 +89,17 @@ watchEffect(
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
defineExpose({
|
|
defineExpose({
|
|
|
|
|
+ load,
|
|
|
setCurrentKey
|
|
setCurrentKey
|
|
|
})
|
|
})
|
|
|
</script>
|
|
</script>
|
|
|
<template>
|
|
<template>
|
|
|
<div :class="treeBoxClass" :style="treeBoxStyle">
|
|
<div :class="treeBoxClass" :style="treeBoxStyle">
|
|
|
- <el-input
|
|
|
|
|
- v-if="showSearchInput"
|
|
|
|
|
- v-model="searchWords"
|
|
|
|
|
- placeholder="请输入关键字"
|
|
|
|
|
- clearable
|
|
|
|
|
- prefix-icon="Search" />
|
|
|
|
|
|
|
+ <el-input v-if="search" v-model="searchWords" placeholder="请输入关键字" clearable>
|
|
|
|
|
+ <template #prefix>
|
|
|
|
|
+ <i class="fs-4 bi bi-search"></i>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </el-input>
|
|
|
<el-tree
|
|
<el-tree
|
|
|
class="pt-3"
|
|
class="pt-3"
|
|
|
ref="treeRef"
|
|
ref="treeRef"
|