liuxiaolong
2019-05-06 2418a2d61feea858e9e63aa52fd64ddfe17e392a
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
<template>
  <div class="d-flex align-items-stretch flex-grow-1 pr">
    <div class="bg-white home-sidenav border-right flex-row-top" :class="isOpenTree?'w-20':'w-0'">
      <!-- style="height: 88.2vh;" -->
      <div class="pl-2 pr-2" style="width:100%;min-width:200px">
        <!-- 组织集合 start -->
        <org-tree
          ref="tree"
          :isSearch="true"
          :data="treeData"
          @currentNode="_currentOrgNode"
          :isOpen="isOpenColony"
          @toggleOpen="isOpenTree = !isOpenTree"
          @save-org-success="getOrgTree"
          @del-device-success="deviceDel"
          @del-org-success="orgDel"
          @add-device="showDeviceModel"
        />
        <!-- 组织集合 end -->
        <hr class="mb-0">
        <!-- 集群设备 start -->
        <colony-tree
          :isSearch="false"
          :data="colonyData"
          @currentNode="_currentColonyNode"
          :isOpenAll="false"
          :isOpen="isOpenColony"
          @setOpenTree="setOpenTree"
          @add-colony="showColonyModel"
        />
        <!-- 集群设备 end -->
      </div>
      <!-- 弹窗 start -->
      <add-device-form
        :item="null"
        ref="deviceForm"
        title="新增设备"
        @submit="deviceSubmit"
        :isShowFooter="false"
      />
      <add-colony-form
        :item="null"
        ref="colonyForm"
        title="新增集群"
        @submit="colonySubmit"
        :isShowFooter="false"
      />
      <!-- 弹窗 end -->
    </div>
    <div class="flex-grow-1" :class="isOpenTree?'w-80':''">
      <!-- 右侧 标题 start -->
      <div class="pl-2 pr-2 py-3 bg-white border-bottom mb-4 flex-box">
        <div
          class="table-switch-btn active"
          :class="tabType==='map'?'active':''"
          @click="tabType='map'"
          v-show="tabType==='table'"
        >
          <i class="fas fa-map"></i>
        </div>
        <div
          class="table-switch-btn active"
          :class="tabType==='table'?'active':''"
          @click="tabType='table'"
          v-show="tabType==='map'"
        >
          <i class="fas fa-list-ul"></i>
        </div>
        <div class="mx-2">
          <el-input
            placeholder="请输入IP地址、设备名称或位置描述..."
            autocomplete="off"
            style="min-width: 18rem;"
            v-model="searchName"
            clearable
            @keyup.enter.native="handleSearch"
          />
        </div>
        <div class="mx-2">
          <b-btn variant="primary" class="mr10" @click="handleSearch">搜索</b-btn>
        </div>
        <!-- <div>
          <b-btn variant="primary" class="btn-circle">
            <span class="fas fa-lock"></span>
            <span class="fas fa-lock-open"></span>
          </b-btn>
        </div>-->
      </div>
      <!-- 右侧 标题 end -->
      <div class="container-p-x">
        <div class="row bg-white py-2 px-2 border overflow-auto">
          <div class="col-md-12 col-lg-12">
            <!-- 集群按钮 非集群按钮 start -->
            <div v-if="tabType!=='map'" class="d-flex">
              <div
                variant="link"
                :class="['table-type-btns',tableType === 'local'?'active':'']"
                @click="tableType='local'"
              >平台设备</div>
              <div class="flex-vertical-center px-3">
                <span class="text-light">|</span>
              </div>
              <div
                variant="link"
                :class="['table-type-btns',tableType === 'colony'?'active':'']"
                @click="tableType='colony'"
              >集群</div>
            </div>
            <!-- 集群按钮 非集群按钮 end -->
            <div :style="{height: tabType==='map'?'75vh':'70vh'}">
              <view-map
                ref="mapDevice"
                v-if="tabType==='map'"
                @upTreeData="getOrgTree"
                :searchName="searchName"
                :currentColonyItem="currentColonyItem"
                :currentOrgItem="currentOrgItem"
              />
              <view-table-local
                ref="viewTableLocal"
                v-if="tabType==='table' && tableType ==='local'"
                @add-device="showDeviceModel"
                :searchName="searchName"
                :currentOrgItem="currentOrgItem"
                @del-device-success="deviceDel"
              />
              <view-table-colony
                ref="viewTableColony"
                v-if="tabType==='table' && tableType ==='colony'"
                :searchName="searchName"
                :analysis="analysis"
                :currentColonyItem="currentColonyItem"
                @del-colony-success="colonyDel"
              />
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 侧边栏按钮 start -->
    <div class="toggleOpen-btn bg-dark" :class="!isOpenTree?'isShow':''" v-if="!isOpenTree">
      <b-button variant="link" class="tree-btn" @click="isOpenTree = !isOpenTree">
        <i class="ion ion-md-swap f20 text-white"></i>
      </b-button>
    </div>
    <!-- 侧边栏按钮 end -->
  </div>
