|
|
@@ -1,104 +0,0 @@
|
|
|
-<script setup lang="ts">
|
|
|
-import apis from "@a"
|
|
|
-import appStore from "@s"
|
|
|
-const props = withDefaults(
|
|
|
- defineProps<{
|
|
|
- modelValue?: string | number
|
|
|
- data?: any
|
|
|
- searchWords?: string
|
|
|
- treeBoxClass?: string
|
|
|
- treeBoxStyle?: string
|
|
|
- }>(),
|
|
|
- {
|
|
|
- searchWords: "",
|
|
|
- treeBoxClass: "h-100",
|
|
|
- treeBoxStyle: "margin-top:15px;background: var(--bs-app-header-minimize-bg-color);"
|
|
|
- }
|
|
|
-)
|
|
|
-const emits = defineEmits<{
|
|
|
- (e: "update:modelValue", v: string): void
|
|
|
- (e: "nodeClick", v: any): void
|
|
|
-}>()
|
|
|
-
|
|
|
-const { searchWords, data } = toRefs(props)
|
|
|
-const treeRef = ref<any>()
|
|
|
-const treeData = ref<any>([])
|
|
|
-
|
|
|
-const filterNode = (value: string, data: any) => {
|
|
|
- if (!value) return true
|
|
|
- return data.label.indexOf(value) !== -1
|
|
|
-}
|
|
|
-function handleNodeClick(data: any) {
|
|
|
- emits("update:modelValue", data.id)
|
|
|
- emits("nodeClick", data)
|
|
|
-}
|
|
|
-function loadTreeData() {
|
|
|
- if (data?.value) {
|
|
|
- treeData.value = data.value
|
|
|
- if (treeData.value.length > 0) {
|
|
|
- initDefaultKey(treeData.value[0].id)
|
|
|
- }
|
|
|
- } else {
|
|
|
- apis.system.userApi.orgTreeSelect().then((res) => {
|
|
|
- treeData.value = res.data
|
|
|
- if (treeData.value.length > 0) {
|
|
|
- initDefaultKey(treeData.value[0].id)
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-}
|
|
|
-/** 初始化默认选中 */
|
|
|
-function initDefaultKey(id: any) {
|
|
|
- emits("update:modelValue", id)
|
|
|
- setTimeout(() => {
|
|
|
- treeRef.value.setCurrentKey(id)
|
|
|
- }, 50)
|
|
|
-}
|
|
|
-function setCurrentKey(id: any) {
|
|
|
- if (!id) {
|
|
|
- id = treeData.value[0].id
|
|
|
- }
|
|
|
- initDefaultKey(id)
|
|
|
-}
|
|
|
-function init() {
|
|
|
- loadTreeData()
|
|
|
-}
|
|
|
-
|
|
|
-onMounted(init)
|
|
|
-/** 根据关键字筛选 */
|
|
|
-watch(
|
|
|
- () => props.searchWords,
|
|
|
- (val) => {
|
|
|
- treeRef.value.filter(val)
|
|
|
- }
|
|
|
-)
|
|
|
-defineExpose({
|
|
|
- setCurrentKey
|
|
|
-})
|
|
|
-</script>
|
|
|
-<template>
|
|
|
- <div :class="treeBoxClass" :style="treeBoxStyle">
|
|
|
- <!-- <el-input v-model="searchWords" placeholder="请输入组织机构名称" clearable prefix-icon="Search" /> -->
|
|
|
- <el-tree
|
|
|
- class="pt-3"
|
|
|
- ref="treeRef"
|
|
|
- :data="treeData"
|
|
|
- :props="{ label: 'label', children: 'children' }"
|
|
|
- :expand-on-click-node="false"
|
|
|
- :filter-node-method="filterNode"
|
|
|
- node-key="id"
|
|
|
- highlight-current
|
|
|
- default-expand-all
|
|
|
- @node-click="handleNodeClick" />
|
|
|
- </div>
|
|
|
-</template>
|
|
|
-
|
|
|
-<style lang="scss" scoped>
|
|
|
-:deep(.el-tree--highlight-current) {
|
|
|
- .el-tree-node.is-current > .el-tree-node__content {
|
|
|
- background-color: var(--bs-primary);
|
|
|
- color: #fff;
|
|
|
- border-radius: 0.25rem;
|
|
|
- }
|
|
|
-}
|
|
|
-</style>
|