index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. <template>
  2. <div>
  3. <div class="head-wrap">
  4. <div class="header">
  5. <img class="logo" src="./images/logo.png" alt="">
  6. <div class="title">危险作业动态标识</div>
  7. </div>
  8. </div>
  9. <div class="conatiner">
  10. <div class="leftSide">
  11. <div class="title">作业项目</div>
  12. <div v-for="(item,index) in items" :key="index" :class="checkItemIndex===index?'item active':'item'" @click="checkItem(item,index)">
  13. <img :src="item.icon" alt="" class="icon">
  14. <div class="name">{{ item.name }}</div>
  15. </div>
  16. </div>
  17. <div class="map-warp">
  18. <div id="vmap" />
  19. </div>
  20. <div class="rightSide">
  21. <div v-if="type==1" class="remark">
  22. <div class="title">使用说明</div>
  23. <ul>
  24. <li>1.点击作业项目下面的图标</li>
  25. <li>2.点击地图绘制点</li>
  26. <li>3.编辑信息保存点位</li>
  27. </ul>
  28. </div>
  29. <div v-if="type==2||type=='drage'" class="saveForm">
  30. <div class="title">作业点基本信息</div>
  31. <div class="item">
  32. <div class="lable">作业项目:</div>
  33. <div class="content">
  34. <img class="icon" :src="saveForm.icon" alt="">
  35. <span>{{ saveForm.name }}</span>
  36. </div>
  37. </div>
  38. <div class="item">
  39. <div class="lable">名称:</div>
  40. <div class="content">
  41. <span>{{ saveForm.name }}</span>
  42. </div>
  43. </div>
  44. <div class="bt-wrap">
  45. <div class="bt save" @click="save">保存</div>
  46. <div class="bt margin" @click="cancel">撤销</div>
  47. </div>
  48. </div>
  49. <div v-if="type==3" class="deleteForm">
  50. <div class="title">作业点基本信息</div>
  51. <div class="item">
  52. <div class="lable">作业项目:</div>
  53. <div class="content">
  54. <img class="icon" :src="deleteForm.icon" alt="">
  55. <span>{{ deleteForm.name }}</span>
  56. </div>
  57. </div>
  58. <div class="item">
  59. <div class="lable">名称:</div>
  60. <div class="content">
  61. <span>{{ deleteForm.name }}</span>
  62. </div>
  63. </div>
  64. <div class="bt-wrap">
  65. <div class="bt" @click="save">保存</div>
  66. <div class="bt delete margin" @click="delMarker">删除</div>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. </template>
  73. <script>
  74. import * as L from 'leaflet'
  75. import '@geoman-io/leaflet-geoman-free'
  76. import { getLayersApi, addApi, delApi, updateApi } from '@/api/aqpt/visualEditor'
  77. import mixins from '@/mixin/mqtt.js'
  78. import { Uint8ArrayToString } from '@/utils'
  79. export default {
  80. mixins: [mixins],
  81. data() {
  82. return {
  83. checkItemIndex: -1,
  84. type: 1,
  85. items: [],
  86. saveForm: {
  87. icon: '',
  88. name: ''
  89. },
  90. deleteForm: {
  91. icon: '',
  92. name: ''
  93. },
  94. dragstartMarker: undefined,
  95. map: undefined,
  96. markerGroup: null,
  97. mapList: [],
  98. mapId: undefined,
  99. mapRasterLayer: require('./images/layout_cont.png'),
  100. layer: null,
  101. state: 0,
  102. veditId: undefined
  103. }
  104. },
  105. created() {
  106. this.init()
  107. },
  108. // beforeRouteEnter(to, from, next) {
  109. // const params = window.location.href.split('?')[1].split('&')
  110. // function getParams(name = 'name') {
  111. // let param
  112. // params.map(item => item.includes('name') ? (param = item.split('=')[1]) : '')
  113. // return param
  114. // }
  115. // next()
  116. // console.log(getParams())
  117. // },
  118. methods: {
  119. init() {
  120. // console.log(this.$route.query)
  121. this.initProject()
  122. this.$nextTick(() => {
  123. this.initMap()
  124. this.initMqtt({
  125. mqttResponse: this.mqttResponse
  126. })
  127. })
  128. },
  129. initProject() {
  130. this.items = [
  131. { icon: require('./images/layers/1.png'), name: '动火作业' },
  132. { icon: require('./images/layers/2.png'), name: '有限空间作业' },
  133. { icon: require('./images/layers/3.png'), name: '高处作业' },
  134. { icon: require('./images/layers/4.png'), name: '起重作业' },
  135. { icon: require('./images/layers/5.png'), name: '预热器清堵作业' },
  136. { icon: require('./images/layers/6.png'), name: '篦冷机清大块作业' },
  137. { icon: require('./images/layers/7.png'), name: '交叉作业' },
  138. { icon: require('./images/layers/8.png'), name: '临时用电作业' },
  139. { icon: require('./images/layers/9.png'), name: '动土作业' },
  140. { icon: require('./images/layers/10.png'), name: '断路作业' },
  141. { icon: require('./images/layers/11.png'), name: '防护设备拆除' },
  142. { icon: require('./images/layers/12.png'), name: '高温及其他危险作业' },
  143. { icon: require('./images/layers/13.png'), name: '盲板抽堵作业' }
  144. ]
  145. },
  146. checkItem(item, index) {
  147. if (this.state === 1) {
  148. this.$message('请保存后再操作!')
  149. return
  150. }
  151. this.checkItemIndex = index
  152. this.type = 2
  153. this.saveForm.icon = item.icon
  154. this.saveForm.name = item.name
  155. this.map.pm.enableDraw('Marker', { snappable: false, tooltips: false })// tooltips: { 'placeMarker': '点击放置标记' },
  156. console.log({
  157. ' this.map.pm.enableDraw': this.map.pm.enableDraw
  158. })
  159. this.state = 1
  160. },
  161. save() {
  162. if (this.type === 3) {
  163. // 删除表单里面的保存
  164. this.type = 1
  165. } else if (this.type === 'drage') {
  166. updateApi({
  167. 'jobactivityTitle': this.layer.options.icon.options.name,
  168. 'jobactQywzjd': this.layer._latlng.lng,
  169. 'jobactQywzwd': this.layer._latlng.lat,
  170. 'veditId': this.veditId,
  171. 'typeId': this.layer.options.icon.options.typeId
  172. }).then(() => {
  173. this.type = 1
  174. this.checkItemIndex = -1
  175. this.state = 2
  176. this.saveForm.icon = ''
  177. this.saveForm.name = ''
  178. this.$message.success('修改成功!')
  179. this.dragstartMarker = undefined
  180. // this.getLayers()
  181. })
  182. } else {
  183. // 新增
  184. addApi({
  185. 'jobactivityTitle': this.layer.options.icon.options.name,
  186. 'jobactQywzjd': this.layer._latlng.lng,
  187. 'jobactQywzwd': this.layer._latlng.lat,
  188. 'veditId': this.veditId,
  189. 'typeId': this.layer.options.icon.options.typeId
  190. }).then(() => {
  191. this.type = 1
  192. this.checkItemIndex = -1
  193. this.state = 2
  194. this.saveForm.icon = ''
  195. this.saveForm.name = ''
  196. this.$message.success('新增成功!')
  197. // this.getLayers()
  198. })
  199. }
  200. },
  201. cancel() {
  202. this.state = 2
  203. this.checkItemIndex = -1
  204. this.saveForm.icon = ''
  205. this.saveForm.name = ''
  206. if (this.type === 'drage') {
  207. this.type = 1
  208. this.dragstartMarker.marker.setLatLng(this.dragstartMarker._latlng)
  209. this.dragstartMarker.marker.dragging.disable()
  210. this.dragstartMarker = undefined
  211. return
  212. }
  213. this.type = 1
  214. if (this.layer && this.layer._leaflet_id && this.map._layers[this.layer._leaflet_id]) {
  215. this.map.removeLayer(this.map._layers[this.layer._leaflet_id])
  216. }
  217. },
  218. delMarker() {
  219. delApi(this.veditId).then(() => {
  220. this.type = 1
  221. this.state = 2
  222. this.checkItemIndex = -1
  223. this.deleteForm.icon = ''
  224. this.deleteForm.name = ''
  225. if (this.map._layers[this.markerId]) {
  226. this.map.removeLayer(this.map._layers[this.markerId])
  227. }
  228. this.$message.success('删除成功!')
  229. // this.getLayers()
  230. })
  231. },
  232. initMap() {
  233. this.map = L.map('vmap', {
  234. minZoom: 1,
  235. maxZoom: 3,
  236. center: [30, 50],
  237. zoom: 1,
  238. crs: L.CRS.Simple,
  239. zoomControl: false
  240. })
  241. this.setRasterLayer()
  242. this.mapListener()
  243. },
  244. setRasterLayer() {
  245. var yx = L.latLng
  246. var xy = function xy(x, y) {
  247. if (L.Util.isArray(x)) {
  248. return yx(x[1], x[0])
  249. }
  250. return yx(y, x)
  251. }
  252. var bounds = [xy(-330, -255), xy(330, 255)]
  253. L.imageOverlay(this.mapRasterLayer, bounds).addTo(this.map)
  254. this.map.fitBounds(bounds)
  255. this.getLayers()
  256. },
  257. getLayers() {
  258. getLayersApi().then((res) => {
  259. if (this.markerGroup !== null) {
  260. this.markerGroup?.clearLayers()
  261. }
  262. this.initMarkers(res.data)
  263. })
  264. },
  265. initMarkers(markerList = []) {
  266. const self = this
  267. const markers = L.layerGroup()
  268. const coordinates = [-100, 100]
  269. const options = { id: 1 }
  270. const icon = 'project-12'
  271. const tip = '盲板抽堵作业'
  272. const iconSize = [40.5, 49.5]
  273. function drawMark(option = { tip, icon, options, coordinates }) {
  274. const myIcon = L.icon({
  275. iconUrl: require(`./images/layers/${option.options.typeId}.png`),
  276. className: option.icon,
  277. iconSize: iconSize
  278. })
  279. const marker = L.marker(option.coordinates, { ...option.options, icon: myIcon, draggable: false })
  280. // .bindPopup(option.tip)
  281. .addTo(markers)
  282. marker.on('click', function(ev) {
  283. if (self.type === 'drage') {
  284. self.$message.success('请先确认当前标记点操作!')
  285. return
  286. }
  287. const id = ev.target.options?.id
  288. self.type = 3
  289. self.veditId = id
  290. self.markerId = ev.target._leaflet_id
  291. self.deleteForm.name = ev.target.options.name
  292. self.deleteForm.icon = require(`./images/layers/${ev.target.options.typeId}.png`)
  293. marker.dragging.enable()
  294. })
  295. marker.on('dragstart', function(ev) {
  296. const id = ev.target.options?.id
  297. self.type = 'drage'
  298. if (self.dragstartMarker === undefined) {
  299. self.dragstartMarker = { marker, _latlng: ev.target._latlng }
  300. }
  301. self.veditId = id
  302. self.markerId = ev.target._leaflet_id
  303. self.saveForm.name = ev.target.options.name
  304. self.saveForm.icon = require(`./images/layers/${ev.target.options.typeId}.png`)
  305. })
  306. marker.on('dragend', function(ev) {
  307. self.layer = ev.target
  308. })
  309. }
  310. markers.addTo(this.map)
  311. this.markerGroup = markers
  312. if (markerList && markerList.length > 0) {
  313. for (let i = 0; i < markerList.length; i++) {
  314. drawMark({
  315. // tip: `${markerList[i].jobactivityTitle}`,
  316. icon: `project-${markerList[i].typeId}`,
  317. coordinates: [markerList[i].jobactQywzwd, markerList[i].jobactQywzjd],
  318. options: { id: markerList[i].veditId, typeId: markerList[i].typeId, name: markerList[i].jobactivityTitle }
  319. })
  320. }
  321. }
  322. },
  323. mapListener() {
  324. const self = this
  325. this.map.on('pm:drawstart', (e) => { // 绘制开始时事件
  326. if (e.shape === 'Marker') {
  327. const iconUrl = this.saveForm.icon
  328. const layer = e.workingLayer
  329. var icon = L.icon({
  330. iconUrl,
  331. iconSize: [40.5, 49.5]
  332. })
  333. layer.setIcon(icon)
  334. }
  335. })
  336. this.map.on('pm:create', (e) => {
  337. if (e.shape === 'Marker') {
  338. const iconUrl = this.saveForm.icon
  339. const name = this.saveForm.name
  340. const typeId = this.checkItemIndex + 1
  341. const layer = e.layer
  342. var icon = L.icon({
  343. iconUrl,
  344. name,
  345. typeId,
  346. iconSize: [27, 33]
  347. })
  348. layer.setIcon(icon)
  349. layer.on('click', function(ev) {
  350. self.type = 3
  351. self.markerId = ev.target._leaflet_id
  352. self.deleteForm.name = ev.target.options.icon.options.name
  353. self.deleteForm.icon = ev.target.options.icon.options.iconUrl
  354. })
  355. self.layer = layer
  356. layer.addTo(this.markerGroup)
  357. }
  358. this.map.pm.disableDraw(e.shape)
  359. })
  360. this.map.on('pm:cut', () => {
  361. this.$message.success('裁剪完毕!')
  362. })
  363. this.map.on('pm:remove', (e) => {
  364. console.log(e, '移除')
  365. })
  366. // this.map.on('pm:globaldragmodetoggled', e => {
  367. // console.log(e, '拖拽结束')
  368. // })
  369. this.map.on('contextmenu', () => {
  370. // 取消所有状态
  371. this.map.pm.disableGlobalDragMode()
  372. this.cancel()
  373. })
  374. // this.map.on('zoomend', (e) => {
  375. // const scale = e.target.getZoom()
  376. // const markers = document.querySelectorAll('.leaflet-marker-icon')
  377. // for (let i = 0; i < markers.length; i++) {
  378. // console.log()
  379. // markers[i].style.transform = `${markers[i].style.transform} scale(${scale})`
  380. // }
  381. // console.log({ markers, scale })
  382. // // this.markerGroup.eachLayer(item => { // })
  383. // })
  384. },
  385. mqttResponse(message) {
  386. const data = message ? Uint8ArrayToString(message) : ''
  387. this.getLayers()
  388. console.log({ message, data })
  389. }
  390. }
  391. }
  392. </script>
  393. <style lang="scss" scoped>
  394. .head-wrap{
  395. padding: 0 16px;
  396. background-color: #071C2B;
  397. .header{
  398. height: 50px;
  399. line-height: 50px;
  400. background-color: #193142;
  401. color: #fff;
  402. text-align: center;
  403. position: relative;
  404. .logo{
  405. display: block;
  406. height: 40px;
  407. position: absolute;
  408. left: 16px;
  409. top: 5px;
  410. }
  411. .title{
  412. font-size: 30px;
  413. font-weight: 600;
  414. letter-spacing: 4px;
  415. }
  416. }
  417. }
  418. .conatiner{
  419. height: 100%;
  420. height: calc(100vh - 70px);
  421. min-width: 1000px;
  422. margin: 0 auto;
  423. padding: 0 16px;
  424. box-sizing: border-box;
  425. background-color: #071C2B;
  426. color: #fff;
  427. display: flex;
  428. justify-content: space-between;
  429. align-items: center;
  430. overflow-x: auto;
  431. margin-top: 20px;
  432. .leftSide{
  433. min-width: 266px;
  434. height: 100%;
  435. overflow-y: auto;
  436. background-color: #193142;
  437. box-sizing: border-box;
  438. .title{
  439. height: 42px;
  440. line-height: 42px;
  441. background-color: #36556b;
  442. font-size: 16px;
  443. color: #666;
  444. text-indent: 10px;
  445. color: #fff;
  446. }
  447. .item{
  448. display: flex;
  449. align-items: center;
  450. height: 48px;
  451. padding-left: 10px;
  452. cursor: default;
  453. &.active{
  454. background-color: rgba(45, 140, 240, 0.16);
  455. }
  456. .icon{
  457. width: 17.5px;
  458. display: block;
  459. }
  460. .name{
  461. font-size: 14px;
  462. padding-left: 12px;
  463. }
  464. }
  465. }
  466. .map-warp{
  467. flex: 1;
  468. height: 100%;
  469. background-color: #071c2b;
  470. #vmap{
  471. background-color: inherit;
  472. width: 100%;
  473. height: 100%;
  474. }
  475. }
  476. .rightSide{
  477. width: 269px;
  478. height: 100%;
  479. overflow-y: auto;
  480. background-color: #193142;
  481. box-sizing: border-box;
  482. padding: 17px 16px;
  483. .title{
  484. color: #fff;
  485. font-size: 16px;
  486. margin-bottom: 16px;
  487. }
  488. .remark{
  489. ul,li{
  490. list-style: none;
  491. margin: 0;
  492. padding: 0;
  493. }
  494. li{
  495. color: rgba(255, 255, 255, 0.7);
  496. line-height: 28px;
  497. font-size: 14px;
  498. margin-bottom: 8px;
  499. }
  500. }
  501. .saveForm,.deleteForm{
  502. .item{
  503. height: 48px;
  504. display: flex;
  505. justify-content: flex-start;
  506. align-items: center;
  507. font-size: 14px;
  508. border-bottom:2px solid rgba(45, 140, 240, 0.16);
  509. .lable{
  510. width: 80px;
  511. font-size: 14px;
  512. }
  513. .content{
  514. display: flex;
  515. justify-content: flex-start;
  516. align-items: center;
  517. overflow: hidden;
  518. text-overflow: ellipsis;
  519. .icon{
  520. width: 17.5px;
  521. display: block;
  522. margin-right:8px;
  523. }
  524. }
  525. }
  526. }
  527. }
  528. .bt-wrap{
  529. margin-top: 65px;
  530. .bt{
  531. width: 100px;
  532. height: 36px;
  533. color: #fff;
  534. font-size: 14px;
  535. line-height: 36px;
  536. text-align: center;
  537. background-color: rgba(24, 144, 255, 0.3);
  538. display: inline-block;
  539. cursor: pointer;
  540. user-select: none;
  541. -moz-user-select: none;
  542. -webkit-user-select: none;
  543. -ms-user-select: none;
  544. &.save{
  545. background-color: #1890ff;
  546. }
  547. &.delete{
  548. background-color: #f97647;
  549. }
  550. &.margin{
  551. margin-left: 12px;
  552. }
  553. }
  554. }
  555. }
  556. </style>
  557. <style>
  558. /* 标记点 */
  559. .leaflet-marker-icon{
  560. background-size: 100%;
  561. background-repeat: no-repeat;
  562. }
  563. .leaflet-marker-icon.leaflet-marker-draggable{
  564. box-shadow: 0 2px 4px #154c74;
  565. background-color: #52b6ff;
  566. border-radius: 4px;
  567. }
  568. .leaflet-marker-icon.project-1{
  569. background-image: url("./images/layers/1.png");
  570. }
  571. .leaflet-marker-icon.project-2{
  572. background-image: url("./images/layers/2.png");
  573. }
  574. .leaflet-marker-icon.project-3{
  575. background-image: url("./images/layers/3.png");
  576. }
  577. .leaflet-marker-icon.project-4{
  578. background-image: url("./images/layers/4.png");
  579. }
  580. .leaflet-marker-icon.project-5{
  581. background-image: url("./images/layers/5.png");
  582. }
  583. .leaflet-marker-icon.project-6{
  584. background-image: url("./images/layers/6.png");
  585. }
  586. .leaflet-marker-icon.project-7{
  587. background-image: url("./images/layers/7.png");
  588. }
  589. .leaflet-marker-icon.project-8{
  590. background-image: url("./images/layers/8.png");
  591. }
  592. .leaflet-marker-icon.project-9{
  593. background-image: url("./images/layers/9.png");
  594. }
  595. .leaflet-marker-icon.project-10{
  596. background-image: url("./images/layers/10.png");
  597. }
  598. .leaflet-marker-icon.project-11{
  599. background-image: url("./images/layers/11.png");
  600. }
  601. .leaflet-marker-icon.project-12{
  602. background-image: url("./images/layers/12.png");
  603. }
  604. .leaflet-marker-icon.project-13{
  605. background-image: url("./images/layers/12.png");
  606. }
  607. </style>