baseEditer.vue 24 KB

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