index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <div class="table-box">
  3. <div class="card table-search" style="overflow: hidden;">
  4. <el-form ref="formRef" :model="pageable" :inline="true" label-width="auto">
  5. <el-form-item label="自动站:" prop="base">
  6. <el-select v-model="pageable.as_code" filterable placeholder="请搜索自动站" remote reserve-keyword
  7. clearable style="width: 200px" @change="changeStation">
  8. <el-option v-for="item in platformList" :key="item.as_code"
  9. :label="item.as_code + ' ' + item.as_name" :value="item.as_code" />
  10. <template #prefix>
  11. <el-icon class="el-input__icon">
  12. <search />
  13. </el-icon>
  14. </template>
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item label="观测时间:" prop="base">
  18. <div>
  19. <el-switch v-model="value1" @change="changetype" class="ml-2" inline-prompt active-text="日"
  20. inactive-text="小时" style="margin-right: 10px;" />
  21. <el-date-picker v-model="dateRange" value-format="YYYY-MM-DD HH:mm"
  22. :format="value1 ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm'"
  23. :type="value1 ? 'daterange' : 'datetimerange'" range-separator="-" start-placeholder="开始时间"
  24. end-placeholder="结束时间" :disabled-date="disabledDate" @focus="handleFocus"
  25. @calendar-change="handleChange" @change="handleDateChange"
  26. :default-time="[new Date(2000, 1, 1, 0, 0), new Date(2000, 1, 1, new Date().getHours(), 0)]"
  27. style="width: 300px;"></el-date-picker>
  28. </div>
  29. </el-form-item>
  30. <el-form-item>
  31. <div>
  32. <el-button type="primary" @click="getHistoryList">查询</el-button>
  33. <el-button plain @click="resetForm">重置</el-button>
  34. </div>
  35. </el-form-item>
  36. </el-form>
  37. </div>
  38. <div class="main_list">
  39. <el-row :gutter="15">
  40. <el-col :span="24">
  41. <div class="chart_item zhuti">
  42. <div style="font-weight: bold;" class="item_title">
  43. <span v-if="value1">日降水量(mm)</span>
  44. <span v-else>小时累计降水量 ({{ isFANDOU ? '翻斗' : '称重'}})(mm)</span>
  45. </div>
  46. <div class="mt5">
  47. <div ref="data" class="data_box"></div>
  48. </div>
  49. </div>
  50. </el-col>
  51. </el-row>
  52. </div>
  53. </div>
  54. </template>
  55. <script setup lang="ts" name="dataSynthesis">
  56. import * as echarts from 'echarts';
  57. import { ElMessage } from "element-plus";
  58. import { useGlobalStore } from "@/stores/modules/global";
  59. import { ref, computed, onMounted, reactive, watch, onDeactivated, onActivated, nextTick } from "vue";
  60. import { getDataItemList, getPlatformList, getRgDataList, getTacRecordList } from "@/api/modules/allData";
  61. import { Platform } from "@/api/interface";
  62. import { parseTime } from '@/utils/index';
  63. import { isToday, isWithinThirtyMinutes, getTimeStamp, getStamp, isWithin24Hours, isDateFuture, isDateRangeWithinDays } from "@/utils/dateTime";
  64. import { useUserStore } from "@/stores/modules/user";
  65. const value1 = ref(true)
  66. const dateRange = ref<[any, any]>([parseTime(new Date(getTimeStamp(5)), '{y}-{m}-{d}') + ' 00:00', parseTime(new Date(), '{y}-{m}-{d}') + ' 00:00']);
  67. const changetype = (e) => {
  68. if (!e) {
  69. dateRange.value = [parseTime(getTimeStamp(2), '{y}-{m}-{d} {h}:{i}'), parseTime(new Date(), '{y}-{m}-{d} {h}') + ':00']
  70. } else {
  71. dateRange.value = [parseTime(new Date(getTimeStamp(5)), '{y}-{m}-{d}') + ' 00:00', parseTime(new Date(), '{y}-{m}-{d}') + ' 00:00']
  72. }
  73. getHistoryList()
  74. }
  75. const handleDateRangeChange = (newVal) => {
  76. const [startDate, endDate] = newVal;
  77. if (endDate && isToday(endDate)) {
  78. // 获取当前时间的整点
  79. const currentHour = new Date().getHours();
  80. const roundedEndDate = new Date(endDate);
  81. roundedEndDate.setHours(0, 0, 0, 0); // 设置分钟、秒、毫秒为0
  82. const startZeroed = new Date(startDate);
  83. startZeroed.setHours(0, 0, 0, 0);
  84. dateRange.value = [parseTime(new Date(startZeroed)), parseTime(new Date(roundedEndDate))];
  85. } else {
  86. const noTodayStart = new Date(startDate).setHours(0, 0, 0, 0);
  87. const noTodayEnd = new Date(endDate).setHours(0, 0, 0, 0);
  88. dateRange.value = [parseTime(new Date(noTodayStart)), parseTime(new Date(noTodayEnd))];
  89. }
  90. };
  91. const handleDateChange = async (e) => {
  92. if (isDateFuture(e[0]) || isDateFuture(e[1])) {
  93. ElMessage.error("不得选择未来的时间");
  94. } else {
  95. if (!value1.value) {
  96. // if (isWithin24Hours(e[0], e[1])) {
  97. // 获取参数
  98. getHistoryList()
  99. // } else {
  100. // ElMessage.error("小时模式下时间间隔不能大于24小时");
  101. // }
  102. } else {
  103. // if (isDateRangeWithinDays(e[0], e[1], 30)) {
  104. await handleDateRangeChange(e)
  105. getHistoryList()
  106. // } else {
  107. // ElMessage.error("日模式下时间间隔不能大于30天");
  108. // }
  109. }
  110. }
  111. }
  112. const pickDay = ref()
  113. const handleFocus = () => {
  114. pickDay.value = null
  115. }
  116. const limitTime = 1000 * 60 * 60 * 24 * 30
  117. const disabledDate = (time: Date) => {
  118. return time.getTime() > Date.now() - 8.64e6
  119. }
  120. const handleChange = (val: Date[]) => {
  121. const [pointDay] = val
  122. pickDay.value = pointDay
  123. }
  124. const pageable = ref({
  125. data_type: false,
  126. time_order: 1,
  127. as_code: undefined,
  128. data_items: [],
  129. pageNum: 1,
  130. });
  131. let historyColumns = [
  132. {
  133. data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
  134. data_id: 309,
  135. data_type: "降水",
  136. data_item: "RI_JIANG_SHUI_LIANG",
  137. data_name: "日降水量",
  138. data_unit: "mm",
  139. data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
  140. data_value: "",
  141. data_order: 0,
  142. data_condition: 0,
  143. isSelected: true
  144. },
  145. {
  146. data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
  147. data_id: 312,
  148. data_type: "降水",
  149. data_item: "XIAO_SHI_LEI_JI_JIANG_SHUI_LIANG_CHENG_ZHONG",
  150. data_name: "小时累计降水量(称重)",
  151. data_unit: "mm",
  152. data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
  153. data_value: "",
  154. data_order: 0,
  155. data_condition: 0
  156. }, {
  157. data_id: 302,
  158. data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
  159. data_type: "降水",
  160. data_name: "小时累计降水量(翻斗)",
  161. data_item: "XIAO_SHI_LEI_JI_JIANG_SHUI_LIANG_FAN_DOU",
  162. data_unit: "mm",
  163. data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
  164. data_value: "",
  165. data_order: 0,
  166. data_condition: 0,
  167. isSelected: true
  168. },
  169. ]
  170. // 查询自动站列表
  171. const queryas = ref<Platform>({
  172. pageSize: 50,
  173. pageNum: 1,
  174. currentpage: 1
  175. })
  176. const userStore = useUserStore();
  177. const platformList = ref<any>(computed(() => userStore.stations))
  178. const selectPlatform = ref()
  179. const getPlatforms = async () => {
  180. pageable.value.as_code = platformList.value[0].as_code
  181. selectPlatform.value = platformList.value[0]
  182. getHistoryList()
  183. };
  184. const changeStation = () => {
  185. getHistoryList()
  186. }
  187. //时间戳转换为指定格式的日期字符串
  188. function formatDate(timestamp, type) {
  189. const date = new Date(timestamp * 1000); // 将时间戳转换为毫秒
  190. const year = date.getFullYear();
  191. const month = String(date.getMonth() + 1).padStart(2, '0');
  192. const day = String(date.getDate()).padStart(2, '0');
  193. const hours = String(date.getHours()).padStart(2, '0');
  194. const minutes = String(date.getMinutes()).padStart(2, '0');
  195. if (type === 1) {
  196. return `${month}/${day} ${hours}:${minutes}`;
  197. } else {
  198. return `${year}-${month}-${day} ${hours}:${minutes}`;
  199. }
  200. }
  201. const timeArr = ref()
  202. const dayArr = ref()
  203. const hourArr1 = ref()
  204. const isFANDOU=ref(false)
  205. const getHistoryList = async () => {
  206. if (isDateFuture(dateRange.value[0]) || isDateFuture(dateRange.value[1])) {
  207. ElMessage.error("不得选择未来的时间");
  208. return false;
  209. }
  210. 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]) });
  211. timeArr.value = data.list?.map(item => {
  212. return formatDate(item.data_time_i, 1)
  213. })
  214. dayArr.value = data.list?.map(item => {
  215. return item[309]
  216. })
  217. hourArr1.value = data.list?.map(item => {
  218. if (item[312] !== '0.0' && item[312] !== '--' && item[312] !== '/') {
  219. return item[312]
  220. } else if (item[302] !== '0.0' && item[302] !== '--' && item[312] !== '/') {
  221. return item[302]
  222. } else {
  223. return '0.0'
  224. }
  225. })
  226. isFANDOU.value = data.list.some(item => {
  227. // 尝试将项转换为数字,如果转换失败(例如,对于 '--'),则返回 NaN
  228. const number = Number(item[302]);
  229. // 检查是否是一个有效的数字且大于 10
  230. return !isNaN(number) && number > 0;
  231. });
  232. nextTick(() => {
  233. showData()
  234. })
  235. };
  236. const formRef = ref()
  237. const data = ref()
  238. const globalStore = useGlobalStore();
  239. const isDark = computed(() => globalStore.isDark);
  240. // resetForm
  241. const resetForm = () => {
  242. dateRange.value = [parseTime(new Date(getTimeStamp(5)), '{y}-{m}-{d}') + ' 00:00', parseTime(new Date(), '{y}-{m}-{d}') + ' 00:00']
  243. value1.value = true
  244. pageable.value.as_code = platformList.value[0].as_code
  245. getHistoryList()
  246. };
  247. const showData = () => {
  248. let mychart = echarts.init(data.value);
  249. let option = {
  250. title: {
  251. text: '暂无数据',
  252. show: !timeArr.value ? true : false,
  253. x: 'center',
  254. y: 'center',
  255. textStyle: {
  256. fontSize: 14,
  257. fontWeight: 'normal',
  258. }
  259. },
  260. tooltip: {
  261. trigger: 'axis',
  262. axisPointer: {
  263. type: 'shadow'
  264. },
  265. formatter: function (params) {
  266. return [
  267. "降水:" + [Number(params[0].value) ? Number(params[0].value) : "/"],
  268. '时间:' + params[0].name
  269. ].join("<br/>");
  270. },
  271. },
  272. grid: {
  273. left: '20',
  274. right: '20',
  275. bottom: '20',
  276. // top: '20',
  277. containLabel: true
  278. },
  279. xAxis: [
  280. {
  281. type: 'category',
  282. data: timeArr.value,
  283. axisTick: {
  284. alignWithLabel: true
  285. },
  286. axisLabel: {
  287. interval: 1,
  288. },
  289. }
  290. ],
  291. yAxis: [
  292. {
  293. type: 'value',
  294. boundaryGap: [0, '20%']
  295. }
  296. ],
  297. series: [
  298. {
  299. name: '降水量',
  300. type: 'bar',
  301. barWidth: '50%',
  302. color: '#88c1ff',
  303. data: value1.value ? dayArr.value : hourArr1.value
  304. }
  305. ]
  306. };
  307. mychart.setOption(option)
  308. window.addEventListener("resize", function () {
  309. mychart.resize();
  310. });
  311. }
  312. // watch(isDark, () => {
  313. // showData()
  314. // });
  315. onMounted(() => {
  316. // showData()
  317. getPlatforms()
  318. })
  319. </script>
  320. <style scoped lang="scss">
  321. .el-row .el-col {
  322. // margin-bottom: 15px;
  323. }
  324. .main_list {
  325. background: transparent !important;
  326. box-shadow: none !important;
  327. padding: 0 !important;
  328. height: calc(100vh - 150px);
  329. margin-bottom: 10px;
  330. overflow-y: scroll;
  331. overflow-x: hidden;
  332. .chart_item {
  333. border-radius: 10px;
  334. padding: 10px;
  335. background-color: #fff;
  336. // height: 100%;
  337. // margin-bottom: 15px;
  338. .item_title {
  339. display: flex;
  340. justify-content: space-between;
  341. align-items: center;
  342. }
  343. .FTP_box {
  344. padding: 0 50px;
  345. display: flex;
  346. align-items: center;
  347. justify-content: space-between;
  348. .FTP_item {
  349. flex: 1;
  350. flex-shrink: 0;
  351. display: flex;
  352. flex-direction: column;
  353. justify-content: center;
  354. align-items: center;
  355. img {
  356. width: 56px;
  357. margin-bottom: 20px;
  358. }
  359. }
  360. }
  361. }
  362. .info_box {
  363. .info_title {
  364. color: #999999;
  365. font-size: 16px;
  366. }
  367. .info_content {
  368. height: 40px;
  369. font-weight: bold;
  370. color: #000;
  371. font-size: 26px;
  372. }
  373. }
  374. }
  375. .data_box {
  376. height: calc(100vh - 215px);
  377. // height: 100%;
  378. }
  379. </style>