baseEditer.vue 25 KB

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