Browse Source

feat: 完成头部天气显示模块以及地址跳转控制

TwoKe 2 years ago
parent
commit
c1373817d5
46 changed files with 242 additions and 25 deletions
  1. BIN
      src/assets/images/icon/dby.png
  2. BIN
      src/assets/images/icon/gh.png
  3. BIN
      src/assets/images/icon/gw.png
  4. BIN
      src/assets/images/icon/nw.png
  5. BIN
      src/assets/images/icon/xz.png
  6. BIN
      src/assets/images/icon/yl.png
  7. BIN
      src/assets/images/weather-icon/1.png
  8. BIN
      src/assets/images/weather-icon/10.png
  9. BIN
      src/assets/images/weather-icon/11.png
  10. BIN
      src/assets/images/weather-icon/12.png
  11. BIN
      src/assets/images/weather-icon/13.png
  12. BIN
      src/assets/images/weather-icon/14.png
  13. BIN
      src/assets/images/weather-icon/15.png
  14. BIN
      src/assets/images/weather-icon/16.png
  15. BIN
      src/assets/images/weather-icon/17.png
  16. BIN
      src/assets/images/weather-icon/18.png
  17. BIN
      src/assets/images/weather-icon/19.png
  18. BIN
      src/assets/images/weather-icon/2.png
  19. BIN
      src/assets/images/weather-icon/20.png
  20. BIN
      src/assets/images/weather-icon/21.png
  21. BIN
      src/assets/images/weather-icon/22.png
  22. BIN
      src/assets/images/weather-icon/23.png
  23. BIN
      src/assets/images/weather-icon/24.png
  24. BIN
      src/assets/images/weather-icon/25.png
  25. BIN
      src/assets/images/weather-icon/26.png
  26. BIN
      src/assets/images/weather-icon/27.png
  27. BIN
      src/assets/images/weather-icon/28.png
  28. BIN
      src/assets/images/weather-icon/29.png
  29. BIN
      src/assets/images/weather-icon/3.png
  30. BIN
      src/assets/images/weather-icon/30.png
  31. BIN
      src/assets/images/weather-icon/31.png
  32. BIN
      src/assets/images/weather-icon/32.png
  33. BIN
      src/assets/images/weather-icon/33.png
  34. BIN
      src/assets/images/weather-icon/34.png
  35. BIN
      src/assets/images/weather-icon/35.png
  36. BIN
      src/assets/images/weather-icon/4.png
  37. BIN
      src/assets/images/weather-icon/5.png
  38. BIN
      src/assets/images/weather-icon/6.png
  39. BIN
      src/assets/images/weather-icon/7.png
  40. BIN
      src/assets/images/weather-icon/8.png
  41. BIN
      src/assets/images/weather-icon/9.png
  42. 54 0
      src/layouts/default/modules/AddressComponent.js
  43. 22 21
      src/layouts/default/modules/Header.vue
  44. 140 0
      src/layouts/default/modules/WeatherComponent.vue
  45. 25 2
      src/router/index.js
  46. 1 2
      src/views/main/right/FireLog/index.vue

BIN
src/assets/images/icon/dby.png


BIN
src/assets/images/icon/gh.png


BIN
src/assets/images/icon/gw.png


BIN
src/assets/images/icon/nw.png


BIN
src/assets/images/icon/xz.png


BIN
src/assets/images/icon/yl.png


BIN
src/assets/images/weather-icon/1.png


BIN
src/assets/images/weather-icon/10.png


BIN
src/assets/images/weather-icon/11.png


BIN
src/assets/images/weather-icon/12.png


BIN
src/assets/images/weather-icon/13.png


BIN
src/assets/images/weather-icon/14.png


BIN
src/assets/images/weather-icon/15.png


BIN
src/assets/images/weather-icon/16.png


BIN
src/assets/images/weather-icon/17.png


BIN
src/assets/images/weather-icon/18.png


BIN
src/assets/images/weather-icon/19.png


BIN
src/assets/images/weather-icon/2.png


BIN
src/assets/images/weather-icon/20.png


BIN
src/assets/images/weather-icon/21.png


BIN
src/assets/images/weather-icon/22.png


BIN
src/assets/images/weather-icon/23.png


BIN
src/assets/images/weather-icon/24.png


BIN
src/assets/images/weather-icon/25.png


BIN
src/assets/images/weather-icon/26.png


BIN
src/assets/images/weather-icon/27.png


