Newer
Older
CloudBrainNew / src / views / cityManage / components / lamp / lamp.vue
StephanieGitHub on 4 Feb 2021 1 KB first commit
<!--
 * @Description: 社会治安
 * @Author: 王晓颖
 * @Date: 2020-12-02 11:12:53
 -->
<template>
  <chart-layout title="城市路灯" @click="getData">
    <div class="block-container">
      <div class="block" style="width:45%">
        <lamp-count ref="lampCount"/>
      </div>
      <div class="block" style="flex:1">
        <transition  mode="out-in" name="el-zoom-in-center">
          <component :is="currentComps[currentComp]" @mouseover.native="stopCompChange" @mouseout.native="compChange"/>
        </transition>
      </div>
    </div>
    <corner1 slot="corner"/>
  </chart-layout>
</template>

<script>
import LampCount from './components/lampCount'
import LampPie from './components/lampPie'
import LampConsumeLine from './components/lampConsumeLine'
export default {
  name: 'Lamp',
  components: {LampConsumeLine, LampPie, LampCount},
  data () {
    return {
      currentComp: 0, // 当前组件index
      currentComps: ['lamp-pie', 'lamp-consume-line'],
      compsTimer: null,
      changeTime: 10 // 切换时间,s
    }
  },
  mounted () {
    this.compChange()
  },
  methods: {
    getData () {
      this.$refs.lampCount.getData()
    },
    compChange () {
      this.compsTimer = setTimeout(() => {
        const max = this.currentComps.length - 1
        if (this.currentComp < max) {
          this.currentComp++
        } else {
          this.currentComp = 0
        }
        this.compChange()
      }, this.changeTime * 1000)
    },
    // 停止切换组件
    stopCompChange () {
      clearInterval(this.compsTimer)
      this.compsTimer = null
    }
  },
  beforeDestroy () {
    this.stopCompChange()
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .block-container{
    height: 100%;
    width: 100%;
    display: flex;
    justify-content: space-between;
    box-sizing: border-box;
    padding: 0.02rem;
    padding-right:0.1rem;
    .block{
      height:100%;
      box-sizing: border-box;
    }
  }
</style>