1
0
forked from dyf/dyf-vue-ui

修改设备分组功能默认展开左边的树,默认加载第一分组的数据

This commit is contained in:
liub
2025-10-11 11:01:03 +08:00
parent 47d8f14ad4
commit 7445e789a4
3 changed files with 39 additions and 104 deletions

View File

@ -10,7 +10,7 @@
</div>
<div class="treeContent">
<el-tree :data="treeData" :props="defaultProps" accordion @node-click="handleNodeClick" :highlight-current="true">
<el-tree :default-expand-all="true" :data="treeData" :props="defaultProps" accordion @node-click="handleNodeClick" :highlight-current="true">
<template #default="{ node, data }">
<div class="custom-tree-node">
<span :class="data.parentId != null ? '' : 'treeBold'">{{ node.label }}</span>
@ -171,13 +171,18 @@
</el-dialog>
<!-- 添加节点的弹出框 -->
<el-dialog :width="350" :draggable="true" v-model="Status.dialogEditNode" :title="cEdit.id ? '修改分组' :(cEdit.pNode?'新增子节点': '新增根节点')" center>
<el-dialog
:width="350"
:draggable="true"
v-model="Status.dialogEditNode"
:title="cEdit.id ? '修改分组' : cEdit.pNode ? '新增子节点' : '新增根节点'"
center
>
<div>
<el-form class="demo-form-inline" :inline="true" :model="cEdit" label-width="auto" style="width: 100%">
<el-form-item label="分组名称"> <el-input v-model="cEdit.groupName" placeholder="请输入" /> </el-form-item
>
<div style="text-indent: 68px;color: #f56c6c;margin-top: -15px;">{{ cEdit.groupName?'':'请输入分组名称' }}</div>
</el-form>
<el-form-item label="分组名称"> <el-input v-model="cEdit.groupName" placeholder="请输入" /> </el-form-item>
<div style="text-indent: 68px; color: #f56c6c; margin-top: -15px">{{ cEdit.groupName ? '' : '请输入分组名称' }}</div>
</el-form>
</div>
<template #footer>
<div class="dialog-footer">
@ -337,18 +342,21 @@ var getDeviceList = () => {
deviceName: GjSearchForm.deviceName
};
showloading();
api
.getNodeDevice(para)
.then((res) => {
deviceList.value = res.rows;
pagin.total = res.total;
})
.catch((ex) => {
console.log('出现了异常', ex);
})
.finally(() => {
hideloading();
});
return new Promise((resolve, reject) => {
api
.getNodeDevice(para)
.then((res) => {
deviceList.value = res.rows;
pagin.total = res.total;
})
.catch((ex) => {
console.log('出现了异常', ex);
})
.finally(() => {
hideloading();
resolve();
});
});
};
//树控件节点点击事件
var handleNodeClick = (node) => {
@ -363,6 +371,12 @@ var handleNodeClick = (node) => {
//树控件筛选后显示的数据源
var treeData = computed(() => {
let arr = api.treeNodeSearch(treeDataOrin.value, searchTxt.value, 'groupName', 'children');
if (arr.length && !checkNode.val) {
checkNode.val = arr[0].id;
getDeviceList().finally(() => {
checkNode.val = '';
});
}
return arr;
});
@ -379,7 +393,7 @@ var editNode = (node) => {
Status.isEditTreeNode = true;
cEdit.value.editNode = node;
cEdit.value.pNode = null;
Status.dialogEditNode=true;
Status.dialogEditNode = true;
//
};
@ -413,7 +427,7 @@ var completeEdit = (node) => {
if (res.code == 200) {
alert('操作成功');
RefreshTree();
Status.dialogEditNode=false;
Status.dialogEditNode = false;
} else {
alert(res.msg);
}
@ -477,7 +491,7 @@ var addNode = (node) => {
};
var saveNode = () => {
if(!cEdit.value.groupName){
if (!cEdit.value.groupName) {
return;
}
let val = new Date().getTime();
@ -917,8 +931,8 @@ onMounted(() => {
}
.custom-tree-node .iconContent .icon {
width: 18px;
height: 18px;
width: 15px;
height: 15px;
visibility: hidden;
}