BIN
src/assets/images/weather-icon/28.png


BIN
src/assets/images/weather-icon/29.png


BIN
src/assets/images/weather-icon/3.png


BIN
src/assets/images/weather-icon/30.png


BIN
src/assets/images/weather-icon/31.png


BIN
src/assets/images/weather-icon/32.png


BIN
src/assets/images/weather-icon/33.png


BIN
src/assets/images/weather-icon/34.png


BIN
src/assets/images/weather-icon/35.png


BIN
src/assets/images/weather-icon/4.png


BIN
src/assets/images/weather-icon/5.png


BIN
src/assets/images/weather-icon/6.png


BIN
src/assets/images/weather-icon/7.png


BIN
src/assets/images/weather-icon/8.png


BIN
src/assets/images/weather-icon/9.png


+ 54 - 0
src/layouts/default/modules/AddressComponent.js

@@ -0,0 +1,54 @@
+export default  {
+  props: {
+    activeStyle: {
+      type: Object,
+      default: () => ({ color: '#A8D7E7' })
+    },
+    otherStyle: {
+      type: Object,
+      default: () => ({ color: "#85e9ff" })
+    },
+    separator: {
+      type: String,
+      default: '>'
+    }
+  },
+  methods: {
+    createPathNodes(path, h, style = null) {
+      const otherNodes = []
+      const { $router, $route } = this
+      path.forEach((item, index) => {
+        otherNodes.push(h('span', { 
+          style: { ...style, cursor: "pointer" }, 
+          on: {
+            click: () => {  
+              if ($route.path !== item.path) {
+                $router.push(item.path)
+              }
+            }  
+          }  
+        }, item.label))
+        
+        if (index !== path.length - 1) {
+          otherNodes.push(h('span', { style }, ` ${this.separator} `))
+        }
+      })
+      return otherNodes;
+    }
+  },
+  render (h) {
+    const { address, index  } = this.$route.meta
+    const children = []
+
+    const currentNodes = this.createPathNodes(address.slice(0, index + 1), h, this.activeStyle)
+    children.push(...currentNodes)
+
+    if (index !== address.length - 1) {
+      const otherNodes = this.createPathNodes(address.slice(index + 1), h, this.otherStyle)
+      children.push(h('span', { style: this.otherStyle }, ` ${this.separator} `))
+      children.push(...otherNodes)
+    }
+
+    return h('div', null, children)
+  }
+}

+ 22 - 21
src/layouts/default/modules/Header.vue

@@ -1,24 +1,33 @@
 <template>
   <div :class="`${namespace}-header`">
-    <div class="title-wrapper">
-      <!-- <div class="title">
-        {{title}}
-      </div> -->
+    <div class="title">
+      <AddressComponent/>
     </div>
-    <div>
-      天气信息
+    <div class="weather">
+      <WeatherComponent />
     </div>
   </div>
 </template>
 
 <script>
+import AddressComponent from './AddressComponent'
+import WeatherComponent from './WeatherComponent.vue'
+
 export default {
   inject: ['namespace'],
+  components: {
+    AddressComponent,
+    WeatherComponent
+  },
   props: {
     title: {
       type: String,
       default: '重庆市消防远程监控',
     },
+  },
+  created() {
+  },
+  methods: {
   }
 }
 </script>
@@ -35,21 +44,13 @@ export default {
     background: url("@/assets/images/header-bg.png") no-repeat;
     background-size: 100% 100%;
     height: 112px;
-
-
-    .title-wrapper {
-      // padding: 21px 24px 38px 24px;
-      // background-size: 715px 195px; 
-      // background-position: -98px -13px;
-      // margin-left: 19px;
-      
-      // .title {
-      //   font-family: DataFont;
-      //   font-size: 48px;
-      //   background-image:-webkit-linear-gradient(bottom,#46b4d6,#f0ffff); 
-      //   -webkit-background-clip:text; 
-      //   -webkit-text-fill-color:transparent;
-      // }
+    .title {
+      height: 100%;
+      font-size: 23px;
+      display: flex;
+      justify-content: center;
+      align-items: center;
+      margin-left: 500px;
     }
   }
 </style>

+ 140 - 0
src/layouts/default/modules/WeatherComponent.vue

@@ -0,0 +1,140 @@
+<template >
+  <div class="weatherComponent">
+    <div class="left">
+      <div class="address">{{location}}</div>
+      <div class="temp">{{currentTemp}}°</div>
+    </div>
+    <div class="center">
+      <div>{{desc}}</div>
+      <div class="weather-temp"><img :src="require(`@/assets/images/weather-icon/${weatherImage}.png`)" />  {{tempRange}}</div>
+      <div class="date-time">
+        <span>{{currentDate}}</span>
+        <span>{{currentTime}}</span>
+      </div>
+    </div>
+    <div class="right">
+      <img :src="require(`@/assets/images/icon/${disasterImage}.png`)" />
+      <span>{{disasterData[disasterImage]}}</span>
+    </div>
+  </div>
+</template>
+
+<script>
+
+const disasterData = {
+  'yl': '雨涝',
+  'nw': '浓雾',
+  'xz': '雪灾',
+  'gw': '高温',
+  'gh': '干旱',
+  'gby': '大暴雨'
+}
+
+export default {
+  name: 'WeatherComponent',
+  data() {
+    return {
+      timer: null,
+      // 当前时间
+      currentDateTime: new Date(),
+      // 天气图片
+      weatherImage: '1',
+      // 描述
+      desc: '晴转多云 降雨量 6mm',
+      // 当前温度
+      currentTemp: '24',
+      // 位置
+      location: '北碚区',
+      // 温度范围
+      tempRange: '18~26°C',
+      // 灾害图片
+      disasterImage: 'yl',
+      disasterData
+    }
+  },
+  computed: {
+    currentDate() {
+      const month = this.checkNumber(this.currentDateTime.getMonth() + 1)
+      const day = this.checkNumber(this.currentDateTime.getDate())
+      return `${this.currentDateTime.getFullYear()}${month}${day}`
+    },
+    currentTime() {
+      const hour = this.checkNumber(this.currentDateTime.getHours())
+      const minute = this.checkNumber(this.currentDateTime.getMinutes())
+      const second = this.checkNumber(this.currentDateTime.getSeconds())  
+      return `${hour}:${minute}:${second}`
+    }
+  },
+  methods: {
+    checkNumber(ch) {
+      if (ch < 10) {
+        return '0' + ch;
+      }
+      return ch
+    },
+    loadData() {
+      this.currentDateTime = new Date();
+    }
+  },
+  mounted() {
+    const {loadData} = this
+    this.timer = setInterval(() => {
+      loadData();
+    }, 1000);
+  },
+  destroyed() {
+    if (this.timer) {
+      clearInterval(this.timer)
+    }
+  }
+}
+</script>
+
+<style scoped lang='less'>
+.weatherComponent {
+  font-size: 15px;
+  width: 362px;
+  height: 72px;
+  display: flex;
+  align-items: center;
+  & > div {
+    margin: 0px 10px;
+  }
+  .left {
+    display: flex;
+    flex-direction: column;
+    justify-content: center;
+    align-items: center;
+    .temp {
+      font-size: 39px;
+    }
+  }
+  .center {
+    .date-time {
+      display: flex;
+      justify-content: space-between;
+      align-items: center;
+    }
+    .weather-temp {
+      display: flex;
+      gap: 8px;
+      align-items: center;
+      img {
+        width: 40px;
+        height: 40px;
+      }
+    }
+  }
+
+  .right {
+    display: flex;
+    gap: 10px;
+    justify-content: flex-start;
+    align-items: center;
+    img {
+      width: 35px;
+      height: 35px;
+    }
+  }
+}
+</style>

+ 25 - 2
src/router/index.js

@@ -5,15 +5,38 @@ import Detail from '@/views/detail/index.vue'
 
 Vue.use(VueRouter)
 
+const address = [
+  {
+    label: '重庆市',
+    path: '/'
+  },
+  {
+    label: '北碚区',
+    path: '/detail'
+  },
+  {
+    label: '北碚区万达广场',
+    path: '/detail'
+  }
+]
+
 const routes = [
   {
     path: '/',
     name: 'Main',
-    component: Main
+    component: Main,
+    meta: {
+      address,
+      index: 0
+    }
   },
   {
-    path: '/detail/:id',
+    path: '/detail',
     name: 'Detail',
+    meta: {
+      address,
+      index: 1
+    },
     component: Detail
   }
 ]

+ 1 - 2
src/views/main/right/FireLog/index.vue

@@ -49,10 +49,9 @@ export default {
       color: #85e9ff;
       gap: 20px;
       cursor: pointer;
-      
     .active {
       color: #ffd169;
     }
-    }
+  }
 }
 </style>