马宇豪
2023-10-20 67ddfbd2db13529c8923838d4dc7ed4cf105b0fe
src/views/monitorData/gasData/index.vue
@@ -39,7 +39,7 @@
                </el-form>
            </div>
            <div id="gasChart" style="height: 500px;width: auto"></div>
            <el-table :data="state.tableData.data" style="width: 100%;margin-top: 20px">
            <el-table :data="state.tableData.data" style="width: 100%;margin-top: 20px" v-loading="loading">
                <el-table-column type="index" label="序号" width="80" />
                <el-table-column align="center" prop="time" label="采集时间"/>
                <el-table-column align="center" prop="windSpeed" label="风速"/>
@@ -67,7 +67,7 @@
</template>
<script setup lang="ts">
import {reactive, ref,onMounted} from "vue";
import {reactive, ref, onMounted, shallowRef} from "vue";
import * as echarts from "echarts";
import { ElMessage, ElMessageBox } from 'element-plus'
import {TableGasState} from "/@/types/monitorData";
@@ -112,10 +112,12 @@
        }
    }
}
const loading = ref(false);
const dataZoomEnd = ref();
const xData = ref([]);
const yData = ref([]);
const markLines = ref(0);
const myChart = shallowRef(null)
onMounted(
    () => {
        getNowTime();
@@ -139,14 +141,20 @@
    }
    let resChart = await gasDataApi().getGasLineChart(chartParam);
    if(resChart.data.code == 100) {
        xData.value = resChart.data.data.map((item: any) => {
            return item.time;
        })
        yData.value = resChart.data.data.map((item: any) => {
            return item.gasValue;
        })
        dataZoomEnd.value = xData.value.length > 25 ? 30 : 100;
        markLines.value = 110;
        if (resChart.data.data) {
            xData.value = resChart.data.data.map((item: any) => {
                return item.time;
            })
            yData.value = resChart.data.data.map((item: any) => {
                return item.gasValue;
            })
            dataZoomEnd.value = xData.value.length > 25 ? 30 : 100;
        }else {
            xData.value = [];
            yData.value = [];
            markLines.value = 0;
            dataZoomEnd.value = 100;
        }
        initCharts();
    }else {
        ElMessage({
@@ -155,6 +163,7 @@
        });
    }
    loading.value = true;
    //表格
    const pageParam = {
        pageIndex: state.tableData.listQuery.pageIndex,
@@ -171,6 +180,7 @@
        state.tableData.total = res.data.total;
        state.tableData.listQuery.pageIndex = res.data.pageIndex;
        state.tableData.listQuery.pageSize = res.data.pageSize;
        loading.value = false;
    }else {
        ElMessage({
            type: 'warning',
@@ -183,7 +193,10 @@
    let res = await gasManageApi().getGas({});
    if(res.data.code == 100) {
        state.tableData.gasList = res.data.data;
        console.log("气体",state.tableData.gasList)
        //默认选择第一个气体
        state.tableData.listQuery.searchParams.gas = state.tableData.gasList[0].id;
        markLines.value = state.tableData.gasList[0].threshold;
        initInfoData();
    }else {
        ElMessage({
@@ -203,18 +216,27 @@
    initInfoData();
};
const search = () => {
    state.tableData.listQuery.pageIndex = 1;
    const gasObj = state.tableData.gasList.filter(item => {
        return item.id == state.tableData.listQuery.searchParams.gas
    });
    markLines.value = gasObj[0].threshold;
    initInfoData();
    console.log("vla",state.tableData.listQuery.searchParams)
}
const reset = () => {
    getNowTime();
    state.tableData.listQuery.searchParams.gas = state.tableData.gasList[0].id;
    markLines.value = state.tableData.gasList[0].threshold;
    state.tableData.listQuery.pageIndex = 1;
    initInfoData();
}
const initCharts = () => {
    const myChart = echarts.init(document.getElementById('gasChart'));
    if (myChart.value != null && myChart.value != "" && myChart.value != undefined) {
        myChart.value.dispose();
    }
     myChart.value = echarts.init(document.getElementById('gasChart'));
    // 指定图表的配置项和数据
    const option = {
        tooltip: {
@@ -234,6 +256,20 @@
            max: Math.max(markLines.value,...yData.value),
            min: Math.min(markLines.value,...yData.value)
        },
        graphic: {
            type: 'text',     // 类型:文本
            left: 'center',
            top: 'middle',
            silent: true,     // 不响应事件
            invisible: yData.value.length > 0,   // 有数据就隐藏
            style: {
                fill: '#9d9d9d',
                fontWeight: 'bold',
                text: '暂无数据',
                fontFamily: 'Microsoft YaHei',
                fontSize: '25px'
            }
        },
        series: [
            {
                data: yData.value,
@@ -245,10 +281,10 @@
                            position: 'end', // 表现内容展示的位置
                            color: 'red'  // 展示内容颜色
                        },
                        yAxis: markLines.value,
                        yAxis: markLines.value == 0 ? '':markLines.value ,
                        lineStyle: {
                            color: "red",
                            width: 1, // 0 的时候可以隐藏线
                            width: markLines.value == 0 ? 0: 1, // 0 的时候可以隐藏线
                            type: "solid" // 实线,不写默认虚线
                        }
                    },],//type: 'average', 平均值,  min最小值,  max 最大值,  median中位数
@@ -272,10 +308,10 @@
        ]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option,true);
    myChart.value.setOption(option,true);
    //自适应宽度
    window.addEventListener('resize', function () {
        myChart.resize();
    window.addEventListener('resize',function () {
        myChart.value.resize();
    })
}
</script>
@@ -298,4 +334,4 @@
    box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.2);
    padding: 3px
}
</style>
</style>