Forráskód Böngészése

feat(views): 暖通图元支持绑定阀门

wangcong 4 napja
szülő
commit
d23aca62b1

+ 33 - 0
src/types/index.ts

@@ -87,6 +87,39 @@ export interface DeviceItem {
   runningStatus: string;
 }
 
+export interface DeviceGroupItem {
+  id: number;
+  createTime: Date | null;
+  updateTime: Date | null;
+  createUserId: number | null;
+  updateUserId: number | null;
+  groupName: string;
+  comment: string | null;
+  parentId: number;
+  userId: number;
+  deleted: boolean | null;
+  deviceGroupChilds: DeviceGroupChild[];
+}
+
+export interface DeviceGroupChild {
+  id: number;
+  groupName: string;
+  comment: string | null;
+  parentId: number;
+  userId: number;
+}
+
+export interface DeviceGroupTree extends DeviceGroupItem {
+  label: string;
+  children: DeviceGroupTreeChild[];
+}
+
+export interface DeviceGroupTreeChild extends DeviceGroupChild {
+  label: string;
+  children: (DeviceItem & { label: string })[];
+}
+
 export interface HvacDevicePen extends Pen {
   hvacDeviceInfo: Partial<DeviceItem>;
+  hvacValveType?: number | string;
 }

+ 2 - 1
src/views/Preview.vue

