修改无分类数据面板bug和搜索问题
This commit is contained in:
parent
9828397dd9
commit
c69984929a
|
|
@ -57,7 +57,7 @@ export class GenDevService {
|
||||||
this.logger.log('初始化设备分类');
|
this.logger.log('初始化设备分类');
|
||||||
// 创建网系类型分类
|
// 创建网系类型分类
|
||||||
let systemTypeTaxonomy = await db.taxonomy.findFirst({
|
let systemTypeTaxonomy = await db.taxonomy.findFirst({
|
||||||
where: { slug: 'network_type' }, // 改名为 network_type
|
where: { slug: 'network_type' },
|
||||||
});
|
});
|
||||||
if (!systemTypeTaxonomy) {
|
if (!systemTypeTaxonomy) {
|
||||||
systemTypeTaxonomy = await db.taxonomy.create({
|
systemTypeTaxonomy = await db.taxonomy.create({
|
||||||
|
|
@ -97,112 +97,7 @@ export class GenDevService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.log('创建三层分类记录');
|
this.logger.log('初始化设备分类完成');
|
||||||
|
|
||||||
// 定义三层分类结构
|
|
||||||
const networkTypes = [
|
|
||||||
{
|
|
||||||
name: '办公网络',
|
|
||||||
systemTypes: [
|
|
||||||
{
|
|
||||||
name: '文印系统',
|
|
||||||
faultTypes: ['电源故障', '主板故障', '内存故障', '硬盘故障'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: '内网系统',
|
|
||||||
faultTypes: ['系统崩溃', '应用程序错误', '病毒感染', '驱动问题'],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: '安全网络',
|
|
||||||
systemTypes: [
|
|
||||||
{
|
|
||||||
name: '监控系统',
|
|
||||||
faultTypes: ['摄像头故障', '录像异常', '存储故障', '网络断开'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: '门禁系统',
|
|
||||||
faultTypes: ['读卡器故障', '门锁故障', '系统异常', '网络故障'],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
// 创建三层分类结构
|
|
||||||
for (const networkTypeData of networkTypes) {
|
|
||||||
// 创建网系类型
|
|
||||||
const networkType = await db.term.findFirst({
|
|
||||||
where: {
|
|
||||||
name: networkTypeData.name,
|
|
||||||
taxonomyId: systemTypeTaxonomy.id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
let networkTypeId;
|
|
||||||
if (!networkType) {
|
|
||||||
const newNetworkType = await db.term.create({
|
|
||||||
data: {
|
|
||||||
name: networkTypeData.name,
|
|
||||||
taxonomyId: systemTypeTaxonomy.id,
|
|
||||||
hasChildren: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
networkTypeId = newNetworkType.id;
|
|
||||||
} else {
|
|
||||||
networkTypeId = networkType.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 为每个网系类型创建系统类型
|
|
||||||
for (const systemTypeData of networkTypeData.systemTypes) {
|
|
||||||
const systemType = await db.term.findFirst({
|
|
||||||
where: {
|
|
||||||
name: systemTypeData.name,
|
|
||||||
taxonomyId: systemSubTypeTaxonomy.id,
|
|
||||||
parentId: networkTypeId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
let systemTypeId;
|
|
||||||
if (!systemType) {
|
|
||||||
const newSystemType = await db.term.create({
|
|
||||||
data: {
|
|
||||||
name: systemTypeData.name,
|
|
||||||
taxonomyId: systemSubTypeTaxonomy.id,
|
|
||||||
parentId: networkTypeId,
|
|
||||||
hasChildren: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
systemTypeId = newSystemType.id;
|
|
||||||
} else {
|
|
||||||
systemTypeId = systemType.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 为每个系统类型创建故障类型
|
|
||||||
for (const faultTypeName of systemTypeData.faultTypes) {
|
|
||||||
const faultType = await db.term.findFirst({
|
|
||||||
where: {
|
|
||||||
name: faultTypeName,
|
|
||||||
taxonomyId: deviceTypeTaxonomy.id,
|
|
||||||
parentId: systemTypeId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!faultType) {
|
|
||||||
await db.term.create({
|
|
||||||
data: {
|
|
||||||
name: faultTypeName,
|
|
||||||
taxonomyId: deviceTypeTaxonomy.id,
|
|
||||||
parentId: systemTypeId,
|
|
||||||
hasChildren: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.log('初始化三层设备分类完成');
|
|
||||||
}
|
}
|
||||||
private async calculateCounts() {
|
private async calculateCounts() {
|
||||||
this.counts = await getCounts();
|
this.counts = await getCounts();
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ const DashboardPage = () => {
|
||||||
|
|
||||||
// 初始化选中的网系和系统类型(选择故障最多的)
|
// 初始化选中的网系和系统类型(选择故障最多的)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (devices && networkTypeTerms && systemTypeTerms && !selectedNetworkType) {
|
if (devices && networkTypeTerms && systemTypeTerms && networkTypeTerms.length > 0 && !selectedNetworkType) {
|
||||||
// 找到故障最多的网系类型
|
// 找到故障最多的网系类型
|
||||||
const networkCounts = {};
|
const networkCounts = {};
|
||||||
networkTypeTerms.forEach(type => {
|
networkTypeTerms.forEach(type => {
|
||||||
|
|
@ -93,7 +93,9 @@ const DashboardPage = () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const maxNetworkTypeId = Object.keys(networkCounts).reduce((a, b) =>
|
const networkCountKeys = Object.keys(networkCounts);
|
||||||
|
if (networkCountKeys.length > 0) {
|
||||||
|
const maxNetworkTypeId = networkCountKeys.reduce((a, b) =>
|
||||||
networkCounts[a] > networkCounts[b] ? a : b
|
networkCounts[a] > networkCounts[b] ? a : b
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -115,13 +117,15 @@ const DashboardPage = () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Object.keys(systemCounts).length > 0) {
|
const systemCountKeys = Object.keys(systemCounts);
|
||||||
const maxSystemTypeId = Object.keys(systemCounts).reduce((a, b) =>
|
if (systemCountKeys.length > 0) {
|
||||||
|
const maxSystemTypeId = systemCountKeys.reduce((a, b) =>
|
||||||
systemCounts[a] > systemCounts[b] ? a : b
|
systemCounts[a] > systemCounts[b] ? a : b
|
||||||
);
|
);
|
||||||
setSelectedSystemType(maxSystemTypeId);
|
setSelectedSystemType(maxSystemTypeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, [devices, networkTypeTerms, systemTypeTerms, selectedNetworkType]);
|
}, [devices, networkTypeTerms, systemTypeTerms, selectedNetworkType]);
|
||||||
|
|
||||||
// 处理日期范围变化
|
// 处理日期范围变化
|
||||||
|
|
@ -233,7 +237,9 @@ const DashboardPage = () => {
|
||||||
|
|
||||||
// 准备三层分类统计数据
|
// 准备三层分类统计数据
|
||||||
const prepareHierarchicalFaultData = () => {
|
const prepareHierarchicalFaultData = () => {
|
||||||
if (!devices || !networkTypeTerms) return { names: [], values: [] };
|
if (!devices || !networkTypeTerms || networkTypeTerms.length === 0) {
|
||||||
|
return { names: [], values: [] };
|
||||||
|
}
|
||||||
|
|
||||||
const hierarchicalCounts = {};
|
const hierarchicalCounts = {};
|
||||||
const totalDevices = devices.length;
|
const totalDevices = devices.length;
|
||||||
|
|
@ -263,7 +269,10 @@ const DashboardPage = () => {
|
||||||
|
|
||||||
// 修改系统类型分布数据(基于选中的网系类型,支持交互)
|
// 修改系统类型分布数据(基于选中的网系类型,支持交互)
|
||||||
const prepareGroupedSystemTypeDistribution = () => {
|
const prepareGroupedSystemTypeDistribution = () => {
|
||||||
if (!devices || !systemTypeTerms || !networkTypeTerms) return { groups: [], values: [] };
|
if (!devices || !systemTypeTerms || !networkTypeTerms ||
|
||||||
|
systemTypeTerms.length === 0 || networkTypeTerms.length === 0) {
|
||||||
|
return { groups: [], values: [] };
|
||||||
|
}
|
||||||
|
|
||||||
const networkGroups: Record<string, string[]> = {};
|
const networkGroups: Record<string, string[]> = {};
|
||||||
const systemTypeCounts: Record<string, number> = {};
|
const systemTypeCounts: Record<string, number> = {};
|
||||||
|
|
@ -273,6 +282,11 @@ const DashboardPage = () => {
|
||||||
? [networkTypeTerms.find(t => t.id === selectedNetworkType)].filter(Boolean)
|
? [networkTypeTerms.find(t => t.id === selectedNetworkType)].filter(Boolean)
|
||||||
: networkTypeTerms;
|
: networkTypeTerms;
|
||||||
|
|
||||||
|
// 如果没有找到目标网系类型,返回空数据
|
||||||
|
if (targetNetworkTypes.length === 0) {
|
||||||
|
return { groups: [], values: [] };
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化网系分组
|
// 初始化网系分组
|
||||||
targetNetworkTypes.forEach(networkType => {
|
targetNetworkTypes.forEach(networkType => {
|
||||||
networkGroups[networkType.name] = [];
|
networkGroups[networkType.name] = [];
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { Select, Spin } from "antd";
|
import { Select, Spin } from "antd";
|
||||||
import { api } from "@nice/client";
|
import { api } from "@nice/client";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState, useRef } from "react";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
interface DeviceTypeSelectProps {
|
interface DeviceTypeSelectProps {
|
||||||
|
|
@ -40,6 +40,19 @@ export default function DeviceTypeSelect({
|
||||||
orderBy: { order: "asc" },
|
orderBy: { order: "asc" },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 使用 useRef 来跟踪之前的 systemTypeId
|
||||||
|
const prevSystemTypeIdRef = useRef<string | undefined>(systemTypeId);
|
||||||
|
|
||||||
|
// 当系统类型改变时,清空当前选择
|
||||||
|
useEffect(() => {
|
||||||
|
if (prevSystemTypeIdRef.current !== systemTypeId) {
|
||||||
|
prevSystemTypeIdRef.current = systemTypeId;
|
||||||
|
if (onChange && value) {
|
||||||
|
onChange(undefined);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [systemTypeId]);
|
||||||
|
|
||||||
// 处理选项数据
|
// 处理选项数据
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (deviceTypes) {
|
if (deviceTypes) {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ server {
|
||||||
# 监听80端口
|
# 监听80端口
|
||||||
listen 80;
|
listen 80;
|
||||||
# 服务器域名/IP地址,使用环境变量
|
# 服务器域名/IP地址,使用环境变量
|
||||||
server_name 192.168.122.194;
|
server_name 192.168.77.194;
|
||||||
|
|
||||||
# 基础性能优化配置
|
# 基础性能优化配置
|
||||||
# 启用tcp_nopush以优化数据发送
|
# 启用tcp_nopush以优化数据发送
|
||||||
|
|
@ -100,7 +100,7 @@ server {
|
||||||
# 仅供内部使用
|
# 仅供内部使用
|
||||||
internal;
|
internal;
|
||||||
# 代理到认证服务
|
# 代理到认证服务
|
||||||
proxy_pass http://192.168.122.194:3000/auth/file;
|
proxy_pass http://192.168.77.194:3000/auth/file;
|
||||||
|
|
||||||
# 请求优化:不传递请求体
|
# 请求优化:不传递请求体
|
||||||
proxy_pass_request_body off;
|
proxy_pass_request_body off;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue