baseEditer.vue 29 KB

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