Parcourir la source

feat 背景图由天气和时间决定

anxiaoxia il y a 1 an
Parent
commit
c00f5a4783
1 fichiers modifiés avec 27 ajouts et 1 suppressions
  1. 27 1
      src/packagesEnv/pages/officehome/index.wpy

+ 27 - 1
src/packagesEnv/pages/officehome/index.wpy

@@ -51,7 +51,7 @@
                     <image
                         class="bg-img"
                         style="top:{{-topBarHeight-roomPicTop}}px;height:{{topBarHeight+roomPicTop}}px"
-                        :src="h5StaticPath+'office_bright.jpg'"
+                        :src="topbgimg"
                     />
                 </div>
                 <div
@@ -668,6 +668,7 @@ import { mapState, mapActions } from '@wepy/x'
 import moment from 'moment'
 import {
     getSpaceAdjustList,
+    getWeather,
     getEquipmentListHttp,
     getMeetingSceneHttp,
     switchoverSceneHttp,
@@ -808,6 +809,7 @@ wepy.page({
     h5StaticPath: config.h5StaticPath + '/page-officehome/',
     h5StaticLogo: config.h5StaticPath,
     lampHide: false, // 灯列表收起
+    topbgimg: null, // 头部背景
     navFixed: false, // 滑动置顶
 
     showWorkOff: false, // 开放办公室的 提前关闭是否展示
@@ -1510,6 +1512,29 @@ wepy.page({
         })
       })
     },
+
+    getWeatherInfo() {
+      getWeather().then(res => {
+        const outWeather = res.content ? res.content : {}
+        var text = outWeather.text || ''
+        this.getnowTime(text) // 头部背景
+      })
+    },
+    getnowTime(text) {   // 头部背景图片
+      let now = moment().hours()
+      if (text.indexOf('霾') > -1) {
+        this.topbgimg = `${this.h5StaticPath}office_smog.jpg`
+      } else {
+        if (now >= 6 && now < 19) {
+                    // 白天
+          this.topbgimg = `${this.h5StaticPath}office_bright.jpg`
+        } else {
+                    // 夜晚
+          this.topbgimg = `${this.h5StaticPath}office_night.jpg`
+        }
+      }
+    },
+
     async getData() {
             // 获取数据
       await this.getSpaceInfo() // 空间指数信息
@@ -1517,6 +1542,7 @@ wepy.page({
       await this.getWorkDayTime() // 工作组时间
       this.getEquipments() // 空间下的设备
       this.checkEquipmentConfigStatus()
+      this.getWeatherInfo()// 天气预报
     },
     getEquipments() {
             // 获取空间下设备