table-list-scroll.vue
6.72 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<template>
<div class="table-list">
<!-- <a-table ref="arcoTableRef" :scroll="{y: 44+'vh'}" :data="dataSource" :loading="loading" :columns="columns"-->
<!-- :bordered="false" :pagination="false"/>-->
<!-- <div class="back-btn" v-show="isShowBtn" @click="backTop">-->
<!-- <icon-arrow-rise/>-->
<!-- </div>-->
<!-- <div class="table-pagination">
<a-pagination :total="dataSource.length" show-total show-jumper></a-pagination><span>页</span>
</div> -->
<a-table :data="tableInfo?.tableData"
:pagination="false"
:loading="loading"
:scroll="{y: 44+'vh'}"
:bordered="false">
<template #columns>
<a-table-column
v-for="(item,index) in tableInfo?.header"
:key="index"
align="center"
:title="item.title"
:data-index="item.dataIndex"
ellipsis
tooltip
>
</a-table-column>
</template>
</a-table>
</div>
</template>
<script setup lang="ts">
import {ref, onMounted, watch, computed} from 'vue';
import useLoading from '@/hooks/loading';
import {getChartInfo} from '@/api/dashboard/api';
import {useIntervalFn} from '@vueuse/core';
import {getTimeObject, handleConfigChart, handlePreConfigChart} from '@/utils/charts';
import {useRoute, useRouter} from "vue-router";
const route = useRoute()
const router = useRouter();
// 定义图表信息的接口
defineProps({
isShowPagination: {
type: Boolean,
default: true,
},
});
const emit = defineEmits(["result"]);
const isFlag = ref(1); // 防抖
const isShowBtn = ref(false); //返回按钮显示状态
const dataSource = ref([]); // 表格数据
const arcoTableRef = ref(null); // 表格实例
const loadData = () => {
};
// 滚动事件
const handleScroll = (event: Event) => {
// 在这里处理滚动事件
const {target} = event;
const {scrollTop, scrollHeight, clientHeight} = target as HTMLDivElement;
// console.log(scrollTop)
if (scrollHeight - scrollTop - clientHeight < 10) {
isFlag.value++;
if (isFlag.value == 2) {
loading.value = true;
loadData()
}
}
if (scrollTop > 150) {
isShowBtn.value = true;
} else {
isShowBtn.value = false;
}
};
// 返回顶部
const backTop = () => {
const bodyElement = arcoTableRef.value?.$el.querySelector('.arco-table-body');
if (bodyElement) {
bodyElement.scrollTop = ({top: 0, behavior: 'smooth'});
}
}
// 状态管理
const {loading, setLoading} = useLoading(false);
const chartInfo = ref<any>({
cardName: '',
echartsOption: {},
singleInfo: null,
singleRightList: [],
});
const tableInfo = ref<any>({
header: [],
tableData: []
});
const timeOptions = ref<any>({});
const chartParams = ref<any>({});
// 时间变化处理函数
const timeBarChange = async (timer: any) => {
timeOptions.value = timer;
await fetchData();
};
const columns = ref<any>();
// 数据获取函数
const fetchData = async () => {
try {
setLoading(true);
const params = {
configId: chartParams.value.dashboardConfigId,
cardKey: chartParams.value.cardKey,
deviceSn: chartParams.value.deviceSn ? chartParams.value.deviceSn : undefined,
isTable: 1,
...getTimeObject(timeOptions.value),
};
const res: any = await getChartInfo(params);
if (res?.code == 200) {
tableInfo.value = res.data.tableInfo;
// console.log(tableInfo.value, 'tableInfo')
} else {
chartInfo.value = {
cardName: '',
echartsOption: {},
singleInfo: null,
};
}
emit('result', res.data);
} catch (error) {
console.error('获取图表数据时出错:', error);
} finally {
setLoading(false);
}
};
// 每5分钟轮询一次数据
useIntervalFn(fetchData, 300000);
onMounted(async () => {
if (route.query) {
chartParams.value = route.query;
}
await fetchData();
// const bodyElement = arcoTableRef.value?.$el.querySelector('.arco-table-body');
// if (bodyElement) {
// bodyElement.addEventListener('scroll', handleScroll);
// }
});
defineExpose({
handleTime: (val: any) => {
timeBarChange(val);
},
});
</script>
<style lang="less" scoped>
.table-list {
background: rgba(52, 144, 227, 0.1);
margin-top: 16px;
width: 100%;
box-sizing: border-box;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.back-btn {
position: absolute;
right: 20px;
bottom: 20px;
width: 30px;
height: 30px;
border-radius: 50%;
background-color: #fff;
text-align: center;
line-height: 30px;
z-index: 11;
}
/* table样式 */
:deep(.arco-table-body) {
background-color: transparent !important;
scroll-behavior: smooth;
}
:deep(.arco-table-header) {
background-color: transparent !important;
}
:deep(.arco-table-element) {
.arco-table-td {
background-color: transparent;
color: #fff;
border: none;
}
.arco-table-th {
background: rgba(7,118,123);
color: #fff;
height: 50px;
}
tbody tr {
height: 50px;
&:nth-child(even) {
background: rgba(7,118,123,0.1);
}
}
.arco-table-tr:hover {
list-style: none;
.arco-table-td {
background-color: rgba(52, 144, 227, 0.05) !important;
}
}
}
/* .arco-table-hover:not(.arco-table-dragging) .arco-table-tr:not(.arco-table-tr-empty):not(.arco-table-tr-summary):hover .arco-table-td:not(.arco-table-col-fixed-left):not(.arco-table-col-fixed-right),
.arco-table-hover .arco-table-tr-d rag .arco-table-td:not(.arco-table-col-fixed-left):not(.arco-table-col-fixed-right) {
background-color: transparent !important;
} */
/* 分页器样式 */
.table-pagination {
padding-bottom: 10px;
box-sizing: border-box;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: flex-end;
padding-right: 24px;
box-sizing: border-box;
:deep(.arco-pagination) {
justify-content: flex-end;
padding-right: 16px;
box-sizing: border-box;
.arco-pagination-total,
.arco-pagination-jumper-text-goto,
.arco-pagination-jumper-prepend,
.arco-pagination-jumper-append {
color: #fff;
}
.arco-pagination-item-active {
background-color: transparent;
color: #409EFF !important;
}
.arco-pagination-item:hover {
background: rgba(52, 144, 227, 0.05);
}
.arco-pagination-list {
span,
li {
color: #fff;
}
}
.arco-pagination-jumper .arco-pagination-jumper-input {
width: 56px;
height: 22px;
border-radius: 2px;
padding: 0px 8px;
gap: 10px;
background: rgba(15, 141, 255, 0.1);
background-color: transparent;
box-sizing: border-box;
border: 1px solid rgba(14, 136, 246, 0.5);
color: #fff;
}
}
span {
color: #fff;
}
}
</style>