feat(iot): 实现设备分类和分组的树形结构管理功能
- 添加设备分类树形展示和展开/折叠功能 - 实现设备分组的层级树形结构显示 - 集成treeselect组件支持分类和分组的选择 - 添加上级分类和类型编码字段及验证规则 - 更新国际化语言包中的分类相关文案 - 优化产品编辑页面的分类选择功能 - 调整登录页面的统一身份认证配置 - 完善删除操作的提示信息和错误处理
This commit is contained in:
@@ -17,6 +17,9 @@
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['iot:category:add']">{{ $t('add') }}</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>
|
||||
<el-col :span="1.5" style="line-height: 28px">
|
||||
<el-checkbox v-model="queryParams.showSenior" style="margin: 0 10px" @change="handleQuery">{{ $t('product.index.091251-8') }}</el-checkbox>
|
||||
<el-tooltip :content="$t('product.index.091251-9')" placement="top"><i class="el-icon-question"></i></el-tooltip>
|
||||
@@ -24,8 +27,9 @@
|
||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
|
||||
<el-table v-loading="loading" :data="categoryList" @selection-change="handleSelectionChange" :border="false">
|
||||
<el-table-column :label="$t('product.category.142342-0')" align="center" prop="categoryName" />
|
||||
<el-table v-if="refreshTable" v-loading="loading" :data="categoryList" :border="false" row-key="categoryId" :default-expand-all="isExpandAll" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
|
||||
<el-table-column :label="$t('product.category.142342-0')" align="left" prop="categoryName" min-width="250" />
|
||||
<el-table-column :label="$t('product.category.142342-12')" align="center" prop="industryCode" width="150" />
|
||||
<el-table-column :label="$t('template.index.891112-12')" align="center" prop="isSys" width="100">
|
||||
<template slot-scope="scope">
|
||||
<dict-tag :options="dict.type.iot_yes_no" :value="scope.row.isSys" />
|
||||
@@ -57,9 +61,19 @@
|
||||
<!-- 添加或修改产品分类对话框 -->
|
||||
<el-dialog :title="$t('product.index.091251-2')" :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('product.category.142342-9')" prop="parentId">
|
||||
<treeselect v-model="form.parentId" :options="categoryOptions" :normalizer="normalizer" :placeholder="$t('product.category.142342-10')" :max-height="300" :searchable="true" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-form-item :label="$t('product.index.091251-2')" prop="categoryName">
|
||||
<el-input v-model="form.categoryName" :placeholder="$t('product.index.091251-3')" />
|
||||
</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('product.category.142342-1')" prop="orderNum">
|
||||
<el-input-number controls-position="right" v-model="form.orderNum" type="number" :placeholder="$t('product.category.142342-2')" style="width: 100%" />
|
||||
</el-form-item>
|
||||
@@ -78,32 +92,35 @@
|
||||
|
||||
<script>
|
||||
import { listCategory, getCategory, delCategory, addCategory, updateCategory } from '@/api/iot/category';
|
||||
import Treeselect from '@riophae/vue-treeselect';
|
||||
import '@riophae/vue-treeselect/dist/vue-treeselect.css';
|
||||
|
||||
export default {
|
||||
name: 'Category',
|
||||
dicts: ['iot_yes_no'],
|
||||
components: { Treeselect },
|
||||
data() {
|
||||
return {
|
||||
// 是否为租户
|
||||
isTenant: false,
|
||||
// 遮罩层
|
||||
loading: true,
|
||||
// 选中数组
|
||||
ids: [],
|
||||
// 非单个禁用
|
||||
single: true,
|
||||
// 非多个禁用
|
||||
multiple: true,
|
||||
// 显示搜索条件
|
||||
showSearch: true,
|
||||
// 总条数
|
||||
total: 0,
|
||||
// 产品分类表格数据
|
||||
categoryList: [],
|
||||
// 分类树选项
|
||||
categoryOptions: [],
|
||||
// 弹出层标题
|
||||
title: '',
|
||||
// 是否显示弹出层
|
||||
open: false,
|
||||
// 是否展开,默认全部展开
|
||||
isExpandAll: true,
|
||||
// 重新渲染表格状态
|
||||
refreshTable: true,
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
showSenior: false,
|
||||
@@ -123,6 +140,13 @@ export default {
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
industryCode: [
|
||||
{
|
||||
required: true,
|
||||
message: this.$t('product.category.142342-14'),
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
isSys: [
|
||||
{
|
||||
required: true,
|
||||
@@ -147,11 +171,53 @@ export default {
|
||||
getList() {
|
||||
this.loading = true;
|
||||
listCategory(this.queryParams).then((response) => {
|
||||
this.categoryList = response.rows;
|
||||
this.categoryList = this.handleTree(response.rows, 'categoryId');
|
||||
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.categoryId,
|
||||
label: node.categoryName,
|
||||
children: node.children,
|
||||
};
|
||||
},
|
||||
// 取消按钮
|
||||
cancel() {
|
||||
this.open = false;
|
||||
@@ -166,6 +232,7 @@ export default {
|
||||
tenantName: null,
|
||||
isSys: null,
|
||||
parentId: null,
|
||||
industryCode: null,
|
||||
orderNum: null,
|
||||
delFlag: null,
|
||||
createBy: null,
|
||||
@@ -186,26 +253,37 @@ export default {
|
||||
this.resetForm('queryForm');
|
||||
this.handleQuery();
|
||||
},
|
||||
// 多选框选中数据
|
||||
handleSelectionChange(selection) {
|
||||
this.ids = selection.map((item) => item.categoryId);
|
||||
this.single = selection.length !== 1;
|
||||
this.multiple = !selection.length;
|
||||
},
|
||||
|
||||
/** 新增按钮操作 */
|
||||
handleAdd() {
|
||||
handleAdd(row) {
|
||||
this.reset();
|
||||
if (row != undefined) {
|
||||
this.form.parentId = row.categoryId;
|
||||
}
|
||||
this.open = true;
|
||||
this.title = this.$t('product.category.142342-6');
|
||||
const params = {
|
||||
pageSize: 9999 // 确保加载所有分类
|
||||
};
|
||||
listCategory(params).then((response) => {
|
||||
this.categoryOptions = this.handleTree(response.rows, 'categoryId');
|
||||
});
|
||||
},
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.reset();
|
||||
const categoryId = row.categoryId || this.ids;
|
||||
getCategory(categoryId).then((response) => {
|
||||
this.form = response.data;
|
||||
this.open = true;
|
||||
this.title = this.$t('product.category.142342-7');
|
||||
// 先加载分类树选项
|
||||
const params = {
|
||||
pageSize: 9999 // 确保加载所有分类
|
||||
};
|
||||
listCategory(params).then((categoryResponse) => {
|
||||
this.categoryOptions = this.handleTree(categoryResponse.rows, 'categoryId');
|
||||
// 再加载分类详情
|
||||
getCategory(row.categoryId).then((response) => {
|
||||
this.form = response.data;
|
||||
this.open = true;
|
||||
this.title = this.$t('product.category.142342-7');
|
||||
});
|
||||
});
|
||||
},
|
||||
/** 提交按钮 */
|
||||
@@ -230,18 +308,14 @@ export default {
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
const categoryIds = row.categoryId || this.ids;
|
||||
let msg = '';
|
||||
this.$modal
|
||||
.confirm(this.$t('product.category.142342-8', [categoryIds]))
|
||||
.confirm(this.$t('product.category.142342-8', [row.categoryName]))
|
||||
.then(function () {
|
||||
return delCategory(categoryIds).then((response) => {
|
||||
msg = response.msg;
|
||||
});
|
||||
return delCategory(row.categoryId);
|
||||
})
|
||||
.then(() => {
|
||||
this.getList();
|
||||
this.$modal.msgSuccess(msg);
|
||||
this.$modal.msgSuccess(this.$t('delSuccess'));
|
||||
})
|
||||
.catch(() => {});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user