liuxiaolong
2019-05-06 8700cf1dc46c350371d865532c2914595187788e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<template>
  <div>
    <b-tabs >
      <b-tab v-for="mapIteam in mapList" :key="mapIteam.id" :title="mapIteam.name" :active="tabMap === mapIteam.id" @click="changeTabMap(mapIteam)" ></b-tab>
    </b-tabs>
    <b-card no-body class="border-top-0 pr"  style="height: 80vh;">
      <div class="mapDeviceType-box border">
        <!-- mapDeviceType -->
          <div class="mapDeviceType-item flex-box py-2 pl10 pr20" v-for="(item,index) in mapDeviceType" :key="index">
            <div class="icon pr5">
              <img :src="'/static/img/map/'+item.deviceTypeIcon+'.png'" width="20px" height="20px" :onerror="noneImg" :alt="item.icon" @mousedown.prevent>
            </div>
            <div class="content">{{item.deviceTypeName}}({{item.count}})</div>
          </div>
      </div>
      <div class="alarm-box">
        <div class="badge badge-success">正常({{alarmCountInfo&&alarmCountInfo.noAlarmCount?alarmCountInfo.noAlarmCount:'0'}})</div>
        <div class="badge badge-danger">报警({{alarmCountInfo&&alarmCountInfo.alarmCount?alarmCountInfo.alarmCount:'0'}})</div>
        <div class="badge badge-default">未在线({{alarmCountInfo&&alarmCountInfo.unOnlieCount?alarmCountInfo.unOnlieCount:'0'}})</div>
      </div>
      <svgDIYMapModel :mapInfo="mapInfo" :iconArr="deviceArr" @iconIteamFn="clickMapDevice" :alarmDeviceList="alarmCountInfo && alarmCountInfo.alarmData"/>
      <h5 class="box-title">校园监控设备分布图</h5>
    </b-card>
    <deviceInfoModal ref="deviceInfoModal" :deviceInfo="deviceInfo"/>
  </div>
</template>
 
<script>
/**
 * 权限菜单弹窗
 * @param { Array } rolesList 权限菜单树形结构
 * @param { Array } rolePermission 权限菜单回显数组,为权限菜单对应id
 * @return { String } submit 返回选中权限id
 * @return { Function } showModel 打开弹窗
 * @return { Function } hideModal 关闭弹窗
 */
