Преглед изворни кода

新增H5端气象服务信息滚动词条功能

张启 пре 4 година
родитељ
комит
faa853567f
3 измењених фајлова са 30 додато и 95 уклоњено
  1. 19 1
      agrcloud-api/meteorological.js
  2. 0 72
      agrcloud-utils/mapinfo.js
  3. 11 22
      pages/index/index.vue

+ 19 - 1
agrcloud-api/meteorological.js

@@ -3,7 +3,25 @@ import request from '@/agrcloud-utils/request';
 // 列表数据
 export function meteorologicalListData(query) {
   return request({
-    url: '',
+    url: '/data/article/door/list',
+    method: 'GET',
+    data: query
+  });
+}
+
+// 详情数据
+export function meteorologicalViewData(query) {
+  return request({
+    url: '/data/article/door/info',
+    method: 'GET',
+    data: query
+  });
+}
+
+// 滚动信息
+export function meteorologicalRollData(query) {
+  return request({
+    url: '/data/earfore/door/roll',
     method: 'GET',
     data: query
   });

+ 0 - 72
agrcloud-utils/mapinfo.js

@@ -1,72 +0,0 @@
-/**
- * 封装地图类信息
- * @author Rockery(1113269755@qq.com)
- */
-
-import indexConfig from '@/agrcloud-config/index.config';
-
-module.exports = (params) => {
-  return new Promise((resolve, reject) => {
-    uni.getLocation({
-      type: 'gcj02',
-      success: (getLocationRes) => {
-        const longitude = getLocationRes.longitude;
-        const latitude = getLocationRes.latitude;
-        uni.request({
-          url: 'https://restapi.amap.com/v3/geocode/regeo',
-          data: {
-            location: longitude + ',' + latitude,
-            key: indexConfig.amapKey
-          },
-          method: "GET",
-          dataType: "json",
-          success: (regeocodeRes) => {
-            if (regeocodeRes.statusCode == 200) {
-              const currAdcode = (((regeocodeRes.data || {}).regeocode || {}).addressComponent || {}).adcode ||
-                '520123';
-              uni.request({
-                url: 'https://restapi.amap.com/v3/weather/weatherInfo',
-                data: {
-                  key: indexConfig.amapKey,
-                  city: currAdcode,
-                  extensions: 'base'
-                },
-                method: "GET",
-                dataType: "json",
-                success: (weatherInfoRes) => {
-                  const weatherInfoLives = ((weatherInfoRes.data || {}).lives || [])[0] || {};
-                  resolve({
-                    locationInfo: getLocationRes,
-                    regeocode: (regeocodeRes.data || {}).regeocode,
-                    weatherInfo: weatherInfoLives
-                  });
-                },
-                fail: weatherInfoErr => {
-                  uni.showToast({
-                    title: weatherInfoErr.errMsg,
-                    icon: 'none'
-                  });
-                  reject('err');
-                }
-              });
-            }
-          },
-          fail: regeocodeErr => {
-            uni.showToast({
-              title: regeocodeErr.errMsg,
-              icon: 'none'
-            });
-            reject('err');
-          }
-        });
-      },
-      fail: (getLocationErr) => {
-        uni.showToast({
-          title: getLocationErr.errMsg,
-          icon: 'none'
-        });
-        reject('err');
-      }
-    });
-  });
-};

+ 11 - 22
pages/index/index.vue

@@ -32,7 +32,6 @@
             mode="horizontal"
             type="none"
             :volume-icon="true"
-            :more-icon="true"
             :is-circular="true"
             :list="titleContentList"></u-notice-bar>
         </view>
@@ -146,12 +145,14 @@
 </template>
 
 <script>
-  import mapinfo from '@/agrcloud-utils/mapinfo';
+  import {
+    meteorologicalRollData
+  } from '@/agrcloud-api/meteorological';
 
   export default {
     data() {
       return {
-        titleContentList: ['气象预警:修文县气象台2021年1月20日10时30分发布晴朗天气'],
+        titleContentList: ['暂无数据!'],
         mainNavigateToObj: {
           complaints: '/pages/complaints/index',
           // meteorological: '/pages/meteorological/index',
@@ -164,7 +165,7 @@
     },
     onLoad() {
       // #ifdef H5
-      // this.initMapinfo();
+      this.getMeteorologicalRollData();
       // #endif
     },
     methods: {
@@ -177,24 +178,12 @@
           url: this.mainNavigateToObj[itemData]
         });
       },
-      initMapinfo() {
-        mapinfo().then((res) => {
-          const currTitleContent = '当前气象信息: ';
-          const currProvince = ((res.regeocode || {}).addressComponent || {}).province;
-          const currCity = ((res.regeocode || {}).addressComponent || {}).city;
-          const currDistrict = ((res.regeocode || {}).addressComponent || {}).district;
-          const currDate = new Date();
-          const currFormatDate = currDate.getFullYear() + '年' + (currDate.getMonth() + 1) + '月' + currDate.getDate() +
-            '日' + currDate.getHours() + '时' + currDate.getMinutes() + '分' + currDate.getSeconds() + '秒';
-          const currWeather = (res.weatherInfo || {}).weather;
-          const currTemperature = (res.weatherInfo || {}).temperature;
-          const currWinddirection = (res.weatherInfo || {}).winddirection;
-          const currWindpower = (res.weatherInfo || {}).windpower;
-          const currHumidity = (res.weatherInfo || {}).humidity;
-          this.titleContentList = [
-            currTitleContent + currProvince + currCity + currDistrict + currFormatDate + currWeather +
-            currTemperature + '℃' + currWinddirection + '风' + currWindpower + '级空气湿度' + currHumidity
-          ];
+      getMeteorologicalRollData() {
+        meteorologicalRollData().then(res => {
+          const rollDataList = res.data || [];
+          this.titleContentList = (rollDataList.length > 0) ? rollDataList : ['暂无数据!'];
+        }).catch(err => {
+          this.titleContentList = ['暂无数据!'];
         });
       }
     }