yangyin
2024-05-16 a11446f488f5bb1e4979e6f85a2619b1d1ba5f65
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<template>
    <LogicManageContainerV2
        ref="logicManageContainerV2Ref"
        type="select-list"
        :selectFolderIcon="(_, data) => data.LogicType !== LOGIC_SITE_CODE"
        :select="{
            label: '泵站',
            requestApi: GetLogicTreeListByPolicyIDStd,
            code: LOGIC_SITE_CODE,
            treeProps,
        }"
        :defaultSelectID="defaultSelectID"
        :list="{
            label: '设备',
 
            requestApi: GetEquipmentTreeDataStd,
            checkFirst,
        }"
        :folderIcon="() => false"
        :contentRef="contentRef"
        :req="request"
        :expandOnClickNode="false"
        @listClick="listClick"
        @selectChange="selectChange"
    >
        <template #main="{ listNode, selectNode }">
            <slot name="main" :listNode="listNode" :selectNode="selectNode" :selectTreeProps="treeProps"> </slot>
        </template>
 
        <template #listNodeSuffix="{ data, node }">
            <div
                v-if="runRecordMap[data.ID]"
                class="run-status flex-center mr5"
                :class="{ 'run-status_work': runRecordMap[data.ID]?.RSa > 0 }"
            >
                {{ runRecordMap[data.ID]?.RSa > 0 ? '开' : '关' }}
            </div>
        </template>
    </LogicManageContainerV2>
</template>
 
<script setup lang="ts">
import LogicManageContainerV2 from '/@/projectCom/components/manage/LogicManageContainerV2.vue';
import request from '/@/utils/request';
import { EQUIPMENT_CODE, LOGIC_SITE_CODE } from '/@/constants';
import { GetEquipmentTreeDataStd } from '/@/api/assets/equipmentStd';
import { GetLogicTreeListByPolicyIDStd } from '/@/api/phm/logicTreeStd';
 
import { computed, nextTick, ref, toRefs, watch } from 'vue';
import { getRunRealRecordListStd } from '/@/api/run/runRealRecord';
import { isFilledArray } from '/@/utils/types';
import { travelTree, getItemMap } from '/@/utils/util';
const props = defineProps({
    contentRef: {
        type: Object,
    },
    // 是否点击左侧树列表时获取数据
    isGetTableData: {
        type: Boolean,
        default: true,
    },
    showRunStatus: {
        type: Boolean,
        default: true,
    },
});
const { showRunStatus } = toRefs(props);
 
const emits = defineEmits<{
    (event: 'selectChange', data): void;
    (event: 'listClick', data): void;
}>();
const defaultSelectID = ref(window.moduleConfig.comprehensive.logicSite.defaultSelectID);
 
const selectChange = (data) => {
    window.moduleConfig.comprehensive.logicSite.defaultSelectID = data[treeProps.id];
    defaultSelectID.value = data[treeProps.id];
    emits('selectChange', data);
};
const checkFirst = (data) => {
    return data.ID === defaultListID.value;
};
 
const defaultListID = ref(window.moduleConfig.assets.equipment.defaultSelectID);
const listClick = (data) => {
    window.moduleConfig.assets.equipment.defaultSelectID = data.ID;
    defaultListID.value = data.ID;
    if (props.isGetTableData) {
        nextTick(() => {
            props.contentRef?.getTableData();
        });
    }
 
    emits('listClick', data);
};
const treeProps = {
    id: 'LogicID',
    label: 'Name',
    children: 'Children',
};
 
//#region ====================== 获取实时运行状态 ======================
const logicManageContainerV2Ref = ref<InstanceType<typeof LogicManageContainerV2>>(null);
const runRecordMap = ref({});
 
if (showRunStatus.value) {
    const treeListData = computed(() => logicManageContainerV2Ref.value?.treeListData);
 
    watch(
        () => treeListData.value,
        async (val) => {
            // 先置空,防止网络过慢,状态没更新
            runRecordMap.value = {};
 
            if (!isFilledArray(val)) {
                return;
            }
            const equipIds = [];
            travelTree(val, (item) => {
                equipIds.push(item.ID);
            });
 
            const realRunRecordList = await getRunRealRecordListStd({
                ObjectType: EQUIPMENT_CODE,
                ObjectIds: equipIds.join(','),
            });
 
            runRecordMap.value = getItemMap(realRunRecordList, 'ObjectID');
        }
    );
}
 
//#endregion
</script>
<style scoped lang="scss">
$run-status-size: 20px;
.run-status {
    width: $run-status-size;
    height: $run-status-size;
    border-radius: 50%;
    font-size: 14px;
    color: white;
    background-color: rgb(159 159 159);
 
    &_work {
        background-color: rgb(1 198 1);
    }
}
</style>