index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <template>
  2. <div class="table-box">
  3. <div class="card table-main">
  4. <!-- 表格头部 操作按钮 -->
  5. <div class="table-header">
  6. <div class="header-button-lf">
  7. <el-form :model="pageable" label-width="auto" :inline="true">
  8. <el-form-item label="自动站:">
  9. <SelectItem :select-data="selectedData" :select-list="platformList" :is-checkbox="true" @update:selectedItems="selectedItems" style="width: 200px"> </SelectItem>
  10. </el-form-item>
  11. <el-form-item label="日期:">
  12. <el-date-picker
  13. v-model="recordDate"
  14. type="month"
  15. placeholder="选择月份"
  16. :disabled-date="disabledDate"
  17. @change="changeMultiTime">
  18. </el-date-picker>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button type="primary" @click="handleQuery"> 查询 </el-button>
  22. <el-button style="margin-left: 10px" @click="resetQuery"> 重置 </el-button>
  23. </el-form-item>
  24. </el-form>
  25. </div>
  26. <div class="header-button-ri">
  27. <slot name="toolButton">
  28. <div class="zt-box">
  29. <img class="img-documented" src="@/assets/images/documented.png"/>
  30. <span class="zt-title">正常</span>
  31. <img class="img-documented" src="@/assets/images/documented_not.png"/>
  32. <span class="zt-title">缺测</span>
  33. </div>
  34. </slot>
  35. </div>
  36. </div>
  37. <!-- 表格主体 -->
  38. <el-table stripe ref="tableRef" :border="true" :data="processTableData" size="small" class="el-table--small">
  39. <el-table-column align="center" width="50">
  40. <template #header>
  41. <div class="group-bias-divide">
  42. <div class="top">日</div>
  43. <div class="bottom">时</div>
  44. </div>
  45. </template>
  46. <template #default="scope">
  47. {{ (scope.$index+1).toString().padStart(2, '0') }}
  48. </template>
  49. </el-table-column>
  50. <template v-for="item in columns" :key="item">
  51. <el-table-column v-bind="item" :align="item.align ?? 'center'">
  52. <template #default="scope">
  53. <img v-if="scope.row[item.prop]===1" class="img-documented" src="@/assets/images/documented.png">
  54. <img v-else class="img-documented" src="@/assets/images/documented_not.png">
  55. </template>
  56. </el-table-column>
  57. </template>
  58. <!-- 无数据 -->
  59. <template #empty>
  60. <div class="table-empty">
  61. <slot name="empty">
  62. <img src="@/assets/images/notData.png" alt="notData" />
  63. <div>暂无数据</div>
  64. </slot>
  65. </div>
  66. </template>
  67. </el-table>
  68. </div>
  69. </div>
  70. </template>
  71. <script setup lang="ts" name="useProTable">
  72. import SelectItem from "@/components/SelectItem/index.vue";
  73. import {ref, computed, onMounted} from "vue";
  74. import { ColumnProps } from "@/components/ProTable/interface";
  75. import {useUserStore} from "@/stores/modules/user";
  76. import {getDataItemList} from "@/api/modules/allData";
  77. //获取站列表
  78. const userStore = useUserStore();
  79. const platformList =ref<any>(computed(() => userStore.stations))
  80. //搜索日期
  81. const recordDate = ref();
  82. const disabledDate = (time) => {
  83. const today = new Date();
  84. const month = today.getMonth();
  85. const year = today.getFullYear();
  86. // 将时间转换为日期对象
  87. const date = new Date(time);
  88. // 比较月份和年份,如果大于当前月份,则禁用
  89. return date.getFullYear() === year && date.getMonth() > month;
  90. };
  91. const changeMultiTime = (time) => {
  92. if (time) {
  93. const year = new Date(time).getFullYear();
  94. const month = new Date(time).getMonth();
  95. const firstDayOfMonth = new Date(year, month, 1).setHours(1, 0, 0, 0); // 当月第一天1点的时间戳
  96. const firstDayOfNextMonth = new Date(year, month + 1, 1).getTime(); // 下一个月第一天的时间戳,设置为00:00:00.000
  97. // 更新时间戳
  98. pageable.value.begin_time = Math.floor(firstDayOfMonth / 1000); // 转换为秒
  99. pageable.value.end_time = Math.floor(firstDayOfNextMonth / 1000); // 转换为秒
  100. //重置表头
  101. columns.value = generateColumns(year,month+1)
  102. } else {
  103. // 如果没有选择月份,则默认为当前月份
  104. const today = new Date();
  105. const firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1).getTime();
  106. const firstDayOfNextMonth = new Date(today.getFullYear(), today.getMonth() + 1, 1).getTime();
  107. // 更新时间戳
  108. pageable.value.begin_time = Math.floor(firstDayOfMonth / 1000); // 转换为秒
  109. pageable.value.end_time = Math.floor(firstDayOfNextMonth / 1000); // 转换为秒
  110. // 重置表头
  111. columns.value = generateColumns(today.getFullYear(),today.getMonth()+1)
  112. }
  113. };
  114. //搜索站号
  115. const selectedData= ref()
  116. const selectedItems =(data)=>{
  117. if(data.length>0){
  118. pageable.value.as_code_list = data
  119. selectedData.value = data
  120. }else {
  121. pageable.value.as_code_list = firstPlatform.value
  122. selectedData.value = firstPlatform.value
  123. }
  124. };
  125. const firstPlatform = computed(() => {
  126. if (platformList.value && platformList.value.length > 0) {
  127. return [platformList.value[0].as_code];
  128. } else {
  129. return [];
  130. }
  131. });
  132. const pageable = ref<any>({
  133. data_type: false,
  134. time_order: 0,
  135. time_space:60,
  136. begin_time:undefined,
  137. end_time: undefined,
  138. as_code_list:[],
  139. data_items:[],
  140. pageNum: 1,
  141. pageSize: 1000,
  142. total: 0
  143. });
  144. const customizeColumns= ref<any>([
  145. {
  146. data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
  147. data_id: 2,
  148. data_type: "风",
  149. data_item: "ER_FEN_ZHONG_PING_JUN_FENG_XIANG",
  150. data_name: "2分钟风向",
  151. data_unit: "°",
  152. data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
  153. data_value: "",
  154. data_order: 0,
  155. data_condition: 0
  156. },
  157. {
  158. data_id: 1,
  159. data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
  160. data_type: "风",
  161. data_name: "2分钟风速",
  162. data_item: "ER_FEN_ZHONG_PING_JUN_FENG_SU",
  163. data_unit: "m/s",
  164. data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
  165. data_value: "",
  166. data_order: 0,
  167. data_condition: 0
  168. },
  169. {
  170. data_id: 4,
  171. data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
  172. data_type: "风",
  173. data_name: "10分钟风向",
  174. data_item: "SHI_FEN_ZHONG_PING_JUN_FENG_XIANG",
  175. data_unit: "°",
  176. data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
  177. data_value: "",
  178. data_order: 0,
  179. data_condition: 0
  180. },
  181. {
  182. data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
  183. data_id: 3,
  184. data_type: "风",
  185. data_item: "SHI_FEN_ZHONG_PING_JUN_FENG_SU",
  186. data_name: "10分钟风速",
  187. data_unit: "m/s",
  188. data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
  189. data_value: "",
  190. data_order: 0,
  191. data_condition: 0
  192. },
  193. {
  194. data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
  195. data_id: 501,
  196. data_type: "能见度",
  197. data_item: "YI_FEN_ZHONG_PING_JUN_NENG_JIAN_DU",
  198. data_name: "1分钟平均能见度",
  199. data_unit: "m",
  200. data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
  201. data_value: "",
  202. data_order: 0,
  203. data_condition: 0
  204. },
  205. {
  206. data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
  207. data_id: 101,
  208. data_type: "温湿度",
  209. data_item: "QI_WEN",
  210. data_name: "气温",
  211. data_unit: "℃",
  212. data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
  213. data_value: "",
  214. data_order: 0,
  215. data_condition: 0
  216. },
  217. {
  218. data_id: 201,
  219. data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
  220. data_type: "气压",
  221. data_name: "水汽压",
  222. data_item: "SHUI_QI_YA",
  223. data_unit: "hPa",
  224. data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
  225. data_value: "",
  226. data_order: 0,
  227. data_condition: 0
  228. },
  229. {
  230. data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
  231. data_id: 109,
  232. data_type: "温湿度",
  233. data_item: "LU_DIAN_WEN_DU",
  234. data_name: "露点温度",
  235. data_unit: "℃",
  236. data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
  237. data_value: "",
  238. data_order: 0,
  239. data_condition: 0
  240. },
  241. {
  242. data_id: 202,
  243. data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
  244. data_type: "气压",
  245. data_name: "本站气压",
  246. data_item: "BEN_ZHAN_QI_YA",
  247. data_unit: "hPa",
  248. data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
  249. data_value: "",
  250. data_order: 0,
  251. data_condition: 0
  252. },{
  253. data_id: 207,
  254. data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
  255. data_type: "气压",
  256. data_name: "海平面气压",
  257. data_item: "HAI_PING_MIAN_QI_YA",
  258. data_unit: "hPa",
  259. data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
  260. data_value: "",
  261. data_order: 0,
  262. data_condition: 0
  263. },
  264. {
  265. data_r_table: "SHI_SHI_LIU_YAO_SU_SHU_JU",
  266. data_id: 312,
  267. data_type: "降水",
  268. data_item: "XIAO_SHI_LEI_JI_JIANG_SHUI_LIANG_CHENG_ZHONG",
  269. data_name: "小时累计降水量(称重)",
  270. data_unit: "mm",
  271. data_h_table: "LI_SHI_LIU_YAO_SU_SHU_JU",
  272. data_value: "",
  273. data_order: 0,
  274. data_condition: 0
  275. }
  276. ])
  277. //重置功能
  278. const resetQuery = () => {
  279. initData()
  280. };
  281. // 查询功能
  282. const handleQuery = () => {
  283. pageable.value.pageNum = 1
  284. getList()
  285. };
  286. const getList = async () => {
  287. if(pageable.value.as_code_list===undefined||pageable.value.as_code_list.length===0){
  288. // 没有站不给数据
  289. processTableData2.value = []
  290. return;
  291. }
  292. pageable.value.data_items = customizeColumns.value
  293. const { data } = await getDataItemList(pageable.value);
  294. processTableData2.value = data.list
  295. pageable.value.total = data.total
  296. processTableData.value = processTableDatas()
  297. };
  298. const processTableData = ref([]);
  299. const processTableData2 = ref([]);
  300. function processTableDatas(){
  301. // 初始化数据数组
  302. const datas = [];
  303. const daysInMonth = new Date(yearDate.value, monthDate.value, 0).getDate();
  304. for (let x = 1; x <= 24; x++) {
  305. const hourStr = x.toString().padStart(2, '0');
  306. const datas2 = {};
  307. for (let i = 1; i <= daysInMonth; i++) {
  308. const dayStr = i.toString().padStart(2, '0');
  309. const monthDateStr = monthDate.value.toString().padStart(2, '0');
  310. const t = `${yearDate.value}-${monthDateStr}-${dayStr}`;
  311. if(x==24){
  312. // 创建一个新的 Date 对象,表示当前时间
  313. let currentDate = new Date(`${yearDate.value}-${monthDateStr}-${dayStr}T00:00`);
  314. // 将日期增加一天
  315. currentDate.setDate(currentDate.getDate() + 1);
  316. // 格式化新的日期为所需的字符串格式
  317. let year = currentDate.getFullYear();
  318. let month = String(currentDate.getMonth() + 1).padStart(2, '0'); // 月份从0开始,所以需要加1
  319. let day = String(currentDate.getDate()).padStart(2, '0');
  320. let hour = String(currentDate.getHours()).padStart(2, '0');
  321. const t2 = `${year}-${month}-${day} ${hour}:00`;
  322. datas2[t] = checkDataTimeExists(t2);
  323. }else {
  324. const t2 = `${yearDate.value}-${monthDateStr}-${dayStr} ${hourStr}:00`;
  325. datas2[t] = checkDataTimeExists(t2);
  326. }
  327. }
  328. datas.push(datas2);
  329. }
  330. return datas;
  331. }
  332. const checkDataTimeExists = (targetDataTime) => {
  333. if (!processTableData2.value || processTableData2.value.length === 0) {
  334. // 数组为空或未定义,返回0
  335. return 0;
  336. }
  337. return processTableData2.value.some(item => {
  338. return item.data_time === targetDataTime;
  339. }) ? 1 : 0;
  340. };
  341. const yearDate = ref();
  342. const monthDate = ref()
  343. // 表格配置项 默认获取当时
  344. const columns = ref<ColumnProps[]>();
  345. // 根据月份生成表头
  346. function generateColumns(year: number, month: number): ColumnProps[] {
  347. yearDate.value = year
  348. monthDate.value = month
  349. const daysInMonth = new Date(year, month, 0).getDate();
  350. const columns: ColumnProps[] = [];
  351. for (let i = 1; i <= daysInMonth; i++) {
  352. columns.push({ prop: `${year}-${month.toString().padStart(2, '0')}-${i.toString().padStart(2, '0')}`, label: i.toString().padStart(2, '0'), width: 51 });
  353. }
  354. return columns;
  355. }
  356. const initData=()=>{
  357. recordDate.value = new Date()
  358. selectedData.value = firstPlatform.value
  359. pageable.value.as_code_list = firstPlatform.value
  360. changeMultiTime(recordDate.value)
  361. columns.value = generateColumns(new Date().getFullYear(),new Date().getMonth()+1)
  362. processTableData.value = processTableDatas()
  363. getList()
  364. }
  365. onMounted(() => {
  366. initData()
  367. });
  368. </script>
  369. <style scoped>
  370. :deep .el-table--small .el-table__row {
  371. height: 29px !important;
  372. font-size: 13px !important;
  373. }
  374. :deep .el-table--small .el-table__header th {
  375. height: 40px !important;
  376. font-size: 14px !important;
  377. }
  378. :deep .el-table--small .cell {
  379. line-height: 22px!important;
  380. }
  381. </style>
  382. <style lang='scss' scoped>
  383. :deep(.group-bias-divide) {
  384. .top {
  385. text-align: right;
  386. padding-right: 0px;
  387. box-sizing: border-box;
  388. line-height: 11px;
  389. font-size: 11px;
  390. }
  391. .bottom {
  392. text-align: left;
  393. padding-left: 0px;
  394. padding-top: 1px;
  395. box-sizing: border-box;
  396. line-height: 10px;
  397. font-size: 11px;
  398. &::before {
  399. content: "";
  400. position: absolute;
  401. width: 1px !important;
  402. height: 90px !important;
  403. top: auto !important;
  404. left: auto !important;
  405. bottom: 0 !important;
  406. right: 0 !important;
  407. background-color: #C7E2FF;
  408. display: block;
  409. transform: rotate(309deg);
  410. transform-origin: bottom;
  411. }
  412. }
  413. }
  414. .img-documented{
  415. width: 15px;
  416. height: 15px;
  417. }
  418. .zt-title{
  419. color: var(--el-text-color-regular);
  420. font-size: var(--el-form-label-font-size);
  421. }
  422. .zt-box{
  423. display: flex;
  424. justify-content: center;
  425. align-items: center;
  426. gap: 10px;
  427. margin-top: 10px
  428. }
  429. </style>