zhouwenxuan
2023-09-05 54ef36700435d541a1154503b14f25ad984f6f90
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
<template>
    <div class="system-gas-container">
        <el-card shadow="hover">
            <div class="system-menu-search mb15">
                <el-form :inline="true" style="display: flex;align-items: flex-start;flex-wrap: wrap" >
                    <el-form-item label="日期:" >
                        <el-date-picker
                            v-model="state.tableData.listQuery.searchParams.time"
                            type="datetimerange"
                            format="YYYY-MM-DD HH:mm:ss"
                            range-separator="~"
                            start-placeholder="开始时间"
                            end-placeholder="结束时间"
                            @change = "chooseTime"
                        />
                    </el-form-item>
                    <el-form-item label="气体:">
                        <el-select
                            v-model="state.tableData.listQuery.searchParams.gas"
                            class="w100"
                            style="max-width: 180px"
                            size="default"
                        >
                            <el-option v-for="item in state.tableData.gasList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-button size="default" type="primary" class="ml10" @click="search()">
                        <el-icon>
                            <ele-Search />
                        </el-icon>
                        查询
                    </el-button>
                    <el-button size="default" class="ml10" @click="reset()">
                        <el-icon>
                            <RefreshLeft />
                        </el-icon>
                        重置
                    </el-button>
                </el-form>
            </div>
            <div id="gasChart" style="height: 500px;width: auto"></div>
            <el-table :data="state.tableData.data" style="width: 100%">
                <el-table-column type="index" label="序号" width="80" />
                <el-table-column align="center" prop="time" label="采集时间"/>
                <el-table-column align="center" prop="windSpeed" label="风速"/>
                <el-table-column align="center" prop="windDirection" label="风向"/>
                <el-table-column align="center" prop="gasName" label="气体名称"/>
                <el-table-column align="center" prop="gasPPM" label="气体浓度"/>
            </el-table>
            <br />
            <el-pagination
                @size-change="onHandleSizeChange"
                @current-change="onHandleCurrentChange"
                class="page-position"
                :pager-count="5"
                :page-sizes="[10, 20, 30]"
                v-model:current-page="state.tableData.listQuery.pageIndex"
                background
                v-model:page-size="state.tableData.listQuery.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="state.tableData.total">
            </el-pagination>
            <br />
            <br />
        </el-card>
    </div>
</template>
 
<script setup lang="ts">
import {reactive, ref,onMounted} from "vue";
import * as echarts from "echarts";
import { ElMessage, ElMessageBox } from 'element-plus'
import {TableGasState} from "/@/types/monitorData";
import { gasManageApi } from "/@/api/basicDataManage/gasManage";
import moment from "moment";
 
const state = reactive<TableGasState>({
    tableData: {
        data: [],
        total: 0,
        loading: false,
        listQuery: {
            pageIndex: 1,
            pageSize: 10,
            searchParams:{
                startTime: '',
                endTime: '',
                time: [],
                gas: ''
            }
        },
        gasList: []
    }
});
 
const chooseTime = (val: any) => {
    console.log("val",val)
    let sTime = Date.parse(new Date(val[0]));
    let eTime = Date.parse(new Date(val[1]));
    const datadiff = eTime - sTime + 86400000;
    const time = 7 * 24 * 60 * 60 * 1000;
    if (sTime > eTime) {
        return false;
    } else {
        if (datadiff > time) {
            ElMessage({
                type: 'error',
                message: '查询时间范围7天内',
            })
            state.tableData.listQuery.searchParams.time = [];
            return false;
        } else {
        }
    }
}
const dataZoomEnd = ref();
const xData = ref(['10:18:26', '10:18:56', '10:19:24', '10:19:54', '10:20:26', '10:20:56', '10:21:24']);
 
onMounted(
    () => {
        getNowTime();
        getAllGas();
        dataZoomEnd.value = xData.value.length > 25 ? 30 : 100; //x轴数量大于25,滑动框显示前30%标签,否则显示100%
        console.log("dataZoomEnd",dataZoomEnd.value)
        initCharts();
    }
);
const getNowTime = () => {
    let isDate = new Date()
    let sTime = `${isDate.getFullYear()}-${isDate.getMonth() + 1}-${isDate.getDate()}`
    let eTime = `${isDate.getFullYear()}-${isDate.getMonth() + 1}-${isDate.getDate()}`
    sTime = `${sTime} 00:00:00`
    eTime = `${eTime} ` + moment().format('HH:mm:ss')
    state.tableData.listQuery.searchParams.time = [sTime,eTime];
}
const initInfoData = () => {
    const param = {
        startTime: moment(state.tableData.listQuery.searchParams.time[0]).format('YYYY-MM-DD HH:mm:ss'),
        endTime: moment(state.tableData.listQuery.searchParams.time[1]).format('YYYY-MM-DD HH:mm:ss')
    }
    console.log("数据列表",param)
};
 
const getAllGas = async () => {
    let res = await gasManageApi().getGas({});
    if(res.data.code == 100) {
        state.tableData.gasList = res.data.data;
    }else {
        ElMessage({
            type: 'warning',
            message: res.data.msg
        });
    }
};
 
const onHandleSizeChange = (val: number) => {
    state.tableData.listQuery.pageSize = val;
    initInfoData();
};
// 分页改变
const onHandleCurrentChange = (val: number) => {
    state.tableData.listQuery.pageIndex = val;
    initInfoData();
};
const search = () => {
    initInfoData();
    console.log("vla",state.tableData.listQuery.searchParams)
}
const reset = () => {
    state.tableData.listQuery.searchParams.time = [];
    state.tableData.listQuery.searchParams.gas = '';
    state.tableData.listQuery.pageIndex = 1;
    initInfoData();
}
 
 
 
const initCharts = () => {
    const myChart = echarts.init(document.getElementById('gasChart'));
    // 指定图表的配置项和数据
    const option = {
        tooltip: {
            trigger: "axis",
            axisPointer: {
                type: 'shadow'
            },
        },
        xAxis: {
            show: true,
            type: 'category',
            // axisLabel: {
            //   interval: 0,
            //   rotate: 45
            // },
            data: xData.value
        },
        yAxis: {
            show: true,
            type: 'value'
        },
        series: [
            {
                data: [150, 230, 224, 218, 135, 147, 260],
                type: 'line',
                markLine: {//图表标线
                    symbol: "none",
                    data: [{
                        label: {
                            position: 'end', // 表现内容展示的位置
                            color: 'red'  // 展示内容颜色
                        },
                        yAxis: '200',
                        lineStyle: {
                            color: "red",
                            width: 1, // 0 的时候可以隐藏线
                            type: "solid" // 实线,不写默认虚线
                        }
                    },],//type: 'average', 平均值,  min最小值,  max 最大值,  median中位数
 
                },
            }
        ],
        // dataZoom: [
        //     {
        //         type: 'slider',
        //         show: dataZoomEnd.value == 100 ? false : true,
        //         realtime: true,
        //         start: 0,
        //         end: dataZoomEnd.value
        //     },
        // ]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
}
</script>
<style scoped lang="scss">
.yellow{
    width: 80px;
    height: 30px;
    background-color: rgb(255,223,37);
    line-height: 30px;
    color: white;
    box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.2);
    padding: 3px
}
.red{
    width: 80px;
    height: 30px;
    background-color: rgb(239,90,161);
    line-height: 30px;
    color: white;
    box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.2);
    padding: 3px
}
</style>