@@ -72,7 +72,8 @@ onMounted(() => {
 const openHvacDevCtrlModal = ({ pen }: { pen: HvacDevicePen }) => {
   const msg: IframeMsg = {
     msgType: getVisual2DMsgType(Visual2DMsgType.OpenDevCtrlModal),
-    hvacDeviceId: pen.hvacDeviceInfo.id
+    hvacDeviceId: pen.hvacDeviceInfo.id,
+    hvacValveType: pen.hvacValveType,
   };
 
   window.parent.postMessage(msg, "*");

+ 1 - 0
src/views/components/Graphics.vue

@@ -1395,6 +1395,7 @@ const dragStart = async (event: DragEvent | MouseEvent|TouchEvent, item: any) =>
     if (data.image.includes('2.5D-采暖系统')) {
       Object.assign(data, {
         description: item.image.match(/2\.5D-采暖系统\/([^\/]+)\.[^.]+$/)?.[1],
+        hvacValveType: item.image.includes('阀门') ? '' : undefined,
         hvacDeviceInfo: {},
         events: [
           {

+ 89 - 3
src/views/components/PenProps.vue

@@ -41,12 +41,21 @@
               </template>
             </t-select-input>
           </div>
+          <div v-if="isHvacValvePen" class="form-item px-12" style="margin-top: -12px">
+            <label style="width: 50px">{{$t('阀门')}}</label>
+            <t-select
+              v-model="data.pen.hvacValveType"
+              :options="valveTypeList"
+              :placeholder="$t('请选择阀门类型')"
+              @change="handleValveChange"
+            />
+          </div>
           <div v-if="data.pen.hvacDeviceInfo" class="form-item px-12" style="margin-top: -12px">
             <label style="width: 50px">{{$t('设备')}}</label>
             <t-cascader
               v-model="data.pen.hvacDeviceInfo.id"
               :keys="{ value: 'id' }"
-              :options="deviceList"
+              :options="currentDeviceList"
               :placeholder="$t('请选择设备')"
               filterable
               clearable
@@ -1319,10 +1328,11 @@ import { s8 } from '@/services/random';
 import { EllipsisIcon, LinkIcon, LinkUnlinkIcon, ChevronDownIcon, FormatVerticalAlignLeftIcon, FormatHorizontalAlignCenterIcon, FormatVerticalAlignCenterIcon, FormatVerticalAlignRightIcon, FormatHorizontalAlignTopIcon, FormatHorizontalAlignBottomIcon  } from 'tdesign-icons-vue-next';
 import { getToken  } from '@le5le/auth-token';
 import { getImgUrl } from '@/services/utils';
-import { DeviceItem } from '@/types';
+import { DeviceItem, DeviceGroupTree } from '@/types';
+import { DeviceType, ValveType, valveTypeList } from '..';
 
 interface Props {
-  deviceList: DeviceItem[];
+  deviceList: DeviceGroupTree[];
 }
 
 const props = defineProps<Props>();
@@ -1576,10 +1586,86 @@ const changeValue = (prop: string) => {
   }
 };
 
+const isHvacValvePen = computed(() => {
+  return data.pen.hvacValveType !== undefined;
+})
+
+const currentDeviceList = computed(() => {
+  if (!isHvacValvePen.value) {
+    return props.deviceList;
+  }
+
+  const valveType = data.pen.hvacValveType as number | string;
+
+  // 根据阀门类型确定目标设备类型
+  let deviceTypes: DeviceType[] = [];
+
+  switch (valveType) {
+    case ValveType.冷冻侧阀:
+    case ValveType.冷却侧阀:
+      deviceTypes = [DeviceType.冷水主机];
+      break;
+    case ValveType.进口阀:
+    case ValveType.出口阀:
+      deviceTypes = [DeviceType.冷却塔];
+      break;
+    case ValveType.旁通阀:
+      deviceTypes = [DeviceType.控制柜];
+      break;
+    case '': // 空字符串返回三种类型
+      deviceTypes = [DeviceType.冷水主机, DeviceType.冷却塔, DeviceType.控制柜];
+      break;
+    default:
+      return []; // 未知类型返回空列表
+  }
+
+  return filterDeviceGroups(props.deviceList, deviceTypes);
+})
+
+/**
+ * 过滤设备组树,移除不包含指定类型设备的分组
+ * @param deviceGroups 原始设备组树
+ * @param deviceTypes 需要保留的设备类型列表
+ * @returns 过滤后的设备组树
+ */
+const filterDeviceGroups = (deviceGroups: DeviceGroupTree[], deviceTypes: DeviceType[]) => {
+  return deviceGroups
+    .map(group => ({
+      ...group,
+      children: group.children
+        .map(child => ({
+          ...child,
+          children: child.children.filter(device =>
+            deviceTypes.includes(device.deviceType)
+          )
+        }))
+        .filter(child => child.children.length > 0) // 过滤空的二级分组
+    }))
+    .filter(group => group.children.length > 0); // 过滤空的一级分组
+}
+
+const handleValveChange = () => {
+  data.pen.hvacDeviceInfo = {};
+}
+
 const handleDeviceChange = (value: CascaderValue<DeviceItem>, context: CascaderChangeContext<DeviceItem>) => {
   if (context.node) {
     data.pen.description = context.node.label
     Object.assign(data.pen.hvacDeviceInfo, context.node.data)
+
+    if (isHvacValvePen.value) {
+      switch (context.node.data.deviceType) {
+        case DeviceType.冷水主机:
+          data.pen.hvacValveType = ValveType.冷冻侧阀;
+          break;
+        case DeviceType.冷却塔:
+          data.pen.hvacValveType = ValveType.进口阀;
+          break;
+        case DeviceType.控制柜:
+          data.pen.hvacValveType = ValveType.旁通阀;
+          break;
+      }
+    }
   } else {
     data.pen.hvacDeviceInfo = {}
   }

+ 41 - 0
src/views/index.ts

@@ -1,3 +1,7 @@
+import i18n from '../i18n';
+
+const $t = i18n.global.t;
+
 /**
  * 实时监测和大屏等模块与其可视化 Iframe 内嵌网页通信的消息前缀
  */
@@ -40,3 +44,40 @@ export const enum VisualModuleType {
 export const getVisual2DMsgType = (type: Visual2DMsgType) => {
   return visual2DMsgPrefix + '-' + type;
 };
+
+export const enum DeviceType {
+  空 = 0,
+  控制柜 = 1,
+  冷水主机 = 2,
+  露点仪 = 3,
+  流量计 = 4,
+  电表 = 5,
+  其他传感器 = 6,
+  阀门 = 7,
+  循环水泵 = 8,
+  冷却塔 = 9,
+  风冷模块机组 = 10,
+  冷却泵 = 11,
+  冷冻泵 = 12,
+  热水泵 = 13,
+  二次冷冻泵 = 14,
+  空调风柜 = 15,
+  EC风机 = 16,
+  其他设备 = 17,
+}
+
+export const enum ValveType {
+  冷冻侧阀 = 101,
+  冷却侧阀 = 102,
+  进口阀 = 103,
+  出口阀 = 104,
+  旁通阀 = 105,
+}
+
+export const valveTypeList = [
+  { label: $t("主机冷冻侧阀"), value: ValveType.冷冻侧阀 },
+  { label: $t("主机冷却侧阀"), value: ValveType.冷却侧阀 },
+  { label: $t("冷却塔进口阀"), value: ValveType.进口阀 },
+  { label: $t("冷却塔出口阀"), value: ValveType.出口阀 },
+  { label: $t("旁通阀"), value: ValveType.旁通阀 },
+];