123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- <template>
- <div class="table-box">
- <div class="card table-search" style="overflow: hidden;">
- <el-form ref="formRef" :model="pageable" :inline="true" label-width="auto">
- <el-form-item label="自动站:" prop="base">
- <el-select v-model="pageable.as_code" filterable placeholder="请搜索自动站" remote reserve-keyword
- clearable style="width: 200px" @change="changeStation">
- <el-option v-for="item in platformList" :key="item.as_code"
- :label="item.as_code + ' ' + item.as_name" :value="item.as_code" />
- <template #prefix>
- <el-icon class="el-input__icon">
- <search />
- </el-icon>
- </template>
- </el-select>
- </el-form-item>
- <el-form-item label="观测时间:" prop="base">
- <div>
- <el-switch v-model="value1" @change="changetype" class="ml-2" inline-prompt active-text="日"
- inactive-text="小时" style="margin-right: 10px;" />
- <el-date-picker v-model="dateRange" value-format="YYYY-MM-DD HH:mm"
- :format="value1 ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm'"
- :type="value1 ? 'daterange' : 'datetimerange'" range-separator="-" start-placeholder="开始时间"
- end-placeholder="结束时间" :disabled-date="disabledDate" @focus="handleFocus"
- @calendar-change="handleChange" @change="handleDateChange"
- :default-time="[new Date(2000, 1, 1, 0, 0), new Date(2000, 1, 1, new Date().getHours(), 0)]"
- style="width: 300px;"></el-date-picker>
- </div>
- </el-form-item>
- <el-form-item>
- <div>
- <el-button type="primary" @click="getHistoryList">查询</el-button>
- <el-button plain @click="resetForm">重置</el-button>
- </div>
- </el-form-item>
- </el-form>
- </div>
- <div class="main_list">
- <el-row :gutter="15">
- <el-col :span="24">
- <div class="chart_item zhuti">
- <div style="font-weight: bold;" class="item_title">
- <span v-if="value1">日降水量(mm)</span>
- <span v-else>小时累计降水量 ({{ isFANDOU ? '翻斗' : '称重'}})(mm)</span>
- </div>
- <div class="mt5">
- <div ref="data" class="data_box"></div>
- </div>
- </div>
- </el-col>
- </el-row>
- </div>
- </div>
- </template>
- <script setup lang="ts" name="dataSynthesis">
- import * as echarts from 'echarts';
- import { ElMessage } from "element-plus";
- import { useGlobalStore } from "@/stores/modules/global";
- import { ref, computed, onMounted, reactive, watch, onDeactivated, onActivated, nextTick } from "vue";
- import { getDataItemList, getPlatformList, getRgDataList, getTacRecordList } from "@/api/modules/allData";
- import { Platform } from "@/api/interface";
- import { parseTime } from '@/utils/index';
- import { isToday, isWithinThirtyMinutes, getTimeStamp, getStamp, isWithin24Hours, isDateFuture, isDateRangeWithinDays } from "@/utils/dateTime";
- import { useUserStore } from "@/stores/modules/user";
- const value1 = ref(true)
- const dateRange = ref<[any, any]>([parseTime(new Date(getTimeStamp(5)), '{y}-{m}-{d}') + ' 00:00', parseTime(new Date(), '{y}-{m}-{d}') + ' 00:00']);
- const changetype = (e) => {
- if (!e) {
- dateRange.value = [parseTime(getTimeStamp(2), '{y}-{m}-{d} {h}:{i}'), parseTime(new Date(), '{y}-{m}-{d} {h}') + ':00']
- } else {
- dateRange.value = [parseTime(new Date(getTimeStamp(5)), '{y}-{m}-{d}') + ' 00:00', parseTime(new Date(), '{y}-{m}-{d}') + ' 00:00']
- }
- getHistoryList()
- }
- const handleDateRangeChange = (newVal) => {
- const [startDate, endDate] = newVal;
- if (endDate && isToday(endDate)) {
- // 获取当前时间的整点
- const currentHour = new Date().getHours();
- const roundedEndDate = new Date(endDate);
- roundedEndDate.setHours(0, 0, 0, 0); // 设置分钟、秒、毫秒为0
- const startZeroed = new Date(startDate);
- startZeroed.setHours(0, 0, 0, 0);
- dateRange.value = [parseTime(new Date(startZeroed)), parseTime(new Date(roundedEndDate))];
- } else {
- const noTodayStart = new Date(startDate).setHours(0, 0, 0, 0);
- const noTodayEnd = new Date(endDate).setHours(0, 0, 0, 0);
- dateRange.value = [parseTime(new Date(noTodayStart)), parseTime(new Date(noTodayEnd))];
- }
- };
- const handleDateChange = async (e) => {
- if (isDateFuture(e[0]) || isDateFuture(e[1])) {
- ElMessage.error("不得选择未来的时间");
- } else {
- if (!value1.value) {
- // if (isWithin24Hours(e[0], e[1])) {
- // 获取参数
- getHistoryList()
- // } else {
- // ElMessage.error("小时模式下时间间隔不能大于24小时");
- // }
- } else {
- // if (isDateRangeWithinDays(e[0], e[1], 30)) {
- await handleDateRangeChange(e)
- getHistoryList()
- // } else {
- // ElMessage.error("日模式下时间间隔不能大于30天");
- // }
- }
- }
- }
- const pickDay = ref()
- const handleFocus = () => {
- pickDay.value = null
- }
- const limitTime = 1000 * 60 * 60 * 24 * 30
- const disabledDate = (time: Date) => {
- return time.getTime() > Date.now() - 8.64e6
- }
- const handleChange = (val: Date[]) => {
- const [pointDay] = val
- pickDay.value = pointDay
- }
- const pageable = ref({
- data_type: false,
- time_order: 1,
- as_code: undefined,
- data_items: [],
- pageNum: 1,
- });
- let historyColumns = [
- {
- data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
- data_id: 309,
- data_type: "降水",
- data_item: "RI_JIANG_SHUI_LIANG",
- data_name: "日降水量",
- data_unit: "mm",
- data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
- data_value: "",
- data_order: 0,
- data_condition: 0,
- isSelected: true
- },
- {
- data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
- data_id: 312,
- data_type: "降水",
- data_item: "XIAO_SHI_LEI_JI_JIANG_SHUI_LIANG_CHENG_ZHONG",
- data_name: "小时累计降水量(称重)",
- data_unit: "mm",
- data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
- data_value: "",
- data_order: 0,
- data_condition: 0
- }, {
- data_id: 302,
- data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
- data_type: "降水",
- data_name: "小时累计降水量(翻斗)",
- data_item: "XIAO_SHI_LEI_JI_JIANG_SHUI_LIANG_FAN_DOU",
- data_unit: "mm",
- data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
- data_value: "",
- data_order: 0,
- data_condition: 0,
- isSelected: true
- },
- ]
- // 查询自动站列表
- const queryas = ref<Platform>({
- pageSize: 50,
- pageNum: 1,
- currentpage: 1
- })
- const userStore = useUserStore();
- const platformList = ref<any>(computed(() => userStore.stations))
- const selectPlatform = ref()
- const getPlatforms = async () => {
- pageable.value.as_code = platformList.value[0].as_code
- selectPlatform.value = platformList.value[0]
- getHistoryList()
- };
- const changeStation = () => {
- getHistoryList()
- }
- //时间戳转换为指定格式的日期字符串
- function formatDate(timestamp, type) {
- const date = new Date(timestamp * 1000); // 将时间戳转换为毫秒
- const year = date.getFullYear();
- const month = String(date.getMonth() + 1).padStart(2, '0');
- const day = String(date.getDate()).padStart(2, '0');
- const hours = String(date.getHours()).padStart(2, '0');
- const minutes = String(date.getMinutes()).padStart(2, '0');
- if (type === 1) {
- return `${month}/${day} ${hours}:${minutes}`;
- } else {
- return `${year}-${month}-${day} ${hours}:${minutes}`;
- }
- }
- const timeArr = ref()
- const dayArr = ref()
- const hourArr1 = ref()
- const isFANDOU=ref(false)
- const getHistoryList = async () => {
- if (isDateFuture(dateRange.value[0]) || isDateFuture(dateRange.value[1])) {
- ElMessage.error("不得选择未来的时间");
- return false;
- }
- const { data } = await getDataItemList({ ...pageable.value, as_code_list: [pageable.value.as_code], data_items: historyColumns, time_space: value1.value ? 1440 : 60, end_time: getStamp(dateRange.value[1]), begin_time: getStamp(dateRange.value[0]) });
- timeArr.value = data.list?.map(item => {
- return formatDate(item.data_time_i, 1)
- })
- dayArr.value = data.list?.map(item => {
- return item[309]
- })
- hourArr1.value = data.list?.map(item => {
- if (item[312] !== '0.0' && item[312] !== '--' && item[312] !== '/') {
- return item[312]
- } else if (item[302] !== '0.0' && item[302] !== '--' && item[312] !== '/') {
- return item[302]
- } else {
- return '0.0'
- }
- })
- isFANDOU.value = data.list.some(item => {
- // 尝试将项转换为数字,如果转换失败(例如,对于 '--'),则返回 NaN
- const number = Number(item[302]);
- // 检查是否是一个有效的数字且大于 10
- return !isNaN(number) && number > 0;
- });
- nextTick(() => {
- showData()
- })
- };
- const formRef = ref()
- const data = ref()
- const globalStore = useGlobalStore();
- const isDark = computed(() => globalStore.isDark);
- // resetForm
- const resetForm = () => {
- dateRange.value = [parseTime(new Date(getTimeStamp(5)), '{y}-{m}-{d}') + ' 00:00', parseTime(new Date(), '{y}-{m}-{d}') + ' 00:00']
- value1.value = true
- pageable.value.as_code = platformList.value[0].as_code
- getHistoryList()
- };
- const showData = () => {
- let mychart = echarts.init(data.value);
- let option = {
- title: {
- text: '暂无数据',
- show: !timeArr.value ? true : false,
- x: 'center',
- y: 'center',
- textStyle: {
- fontSize: 14,
- fontWeight: 'normal',
- }
- },
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- type: 'shadow'
- },
- formatter: function (params) {
- return [
- "降水:" + [Number(params[0].value) ? Number(params[0].value) : "/"],
- '时间:' + params[0].name
- ].join("<br/>");
- },
- },
- grid: {
- left: '20',
- right: '20',
- bottom: '20',
- // top: '20',
- containLabel: true
- },
- xAxis: [
- {
- type: 'category',
- data: timeArr.value,
- axisTick: {
- alignWithLabel: true
- },
- axisLabel: {
- interval: 1,
- },
- }
- ],
- yAxis: [
- {
- type: 'value',
- boundaryGap: [0, '20%']
- }
- ],
- series: [
- {
- name: '降水量',
- type: 'bar',
- barWidth: '50%',
- color: '#88c1ff',
- data: value1.value ? dayArr.value : hourArr1.value
- }
- ]
- };
- mychart.setOption(option)
- window.addEventListener("resize", function () {
- mychart.resize();
- });
- }
- // watch(isDark, () => {
- // showData()
- // });
- onMounted(() => {
- // showData()
- getPlatforms()
- })
- </script>
- <style scoped lang="scss">
- .el-row .el-col {
- // margin-bottom: 15px;
- }
- .main_list {
- background: transparent !important;
- box-shadow: none !important;
- padding: 0 !important;
- height: calc(100vh - 150px);
- margin-bottom: 10px;
- overflow-y: scroll;
- overflow-x: hidden;
- .chart_item {
- border-radius: 10px;
- padding: 10px;
- background-color: #fff;
- // height: 100%;
- // margin-bottom: 15px;
- .item_title {
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .FTP_box {
- padding: 0 50px;
- display: flex;
- align-items: center;
- justify-content: space-between;
- .FTP_item {
- flex: 1;
- flex-shrink: 0;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- img {
- width: 56px;
- margin-bottom: 20px;
- }
- }
- }
- }
- .info_box {
- .info_title {
- color: #999999;
- font-size: 16px;
- }
- .info_content {
- height: 40px;
- font-weight: bold;
- color: #000;
- font-size: 26px;
- }
- }
- }
- .data_box {
- height: calc(100vh - 215px);
- // height: 100%;
- }
- </style>
|