index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <!-- 底图 -->
  2. <template>
  3. <div id='floor_base' v-loading='loading' ref='graphy'>
  4. <canvas :id='`canvas${id}`' :width='canvasWidth' :height='canvasHeight' tabindex='0'></canvas>
  5. <!-- 地图底部操作按钮 -->
  6. <div class='strip-bottom'>
  7. <canvasFun @fit='fit' @savePng='savePng' @saveSvg='saveSvg' @saveJson='saveJson' @scale='scale' @showText='showText' ref='canvasFun'></canvasFun>
  8. </div>
  9. <room-box ref='boxRoom'></room-box>
  10. </div>
  11. </template>
  12. <script>
  13. import { SFengParser } from '@saga-web/feng-map'
  14. import { SFloorParser, ItemOrder } from '@saga-web/big'
  15. import { FloorView } from '@/lib/FloorView'
  16. import { FloorScene } from '@/lib/FloorScene'
  17. import RoomBox from '@/views/room/index'
  18. import canvasFun from '@/components/floorMap/canvasFun'
  19. import { readGroup, queryStatis } from '@/api/public'
  20. import { queryShops } from '@/api/equipmentList.js'
  21. import { STopologyParser } from '@/lib/parsers/STopologyParser'
  22. import { mapGetters, mapActions } from 'vuex'
  23. import { SImageItem } from '@saga-web/graph/lib'
  24. import bus from '@/utils/bus.js'
  25. // import { uuid } from "@/components/mapClass/until";
  26. export default {
  27. data() {
  28. return {
  29. appName: '万达可视化系统',
  30. key: '23f30a832a862c58637a4aadbf50a566',
  31. mapServerURL: `http://map.wanda.cn/editor`,
  32. canvasWidth: 600,
  33. canvasHeight: 800,
  34. loading: false, // 限制重复查询
  35. view: null,
  36. urlMsg: {},
  37. canvasID: 'canvas',
  38. floorid: '', //楼层id
  39. topologyParser: null, // 解析器数据
  40. fParser: null, // 底图解析器
  41. wellMap: {} // 电井控制商铺映射
  42. }
  43. },
  44. props: {
  45. id: {
  46. default: '1',
  47. type: String
  48. },
  49. categoryId: {
  50. default: '',
  51. type: String
  52. },
  53. // 弹窗高度,适配底图高度使用
  54. modalHeight: {
  55. type: [Number, undefined],
  56. default: undefined
  57. },
  58. loadName: null,
  59. type: null
  60. },
  61. components: { RoomBox, canvasFun },
  62. computed: {
  63. ...mapGetters(['plazaId', 'fmapID', 'haveFengMap', 'bunkObj'])
  64. },
  65. methods: {
  66. ...mapActions(['getfmapID']),
  67. init(floorid) {
  68. // this.loading = true
  69. this.floorid = floorid
  70. this.mapSize()
  71. this.$refs.canvasFun.isShow = false
  72. setTimeout(() => {
  73. if (this.haveFengMap) {
  74. this.clearGraphy()
  75. this.scene = new FloorScene()
  76. this.scene.selectContainer.connect('listChange', this, this.listChange)
  77. if (this.canvasID != `canvas${this.id}`) {
  78. this.canvasID = `canvas${this.id}`
  79. }
  80. this.parserData(floorid)
  81. }
  82. }, 100)
  83. },
  84. parserData(floor) {
  85. if (floor == 'g80') {
  86. // 屋顶
  87. if (window.fengmapData.frImg) {
  88. let imgItem = new SImageItem(null, `${this.mapServerURL}/webtheme/${this.fmapID}/${window.fengmapData.frImg}`)
  89. this.scene.addItem(imgItem)
  90. this.view.scene = this.scene
  91. this.view.minScale = this.view.scale
  92. if (this.$refs.canvasFun) {
  93. this.$refs.canvasFun.everyScale = this.view.scale
  94. }
  95. this.view.fitSceneToView()
  96. }
  97. } else {
  98. if (window.fengmapData.gnameToGid[floor]) {
  99. window.fengmapData.parseData(window.fengmapData.gnameToGid[floor], res => {
  100. if (res.err) {
  101. console.log('errr', res.err)
  102. return
  103. }
  104. this.fParser = new SFloorParser(null)
  105. this.fParser.parseData(res)
  106. this.fParser.spaceList.forEach(t => {
  107. this.scene.addItem(t)
  108. if (t.data.Name && this.bunkObj[t.data.Name]) {
  109. t.name = this.bunkObj[t.data.Name].detailtype
  110. } else {
  111. t.name = ''
  112. }
  113. })
  114. this.fParser.wallList.forEach(t => this.scene.addItem(t))
  115. this.fParser.virtualWallList.forEach(t => this.scene.addItem(t))
  116. this.fParser.doorList.forEach(t => this.scene.addItem(t))
  117. this.fParser.columnList.forEach(t => this.scene.addItem(t))
  118. this.fParser.casementList.forEach(t => this.scene.addItem(t))
  119. this.view.scene = this.scene
  120. this.view.fitSceneToView()
  121. this.view.minScale = this.view.scale
  122. if (this.$refs.canvasFun) {
  123. this.$refs.canvasFun.everyScale = this.view.scale
  124. }
  125. })
  126. } else {
  127. console.log('楼层不正确')
  128. }
  129. }
  130. this.readGroup(this.floorid).then(data => {
  131. this.loading = false
  132. if (data.Result == 'failure') {
  133. this.$store.commit('SETISMESSAGE', false)
  134. return
  135. } else {
  136. this.$store.commit('SETISMESSAGE', true)
  137. }
  138. // 无返回Data处理
  139. if (!(data.Data && data.Data.length)) {
  140. return false
  141. }
  142. // 请求回来的备注
  143. if (data.Data && data.Data[0].Note) {
  144. let note = data.Data[0].Note
  145. bus.$emit('queryRemarksMethods', note)
  146. } else {
  147. bus.$emit('queryRemarksMethods', '')
  148. }
  149. //土建系统的图例展示
  150. if (this.$cookie.get('categoryId') == 'SCPZ') {
  151. let scpzTable = []
  152. scpzTable = data.Data[0].Elements.Nodes || []
  153. this.$store.commit('SETSCPZTABLE', scpzTable)
  154. }
  155. // 放到后边 $cookie graphId
  156. this.$cookie.set('graphId', data.Data[0].ID, 3)
  157. if (this.$cookie.get('graphId')) {
  158. // 得到graphId 就请求图例
  159. // 除土建系统之外的图例展示 包括楼层功能
  160. bus.$emit('queryViewMethods')
  161. }
  162. this.topologyParser = new STopologyParser(null)
  163. this.topologyParser.parseData(data.Data[0].Elements)
  164. // 多边形
  165. this.topologyParser.zoneLegendList.forEach(t => {
  166. this.scene.addItem(t)
  167. })
  168. // 增加文字
  169. this.topologyParser.textMarkerList.forEach(t => {
  170. this.scene.addItem(t)
  171. })
  172. // 增加图片
  173. this.topologyParser.imageMarkerList.forEach(t => {
  174. this.scene.addItem(t)
  175. })
  176. // 增加直线
  177. this.topologyParser.lineMarkerList.forEach(t => {
  178. this.scene.addItem(t)
  179. })
  180. // 增加图标类图例
  181. this.topologyParser.imageLegendList.forEach(t => {
  182. this.scene.addItem(t)
  183. })
  184. // 增加管线类
  185. // 增加图标类图例
  186. this.topologyParser.relationList.forEach(t => {
  187. this.scene.addItem(t)
  188. })
  189. this.view.fitSceneToView()
  190. })
  191. },
  192. clearGraphy() {
  193. if (this.view) {
  194. this.view.scene = null
  195. return
  196. }
  197. this.view = new FloorView(`canvas${this.id}`)
  198. },
  199. listChange(item, ev) {
  200. if (ev[0].length) {
  201. let selectItem1 = ev[0][0],
  202. name = selectItem1.data.Name,
  203. location = selectItem1.data.AttachObjectIds[0] ? selectItem1.data.AttachObjectIds[0].id : ''
  204. if (name.slice(name.length - 2, name.length) == '机房') {
  205. if (location) {
  206. this.$refs.boxRoom.open({ name: name, type: this.type, location: location })
  207. } else {
  208. this.$message('未添加位置类型')
  209. }
  210. }
  211. // 选中电井设置电井关联的商铺高亮
  212. this.setHightLight(ev[0])
  213. } else {
  214. this.clearHightLight()
  215. }
  216. },
  217. // 选中电井关联的商铺高亮
  218. setHightLight(arr) {
  219. this.clearHightLight()
  220. arr.forEach(item => {
  221. let location = item.data.AttachObjectIds[0] ? item.data.AttachObjectIds[0].id : ''
  222. // 添加了位置类型并且选中的类型为电井类型
  223. if (
  224. (item.data.GraphElementId == '100050' ||
  225. item.data.GraphElementId == '100055' ||
  226. item.data.GraphElementId == '100056' ||
  227. item.data.GraphElementId == '100057') &&
  228. location
  229. ) {
  230. if (this.wellMap.hasOwnProperty(location)) {
  231. this.wellMap[location].forEach(item => {
  232. item.highLightFlag = true
  233. item.zOrder = 30
  234. })
  235. } else {
  236. let getParams = {
  237. plazaId: this.plazaId,
  238. floor: this.floorid,
  239. keyword: `${location}:wellnum;`
  240. }
  241. queryShops({ getParams }).then(res => {
  242. let shopsnumList = []
  243. let shopsnumItemList = []
  244. if (res.data && res.data.length) {
  245. for (let floor in res.data[0]) {
  246. if (res.data[0][floor].length) {
  247. res.data[0][floor].forEach(v => {
  248. shopsnumList = shopsnumList.concat(v.shopsnumList.split(','))
  249. })
  250. }
  251. }
  252. }
  253. if (shopsnumList.length) {
  254. this.fParser.spaceList.forEach(item => {
  255. if (shopsnumList.findIndex(name => name == item.data.Name) != -1) {
  256. item.highLightFlag = true
  257. item.zOrder = 30
  258. shopsnumItemList.push(item)
  259. }
  260. })
  261. this.wellMap[location] = shopsnumItemList
  262. }
  263. })
  264. }
  265. }
  266. })
  267. },
  268. // 清除电井关联商铺的高亮状态
  269. clearHightLight() {
  270. for (let key in this.wellMap) {
  271. this.wellMap[key].forEach(item => {
  272. item.highLightFlag = false
  273. item.zOrder = ItemOrder.spaceOrder
  274. })
  275. }
  276. },
  277. // 适配底图到窗口
  278. fit() {
  279. this.view.fitSceneToView()
  280. },
  281. // 保存为png
  282. savePng() {
  283. this.view.saveImage(`${this.loadName}.png`, 'png')
  284. //console.log(`${this.loadName}.png`)
  285. },
  286. // 保存为svg
  287. saveSvg() {
  288. this.view.saveSceneSvg(`${this.loadName}.svg`, 6400, 4800)
  289. },
  290. // 保存为json
  291. saveJson() {
  292. this.view.saveFloorJson(`${this.loadName}.json`)
  293. },
  294. // 缩放
  295. scale(val) {
  296. if (!this.view) {
  297. return
  298. }
  299. let scale = this.view.scale
  300. this.view.scaleByPoint(val / scale, this.canvasWidth / 2, this.canvasHeight / 2)
  301. },
  302. // 小眼睛控制显示铺位名称
  303. showText(val) {
  304. // this.topologyParser.zoneLegendList.forEach(t => {
  305. // t.showText = val
  306. // })
  307. this.fParser.spaceList.forEach(t => {
  308. t.showBaseName = val
  309. })
  310. },
  311. // 读取数据
  312. readGroup(FloorID) {
  313. const data = {
  314. BuildingID: '1',
  315. FloorID: FloorID,
  316. categoryId: this.categoryId ? this.categoryId : this.$cookie.get('categoryId'),
  317. projectId: this.urlMsg.ProjectID,
  318. Pub: true
  319. }
  320. return readGroup(data)
  321. },
  322. // 地图尺寸
  323. mapSize() {
  324. this.canvasWidth = this.$refs.graphy.offsetWidth
  325. if (window.screen.height == '768') {
  326. this.canvasHeight = this.$refs.graphy.offsetHeight - 100
  327. } else {
  328. this.canvasHeight = 900
  329. }
  330. // 弹窗中底图高度适配
  331. if (this.modalHeight) {
  332. this.canvasHeight = this.modalHeight
  333. }
  334. },
  335. getEvent() {
  336. bus.$on('changeShow', res => {
  337. this.topologyParser.zoneLegendList.forEach(t => {
  338. let id = t.data.GraphElementId
  339. t.maskFlag = !(res.indexOf(id) > -1)
  340. })
  341. this.topologyParser.textMarkerList.forEach(t => {
  342. let id = t.data.GraphElementId
  343. t.maskFlag = !(res.indexOf(id) > -1)
  344. })
  345. this.topologyParser.imageMarkerList.forEach(t => {
  346. let id = t.data.GraphElementId
  347. t.maskFlag = !(res.indexOf(id) > -1)
  348. })
  349. this.topologyParser.lineMarkerList.forEach(t => {
  350. let id = t.data.GraphElementId
  351. t.maskFlag = !(res.indexOf(id) > -1)
  352. })
  353. this.topologyParser.imageLegendList.forEach(t => {
  354. let id = t.data.GraphElementId
  355. t.maskFlag = !(res.indexOf(id) > -1)
  356. })
  357. this.topologyParser.relationList.forEach(t => {
  358. let id = t.data.GraphElementId
  359. t.maskFlag = !(res.indexOf(id) > -1)
  360. })
  361. })
  362. }
  363. },
  364. watch: {
  365. 'view.scale': {
  366. handler(n) {
  367. if (this.$refs.canvasFun) {
  368. let s = (n * 10) / this.view.minScale
  369. this.$refs.canvasFun.sliderVal = s > 1000 ? 1000 : s
  370. }
  371. }
  372. },
  373. haveFengMap(val) {
  374. if (val) {
  375. this.init(this.floorid)
  376. }
  377. }
  378. },
  379. mounted() {
  380. this.mapSize()
  381. this.getEvent()
  382. },
  383. created() {
  384. this.urlMsg = {
  385. categoryId: this.$cookie.get('categoryId'),
  386. ProjectID: this.plazaId,
  387. BuildingID: '1',
  388. FloorID: this.$cookie.get('floorMapId') || 'f1',
  389. fmapID: this.fmapID
  390. }
  391. }
  392. }
  393. </script>
  394. <style lang="less" scoped>
  395. #floor_base {
  396. position: relative;
  397. height: 100%;
  398. .fengMap {
  399. position: fixed;
  400. width: 100px;
  401. height: 100px;
  402. z-index: -1;
  403. }
  404. .strip-bottom {
  405. position: absolute;
  406. right: 0;
  407. bottom: 40px;
  408. width: 100%;
  409. }
  410. }
  411. </style>