baseEditer.vue 26 KB

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