index.vue
4.1 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
<!--
* 功能:峰谷数据
* 作者:曹晓桐
* 日期:2023-11-19
-->
<template>
<div>
<a-row :gutter="15">
<!-- 左侧树 start -->
<a-col :span="4">
<search-tree :title="$t('global.device')" :time="true" :multiple="true" @onChange="searchTreeChange" />
</a-col>
<!-- 左侧树 end -->
<!-- 右侧内容 start -->
<a-col :span="20">
<a-card class="general-card" :title="$t('power.energy.search.queryData')" v-if="renderData.length > 0">
<!-- <template #extra>
<a-button @click="downloadTableData" type="primary">
<template #icon>
<icon-download />
</template>
下载
</a-button>
</template> -->
<a-table :data="renderData" :loading="loading" :bordered="{ wrapper: true, cell: true }" :pagination="false"
:scroll="{ x: tableWidth, y: '100%' }">
<template #columns>
<a-table-column v-for="(item, index) in customColumnsValue" :key="index" :title="item.title"
:data-index="item.dataIndex" :fixed="item.fixed" :width="item.width"
:align="item.align"></a-table-column>
</template>
</a-table>
</a-card>
<custom-empty v-else />
</a-col>
<!-- 右侧内容 end -->
</a-row>
</div>
</template>
<script setup lang="ts">
import { onMounted, reactive, ref } from "vue";
import useLoading from "@/hooks/loading";
import { ppfvList } from "@/api/system/home-power";
import dayjs from "dayjs";
import { TableColumnData } from "@arco-design/web-vue";
import { download } from "@/api/download";
//加载中
const { loading, setLoading } = useLoading(false);
const tableWidth = ref < number > ();
const customColumnsValue = ref < any > ();
//数据
const renderData = ref < any > ([]);
//自定义头
const searchParams = ref < any > ({});
/**
* 搜索树Change
*/
const searchTreeChange = async (val: any) => {
searchParams.value = val;
await fetchData();
}
/**
* 获取图表类型
* @param param 时间参数
*/
const fetchData = async () => {
setLoading(true);
try {
let param = {
...searchParams.value
}
let res = await ppfvList(param);
if (res.code == 200 && res.data && res.data.length > 0) {
let data: any = [];
let columns: any = [];
let width = 0;
res.data.forEach((item: any, index: any) => {
let info: any = {};
item.forEach((citem: any, cindex: any) => {
info[citem.key] = citem.value;
if (index == 0) {
let temp: any = {
title: citem.key,
dataIndex: citem.key,
width: 120,
align: "center"
};
if (citem.key == '设备') {
temp["fixed"] = "left";
temp["align"] = "left";
temp["width"] = 220;
}
if (citem.key == '总') {
temp["fixed"] = "right";
temp["align"] = "center";
temp["width"] = 150;
}
width += temp.width;
columns.push(temp)
}
})
data.push(info);
})
customColumnsValue.value = columns;
renderData.value = data;
tableWidth.value = width;
} else {
renderData.value = [];
}
} catch (ex) {
renderData.value = [];
console.error("峰谷数据出错", ex)
} finally {
setLoading(false);
}
}
/**
* 合计
*/
const summary = () => {
}
/**
* 下载表格数据
*/
const downloadTableData = () => {
// download(url, params, filename)
// download("/api/system/home-power/ppfvList", searchParams.value, "峰谷数据").then(res => {
// console.log('res',res)
// }).catch(error=>{
// console.log('error', error)
// })
}
onMounted(async () => {
const dateNow = dayjs().format("YYYY-MM-DD HH:mm");
})
</script>
<style scoped>
.title {
font-size: 16px;
}
</style>