ranMapNeDetailModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <!-- 지도형 3Depth 정보 팝업 : S -->
  3. <v-dialog
  4. v-model="isModal"
  5. persistent
  6. width="62.5rem"
  7. >
  8. <div class="v-common-dialog-wrapper custom-dialog alert">
  9. <div class="modal-tit">
  10. <strong>{{neInfo.neName}}</strong>
  11. <button class="btn-close" @click="fnClose"></button>
  12. </div>
  13. <div class="v-common-dialog-content pa-0">
  14. <div class="core--list--component">
  15. <div class="map--area big--map">
  16. <!--맵 영역-->
  17. <div id="ran_detail_map" style="height: 100%;"></div>
  18. </div>
  19. </div>
  20. <!-- NE 상세 정보 : S -->
  21. <div class="core--list--component mt--0">
  22. <h2 class="fw--500 mb--125rem">상세 정보</h2>
  23. <div class="form-style1 col4 shadow--type">
  24. <table>
  25. <colgroup>
  26. <col style="width:9.375rem;">
  27. <col style="width: calc(50% - 9.375rem);">
  28. <col style="width:9.375rem;">
  29. <col style="width: calc(50% - 9.375rem);">
  30. </colgroup>
  31. <tbody>
  32. <tr>
  33. <th>테넌트 이름</th>
  34. <td>
  35. {{neInfo.tenantName}}
  36. </td>
  37. <th>NE 그룹 이름</th>
  38. <td>
  39. {{neInfo.neGroup}}
  40. </td>
  41. </tr>
  42. <tr>
  43. <th>NE 유형</th>
  44. <td>
  45. {{neInfo.neType}}
  46. </td>
  47. <th>NE 이름</th>
  48. <td>
  49. {{neInfo.neName}}
  50. </td>
  51. </tr>
  52. <tr>
  53. <th>위치</th>
  54. <td colspan="3">
  55. {{neInfo.neAddress}}
  56. </td>
  57. </tr>
  58. </tbody>
  59. </table>
  60. </div>
  61. </div>
  62. <!-- NE 상세 정보 : E -->
  63. </div>
  64. <div class="btn-wrap nw--btn--wrap" style="padding-top:1.88rem">
  65. <div></div>
  66. <div class="inner--btn--wrap">
  67. <v-btn
  68. class="custom-btn btn-gray mini"
  69. @click="fnClose"
  70. >
  71. <i class="ico"></i>
  72. 닫기
  73. </v-btn>
  74. </div>
  75. </div>
  76. </div>
  77. </v-dialog>
  78. <!-- 지도형 3Depth 정보 팝업 : E -->
  79. </template>
  80. <script setup>
  81. /***********************
  82. * import
  83. ************************/
  84. import { useI18n } from "vue-i18n";
  85. import useUtil from "@/composables/useUtil";
  86. /***********************
  87. * plugins inject
  88. ************************/
  89. const { $toast, $log, $dayjs, $eventBus } = useNuxtApp()
  90. // props
  91. const props = defineProps({
  92. neInfo: {
  93. type: Object,
  94. default: function () {
  95. return {
  96. tenantName: '',
  97. neName: '',
  98. neType: '',
  99. neGroup: '',
  100. neAddress: '',
  101. neLocLatitude: '',
  102. neLocLongitude: ''
  103. }
  104. },
  105. },
  106. centerPosition: Object
  107. })
  108. // 참조가능 데이터 설정
  109. defineExpose({})
  110. // 발신 이벤트 선언
  111. const emit = defineEmits(["closeModal"])
  112. const i18n = useI18n()
  113. /***********************
  114. * data & created
  115. ************************/
  116. const isModal = ref(true)
  117. const map = ref(null) // 카카오 맵 객체
  118. const remToPx = () => parseFloat(getComputedStyle(document.documentElement).fontSize)
  119. const rowHeightRem = 2.5 // 원하는 rem 값
  120. const rowHeightPx = rowHeightRem * remToPx()
  121. const gridApi = shallowRef()
  122. const markers = ref([])
  123. onMounted(() => {
  124. fnInit()
  125. })
  126. /***********************
  127. * Methods
  128. ************************/
  129. function fnInit(){
  130. nextTick().then(() => {
  131. if (window.kakao && window.kakao.maps) {
  132. loadMap()
  133. } else {
  134. loadScript()
  135. }
  136. })
  137. }
  138. /**
  139. * kakao 스크립트 로드
  140. */
  141. function loadScript() {
  142. const script = document.createElement('script')
  143. script.async = true
  144. script.onload = () => {
  145. window.kakao.maps.load(loadMap)
  146. }
  147. script.src = `//dapi.kakao.com/v2/maps/sdk.js?autoload=false&libraries=services,clusterer,drawing&appkey=${import.meta.env.VITE_APP_KAKAO_APP_KEY}`
  148. document.head.appendChild(script)
  149. }
  150. /**
  151. * kakao 지도 로드
  152. */
  153. async function loadMap() {
  154. const mapContainer = document.getElementById('ran_detail_map')
  155. let mapOption = {
  156. center: new kakao.maps.LatLng(props.centerPosition.lat, props.centerPosition.lng), // 지도의 중심좌표
  157. level: 3, // 지도의 확대 레벨
  158. }
  159. map.value = new kakao.maps.Map(mapContainer, mapOption)
  160. let zoomControl = new kakao.maps.ZoomControl()
  161. // map.value.addControl(zoomControl, kakao.maps.ControlPosition.BOTTOMRIGHT)
  162. // fnSetEventListener() // 지도 이벤트 등록
  163. fnDrawMarker()
  164. }
  165. /**
  166. * 상세팝업 닫기
  167. */
  168. function fnClose(){
  169. isModal.value = false
  170. setTimeout(() => {
  171. emit('closeModal')
  172. }, 250);
  173. }
  174. /**
  175. * 마커 생성 데이터 세팅
  176. */
  177. function fnDrawMarker(){
  178. let position = new kakao.maps.LatLng(props.neInfo.neLocLatitude, props.neInfo.neLocLongitude)
  179. let markerObj = {
  180. overlay: null,
  181. markers: null,
  182. data: props.neInfo,
  183. click: false,
  184. position: position
  185. }
  186. markers.value.push(markerObj)
  187. markers.value[0].markers = fnCreateMarker(position, 0)
  188. map.value.panTo(position)
  189. setTimeout(() => {
  190. // 정보 레이어 오픈
  191. fnGetInfo(markers.value[0].data, 0)
  192. }, 1);
  193. }
  194. import { filename } from 'pathe/utils'
  195. // 이미지 가져오기 (vite문법)
  196. const glob = import.meta.glob('~/assets/img/ico_*.{png,svg}', { eager: true })
  197. const getImages = Object.fromEntries(
  198. Object.entries(glob).map(([key, value]) => [filename(key), value.default])
  199. )
  200. // NE 수 > 이벤트 단계 클래스
  201. const getNeEventCls = computed(() => {
  202. return (obj) => {
  203. let eventCls = ''
  204. if(!_isEmpty(obj)) {
  205. if(obj.minCnt > 0) eventCls = 'black'
  206. if(obj.majCnt > 0) eventCls = 'blue'
  207. if(obj.criCnt > 0) eventCls = 'red'
  208. }
  209. return eventCls
  210. }
  211. })
  212. // 마커 이미지 파일명 세팅
  213. function fnGetMarkerImage(){
  214. let color = getNeEventCls.value(props.neInfo)
  215. if(color == 'red') return 'ico_red_pin'
  216. else if(color == 'blue') return 'ico_blue_pin'
  217. else if(color == 'black') return 'ico_black_pin'
  218. else return 'ico_gray_pin'
  219. }
  220. /**
  221. * 마커 생성
  222. */
  223. function fnCreateMarker(position, index) {
  224. // 마커 이미지 설정
  225. const markerImageSrc = getImages[fnGetMarkerImage()] // assets 폴더의 이미지 경로
  226. const markerImageSize = new kakao.maps.Size(40, 40); // 마커 이미지 사이즈
  227. const markerImage = new kakao.maps.MarkerImage(markerImageSrc, markerImageSize);
  228. let markerOption = {
  229. map: map.value, // 마커를 표시할 지도
  230. position: position, // 마커의 위치
  231. clickable: true,
  232. image: markerImage,
  233. zIndex: 1,
  234. }
  235. let marker = new kakao.maps.Marker(markerOption)
  236. // 마커 클릭 이벤트등록
  237. kakao.maps.event.addListener(marker,'click', fnClickMarker(index))
  238. return marker
  239. }
  240. /**
  241. * 마커 클릭
  242. */
  243. function fnClickMarker(index) {
  244. const clickData = markers.value[index].data
  245. const openInfoWindow = function () {
  246. // 마커 클릭 > 상태변경 > z-index 및 맵 이동
  247. fnMarkerClickChk(index)
  248. fnGetInfo(clickData, index)
  249. }
  250. return openInfoWindow
  251. }
  252. /**
  253. * 마커 클릭 이벤트
  254. */
  255. function fnMarkerClickChk(index) {
  256. fnSetUnClickMarker()
  257. markers.value[index].click = true
  258. markers.value[index].markers.setZIndex(3)
  259. let moveLatLng = markers.value[index].position
  260. map.value.panTo(moveLatLng)
  261. }
  262. /**
  263. * 마커 클릭 상태 해제 및 z인덱스 초기화
  264. */
  265. function fnSetUnClickMarker() {
  266. markers.value.forEach((item) => {
  267. item.click = false
  268. item.markers.setZIndex(2)
  269. })
  270. }
  271. function fnGetInfo(data, index){
  272. // 열려 있던 오버레이 닫기
  273. fnCloseMarkerInfoOverlay()
  274. // 오버레이 생성
  275. markers.value[index].overlay = fnCreateCustomOverlay(data, index)
  276. // 오버레이 z-index 설정
  277. markers.value[index].overlay.setZIndex(999)
  278. // 오버레이 열기
  279. markers.value[index].overlay.setMap(map.value)
  280. // 오버레이 이벤트 등록
  281. fnCustomOverlayAddEventListener()
  282. }
  283. /**
  284. * 커스텀 오버레이 생성
  285. */
  286. function fnCreateCustomOverlay(data, index) {
  287. let cpu = JSON.parse(data.cpu)
  288. let memory = JSON.parse(data.mem)
  289. let content = `
  290. <div class="area--info" style="top: -10.7rem; right: -6rem;">
  291. <div class="area--info--title">
  292. <p style="overflow:hidden; text-overflow: ellipsis;">${data.neName}</p>
  293. <button class="btn-close" id="overlayCloseBtn"></button>
  294. </div>
  295. <ul>
  296. <li><i class="ico green"></i><span>STATUS</span><span class="active">ACTIVE</span></li>
  297. <li><i class="ico red"></i><span>CPU</span><span class="">${cpu.AVG_CPU_L}%</span></li>
  298. <li><i class="ico green"></i><span>MEMORY</span><span class="">${memory.AVG_MEM_L}%</span></li>
  299. <li><i class="ico green"></i><span>DISK</span><span class="">${data.disk}</span></li>
  300. </ul>
  301. </div>`
  302. // 커스텀 오버레이 생성
  303. let customOverlay = new kakao.maps.CustomOverlay({
  304. position: markers.value[index].position,
  305. content: content
  306. })
  307. return customOverlay
  308. }
  309. /**
  310. * 커스텀 오버레이 이벤트 등록
  311. */
  312. function fnCustomOverlayAddEventListener(){
  313. // 오버레이 닫기 버튼
  314. const closeBtn = document.querySelector('#overlayCloseBtn')
  315. closeBtn.addEventListener('click', fnCloseBtnOverlay)
  316. }
  317. /**
  318. * 마커 정보 오버레이 닫기 버튼
  319. */
  320. function fnCloseBtnOverlay() {
  321. fnCloseMarkerInfoOverlay()
  322. fnSetUnClickMarker()
  323. }
  324. /**
  325. * 모든 마커 정보 오버레이 닫기
  326. */
  327. function fnCloseMarkerInfoOverlay() {
  328. for (var i = 0; i < markers.value.length; i++) {
  329. if (markers.value[i].overlay) {
  330. markers.value[i].overlay.setMap(null)
  331. markers.value[i].overlay = null
  332. }
  333. }
  334. }
  335. /*********************
  336. * grid 관련
  337. *********************/
  338. // Grid 데이터 바인딩
  339. function fnOnGridReady(params){
  340. gridApi.value = params.api
  341. }
  342. function actionCellRenderer2(params) {
  343. let _cls = "";
  344. if(params.data.color == 'red'){
  345. _cls = 'pin--red';
  346. } else if(params.data.color == 'blue'){
  347. _cls = 'pin--blue';
  348. } else if(params.data.color == 'gray'){
  349. _cls = 'pin--gray';
  350. } else if(params.data.color == 'black'){
  351. _cls = 'pin--black';
  352. }
  353. let pin = `<span class="${_cls}">${params.data.neName}</span>`;
  354. return pin;
  355. }
  356. function actionCellRenderer3(params) {
  357. let _cls0 = "";
  358. let _cls1 = "";
  359. let _cls2 = "";
  360. let _cls3 = "";
  361. if(params.data.th4[0]){_cls0 = 'evt--critical';}
  362. if(params.data.th4[1]){_cls1 = 'evt--major';}
  363. if(params.data.th4[2]){_cls2 = 'evt--minor';}
  364. let pin = "";
  365. if (_cls0) {
  366. pin += `<span class="${_cls0}">CRITICAL (${params.data.th4[0]}) </span>`;
  367. }
  368. if (_cls1) {
  369. pin += `<span class="${_cls1}">MAJOR (${params.data.th4[1]}) </span>`;
  370. }
  371. if (_cls2) {
  372. pin += `<span class="${_cls2}">MINOR (${params.data.th4[2]}) </span>`;
  373. }
  374. if(pin == ""){
  375. pin += `<span class="evt--none">-</span>`;
  376. }
  377. return pin;
  378. }
  379. </script>