feat(iot): 实现设备分类和分组的树形结构管理功能

- 添加设备分类树形展示和展开/折叠功能
- 实现设备分组的层级树形结构显示
- 集成treeselect组件支持分类和分组的选择
- 添加上级分类和类型编码字段及验证规则
- 更新国际化语言包中的分类相关文案
- 优化产品编辑页面的分类选择功能
- 调整登录页面的统一身份认证配置
- 完善删除操作的提示信息和错误处理
This commit is contained in:
Gjm
2026-04-08 15:26:50 +08:00
parent 7a81a41c78
commit 4f468c4569
6 changed files with 312 additions and 63 deletions

View File

@@ -18,11 +18,15 @@
<el-col :span="1.5">
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['iot:group:add']">{{ $t('iot.group.index.637432-5') }}</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="info" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll">{{ $t('role.index.094567-18') }}</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="groupList" :border="false" @selection-change="handleSelectionChange">
<el-table-column :label="$t('iot.group.index.637432-0')" align="center" prop="groupName" min-width="200" />
<el-table v-if="refreshTable" v-loading="loading" :data="groupList" :border="false" row-key="groupId" :default-expand-all="isExpandAll" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
<el-table-column :label="$t('iot.group.index.637432-0')" align="left" prop="groupName" min-width="200" />
<el-table-column :label="$t('product.category.142342-12')" align="center" prop="industryCode" width="150" />
<el-table-column :label="$t('iot.group.index.637432-6')" align="center" prop="groupOrder" width="100" />
<el-table-column :label="$t('iot.group.index.637432-7')" align="center" prop="createTime" width="160">
<template slot-scope="scope">
@@ -54,12 +58,23 @@
<!-- 添加或修改设备分组对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-row>
<el-col :span="24">
<el-form-item :label="$t('iot.group.index.637432-28')" prop="parentId">
<treeselect v-model="form.parentId" :options="groupOptions" :normalizer="normalizer" :placeholder="$t('iot.group.index.637432-29')" :max-height="300" :searchable="true" />
</el-form-item>
</el-col>
</el-row>
<el-form-item :label="$t('iot.group.index.637432-0')" prop="groupName">
<el-input v-model="form.groupName" :placeholder="$t('iot.group.index.637432-1')" />
</el-form-item>
<el-form-item :label="$t('product.category.142342-12')" prop="industryCode">
<el-input v-model="form.industryCode" :placeholder="$t('product.category.142342-13')" />
</el-form-item>
<el-form-item :label="$t('iot.group.index.637432-6')" prop="groupOrder">
<el-input v-model="form.groupOrder" type="number" :placeholder="$t('iot.group.index.637432-15')" />
</el-form-item>
<el-form-item :label="$t('iot.group.index.637432-9')" prop="remark">
<el-input v-model="form.remark" type="textarea" :placeholder="$t('iot.group.index.637432-16')" />
</el-form-item>
@@ -77,11 +92,14 @@
import deviceList from './device-list';
import { listGroup, getGroup, delGroup, addGroup, updateGroup } from '@/api/iot/group';
import { getUserId } from '@/utils/auth';
import Treeselect from '@riophae/vue-treeselect';
import '@riophae/vue-treeselect/dist/vue-treeselect.css';
export default {
name: 'Group',
components: {
deviceList,
Treeselect,
},
data() {
return {
@@ -103,14 +121,20 @@ export default {
total: 0,
// 设备分组表格数据
groupList: [],
// 分组树选项
groupOptions: [],
// 弹出层标题
title: '',
// 是否显示弹出层
open: false,
// 是否展开,默认全部展开
isExpandAll: true,
// 重新渲染表格状态
refreshTable: true,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
pageSize: 20,
groupName: null,
userId: null,
},
@@ -165,11 +189,53 @@ export default {
getList() {
this.loading = true;
listGroup(this.queryParams).then((response) => {
this.groupList = response.rows;
this.groupList = this.handleTree(response.rows, 'groupId');
this.total = response.total;
this.loading = false;
});
},
/** 转换树形结构 */
handleTree(data, id) {
const tree = [];
const map = {};
data.forEach(item => {
map[item[id]] = item;
});
data.forEach(item => {
const parent = map[item.parentId];
if (parent) {
if (!parent.children) {
parent.children = [];
}
parent.children.push(item);
} else {
tree.push(item);
}
});
return tree;
},
/** 展开/折叠操作 */
toggleExpandAll() {
this.refreshTable = false;
this.isExpandAll = !this.isExpandAll;
this.$nextTick(() => {
this.refreshTable = true;
});
},
/** 转换分组数据结构 */
normalizer(node) {
if (node.children && !node.children.length) {
delete node.children;
}
return {
id: node.groupId,
label: node.groupName,
children: node.children,
};
},
// 取消按钮
cancel() {
this.open = false;
@@ -183,6 +249,8 @@ export default {
groupOrder: null,
userId: null,
userName: null,
parentId: null,
industryCode: null,
delFlag: null,
createBy: null,
createTime: null,
@@ -209,19 +277,35 @@ export default {
this.multiple = !selection.length;
},
/** 新增按钮操作 */
handleAdd() {
handleAdd(row) {
this.reset();
if (row != undefined) {
this.form.parentId = row.groupId;
}
this.open = true;
this.title = this.$t('iot.group.index.637432-22');
const params = {
pageSize: 9999 // 确保加载所有分组
};
listGroup(params).then((response) => {
this.groupOptions = this.handleTree(response.rows, 'groupId');
});
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const groupId = row.groupId || this.ids;
getGroup(groupId).then((response) => {
this.form = response.data;
this.open = true;
this.title = this.$t('iot.group.index.637432-23');
// 先加载分组树选项
const params = {
pageSize: 9999 // 确保加载所有分组
};
listGroup(params).then((groupResponse) => {
this.groupOptions = this.handleTree(groupResponse.rows, 'groupId');
// 再加载分组详情
getGroup(row.groupId).then((response) => {
this.form = response.data;
this.open = true;
this.title = this.$t('iot.group.index.637432-23');
});
});
},
/** 选择设备 */
@@ -252,11 +336,10 @@ export default {
},
/** 删除按钮操作 */
handleDelete(row) {
const groupIds = row.groupId || this.ids;
this.$modal
.confirm(this.$t('iot.group.index.637432-26', [groupIds]))
.confirm(this.$t('iot.group.index.637432-26', [row.groupName]))
.then(function () {
return delGroup(groupIds);
return delGroup(row.groupId);
})
.then(() => {
this.getList();