import CommonModel from '@/server/models/CommonModel'
import {
  getDIYMapBasicInfo,
  getDIYMapmapDevices,
  getDeviceHumidityNum,
  getDeviceTemperatureNum
} from '@/server/common.js'
import { getMapDeviceType } from '@/server/home.js'
import svgDIYMapModel from '@/components/map/svgDIYMapModel'
import deviceInfoModal from './DeviceInfoModal'
export default {
  name: 'homeSvgMap',
  props: {},
  data() {
    return {
      noneImg: 'this.src="' + require('@/assets/img/noneImg.png') + '"',
      userInfo: this.$store.getters.basicUserInfo,
      /* webSocket声明 */
      CanteenStateWS: new CommonModel(),
      alarmDeviceCountWsClient: null,
      alarmCountInfo: null,
 
      mapList: [],
      tabMap: '',
      /* 地图组件使用 */
      mapInfo: null,
      deviceArr: [],
 
      deviceInfo: null,
 
      mapDeviceType: []
    }
  },
  methods: {
    /* 设备类型 */
    async getMapDeviceType(mapId) {
      let res = await getMapDeviceType({
        orgId: this.userInfo.orgId,
        mapId
      })
      if (res && !res.error) {
        this.mapDeviceType = res
      }
    },
    async getDIYMapBasicInfo() {
      let res = await getDIYMapBasicInfo({
        orgId: this.userInfo.orgId,
        modules: 'home'
      })
      if (res && res.length) {
        this.mapList = res
        /* 初始化 */
        this.tabMap = res.length ? '' : res[0].id
        this.mapInfo = res.length ? null : res[0]
        // res[0] && res[0].id && this.getDIYMapmapDevices(res[0].id)
      } else {
        this.$toast({
          message: '暂无地图',
          type: 'warning'
        })
      }
    },
    async getDIYMapmapDevices(mapId) {
      let res = await getDIYMapmapDevices({
        orgId: this.userInfo.orgId,
        mapId
      })
      if (res && !res.error) {
        this.deviceArr = res
      }
    },
    /* 获取湿度数值 */
    async getDeviceHumidityNum(data) {
      let res = await getDeviceHumidityNum({
        orgId: this.userInfo.orgId,
        deviceId: data.id
      })
      if (res && !res.error) {
        this.deviceInfo = {
          ...this.deviceInfo,
          humidityNum: res.result ? res.result : null
        }
      } else if (res.error) {
        this.$toast({
          message: res && res.message ? res.message : '',
          type: 'error'
        })
      }
    },
    /* 获取温度数值 */
    async getDeviceTemperatureNum(data) {
      let res = await getDeviceTemperatureNum({
        orgId: this.userInfo.orgId,
        deviceId: data.id
      })
      if (res && !res.error) {
        this.deviceInfo = {
          ...this.deviceInfo,
          temperatureNum: res.result ? res.result : null
        }
      } else if (res.error) {
        this.$toast({
          message: res && res.message ? res.message : '',
          type: 'error'
        })
      }
    },
    /* ws获取地图警报数量 start */
    getAllAlarmDeviceCountMap(mapId) {
      try {
        let token =
          sessionStorage.getItem('loginedInfo') &&
          JSON.parse(
            sessionStorage.getItem('loginedInfo')
          ).access_token.replace('bearer ', '')
        this.CanteenStateWS.getAllAlarmDeviceCountMap(
          {
            orgId: this.userInfo.orgId,
            access_token: token,
            mapId,
            startTime: this.$moment(
              this.$moment().format('YYYY-MM-DD 00:00:00'),
              'YYYY-MM-DD HH:mm:ss'
            ).valueOf(),
            endTime: this.$moment(
              this.$moment().format('YYYY-MM-DD 23:59:59'),
              'YYYY-MM-DD HH:mm:ss'
            ).valueOf()
          },
          this.alarmCountInfoMsg,
          err => {
            console.log(err, '获取地图警报数量--出错')
          },
          close => {
            console.log(close, '获取地图警报数量--关闭')
          },
          e => {
            this.alarmDeviceCountWsClient = e
          }
        )
      } catch (ex) {
        console.log('获取地图警报数量--异常', ex)
      }
    },
    alarmCountInfoMsg(res) {
      if (res) {
        this.alarmCountInfo = res
      }
      // console.log(res, '获取地图警报数量--接收数据')
    },
    /* ws获取地图警报数量 end */
    changeTabMap(mapIteam) {
      if (mapIteam.id && mapIteam.url && mapIteam.id) {
        this.tabMap = mapIteam.id
        this.mapInfo = mapIteam
        /* 查询设备 */
        this.getDIYMapmapDevices(mapIteam.id)
        this.getMapDeviceType(mapIteam.id)
      } else {
        this.$notify({
          group: 'foo',
          type: 'warn',
          title: '抱歉,这条数据有错误',
          text: '这条数据有错误,请联系管理员'
        })
        return false
      }
    },
    clickMapDevice({ data }) {
      const josn = JSON.parse(JSON.stringify(data))
      if (data) {
        /* 根据 data.deviceType */
        josn.deviceLable = this.$store.state.deviceDict[data.deviceType]
        switch (data.deviceType) {
          case '1':
            break
          case '2':
            break
          case '3':
            break
          case '4':
            this.getDeviceTemperatureNum(josn)
            break
          case '5':
            this.getDeviceHumidityNum(josn)
            break
        }
        this.deviceInfo = josn
        this.$refs.deviceInfoModal.showModal()
      }
    }
  },
  created() {
    this.getDIYMapBasicInfo()
  },
  watch: {
    mapInfo: {
      handler(newVal, oldVal) {
        if (newVal && newVal !== oldVal) {
          /* ws 获取报警数量 */
          this.alarmDeviceCountWsClient && this.alarmDeviceCountWsClient.close()
          this.getAllAlarmDeviceCountMap(newVal.id)
        }
      },
      deep: true,
      immediate: true
    }
  },
  components: {
    svgDIYMapModel,
    deviceInfoModal
  }
}
</script>
 
<style lang="scss" scoped>
.box-title{
  position: absolute;
  bottom: 0px;
  right: 60px;
  color: #26b4ff;
}
.btn-content {
  display: flex;
  justify-content: flex-end;
}
.alarm-box {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 9;
  .badge-default {
    background: #ccc;
  }
}
div,ul,li,img,span,a,p{
  /* 抑制选中 */
    -moz-user-select: none;
    -webkit-user-select: none;
    user-select: none;
}
.mapDeviceType-box{
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 9;
  background: rgba(255,255,255,0.8)
}
.mapDeviceType-box .mapDeviceType-item{
  /* .icon{} */
  .content{
    line-height: 20px;
  }
}
</style>