index.vue
5.25 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
<!--
* 功能:表格
* 作者:闫李壮
* 日期:2024-06-04
-->
<template>
<a-card :title="public.chartType == 15?tableInfo.cardName:tableInfoOrder.cardName">
<!-- 额外操作栏,只有当configType为1时显示 -->
<template #extra v-if="configType === 1">
<time-bar @change="timeBarChange" :chart-type="public.chartType" isCurrentDateDisabled/>
</template>
<template v-if="public.chartType == 15">
<transition-table v-show="tableInfo.tableData.length"
:data="tableInfo.tableData"
:columns="tableInfo.header">
</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"
:columns="tableInfoOrder.header">
</transition-table>
<a-empty v-show="!tableInfoOrder.tableData?.length"/>
</template>
</a-card>
</template>
<script lang="ts" setup>
import {useRoute, useRouter} from 'vue-router'
import {inject, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch} from 'vue';
import TransitionTable from '@/components/transition-table/index.vue'
import useLoading from '@/hooks/loading';
import {getChartInfo} from '@/api/dashboard/api';
import {getTimeObject} from "@/utils/charts";
import {SocketData} from "@/api/websocketService";
import {findById} from "@/utils/ruoyi";
import {useCompanyStore} from "@/store";
import {storeToRefs} from "pinia";
//加载中
const router = useRouter();
const props = defineProps({
public: {
type: Object,
default: () => {
return {}
}
},
configType: {
type: Number,
default: 1,
},
// 设备编号, -------------------------------------------没有timeBar的组件一定要传
deviceSn: {
type: String,
default: ''
}
})
const {loading, setLoading} = useLoading(false);
const varSn = ref<any>('');
const tableInfo = reactive<any>({
cardName: '',
header: [],
tableData: []
});
const tableInfoOrder = reactive<any>({
cardName: '',
header: [],
tableData: []
});
const timeOptions = ref<any>({});
const route = useRoute();
const companyStore = useCompanyStore();
const {companyValue, companyList, selectCompany} = storeToRefs(companyStore); // 选择的机构, 机构列表
// WebSocket 数据
const {data, sendData}: SocketData = inject('webSocketData', {
data: {value: 0},
sendData: () => {
}
});
const timeBarChange = async (timer: any) => {
timeOptions.value = timer;
await fetchData();
}
const fetchData = async () => {
try {
setLoading(true);
if (props.public.chartType == 15) onSubscribe();
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.cardName = res.data.cardName;
tableInfo.header = res.data.tableInfo.header;
tableInfo.tableData = res.data.tableInfo.tableData;
subscribe();
} else if (props.public.chartType == 16) {
tableInfoOrder.cardName = res.data.cardName;
tableInfoOrder.header = res.data.tableInfo.header;
tableInfoOrder.tableData = res.data.tableInfo.tableData;
}
} else {
if (props.public.chartType == 15) {
tableInfo.cardName = '';
tableInfo.header = [];
tableInfo.tableData = [];
subscribe();
} else if (props.public.chartType == 16) {
tableInfoOrder.cardName = '';
tableInfoOrder.header = [];
tableInfoOrder.tableData = [];
}
}
} catch (error) {
console.error('获取图表数据时出错:', error);
} finally {
setLoading(false);
}
}
// 监听 WebSocket 数据
watch(data, async (newVal: any) => {
if (newVal.stationSn == selectCompany.value?.deptSn && props.public.chartType == 15) {
let item: any = {
id: tableInfo.tableData.length + 1,
'时间': newVal.happenTime,
'事件': newVal.content,
'站点': newVal.stationName,
'设备': `${newVal.deviceName} ${newVal.deviceVarName}`,
'类别': newVal.categoryName,
'等级': newVal.triggerLevelName,
'状态': newVal.triggerStatusName,
'操作': '处理',
}
tableInfo.tableData.unshift(item);
}
});
// 订阅
const subscribe = () => {
sendData({
action: 'subscribe',
bizSn: selectCompany.value.deptSn
});
}
// 取消订阅
const onSubscribe = () => {
sendData({
action: 'unsubscribe',
bizSn: selectCompany.value.deptSn
});
}
onMounted(() => {
nextTick(() => {
fetchData();
})
})
onBeforeUnmount(() => {
onSubscribe();
})
defineExpose({
timeBarChange
})
</script>
<style lang="less" scoped>
@border-color: var(--color-border-2);
.arco-card {
width: 100%;
height: 100%;
padding-bottom: 12px;
box-sizing: border-box;
/* 调整卡片组件高度 */
:deep(.arco-card-body) {
height: calc(100% - 46px);
padding: 0;
overflow: hidden;
}
}
.arco-empty {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
</style>