baseEditer.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  1. <template>
  2. <div id="baseEditer" ref="graphy">
  3. <div id="fengMap"></div>
  4. <div class="canvas-container">
  5. <canvas id="canvas" :width="canvasWidth" :height="canvasHeight" ref="canvas" tabindex="0"></canvas>
  6. </div>
  7. <menuList :style="menuStyle"></menuList>
  8. </div>
  9. </template>
  10. <script>
  11. import { SFengParser, ProjectRf } from "@saga-web/feng-map";
  12. import { SFloorParser } from "@saga-web/big";
  13. import { FloorView } from "./../lib/FloorView";
  14. import { EditScence } from "./mapClass/EditScence";
  15. import bus from "@/bus";
  16. import bus2 from "@/bus2";
  17. import {
  18. saveGroup,
  19. readGroup,
  20. queryTypeGraph,
  21. publishGraph
  22. } from "@/api/editer.js";
  23. import { STopologyParser } from "./../lib/parsers/STopologyParser";
  24. import { uuid } from "@/components/mapClass/until";
  25. import { SImageItem, SImageShowType } from "@saga-web/graph/lib";
  26. import { SImageLegendItem } from "@/lib/items/SImageLegendItem";
  27. import store from "../store";
  28. import { Loading } from "element-ui";
  29. import { Message } from "element-ui";
  30. import { SCircleItem } from "@/lib/items/SCircleItem";
  31. import menuList from "@/components/edit/menu_list.vue";
  32. window.FENGMAP = null;
  33. const isMac = /macintosh|mac os x/i.test(navigator.userAgent);
  34. //// 底图空间增加字段 isExtracted:boolean true 已被提取过
  35. export default {
  36. props: {
  37. cmdType: {
  38. type: String,
  39. default: "choice",
  40. required: false
  41. },
  42. changeTextMsg: {
  43. type: String,
  44. default: "",
  45. required: false
  46. }
  47. },
  48. components: {
  49. menuList
  50. },
  51. data() {
  52. return {
  53. appName: "万达可视化系统",
  54. key: "23f30a832a862c58637a4aadbf50a566",
  55. mapServerURL: "http://map.wanda.cn/editor",
  56. mapthemeUrl: `http://map.wanda.cn/editor/webtheme`,
  57. canvasWidth: 700,
  58. canvasHeight: 800,
  59. fParser: null,
  60. scene: null,
  61. view: null,
  62. floorList: {},
  63. urlMsg: {},
  64. chiceItemList: [], //选中itemlist
  65. hasTypeList: [], // 当前类型下包含的typeid(提取)
  66. graphId: "",
  67. initScale: 1, //加载好底图之后的,初始缩放比例
  68. changeScaleByClick: false, //区分 滚轮,点击 事件改变的缩放比例
  69. autoSave: null,
  70. menuStyle: {
  71. top: 0,
  72. left: 0
  73. },
  74. count: 0, // 顶楼为多张图时计数器
  75. };
  76. },
  77. mounted() {
  78. this.canvasWidth = this.$refs.graphy.offsetWidth;
  79. this.canvasHeight = this.$refs.graphy.offsetHeight - 10;
  80. this.init();
  81. // 挂在bus
  82. this.getBus();
  83. if (this.urlMsg.categoryId) {
  84. store.dispatch("getGraphElement", { PageSize: 1000, Deleted: false, GraphCategoryIds:[this.urlMsg.categoryId] });
  85. }
  86. window.vm = this;
  87. const that = this;
  88. document.onkeydown = function(event) {
  89. console.log('ctrl',event,isMac)
  90. const e = event || window.event || arguments.callee.caller.arguments[0];
  91. if (e && e.key == "Control") {
  92. // 按 ctrl
  93. that.scene.isDownCtrl = true;
  94. }
  95. if(e && e.key == "Meta" && isMac){
  96. console.log('meta',event,isMac)
  97. // 如果为苹果键
  98. that.scene.isDownCtrl = true;
  99. }
  100. };
  101. document.onkeyup = function(event) {
  102. const e = event || window.event || arguments.callee.caller.arguments[0];
  103. if (e && e.key == "Control") {
  104. // 按 ctrl
  105. that.scene.isDownCtrl = false;
  106. this.scene.setCmd = "choice";
  107. }
  108. if(e && e.key == "Meta" && isMac){
  109. // 如果为苹果键
  110. that.scene.isDownCtrl = false;
  111. this.scene.setCmd = "choice";
  112. }
  113. };
  114. // 监听粘贴事件
  115. // document.onpaste = e =>{
  116. // const text = e.clipboardData.getData('Text')
  117. // this.scene.crossPagePaste(text)
  118. // }
  119. // 自动保存(时间差为一分钟)
  120. this.autoSave = setInterval(() => {
  121. this.saveMsgNoMessage();
  122. }, 300000);
  123. },
  124. methods: {
  125. init() {
  126. this.loadings = Loading.service({
  127. lock: true,
  128. text: "Loading",
  129. spinner: "el-icon-loading",
  130. background: "rgba(0, 0, 0, 0.7)"
  131. });
  132. document.getElementById(`canvas`).focus();
  133. this.clearGraphy();
  134. this.scene = new EditScence();
  135. if (this.urlMsg.fmapID.includes("null")) {
  136. this.loadings.close();
  137. this.view.scene = this.scene;
  138. this.readGraph();
  139. }
  140. window.FENGMAP = new SFengParser(
  141. "fengMap",
  142. this.mapServerURL + "/fmap/" + this.urlMsg.fmapID,
  143. this.key,
  144. this.appName,
  145. null,
  146. this.mapthemeUrl
  147. );
  148. const floorid = this.urlMsg.FloorID;
  149. window.FENGMAP.loadMap(this.urlMsg.fmapID, resp => {
  150. this.floorList = resp;
  151. window.FENGMAP.loadTheme(
  152. `${this.mapServerURL}/webtheme/${this.urlMsg.fmapID}/${this.urlMsg.fmapID}.theme`
  153. )
  154. .then(response => {
  155. console.log("获取rf成功", response);
  156. this.parserData(floorid);
  157. // this.readGraph();
  158. // loadings.close();
  159. })
  160. .catch(() => {
  161. this.loadings.close();
  162. });
  163. // this.view.fitSceneToView();
  164. });
  165. // 获取typeid
  166. this.getTypeId();
  167. this.scene.emitChange = this.emitChange;
  168. this.scene.scenceUpdate = this.scenceUpdate;
  169. },
  170. parserData(floor) {
  171. if (floor == "g80") {
  172. // 屋顶
  173. if (window.FENGMAP.frImg) {
  174. const pj = this.urlMsg.fmapID.split('_')[0]
  175. // 单张图片
  176. if (!ProjectRf[pj]) {
  177. const imgItem = new SImageItem(
  178. null,
  179. `${this.mapServerURL}/webtheme/${this.urlMsg.fmapID}/${window.FENGMAP.frImg}`
  180. );
  181. imgItem.showType = SImageShowType.AutoFit;
  182. imgItem.connect("imgLoadOver", this, () => {
  183. this.readGraph();
  184. });
  185. this.scene.addItem(imgItem);
  186. this.view.scene = this.scene;
  187. } else {
  188. // 多张图
  189. try {
  190. // 初始化0
  191. this.count = 0;
  192. ProjectRf[pj].forEach(t => {
  193. const item = new SImageItem(
  194. null,
  195. `${this.mapServerURL}/webtheme/${this.urlMsg.fmapID}/${t.name}`
  196. );
  197. item.width = t.width
  198. item.height = t.height
  199. item.moveTo(t.x, t.y)
  200. item.connect("imgLoadOver", this, () => {
  201. this.countRf(ProjectRf[pj].length);
  202. });
  203. this.scene.addItem(item);
  204. })
  205. this.view.scene = this.scene;
  206. } catch(e) {
  207. console.log(e);
  208. }
  209. }
  210. } else {
  211. // 屋顶图不为图片
  212. this.readBaseMap(floor);
  213. }
  214. } else {
  215. if (this.floorList[floor]) {
  216. this.readBaseMap(floor);
  217. } else {
  218. console.log("楼层不正确");
  219. }
  220. }
  221. },
  222. // 解析底图
  223. readBaseMap(floor){
  224. window.FENGMAP.parseData(this.floorList[floor], res => {
  225. if (res.err) {
  226. console.log(res.err);
  227. return;
  228. }
  229. this.fParser = new SFloorParser(null);
  230. this.fParser.parseData(res);
  231. this.scene.fidToItem = {};
  232. this.fParser.spaceList.forEach(t => {
  233. t.nameColor = "#2a2a2a";
  234. t.zOrder = t.zOrder + t.data.Height;
  235. t.selectable = true;
  236. this.scene.fidToItem[t.data.SourceId] = t;
  237. this.scene.addItem(t);
  238. });
  239. this.scene.spaceList = this.fParser.spaceList;
  240. this.fParser.wallList.forEach(t => {
  241. // if (!t.data.HasHole) {
  242. this.scene.addItem(t)
  243. // }
  244. });
  245. this.fParser.virtualWallList.forEach(t => this.scene.addItem(t));
  246. this.fParser.doorList.forEach(t => this.scene.addItem(t));
  247. this.fParser.columnList.forEach(t => this.scene.addItem(t));
  248. this.fParser.casementList.forEach(t => this.scene.addItem(t));
  249. this.fParser.pList = [];
  250. res.PList.forEach(t => {
  251. const item = new SCircleItem(null, t);
  252. this.fParser.pList.push(item);
  253. this.scene.fidToItem[t.SourceId] = item;
  254. this.scene.addItem(item);
  255. });
  256. this.view.scene = this.scene;
  257. this.readGraph();
  258. console.log("success");
  259. });
  260. },
  261. // 读取绘制数据
  262. readGraph() {
  263. this.readGroup().then(data => {
  264. if (data.Data) {
  265. this.graphId = data.Data[0].ID;
  266. bus.$emit("setGraphId", this.graphId);
  267. const parserData = new STopologyParser(null);
  268. const itemMap = {};
  269. parserData.parseData(data.Data[0].Elements);
  270. // 多边形(此item需在直线item添加之前添加)
  271. parserData.zoneLegendList.forEach(t => {
  272. this.scene.addItem(t);
  273. // 记录提取
  274. if (t.data.Properties && t.data.Properties.FID) {
  275. this.scene.fidToItem[t.data.Properties.FID].isExtracted = true;
  276. }
  277. this.scene.Nodes.push(t);
  278. itemMap[t.id] = t;
  279. });
  280. // 增加文字(此item需在直线item添加之前添加)
  281. parserData.textMarkerList.forEach(t => {
  282. this.scene.addItem(t);
  283. this.scene.Markers.push(t);
  284. itemMap[t.id] = t;
  285. });
  286. // 增加图片(此item需在直线item添加之前添加)
  287. parserData.imageMarkerList.forEach(t => {
  288. this.scene.addItem(t);
  289. this.scene.Markers.push(t);
  290. itemMap[t.id] = t;
  291. });
  292. // 增加图标类图例(此item需在管线item添加之前添加)
  293. parserData.imageLegendList.forEach(t => {
  294. this.scene.addItem(t);
  295. // 记录提取
  296. if (t.data.Properties && t.data.Properties.FID) {
  297. this.scene.fidToItem[t.data.Properties.FID].isExtracted = true;
  298. }
  299. this.scene.Nodes.push(t);
  300. if (t.anchorList && t.anchorList.length) {
  301. t.anchorList.forEach(anc => {
  302. itemMap[anc.id] = anc;
  303. });
  304. }
  305. });
  306. // 增加直线
  307. parserData.lineMarkerList.forEach(t => {
  308. this.scene.addItem(t);
  309. this.scene.Markers.push(t);
  310. // 设置关联Item
  311. if (t.data.Properties && t.data.Properties.StartItemId) {
  312. const startItem = itemMap[t.data.Properties.StartItemId];
  313. startItem?.connect("onMove", t, t.changePos);
  314. t.startItem = startItem || null;
  315. }
  316. if (t.data.Properties && t.data.Properties.EndItemId) {
  317. const endItem = itemMap[t.data.Properties.EndItemId];
  318. endItem?.connect("onMove", t, t.changePos);
  319. t.endItem = endItem || null;
  320. }
  321. });
  322. // 增加管线类(需在图标类图例添加后添加)
  323. parserData.relationList.forEach(t => {
  324. this.scene.addItem(t);
  325. this.scene.Relations.push(t);
  326. // 设置锚点
  327. if (t.anchor1ID) {
  328. const startAnc = itemMap[t.anchor1ID];
  329. if (startAnc) {
  330. startAnc.isConnected = true;
  331. startAnc.parent?.connect("changePos", t, t.changePos);
  332. t.startAnchor = startAnc || null;
  333. }
  334. }
  335. if (t.anchor2ID) {
  336. const endAnc = itemMap[t.anchor2ID];
  337. if (endAnc) {
  338. endAnc.isConnected = true;
  339. endAnc.parent?.connect("changePos", t, t.changePos);
  340. t.endAnchor = endAnc || null;
  341. }
  342. }
  343. });
  344. }
  345. console.log(11111111111111111111111111);
  346. this.view.fitSceneToView();
  347. // 设置初始化缩放比例
  348. this.initScale = this.view.scale;
  349. this.view.maxScale = this.initScale * 10;
  350. this.view.minScale = this.initScale / 10;
  351. bus2.$emit("initScale", this.view.scale);
  352. bus2.$emit("elementDataChange", this.scene);
  353. this.loadings.close()
  354. });
  355. },
  356. // 顶楼为多张图时计数器
  357. countRf(len) {
  358. this.count++
  359. console.log(len == this.count);
  360. if (len == this.count) {
  361. this.readGraph();
  362. } else {
  363. console.log('所有图片未加载完成');
  364. }
  365. },
  366. // 监听变化
  367. emitChange(itemMsg) {
  368. this.chiceItemList = itemMsg.itemList;
  369. this.$emit("changeFocusItem", itemMsg);
  370. bus2.$emit("FocusItemChanged", itemMsg);
  371. },
  372. // 监听场景元素数据变化
  373. scenceUpdate(scence) {
  374. bus2.$emit("elementDataChange", scence);
  375. },
  376. clearGraphy() {
  377. if (this.view) {
  378. this.view.scene = null;
  379. return;
  380. }
  381. this.view = new FloorView("canvas");
  382. document.getElementById("canvas").focus();
  383. },
  384. getBus() {
  385. bus.$off();
  386. bus.$on("changeText", val => {
  387. this.scene.updatedText(val);
  388. });
  389. bus.$on("changeFont", val => {
  390. this.scene.updatedFontSize(val);
  391. });
  392. bus.$on("changeLineWidth", val => {
  393. this.scene.updatedLineWidth(val);
  394. });
  395. bus.$on("changeBorderColor", val => {
  396. this.scene.updatedBorderColor(val);
  397. });
  398. bus.$on("changeFontColor", val => {
  399. this.scene.updatedFontColor(val);
  400. });
  401. bus.$on("itemWidth", val => {
  402. this.scene.updatedWidth(Number(val));
  403. });
  404. bus.$on("itemHeight", val => {
  405. this.scene.updatedHeight(Number(val));
  406. });
  407. bus.$on("itemPositon", (x, y) => {
  408. this.scene.updatedPosition(Number(x), Number(y));
  409. });
  410. bus.$on("changebackColor", val => {
  411. this.scene.updatedbackColor(val);
  412. });
  413. bus.$on("deleiteItem", () => {
  414. this.scene.deleiteItem();
  415. });
  416. bus.$on("changeAlignItem", val => {
  417. this.scene.changeAlignItem(val);
  418. });
  419. bus.$on("changeOrderItem", val => {
  420. this.scene.changeOrderItem(val);
  421. });
  422. bus.$on("extractItem", () => {
  423. const map = {},
  424. type = {};
  425. this.fParser.spaceList.forEach(t => {
  426. if (this.hasTypeList.indexOf(t.data.Type) > -1) {
  427. type[t.data.Type] = "Zone";
  428. if (map[t.data.Type]) {
  429. map[t.data.Type]++;
  430. } else {
  431. map[t.data.Type] = 1;
  432. }
  433. }
  434. });
  435. this.fParser.pList.forEach(t => {
  436. if (this.hasTypeList.indexOf(t.data.Type) > -1) {
  437. type[t.data.Type] = "Image";
  438. if (map[t.data.Type]) {
  439. map[t.data.Type]++;
  440. } else {
  441. map[t.data.Type] = 1;
  442. }
  443. }
  444. });
  445. const data = [];
  446. for (const key in map) {
  447. data.push({
  448. key: key,
  449. name: key,
  450. age: "",
  451. number: map[key],
  452. type: type[key],
  453. address: "提取"
  454. });
  455. }
  456. bus2.$emit("exportItem", data);
  457. });
  458. bus.$on("saveMsgItem", () => {
  459. const loading = Message({
  460. message: "保存中,切勿关闭窗口!",
  461. type: "warning"
  462. });
  463. this.saveMsg()
  464. .then(() => {
  465. loading.close();
  466. })
  467. .catch(() => {
  468. loading.close();
  469. });
  470. });
  471. bus.$on("exportByKey", val => {
  472. if (val.type == "Image") {
  473. const list = this.fParser.pList
  474. .map(t => {
  475. if (val.key.indexOf(t.data.Type)>-1 && val.age.Url) {
  476. if (!t.isExtracted) {
  477. t.isExtracted = true;
  478. const data = {
  479. ID: uuid(),
  480. Name: "",
  481. // Name: val.age.Name,
  482. GraphElementType: val.age.Type,
  483. Num: 1,
  484. GraphElementId: val.age.Id,
  485. AttachObjectIds: [],
  486. Pos: { X: t.data.Pos.X, Y: -t.data.Pos.Y },
  487. Scale: { X: 1, Y: 1, Z: 1 }, // 缩放
  488. Rolate: { X: 0, Y: 0, Z: 0 },
  489. Size: { Width: 0, Height: 0 }, // 大小
  490. Type: val.age.Type,
  491. Properties: {
  492. IconUrl: '/serve/topology-wanda/Picture/query/' + val.age.Url,
  493. Url: '/serve/topology-wanda/Picture/query/' + val.age.Url,
  494. Num: 1, // 此num与信息工程化得num无关
  495. Size: {
  496. Width: val.age.Size?val.age.Size.Width?val.age.Size.Width:32:32, //icon 的宽
  497. Height: val.age.Size?val.age.Size.Height?val.age.Size.Height:32:32, //icon 的高
  498. },
  499. font: 16, //font
  500. color: "#1F2429", //字体颜色
  501. FrameColor: val.age.FrameColor,
  502. GraphCategoryId: val.age.GraphCategoryId,
  503. InfoSystemId: val.age.InfoSystemId?val.age.InfoSystemId:'', //信息工程话分类ID分类
  504. FID: t.data.SourceId,
  505. InfoTypeId:val.age.InfoTypeId.length? val.age.InfoTypeId :[],
  506. InfoLocal:val.age.InfoLocal.length ?val.age.InfoLocal :[]
  507. },
  508. };
  509. const item = new SImageLegendItem(null, data);
  510. item.selectable = true;
  511. item.moveable = true;
  512. this.scene.addItem(item);
  513. this.scene.Nodes.push(item);
  514. return item;
  515. }
  516. }
  517. })
  518. .filter(item => item);
  519. this.scene.AddListCommand(list);
  520. bus2.$emit("elementDataChange", this.scene);
  521. } else if (val.type == "Zone") {
  522. const list = this.fParser.spaceList
  523. .map(t => {
  524. if (val.key.indexOf(t.data.Type)>-1 && val.age.Url) {
  525. if (!t.isExtracted) {
  526. t.isExtracted = true;
  527. return {
  528. ID: uuid(),
  529. Name: val.age.Name,
  530. GraphElementType: val.age.Type,
  531. GraphElementId: val.age.Id,
  532. AttachObjectIds: [],
  533. Pos: { x: t.x, y: t.y },
  534. OutLine: t.pointArr[0],
  535. SubType: val.age.SubType,
  536. Properties: {
  537. IconUrl:
  538. "/serve/topology-wanda/Picture/query/" + val.age.Url,
  539. InfoSystemId: val.age.InfoSystemId
  540. ? val.age.InfoSystemId
  541. : "", //信息工程话分类ID分类
  542. StrokeColor: val.age.Color,
  543. FillColor: val.age.FillColor,
  544. LineWidth: val.age.LineWidth,
  545. LineDash: val.age.LineDash,
  546. font: 14,
  547. color: "#1F2429",
  548. TextPos: { X: 0, Y: 0 },
  549. FID: t.data.SourceId,
  550. InfoTypeId: val.age.InfoTypeId.length
  551. ? val.age.InfoTypeId
  552. : [],
  553. InfoLocal: val.age.InfoLocal.length
  554. ? val.age.InfoLocal
  555. : []
  556. },
  557. Num: 1
  558. };
  559. }
  560. }
  561. })
  562. .filter(item => item);
  563. const parserData = new STopologyParser(null);
  564. parserData.parseData({ Nodes: list });
  565. parserData.zoneLegendList.forEach(t => {
  566. t.$emit("finishCreated");
  567. this.scene.addItem(t);
  568. this.scene.Nodes.push(t);
  569. });
  570. // undo/redo事件
  571. this.scene.AddListCommand(parserData.zoneLegendList);
  572. bus2.$emit("elementDataChange", this.scene);
  573. }
  574. });
  575. // 设备图例样式对象
  576. bus.$on("setLenged", obj => {
  577. this.scene.setlegend = obj;
  578. });
  579. // 修改图片url
  580. bus.$on("upadataImageUrl", val => {
  581. this.scene.upadataImageUrl(val);
  582. });
  583. // 改变边框样式
  584. bus.$on("changeBorder", val => {
  585. this.scene.upadataBorder(val);
  586. });
  587. // 改变图例名称
  588. bus.$on("changeLengedName", val => {
  589. this.scene.upadataLengedName(val);
  590. });
  591. // 改变图例名称
  592. bus.$on("changeImageNum", val => {
  593. this.scene.upadatImageNum(val);
  594. });
  595. // 修改填充色
  596. bus.$on("changefillColor", val => {
  597. this.scene.upadatfillColor(val);
  598. });
  599. bus.$on("CUSTOMbgColor", val => {
  600. this.scene.updateCustomBgColor(val);
  601. });
  602. bus.$on("CUSTOMbdColor", val => {
  603. this.scene.updateCustomBdColor(val);
  604. });
  605. // 修改当前得状态是否为编辑状态
  606. bus.$on("OpenEditStatus", () => {
  607. ` `; // 获取焦点item (必须选中且仅选中一个)
  608. if (
  609. this.chiceItemList &&
  610. this.chiceItemList.length &&
  611. this.chiceItemList.length == 1
  612. ) {
  613. if (this.scene.grabItem) {
  614. this.view.tryDbclick();
  615. } else {
  616. this.scene.grabItem = this.chiceItemList[0];
  617. this.view.tryDbclick();
  618. }
  619. }
  620. });
  621. //修改图例说明
  622. bus.$on("changeitemExplain", val => {
  623. this.scene.upadatitemExplain(val);
  624. });
  625. //发布图
  626. bus.$on("publishGraph", val => {
  627. publishGraph({ graphId: this.graphId, pubUser: "" }).then(res => {
  628. if (res.Result == "success") {
  629. this.$message.success(res.Message);
  630. } else {
  631. this.$message.error(res.Message);
  632. }
  633. });
  634. });
  635. //创建区域是否点选
  636. bus.$on("changeDrawType", val => {
  637. this.scene.isSelecting = val == "select";
  638. }),
  639. //发布图
  640. bus.$on("publishMap", () => {
  641. const loading = Message({
  642. message: "保存中,切勿关闭窗口!",
  643. type: "warning"
  644. });
  645. // 发布信息时必须保存数据
  646. this.saveMsg()
  647. .then(res => {
  648. loading.close();
  649. if (res) {
  650. this.publishBtn();
  651. }
  652. })
  653. .catch(() => {
  654. loading.close();
  655. });
  656. });
  657. /**
  658. * @name changeScale缩放底图
  659. * @param { Number } zoom 缩放比例
  660. *
  661. */
  662. // TODO: changeScale缩放底图
  663. bus.$on("changeScale", zoom => {
  664. if (zoom == 1) {
  665. this.view.fitSceneToView();
  666. return;
  667. }
  668. const { scale } = this.view;
  669. this.changeScaleByClick = true;
  670. this.view.scaleByPoint(
  671. zoom,
  672. this.canvasWidth / 2,
  673. this.canvasHeight / 2
  674. );
  675. this.changeScaleByClick = false;
  676. });
  677. // 更改图例数据工程化数据
  678. bus.$on("changeAttachObjectIds", arr => {
  679. this.scene.upadatAttachObjectIds(arr);
  680. });
  681. // redo
  682. bus.$on("changeRedo", () => {
  683. this.scene.redo();
  684. });
  685. // uodo/
  686. bus.$on("changeUndo", () => {
  687. this.scene.undo();
  688. });
  689. // 选中状态
  690. bus.$on("toggleItem", item => {
  691. this.scene.toggleItem(item);
  692. });
  693. //
  694. bus.$on('itemAngle', ang => {
  695. this.scene.updateItemAng(ang);
  696. })
  697. },
  698. // 读取数据
  699. readGroup() {
  700. const data = {
  701. categoryId: this.urlMsg.categoryId,
  702. projectId: this.urlMsg.projectId,
  703. BuildingID: this.urlMsg.BuildingID, // 建筑ID
  704. FloorID: this.urlMsg.FloorID // 楼层id
  705. };
  706. return readGroup(data);
  707. },
  708. //发布
  709. publishBtn() {
  710. const loadings = Loading.service({
  711. lock: true,
  712. text: "Loading",
  713. spinner: "el-icon-loading",
  714. background: "rgba(0, 0, 0, 0.7)"
  715. });
  716. const data = {
  717. BuildingID: this.urlMsg.BuildingID,
  718. CategoryID: this.urlMsg.categoryId,
  719. FloorID: this.urlMsg.FloorID,
  720. GraphId: this.graphId,
  721. ProjectID: this.urlMsg.projectId,
  722. PubUser: ""
  723. };
  724. publishGraph(data).then(res => {
  725. loadings.close();
  726. if (res.Result == "success") {
  727. Message({
  728. message: "发布成功!",
  729. type: "success"
  730. });
  731. setTimeout(() => {
  732. /* const token = this.$store.getters["token"];
  733. const data = `categoryId=${this.urlMsg.categoryId}&projectId=${this.urlMsg.projectId}&BuildingID=${this.urlMsg.BuildingID}&FloorID=${this.urlMsg.FloorID}&fmapID=${this.urlMsg.fmapID}&token=${token}`;
  734. const url =
  735. window.location.origin +
  736. "/wandaEditer/drafts?" +
  737. encodeURIComponent(data);
  738. window.open(url, true); */
  739. // // 发布成功跳转草稿箱
  740. const token = this.$store.getters["token"];
  741. this.$router.push({
  742. path: "drafts",
  743. query: {
  744. projectId: this.urlMsg.projectId,
  745. BuildingID: this.urlMsg.BuildingID,
  746. fmapID: this.urlMsg.fmapID,
  747. token: token
  748. }
  749. });
  750. }, 2000);
  751. } else {
  752. Message({
  753. message: res.Message,
  754. type: "error"
  755. });
  756. }
  757. });
  758. },
  759. // 获取typeid
  760. getTypeId() {
  761. const data = {
  762. categoryId: this.urlMsg.categoryId
  763. };
  764. queryTypeGraph(data).then(res => {
  765. this.hasTypeList = res.Data.map(t => Number(t));
  766. });
  767. },
  768. saveMsg() {
  769. const Elements = this.scene.saveMsgItem();
  770. const Seq = Number(this.urlMsg.seq);
  771. const data = {
  772. Elements,
  773. Name: this.appName, // 名称
  774. CategoryId: this.urlMsg.categoryId,
  775. ProjectID: this.urlMsg.projectId, // 项目ID
  776. BuildingID: this.urlMsg.BuildingID, // 建筑ID
  777. FloorID: this.urlMsg.FloorID, // 楼层id
  778. Seq // 楼层id
  779. };
  780. return new Promise(resolve => {
  781. saveGroup(data)
  782. .then(res => {
  783. if (res.Result == "success") {
  784. this.graphId = res.Data;
  785. Message({
  786. message: "保存成功!",
  787. type: "success"
  788. });
  789. resolve(true);
  790. } else {
  791. Message({
  792. message: "保存失败!",
  793. type: "error"
  794. });
  795. resolve(false);
  796. }
  797. })
  798. .catch(err => {
  799. Message({
  800. message: "保存失败!",
  801. type: "error"
  802. });
  803. resolve(false);
  804. });
  805. });
  806. },
  807. // 自动保存接口
  808. saveMsgNoMessage() {
  809. const Elements = this.scene.saveMsgItem();
  810. const Seq = Number(this.urlMsg.seq);
  811. const data = {
  812. Elements,
  813. Name: this.appName, // 名称
  814. CategoryId: this.urlMsg.categoryId,
  815. ProjectID: this.urlMsg.projectId, // 项目ID
  816. BuildingID: this.urlMsg.BuildingID, // 建筑ID
  817. FloorID: this.urlMsg.FloorID, // 楼层id
  818. Seq // 楼层id
  819. };
  820. saveGroup(data)
  821. .then(res => {
  822. if (res.Result == "success") {
  823. this.graphId = res.Data;
  824. console.log("自动保存成功");
  825. } else {
  826. Message({
  827. message: "服务器连接失败!请关掉编辑器窗口,重新打开绘制!",
  828. type: "error"
  829. });
  830. console.log("自动保存失败");
  831. }
  832. })
  833. .catch(err => {
  834. Message({
  835. message: "服务器连接失败!请关掉编辑器窗口,重新打开绘制!",
  836. type: "error"
  837. });
  838. console.log("自动保存失败");
  839. });
  840. }
  841. },
  842. watch: {
  843. cmdType: {
  844. handler(cmd) {
  845. if (cmd == null || cmd == "") {
  846. cmd = "choice";
  847. }
  848. this.scene.setCmd = cmd;
  849. },
  850. deep: true
  851. },
  852. "scene.cmd": {
  853. handler(cmd) {
  854. this.$emit("setCmdType", cmd);
  855. },
  856. deep: true
  857. },
  858. // 监听scale的变化
  859. "view.scale": {
  860. handler(scale) {
  861. // 滚轮触发的缩放
  862. if (!this.changeScaleByClick) {
  863. bus2.$emit("mouseScale", scale / this.initScale);
  864. }
  865. }
  866. }
  867. },
  868. created() {
  869. // // 禁用鼠标右键菜单
  870. // window.oncontextmenu=(e) => {
  871. // console.log("#############",e);
  872. // this.menuStyle.top = `${e.clientY}px`
  873. // this.menuStyle.left = `${e.clientX}px`
  874. // //取消默认的浏览器自带右键 很重要!!
  875. // e.preventDefault();
  876. // }
  877. const href = window.location.href;
  878. // 路由
  879. // const route = href.split("?")[0];
  880. // 参数处理
  881. let params = href.split("?")[1];
  882. if (!params) {
  883. // 参数有问题
  884. return false;
  885. }
  886. params = decodeURIComponent(params);
  887. // params = "categoryId=NTXT&ProjectID=5&BuildingID=1&FloorID=1"; // mock 参数
  888. const paramsArr = params.split("&");
  889. console.log("paramsArr", paramsArr);
  890. const obj = {};
  891. paramsArr.map(item => {
  892. const arr = item.split("=");
  893. obj[arr[0]] = arr[1];
  894. });
  895. this.urlMsg = obj;
  896. },
  897. beforeDestroy() {
  898. // 销毁自动保存
  899. clearInterval(this.autoSave);
  900. }
  901. };
  902. </script>
  903. <style lang="less" scoped>
  904. #baseEditer {
  905. background: #f7f9fa;
  906. width: 100%;
  907. height: 100%;
  908. // overflow: hidden;
  909. // position: relative;
  910. #fengMap {
  911. position: absolute;
  912. width: 100px;
  913. height: 100px;
  914. z-index: -1;
  915. }
  916. .canvas-container {
  917. width: 100%;
  918. height: 100%;
  919. }
  920. }
  921. </style>