Selaa lähdekoodia

新增农业云H5“首页”图片、图标信息

张启 4 vuotta sitten
vanhempi
sitoutus
5aa53c9dd3

+ 72 - 0
agrcloud-utils/mapinfo.js

@@ -0,0 +1,72 @@
+/**
+ * 封装地图类信息
+ * @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');
+      }
+    });
+  });
+};

+ 21 - 19
pages/index/index.vue

@@ -164,25 +164,7 @@
     },
     onLoad() {
       // #ifdef H5
-      mapinfo().then((res) => {
-        console.log(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
-        ];
-      });
+      // this.initMapinfo();
       // #endif
     },
     methods: {
@@ -194,6 +176,26 @@
         uni.navigateTo({
           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
+          ];
+        });
       }
     }
   };

BIN
static/agrcloud-images/agrcloud-head-notice-icon.png


BIN
static/agrcloud-images/agrcloud-main-page-complaints-bg.png


BIN
static/agrcloud-images/agrcloud-main-page-complaints-icon.png


BIN
static/agrcloud-images/agrcloud-main-page-experts-bg.png


BIN
static/agrcloud-images/agrcloud-main-page-experts-icon.png


BIN
static/agrcloud-images/agrcloud-main-page-meteorological-bg.png


BIN
static/agrcloud-images/agrcloud-main-page-meteorological-icon.png


BIN
static/agrcloud-images/agrcloud-main-page-monitoring-bp.png


BIN
static/agrcloud-images/agrcloud-main-page-monitoring-icon.png


BIN
static/agrcloud-images/agrcloud-main-page-notice-bp.png


BIN
static/agrcloud-images/agrcloud-main-page-notice-icon.png


BIN
static/agrcloud-images/agrcloud-main-page-regulations-bp.png


BIN
static/agrcloud-images/agrcloud-main-page-regulations-icon.png