web
10 天以前 a8dd05927a7ca3b34f7729604744a24375f3549f
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
<script setup>
import {onMounted, ref} from 'vue'
import * as echarts from 'echarts/core';
import {getFlowPointList} from "@/api/screen/index.js";
import {getFlowDate} from "@/api/screen/ecology/index.js";
 
const cascaderOption = { label: 'pointName', value: 'id', children: 'childrenList', checkStrictly: true, expandTrigger: 'hover', emitPath: false }; //级联选择器配置
const typeOption = ref([])
const pointId = ref()
const timeType = ref(2)
const ssChartRef = ref(); //瞬时图表
const ljChartRef = ref(); //累计图表
let ssCharts = null;
let ljCharts = null;
const tongjiData = ref([])
 
const selectOption = ref([
    {label: '本年', value: 6},
    {label: '本季', value: 5},
    {label: '本月', value: 4},
    {label: '本周', value: 3},
    {label: '本日', value: 2},
])
 
// 获取折线图配置
const getLineOption = (data, startColor, endColor) => {
    let xdata = [];
    let sdata = [];
    data.forEach(item => {
        xdata.push(item.dateTime)
        sdata.push(item.newFlow)
    })
    return {
        tooltip: {
            trigger: 'axis',
        },
        grid: {
            left: 60,
            right: 20,
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: xdata,
            axisLabel: {
                color: '#fff',
                fontSize: '1.2rem',
                rotate: -15,
            },
        },
        yAxis: {
            type: 'value',
            name: 'm³/s',
            nameTextStyle: {
                color: '#fff',
                fontSize: '1.2rem'
            },
            axisLabel: {
                color: '#fff',
                fontSize: '1.2rem'
            }
        },
        series: [
            {
                data: sdata,
                type: 'line',
                areaStyle: {
                    color: {
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0, color: startColor // 0% 处的颜色
                        }, {
                            offset: 1, color: endColor // 100% 处的颜色
                        }],
                        global: false // 缺省为 false
                    }
                }
            }
        ]
    }
}
// 获取柱状图配置
const getBarOption = (data, color) => {
    let xdata = [];
    let sdata = [];
    data.forEach(item => {
        xdata.push(item.dateTime)
        sdata.push(item.totalFlow)
    })
    return {
        tooltip: {
            trigger: 'axis',
        },
        grid: {
            left: 60,
            right: 20,
        },
        xAxis: {
            type: 'category',
            data: xdata,
            axisLabel: {
                color: '#fff',
                fontSize: '1.2rem',
                rotate: -15,
            }
        },
        yAxis: {
            type: 'value',
            name: '10⁸m³',
            nameTextStyle: {
                color: '#fff',
                fontSize: '1.2rem'
            },
            axisLabel: {
                color: '#fff',
                fontSize: '1.2rem'
            }
        },
        series: [
            {
                data: sdata,
                type: 'bar',
                itemStyle: {
                    color: color
                }
            }
        ]
    }
}
 
// 新扎口图表
const updateLine = () => {
    const option = getLineOption(tongjiData.value, 'rgba(94,229,92,1)', 'rgba(94,229,92,0.2)')
    ssCharts.setOption(option)
}
const updateBar = () => {
    const option = getBarOption(tongjiData.value, 'rgba(94,229,92,1)')
    ljCharts.setOption(option)
}
 
 
// 获取监测点
const getPoint = () => {
    getFlowPointList().then(res => {
        typeOption.value = res.data
        pointId.value = res.data[0]?.childrenList?.[0].id
        getFlowTongjiData()
    })
}
 
// 获取统计数据
const getFlowTongjiData = () => {
    let params = {
        pointId: pointId.value,
        dataType: timeType.value
    }
    getFlowDate(params).then(res => {
        tongjiData.value = res.data
        updateCharts()
    })
}
 
// 初始化echarts
const initCharts = () => {
    if (ssChartRef.value) {
        ssCharts = echarts.init(ssChartRef.value);
    }
    if (ljChartRef.value) {
        ljCharts = echarts.init(ljChartRef.value);
    }
}
 
// 更新echarts
const updateCharts = () => {
    updateLine()
    updateBar()
}
 
onMounted(() => {
    initCharts()
    getPoint()
})
</script>
 
<template>
    <div class="ecology">
        <div class="ecology-l item">
            <div class="item-t">
                <el-cascader size="large"
                             v-model="pointId"
                             :options="typeOption"
                             :show-all-levels="false"
                             :props="cascaderOption"
                             clearable
                             style="width: 30rem; marginRight:10rem"
                             @change="getFlowTongjiData"
                />
                <el-select
                    v-model="timeType"
                    class="m-2"
                    placeholder="请选择筛选时间"
                    size="large"
                    style="width: 20rem"
                    @change="getFlowTongjiData"
                >
                    <el-option
                        v-for="item in selectOption"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    />
                </el-select>
            </div>
            <div class="charts-t">瞬时流量分析</div>
            <div class="item-chart-ss" ref="ssChartRef"></div>
            <div class="charts-t">累计流量分析</div>
            <div class="item-chart-lj" ref="ljChartRef"></div>
        </div>
    </div>
</template>
 
<style scoped lang="scss">
.ecology {
    height: 100%;
    background: linear-gradient(180deg, #91BDDB 0%, rgba(102, 102, 102, 0.5) 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
 
    .item {
        width: 95%;
        height: 96%;
        padding: 1rem 20rem;
        background: rgba(23, 108, 229, 0.3);
        border: 1px solid #176CE5;
        border-radius: 8px;
        .item-t {
            height: 5%;
            display: flex;
            align-items: center;
        }
        .charts-t{
            font-size: 1.5rem;
            color: #fff;
            text-align: right;
        }
        .item-chart-ss {
            height: 44%;
        }
 
        .item-chart-lj {
            height: 44%
        }
    }
}
</style>