This commit is contained in:
神仙都没用 2023-11-24 16:39:24 +08:00
parent 561b6a670d
commit 0d144e3089
3 changed files with 18 additions and 10 deletions

View File

@ -31,11 +31,13 @@
<el-tree <el-tree
class="tree" class="tree"
highlight-current highlight-current
auto-expand-parent
:expand-on-click-node="false"
:ref="setRefs('tree')"
:lazy="tree.lazy" :lazy="tree.lazy"
:data="list" :data="list"
:props="tree.props" :props="tree.props"
:load="tree.onLoad" :load="tree.onLoad"
:default-expanded-keys="tree.defaultExpandedKeys"
@node-click="select" @node-click="select"
> >
<template #default="{ data }"> <template #default="{ data }">
@ -148,7 +150,7 @@ import {
Refresh as IconRefresh, Refresh as IconRefresh,
Plus Plus
} from "@element-plus/icons-vue"; } from "@element-plus/icons-vue";
import { useBrowser } from "/@/cool"; import { useBrowser, useCool } from "/@/cool";
import { ContextMenu, useForm, setFocus } from "@cool-vue/crud"; import { ContextMenu, useForm, setFocus } from "@cool-vue/crud";
import { ElMessage, ElMessageBox } from "element-plus"; import { ElMessage, ElMessageBox } from "element-plus";
import { ClViewGroup } from "./hook"; import { ClViewGroup } from "./hook";
@ -158,6 +160,7 @@ import { deepTree } from "/@/cool/utils";
const { browser, onScreenChange } = useBrowser(); const { browser, onScreenChange } = useBrowser();
const slots = useSlots(); const slots = useSlots();
const Form = useForm(); const Form = useForm();
const { refs, setRefs } = useCool();
// //
const config = reactive( const config = reactive(
@ -330,10 +333,12 @@ async function refresh(params?: any) {
let req; let req;
if (tree.visible) { if (tree.visible) {
//
req = config.service.list(data).then((res) => { req = config.service.list(data).then((res) => {
list.value = deepTree(res); list.value = deepTree(res);
}); });
} else { } else {
//
req = config.service.page(data).then((res) => { req = config.service.page(data).then((res) => {
const arr = config.onData?.(res.list) || res.list; const arr = config.onData?.(res.list) || res.list;
@ -352,10 +357,13 @@ async function refresh(params?: any) {
const item = selected.value || list.value[0]; const item = selected.value || list.value[0];
if (item) { if (item) {
tree.defaultExpandedKeys = [item.id]; if (tree.visible) {
} const node = refs.tree.getNode(item);
node.expand();
}
select(item); select(item);
}
}) })
.catch((err) => { .catch((err) => {
ElMessage.error(err.message); ElMessage.error(err.message);
@ -509,8 +517,6 @@ defineExpose({
display: flex; display: flex;
align-items: center; align-items: center;
line-height: 1; line-height: 1;
height: 100%;
width: 100%;
} }
} }

View File

@ -7,9 +7,11 @@ import ClAvatar from "../components/avatar/index";
export function useDeptViewGroup(options: DeepPartial<ClViewGroup.Options>) { export function useDeptViewGroup(options: DeepPartial<ClViewGroup.Options>) {
const { ViewGroup } = useViewGroup({ const { ViewGroup } = useViewGroup({
...options, ...options,
label: "员工列表",
service: service.base.sys.department, service: service.base.sys.department,
enableAdd: false, enableAdd: false,
label: "员工列表", enableRefresh: false,
enableContextMenu: false,
tree: { tree: {
lazy: true, lazy: true,
onLoad(node: Node, resolve: (data: TreeData) => void) { onLoad(node: Node, resolve: (data: TreeData) => void) {
@ -25,6 +27,7 @@ export function useDeptViewGroup(options: DeepPartial<ClViewGroup.Options>) {
/> />
); );
}); });
res.unshift(...(node.data.children || [])); res.unshift(...(node.data.children || []));
resolve(res); resolve(res);

View File

@ -33,11 +33,11 @@
v-loading="loading" v-loading="loading"
node-key="id" node-key="id"
default-expand-all default-expand-all
highlight-current
:data="list" :data="list"
:props="{ :props="{
label: 'name' label: 'name'
}" }"
highlight-current
:draggable="isDrag" :draggable="isDrag"
:allow-drag="allowDrag" :allow-drag="allowDrag"
:allow-drop="allowDrop" :allow-drop="allowDrop"
@ -450,7 +450,6 @@ onMounted(function () {
&.is-active { &.is-active {
color: var(--color-primary); color: var(--color-primary);
font-weight: bold;
} }
} }