baseEditer.vue 27 KB

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