智慧园区前端大屏
linwe
2024-11-14 4b7d2c5f13c7c816746ecd7c64fc4d8bb7580e70
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
<!--
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2024-10-26 16:09:35
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2024-10-28 11:04:58
 * @FilePath: \bigScreen\src\views\layout\components\mainSearch.vue
 * @Description: 
 * 
 * Copyright (c) 2024 by shuishen, All Rights Reserved. 
-->
<template>
  <div class="page-search">
    <el-input size="medium" placeholder="请输入内容" :suffix-icon="Search" @input="onSearch()" v-model="searchVal"
      @focus="onFocus"></el-input>
    <div class="page-search-value-box" v-show="isShowSearchSKValBox">
      <ul>
        <li v-for="(item, index) in searchSKValList" :key="index" @click="sKValItemClick(item)">{{ item.name }}
        </li>
      </ul>
    </div>
  </div>
</template>
 
<script setup>
import { fuzzyQuery } from '../../../api/firmInfo/firmInfo'
 
// 搜索栏相关
let isShowSearchSKValBox = false
let searchVal = ref('')
let searchSKValList = ref([])
 
const onSearch = () => {
  if (searchVal.value == '') {
    isShowSearchSKValBox = false
    // 清空
    clearPoint()
  } else {
    isShowSearchSKValBox = true
    getFuzzyQuery()
  }
}
 
function getFuzzyQuery() {
  fuzzyQuery({
    name: searchVal.value
  }).then(res => {
    // console.log(res.data.data)
    searchSKValList.value = res.data.data
  })
}
 
const onFocus = () => {
  onSearch()
}
 
const sKValItemClick = (item) => {
  isShowSearchSKValBox = false
  if (item.lat && item.lng) {
    handleCheckChange(item)
  } else {
    console.log('没有经纬度')
  }
}
let addTileLayers = {}
const handleCheckChange = (item) => {
  console.log(item)
  // 先清空,在添加
  clearPoint()
  if (!addTileLayers[item.name]) {
    addTileLayers[item.name] = new DC.HtmlLayer(item.name)
    window.$viewer.addLayer(addTileLayers[item.name])
    let iconEl = ''
    if ('showPanel' in item && item.showPanel == false) {
      if (item.backgroundIcon) {
        iconEl = `
                        <div class="map-name">${i[item.showParams] || item.name}</div>
                        <div class="map-icon">
                          <img src="${item.backgroundIcon}">
                        </div>
                        `
      }
    } else {
      iconEl = `<div class="marsBlueGradientPnl">
                               <div>${item.name}</div>  </div>`
    }
    let divIcon = new DC.DivIcon(
      new DC.Position(item.lng, item.lat, 0),
      `<div class="public-map-popup">
                  ${iconEl}
                </div>`
    )
 
    divIcon.attrParams = item
 
    let incident = () => { }
 
    if (item.incident) incident = item.incident
 
    divIcon.on(DC.MouseEventType.CLICK, incident)
 
    addTileLayers[item.name].addOverlay(divIcon)
    window.$viewer.flyToPosition(new DC.Position(item.lng, item.lat, 2000, 0, -90, 0))
 
  } else {
    console.log('已存在*******************************')
    window.$viewer.removeLayer(addTileLayers[item.name])
  }
}
 
 
function clearPoint() {
  let arr = Object.keys(addTileLayers)
  arr.forEach(i => {
    addTileLayers[i] && window.$viewer.removeLayer(addTileLayers[i])
  })
}
 
onUnmounted(() => {
  let arr = Object.keys(addTileLayers)
  arr.forEach(i => {
    addTileLayers[i] && window.$viewer.removeLayer(addTileLayers[i])
  })
})
</script>
 
<style lang="scss" scoped>
.page-search {
  position: absolute;
  left: 488px;
  z-index: 99;
  top: 110px;
  pointer-events: auto;
 
  ::v-deep(.el-input) {
    height: 38px;
    width: 280px;
 
    .el-input__wrapper {
      font-size: 16px;
      font-weight: 400;
      border: 1px solid #4081CB;
      border-radius: 4px;
      background: rgba(135, 158, 199, 0.3);
      box-shadow: inset 0px 3px 7px 0px rgba(42, 138, 236, 0.95);
 
      .el-input__inner {
        color: #BFD3E5;
      }
    }
  }
 
  .page-search-value-box {
    position: absolute;
    width: 100%;
    height: 200px;
    left: 0;
    top: 40px;
    background: rgba(135, 158, 199, 0.3);
    border-radius: 2px;
    overflow-y: scroll;
 
    ul>li {
      color: #ffffff;
      cursor: pointer;
      height: 20px;
      margin: 3px;
      line-height: 20px;
      padding-left: 10px;
      overflow: hidden;
    }
 
    ul>li:hover {
      background-color: #0e1a35;
    }
  }
 
  .page-search-value-box::-webkit-scrollbar {
    display: none
  }
}
</style>