</template>
<script>
import OrgTree from './components/OrgTree'
import ColonyTree from './components/ColonyTree'
import addColonyForm from './components/addColonyForm'
import addDeviceForm from './components/addDeviceForm'
import ViewMap from './components/mapDeviceList'
import ViewTableColony from './components/ViewTableColony'
import ViewTableLocal from './components/ViewTableLocal'
import { getAllColonyNode } from '@/server/home.js'
import { getOrgDeviceTree, getAnalysis } from '@/server/common.js'
import { Input } from 'element-ui'
export default {
  name: 'home',
  metaInfo: {
    title: '首页'
  },
  components: {
    orgTree: OrgTree,
    colonyTree: ColonyTree,
    addDeviceForm,
    addColonyForm,
    viewMap: ViewMap,
    viewTableColony: ViewTableColony,
    viewTableLocal: ViewTableLocal,
    elInput: Input
  },
  data() {
    return {
      userInfo: this.$store.getters.basicUserInfo,
      tabType: 'map', // table , map
      tableType: 'local', // colony 集群设备 local 本地设备
      isOpenTree: true,
      treeData: [],
      currentOrgItem: { id: '0', type: 'MENU', name: '平台设备' },
      /* 集群树 */
      colonyData: [],
      currentColonyItem: { id: '0', type: '1', name: '集群设备' },
      /* 检索条件 */
      searchName: '',
      localOrg: '0',
      colonyOrg: '0',
      colonyType: '1', // 点击节点类型(1:集群,2:节点,3:设备)
      analysis: '',
      isOpenColony: false
    }
  },
  computed: {
    orgId() {
      return this.$store.getters.basicUserInfo.orgId
    },
    userId() {
      return this.$store.getters.basicUserInfo.id
    }
  },
  methods: {
    // 获取用户登录分析系统是何种权限
    async getAnalysis() {
      let res = await getAnalysis({ userId: this.userId })
      if (res.success && res.code === 200 && res.data) {
        console.log(res.data)
        this.analysis = res.data
        // this.treeData = res
      }
    },
    // * 获取组织树
    async getOrgTree() {
      let res = await getOrgDeviceTree({ orgById: this.orgId })
      if (res) {
        this.treeData = res
        // if (this.$route.query.currentId) {
        //   this.$refs.tree.setCurrentKey(this.$route.query.currentId)
        //   this.currentId = this.$route.query.currentId
        //   this.$nextTick(() => {
        //     this.currentOrgItem = this.$refs.tree.getCurrentNode()
        //   })
        // } else {
        //   const { child, ...item } = this.treeData[0]
        //   this.currentOrgItem = item
        //   this.$refs.tree.setCurrentKey(item.id)
        //   this.currentId = item.id
        // }
      }
    },
    /* 查询集群树 */
    async getAllColonyNode() {
      let res = await getAllColonyNode({ orgById: this.orgId })
      if (res) {
        this.colonyData = res
        // if (this.$route.query.currentId) {
        //   this.$refs.tree.setCurrentKey(this.$route.query.currentId)
        //   this.currentId = this.$route.query.currentId
        //   this.$nextTick(() => {
        //     this.currentOrgItem = this.$refs.tree.getCurrentNode()
        //   })
        // } else {
        //   const { child, ...item } = this.treeData[0]
        //   this.currentOrgItem = item
        //   this.$refs.tree.setCurrentKey(item.id)
        //   this.currentId = item.id
        // }
      }
    },
    /* 搜索框 */
    handleSearch() {
      if (this.tabType === 'map') {
        this.$refs.mapDevice && this.$refs.mapDevice.findDeviceByParams()
      } else if (this.tableType === 'local') {
        // 检索 平台设备
        this.$refs.viewTableLocal && this.$refs.viewTableLocal._initData()
      } else if (this.tableType === 'colony') {
        // 检索 集群设备
        this.$refs.viewTableColony && this.$refs.viewTableColony._initData()
      }
    },
    /* 平台设备操作 */
    // 点击树
    _currentOrgNode(node) {
      this.currentOrgItem = node
      this.localOrg = node.id ? node.id : '0'
      console.log(node, 'node---平台设备操作', this.localOrg)
    },
    // 删除设备
    deviceDel() {
      this.getOrgTree()
      this.currentOrgItem = { id: '0', type: 'MENU', name: '平台设备' }
      // 列表或者表格刷新
      this.handleSearch()
      this.$refs.mapDevice.findAllDevice()
    },
    orgDel() {
      this.getOrgTree()
      this.currentOrgItem = { id: '0', type: 'MENU', name: '平台设备' }
      // 列表或者表格刷新
      this.handleSearch()
    },
    /* 集群设备操作 */
    // 上下折叠
    setOpenTree() {
      this.isOpenColony = !this.isOpenColony
      console.log(this.isOpenColony, '---isOpenColony----')
    },
    // 点击树
    _currentColonyNode(node) {
      console.log(node, 'node--集群')
      this.currentColonyItem = node
      this.colonyOrg = node.id ? node.id : '0'
      // colonyType:'1', // 点击节点类型(1:集群,2:节点,3:设备)
    },
    /* 弹窗函数 start */
    showColonyModel() {
      // 集群添加弹窗
      this.$refs.colonyForm.showModel()
    },
    colonySubmit() {
      // 保存成功触发
      this.getAllColonyNode()
      // 列表或者表格刷新
      this.handleSearch()
      this.$refs.mapDevice.findAllDevice()
      console.log('添加集群保存成功触发')
    },
    colonyDel() {
      // 删除集群成功回调
      // 保存成功触发
      this.getAllColonyNode()
      // 列表或者表格刷新
      this.handleSearch()
      this.$refs.mapDevice.findAllDevice()
    },
    // 设备添加弹窗
    showDeviceModel(data) {
      console.log(data, '添加弹窗')
      this.$refs.deviceForm.showModel(data)
      // this.$refs.deviceForm.showModel({ data, type: 'add' })
      // this.$refs.deviceForm.showModel({data,type:'edit'})
    },
    deviceSubmit() {
      // 保存成功触发
      this.getOrgTree()
      // 列表或者表格刷新
      this.handleSearch()
      console.log('保存成功触发')
      this.$refs.mapDevice.findAllDevice()
    }
    /* 弹窗函数 end */
  },
  created() {
    this.getAnalysis()
    // 查询平台设备
    this.getOrgTree()
    // 查询集群树
    this.getAllColonyNode()
  },
  watch: {}
}
</script>
<style lang="scss">
.ui-icon-lg {
  font-size: 30px;
  width: 60px;
  height: 60px;
  line-height: 60px !important;
}
.home-sidenav {
  transition: all 0.5s;
  overflow: hidden;
}
.w-20 {
  width: 20%;
}
.w-80 {
  width: 80%;
}
.w-0 {
  width: 0%;
}
.toggleOpen-btn {
  border-radius: 5px;
  position: absolute;
  left: -8px;
  top: 3.5rem;
  transition: all 2s;
  opacity: 0;
}
.toggleOpen-btn.isShow {
  opacity: 1;
}
 
.table-switch-btn {
  height: 40px;
  line-height: 30px;
  font-size: 30px;
  padding: 5px 8px;
  color: #ccc;
  cursor: pointer;
  &.active {
    color: #35bde7;
  }
}
.bg-grid {
  background: #ccc;
}
.btn-circle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  text-align: center;
  padding: 0;
}
.table-type-btns {
  font-size: 22px;
  padding: 10px 0px;
  font-weight: 900;
  color: #868686;
  transition: all 0.5s;
  cursor: pointer;
  // &.btn-link:hover {
  //   color: #3c8ae2;
  // }
  &:after {
    content: '';
    display: block;
    background: transparent;
    width: 0%;
    height: 2px;
    transition: all 0.5s;
  }
  &.active {
    color: #35bde7;
    &:after {
      background: #35bde7;
      width: 100%;
    }
  }
}
</style>