소스 검색

增加天气监测的历史数据页面,包含列表和导出

yanglzh 2 년 전
부모
커밋
b3e67dca18

+ 0 - 1
src/api/assess/index.ts

@@ -2,7 +2,6 @@ import { get, post, del, put } from '/@/utils/request';
 import getOrigin from '/@/utils/origin';
 
 const baseUrl = getOrigin(import.meta.env.VITE_ASSESS_URL);
-console.log(baseUrl)
 
 export default {
   getList: (params?: object) => get(baseUrl + '/setup', params),

+ 3 - 1
src/api/datahub/index.ts

@@ -1,4 +1,4 @@
-import { get, post, del, put } from '/@/utils/request';
+import { get, post, del, put, file } from '/@/utils/request';
 
 export default {
 
@@ -67,6 +67,8 @@ export default {
       getWhichCityWeather: (params: object) => get('/envirotronics/weather/getInfoById', params),
       getTemperatureEchartById: (params: object) => get('/envirotronics/weather/getTemperatureEchartById', params),
       getWindpowerEchartById: (params: object) => get('/envirotronics/weather/getWindpowerEchartById', params),
+      getCityWeatherHistory: (params: object) => get('/envirotronics/weather/GetCityWeatherHistory', params),
+      getCityWeatherHistoryExport: (params: object) => file('/envirotronics/weather/GetCityWeatherHistoryExport', params),
    },
    statistics:{
       getStatisticsChartData: (params: object) => get('/statistics/bar/chart/data', params),

+ 1 - 1
src/api/system/index.ts

@@ -1,7 +1,7 @@
 import { get, post, del, put, file } from '/@/utils/request';
 import getOrigin from '/@/utils/origin';
 const baseUrl = getOrigin(import.meta.env.VITE_SERVER_URL);
-console.log(baseUrl)
+
 
 export default {
   sysinfo: () => get('/sysinfo'),

+ 1 - 1
src/layout/navBars/breadcrumb/user.vue

@@ -163,7 +163,7 @@ export default defineComponent({
             await resetRoute(); // 删除/重置路由
             ElMessage.success(t('message.user.logOutSuccess'));
             setTimeout(() => {
-              Session.clear(); // 清除缓存/token等
+              localStorage.clear(); // 清除缓存/token等
               window.location.href = ''; // 去登录页
             }, 500);
           })

+ 84 - 0
src/views/heating/monitor/history-weather.vue

@@ -0,0 +1,84 @@
+<template>
+	<div class="weather-history">
+		<div class="flex-row">
+			<div class="title">{{ cityName }}历史天气</div>
+			<div class="flex search">
+				<el-date-picker
+					v-model="dateTime"
+					type="month"
+					format="YYYY-MM"
+					value-format="YYYY-MM"
+					placeholder="选择年月"
+					:clearable="false"
+					style="width: 130px"
+					class="mr-4"
+					@change="getData"
+				/>
+				<el-button type="primary" @click="exportFile">导出</el-button>
+			</div>
+		</div>
+		<el-table :data="list" border max-height="calc(100vh  - 210px)" v-loading="loading" style="width: 100%" class="mt-5">
+			<el-table-column label="日期" prop="createdAt" align="center" />
+			<el-table-column label="最高风力(级)" prop="maxWindpower" align="center" />
+			<el-table-column label="最低风力(级)" prop="minWindpower" align="center" />
+			<el-table-column label="平均风力(级)" prop="avgWindpower" align="center" />
+			<el-table-column label="日照时长" prop="sunshineDuration" align="center" />
+			<el-table-column label="最高气温(℃)" prop="maxTemperature" align="center" />
+			<el-table-column label="最低气温(℃)" prop="minTemperature" align="center" />
+			<el-table-column label="当日平均气温(℃)" prop="avgTemperature" align="center" min-width="100" />
+		</el-table>
+	</div>
+</template>
+
+<script lang="ts" setup>
+import { useRoute } from 'vue-router'
+import { ref } from 'vue'
+import dayjs from 'dayjs'
+import api from '/@/api/datahub'
+import downloadFile from '/@/utils/download'
+
+const route = useRoute()
+
+const list = ref<any[]>([])
+const cityName = ref('')
+const dateTime = ref(dayjs().format('YYYY-MM'))
+const loading = ref(true)
+
+function getData() {
+	list.value = []
+	api.weather
+		.getCityWeatherHistory({
+			id: route.params.id,
+			dateTime: dateTime.value,
+		})
+		.then(({ Info }: { Info: any[] }) => {
+			if (Info?.length) {
+				cityName.value = Info[0].name
+				list.value = Info
+			}
+		})
+		.finally(() => (loading.value = false))
+}
+
+getData()
+
+function exportFile() {
+	api.weather.getCityWeatherHistoryExport({
+		id: route.params.id,
+		dateTime: dateTime.value,
+	}).then((res: any) => {
+    downloadFile(res, cityName.value + dateTime.value + '-天气预报导出.xlsx')
+  })
+}
+</script>
+
+<style scoped lang="scss">
+.weather-history {
+	background: #fff;
+	padding: 20px;
+	.title {
+		font-size: 18px;
+		font-weight: bold;
+	}
+}
+</style>

+ 14 - 8
src/views/heating/monitor/weather.vue → src/views/heating/monitor/weather/index.vue

@@ -19,11 +19,14 @@
       <el-row :gutter="15" class="home-card-two mb15">
         <el-col>
           <div class="weather-info">
-            <section v-if="oneCityInfo.weather">
-              <span class="temperature">{{ oneCityInfo.Temperature }}℃</span>
-              <img :src="`/imgs/weather/${oneCityInfo.weather}.svg`" alt="">
-              <span class="weather">{{ oneCityInfo.weather }}</span>
-              <span>{{ oneCityInfo.reporttime }}更新</span>
+            <section v-if="oneCityInfo.weather" style="display: flex;justify-content: space-between;">
+              <div>
+                <span class="temperature">{{ oneCityInfo.Temperature }}℃</span>
+                <img :src="`/imgs/weather/${oneCityInfo.weather}.svg`" alt="">
+                <span class="weather">{{ oneCityInfo.weather }}</span>
+                <span>{{ oneCityInfo.reporttime }}更新</span>
+              </div>
+              <div class="history" @click="$router.push('/heating-monitor/weather-history/' + oneCityInfo.id)">历史数据 &gt;</div>
             </section>
             <section>
               <span style="margin-right: 20px;">地点:{{ currentcityName }}</span>
@@ -82,7 +85,7 @@ let global: any = {
 };
 
 export default defineComponent({
-  name: 'home',
+  name: 'weather',
   setup() {
     const homeTemLineRef = ref();
     const homeWindLineRef = ref();
@@ -91,7 +94,7 @@ export default defineComponent({
     const state = reactive({
       city: '',
       cityList: [],
-      oneCityInfo: {},
+      oneCityInfo: {} as any,
       temperatureType: 1,
       windpowerType: 1,
       ranges: [
@@ -580,7 +583,10 @@ export default defineComponent({
 
 <style scoped lang="scss">
 $homeNavLengh: 8;
-
+.history{
+  font-weight: bold;
+  cursor: pointer;
+}
 .monitor-weather {
 	overflow: hidden;
 	display: flex;