index.vue
5.9 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!--
* 功能:表格
* 作者:闫李壮
* 日期:2024-06-04
-->
<template>
<div class="table-list-view">
<template v-if="public.chartType == 15">
<transition-table v-show="tableInfo.tableData.length"
:data="tableInfo.tableData"
:preview="public.tablePre"
:columns="tableInfo.header"
:table-css="tableCss">
</transition-table>
<a-empty v-show="!tableInfo.tableData.length"/>
</template>
<template v-if="public.chartType == 16">
<transition-table v-show="tableInfoOrder.tableData.length"
:data="tableInfoOrder.tableData"
:preview="public.tablePre"
:columns="tableInfoOrder.header"
:table-css="tableCss">
</transition-table>
<a-empty v-show="!tableInfoOrder.tableData.length"/>
</template>
</div>
</template>
<script lang="ts" setup>
import {useRoute, useRouter} from 'vue-router';
import {inject, onBeforeUnmount, onMounted, onUnmounted, reactive, ref, watch} from 'vue';
import useLoading from '@/hooks/loading';
import {getChartInfo} from '@/api/dashboard/api';
import {getTimeObject} from "@/utils/charts";
import TransitionTable from "@/components/transition-table/index.vue";
import {DeviceVarAlarmMessage, SocketData} from "@/api/websocketService";
import {useCompanyStore} from "@/store";
import {findById} from "@/utils/ruoyi";
import {storeToRefs} from "pinia";
import dayjs from "dayjs";
//加载中
const router = useRouter();
const route = useRoute();
const companyStore = useCompanyStore();
const {companyList} = companyStore; // 选择的机构, 机构列表
const props = defineProps({
public: {
type: Object,
default: () => {
return {}
}
},
configType: {
type: Number,
default: 1,
},
// 设备编号, -------------------------------------------没有timeBar的组件一定要传
deviceSn: {
type: String,
default: ''
}
})
const {loading, setLoading} = useLoading(false);
const tableCss = {
columns: {
color: props.public.tablePre == 1 ? 'var(--color-text-1)' : '#FFFFFF',
background: 'rgba(52, 144, 227, 0.05)'
},
data: {
color: props.public.tablePre == 1 ? 'var(--color-text-1)' : '#FFFFFF',
background: 'rgba(52, 144, 227, 0.1)'
}
}
const tableInfo = ref<any>({
cardName: '',
header: [],
tableData: []
})
const tableInfoOrder = ref<any>({
cardName: '',
header: [],
tableData: []
})
const timeOptions = ref<any>({
timer: dayjs().format("YYYY"),
timeUnit: 2,
});
const selectCompany = ref<any>(route.query.stationId ? findById(companyList, Number(route.query.stationId)) : storeToRefs(companyStore).selectCompany.value);
const timeBarChange = async (timer: any) => {
timeOptions.value = timer;
await fetchData();
}
const fetchData = async () => {
if (!props.public.cardKey || !props.public.dashboardConfigId) {
return;
}
if (props.public.chartType == 15) onSubscribe();
try {
setLoading(true);
const params = {
configId: props.public.dashboardConfigId,
cardKey: props.public.cardKey,
deviceSn: props.public.deviceSn,
...getTimeObject(timeOptions.value)
};
const res: any = await getChartInfo(params);
if (res.code === 200 && res.data) {
if (props.public.chartType == 15) {
tableInfo.value.cardName = res.data.cardName;
tableInfo.value.header = res.data.tableInfo?.header;
tableInfo.value.tableData = res.data.tableInfo ? res.data.tableInfo.tableData : [];
subscribe();
} else if (props.public.chartType == 16) {
tableInfoOrder.value.cardName = res.data.cardName;
tableInfoOrder.value.header = res.data.tableInfo?.header;
tableInfoOrder.value.tableData = res.data.tableInfo ? res.data.tableInfo.tableData : [];
}
} else {
if (props.public.chartType == 15) {
tableInfo.value.cardName = "";
tableInfo.value.header = [];
tableInfo.value.tableData = [];
subscribe();
} else if (props.public.chartType == 16) {
tableInfoOrder.value.cardName = "";
tableInfoOrder.value.header = [];
tableInfoOrder.value.tableData = [];
}
}
} catch (error) {
console.error('获取图表数据时出错:', error);
} finally {
setLoading(false);
}
}
// WebSocket 数据
const {data, sendData}: SocketData = inject('webSocketData', {
data: {value: 0},
sendData: () => {
}
});
// 订阅
const subscribe = () => {
sendData({
action: 'subscribe',
bizSn: selectCompany.value.deptSn
});
}
// 取消订阅
const onSubscribe = () => {
sendData({
action: 'unsubscribe',
bizSn: selectCompany.value.deptSn
});
}
watch(data, async (newVal: DeviceVarAlarmMessage) => {
if (newVal.stationSn == selectCompany.value.deptSn && props.public.chartType == 15) {
let item: any = {
id: tableInfo.value.tableData.length + 1,
'时间': newVal.happenTime,
'事件': newVal.content,
'站点': newVal.stationName,
'设备': `${newVal.deviceName} ${newVal.deviceVarName}`,
'类别': newVal.categoryName,
'等级': newVal.triggerLevelName,
'状态': newVal.triggerStatusName,
'操作': '处理',
}
tableInfo.value.tableData.unshift(item);
}
});
onMounted(() => {
// console.log(props.public, '公共')
if (route.query.stationId) {
selectCompany.value = findById(companyList, Number(route.query.stationId));
} else {
selectCompany.value = storeToRefs(companyStore).selectCompany.value;
}
fetchData();
})
onUnmounted(() => {
onSubscribe();
})
defineExpose({
handleTime: (val: any) => {
timeBarChange(val);
},
})
</script>
<style lang="less" scoped>
.table-list-view {
width: 100%;
height: 100%;
color: #FFFFFF;
margin-top: 6px;
}
.arco-empty {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
</style>