- 添加设备分类树形展示和展开/折叠功能 - 实现设备分组的层级树形结构显示 - 集成treeselect组件支持分类和分组的选择 - 添加上级分类和类型编码字段及验证规则 - 更新国际化语言包中的分类相关文案 - 优化产品编辑页面的分类选择功能 - 调整登录页面的统一身份认证配置 - 完善删除操作的提示信息和错误处理
374 lines
15 KiB
Vue
374 lines
15 KiB
Vue
<template>
|
|
<div class="iot-group">
|
|
<el-card v-show="showSearch" style="margin-bottom: 10px">
|
|
<el-form ref="queryForm" :model="queryParams" :inline="true" size="mini" label-width="68px" style="margin-bottom: -18px">
|
|
<el-form-item :label="$t('iot.group.index.637432-0')" prop="groupName">
|
|
<el-input v-model="queryParams.groupName" :placeholder="$t('iot.group.index.637432-1')" clearable @keyup.enter.native="handleQuery" />
|
|
</el-form-item>
|
|
|
|
<el-form-item style="float: right">
|
|
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('iot.group.index.637432-3') }}</el-button>
|
|
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('iot.group.index.637432-4') }}</el-button>
|
|
</el-form-item>
|
|
</el-form>
|
|
</el-card>
|
|
|
|
<el-card>
|
|
<el-row :gutter="10" style="margin-bottom: 15px">
|
|
<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-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">
|
|
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column :label="$t('iot.group.index.637432-8')" align="center" prop="userName" width="100" />
|
|
<el-table-column :label="$t('iot.group.index.637432-9')" align="left" header-align="center" prop="remark" min-width="150" />
|
|
<el-table-column :label="$t('iot.group.index.637432-10')" align="center" class-name="small-padding fixed-width" width="300">
|
|
<template slot-scope="scope">
|
|
<el-button size="small" type="text" icon="el-icon-search" @click="handleViewDevice(scope.row.groupId)" v-hasPermi="['iot:device:list']">
|
|
{{ $t('iot.group.index.637432-11') }}
|
|
</el-button>
|
|
<el-button size="small" type="text" icon="el-icon-plus" @click="selectDevice(scope.row)" v-hasPermi="['iot:group:add']">{{ $t('iot.group.index.637432-12') }}</el-button>
|
|
<el-button size="small" type="text" icon="el-icon-view" @click="handleUpdate(scope.row)" v-hasPermi="['iot:group:query']">{{ $t('iot.group.index.637432-13') }}</el-button>
|
|
<el-button size="small" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['iot:group:remove']">
|
|
{{ $t('iot.group.index.637432-14') }}
|
|
</el-button>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
|
|
<pagination style="margin-bottom: 20px" v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
|
|
</el-card>
|
|
|
|
<!-- 分组设备列表 -->
|
|
<deviceList ref="groupDeviceList" :group="group"></deviceList>
|
|
|
|
<!-- 添加或修改设备分组对话框 -->
|
|
<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>
|
|
</el-form>
|
|
<div slot="footer" class="dialog-footer">
|
|
<el-button type="primary" @click="submitForm" v-show="form.groupId" v-hasPermi="['iot:group:edit']">{{ $t('iot.group.index.637432-17') }}</el-button>
|
|
<el-button type="primary" @click="submitForm" v-hasPermi="['iot:group:add']" v-show="!form.groupId">{{ $t('iot.group.index.637432-18') }}</el-button>
|
|
<el-button @click="cancel">{{ $t('iot.group.index.637432-19') }}</el-button>
|
|
</div>
|
|
</el-dialog>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
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 {
|
|
// 是否管理员
|
|
isAdmin: false,
|
|
// 我的分组
|
|
myGroup: false,
|
|
// 遮罩层
|
|
loading: true,
|
|
// 选中数组
|
|
ids: [],
|
|
// 非单个禁用
|
|
single: true,
|
|
// 非多个禁用
|
|
multiple: true,
|
|
// 显示搜索条件
|
|
showSearch: true,
|
|
// 总条数
|
|
total: 0,
|
|
// 设备分组表格数据
|
|
groupList: [],
|
|
// 分组树选项
|
|
groupOptions: [],
|
|
// 弹出层标题
|
|
title: '',
|
|
// 是否显示弹出层
|
|
open: false,
|
|
// 是否展开,默认全部展开
|
|
isExpandAll: true,
|
|
// 重新渲染表格状态
|
|
refreshTable: true,
|
|
// 查询参数
|
|
queryParams: {
|
|
pageNum: 1,
|
|
pageSize: 20,
|
|
groupName: null,
|
|
userId: null,
|
|
},
|
|
// 设备分组
|
|
group: {},
|
|
// 表单参数
|
|
form: {},
|
|
// 表单校验
|
|
rules: {
|
|
groupName: [
|
|
{
|
|
required: true,
|
|
message: this.$t('iot.group.index.637432-20'),
|
|
trigger: 'blur',
|
|
},
|
|
],
|
|
groupOrder: [
|
|
{
|
|
required: true,
|
|
message: this.$t('iot.group.index.637432-21'),
|
|
trigger: 'blur',
|
|
},
|
|
],
|
|
},
|
|
};
|
|
},
|
|
created() {
|
|
this.getList();
|
|
this.init();
|
|
},
|
|
methods: {
|
|
init() {
|
|
if (this.$store.state.user.roles.indexOf('tenant') === -1 && this.$store.state.user.roles.indexOf('general') === -1) {
|
|
this.isAdmin = true;
|
|
}
|
|
},
|
|
// 我的分组改变事件
|
|
myGroupChange() {
|
|
this.queryParams.userId = this.myGroup ? getUserId() : null;
|
|
},
|
|
/** 查看设备按钮操作 */
|
|
handleViewDevice(groupId) {
|
|
this.$router.push({
|
|
path: '/iot/device',
|
|
query: {
|
|
t: Date.now(),
|
|
groupId: groupId,
|
|
},
|
|
});
|
|
},
|
|
/** 查询设备分组列表 */
|
|
getList() {
|
|
this.loading = true;
|
|
listGroup(this.queryParams).then((response) => {
|
|
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;
|
|
this.reset();
|
|
},
|
|
// 表单重置
|
|
reset() {
|
|
this.form = {
|
|
groupId: null,
|
|
groupName: null,
|
|
groupOrder: null,
|
|
userId: null,
|
|
userName: null,
|
|
parentId: null,
|
|
industryCode: null,
|
|
delFlag: null,
|
|
createBy: null,
|
|
createTime: null,
|
|
updateBy: null,
|
|
updateTime: null,
|
|
remark: null,
|
|
};
|
|
this.resetForm('form');
|
|
},
|
|
/** 搜索按钮操作 */
|
|
handleQuery() {
|
|
this.queryParams.pageNum = 1;
|
|
this.getList();
|
|
},
|
|
/** 重置按钮操作 */
|
|
resetQuery() {
|
|
this.resetForm('queryForm');
|
|
this.handleQuery();
|
|
},
|
|
// 多选框选中数据
|
|
handleSelectionChange(selection) {
|
|
this.ids = selection.map((item) => item.groupId);
|
|
this.single = selection.length !== 1;
|
|
this.multiple = !selection.length;
|
|
},
|
|
/** 新增按钮操作 */
|
|
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 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');
|
|
});
|
|
});
|
|
},
|
|
/** 选择设备 */
|
|
selectDevice(row) {
|
|
this.group = row;
|
|
// 刷新子组件
|
|
this.$refs.groupDeviceList.openDeviceList = true;
|
|
},
|
|
/** 提交按钮 */
|
|
submitForm() {
|
|
this.$refs['form'].validate((valid) => {
|
|
if (valid) {
|
|
if (this.form.groupId != null) {
|
|
updateGroup(this.form).then((response) => {
|
|
this.$modal.msgSuccess(this.$t('iot.group.index.637432-24'));
|
|
this.open = false;
|
|
this.getList();
|
|
});
|
|
} else {
|
|
addGroup(this.form).then((response) => {
|
|
this.$modal.msgSuccess(this.$t('iot.group.index.637432-25'));
|
|
this.open = false;
|
|
this.getList();
|
|
});
|
|
}
|
|
}
|
|
});
|
|
},
|
|
/** 删除按钮操作 */
|
|
handleDelete(row) {
|
|
this.$modal
|
|
.confirm(this.$t('iot.group.index.637432-26', [row.groupName]))
|
|
.then(function () {
|
|
return delGroup(row.groupId);
|
|
})
|
|
.then(() => {
|
|
this.getList();
|
|
this.$modal.msgSuccess(this.$t('iot.group.index.637432-27'));
|
|
})
|
|
.catch(() => {});
|
|
},
|
|
/** 导出按钮操作 */
|
|
handleExport() {
|
|
this.download(
|
|
'iot/group/export',
|
|
{
|
|
...this.queryParams,
|
|
},
|
|
`group_${new Date().getTime()}.xlsx`
|
|
);
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.iot-group {
|
|
padding: 20px;
|
|
}
|
|
::v-deep .el-dialog__body {
|
|
border-top: 1px solid #dcdfe6;
|
|
box-sizing: border-box;
|
|
padding: 20px;
|
|
}
|
|
</style>
|