index.vue 17 KB

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