baseEditer.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  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
  131. .loadTheme(
  132. `${this.mapServerURL}/webtheme/${this.urlMsg.fmapID}/${this.urlMsg.fmapID}.theme`
  133. )
  134. .then(response => {
  135. console.log("获取rf成功", response);
  136. this.parserData(floorid);
  137. // this.readGraph();
  138. // loadings.close();
  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.$on("changeText", val => {
  323. this.scene.updatedText(val);
  324. });
  325. bus.$on("changeFont", val => {
  326. this.scene.updatedFontSize(val);
  327. });
  328. bus.$on("changeLineWidth", val => {
  329. this.scene.updatedLineWidth(val);
  330. });
  331. bus.$on("changeBorderColor", val => {
  332. this.scene.updatedBorderColor(val);
  333. });
  334. bus.$on("changeFontColor", val => {
  335. this.scene.updatedFontColor(val);
  336. });
  337. bus.$on("itemWidth", val => {
  338. this.scene.updatedWidth(Number(val));
  339. });
  340. bus.$on("itemHeight", val => {
  341. this.scene.updatedHeight(Number(val));
  342. });
  343. bus.$on("itemPositon", (x, y) => {
  344. this.scene.updatedPosition(Number(x), Number(y));
  345. });
  346. bus.$on("changebackColor", val => {
  347. this.scene.updatedbackColor(val);
  348. });
  349. bus.$on("deleiteItem", () => {
  350. this.scene.deleiteItem();
  351. });
  352. bus.$on("changeAlignItem", val => {
  353. this.scene.changeAlignItem(val);
  354. });
  355. bus.$on("changeOrderItem", val => {
  356. this.scene.changeOrderItem(val);
  357. });
  358. bus.$on("extractItem", () => {
  359. const map = {},type={};
  360. this.fParser.spaceList.forEach(t => {
  361. if (this.hasTypeList.indexOf(t.data.Type) > -1) {
  362. type[t.data.Type] = 'Zone'
  363. if (map[t.data.Type]) {
  364. map[t.data.Type]++;
  365. } else {
  366. map[t.data.Type] = 1;
  367. }
  368. }
  369. });
  370. this.fParser.pList.forEach(t => {
  371. if (this.hasTypeList.indexOf(t.data.Type) > -1) {
  372. type[t.data.Type] = 'Image'
  373. if (map[t.data.Type]) {
  374. map[t.data.Type]++;
  375. } else {
  376. map[t.data.Type] = 1;
  377. }
  378. }
  379. });
  380. const data = [];
  381. for (const key in map) {
  382. data.push({
  383. key: key,
  384. name: key,
  385. age: "",
  386. number: map[key],
  387. type: type[key],
  388. address: "提取"
  389. });
  390. }
  391. bus.$emit("exportItem", data);
  392. });
  393. bus.$on("saveMsgItem", () => {
  394. const loading = Message({
  395. message: "保存中,切勿关闭窗口!",
  396. type: "warning"
  397. });
  398. this.saveMsg()
  399. .then(() => {
  400. loading.close();
  401. })
  402. .catch(() => {
  403. loading.close();
  404. });
  405. });
  406. bus.$on("exportByKey", val => {
  407. if (val.type == "Image") {
  408. const list = this.fParser.pList.map(t => {
  409. if (t.data.Type == val.key && val.age.Url) {
  410. if (!t.isExtracted) {
  411. t.isExtracted = true;
  412. const data = {
  413. ID: uuid(),
  414. Name: '',
  415. // Name: val.age.Name,
  416. GraphElementType: val.age.Type,
  417. Num: 1,
  418. GraphElementId: val.age.Id,
  419. AttachObjectIds: [],
  420. Pos: { X: t.data.Pos.X, Y: -t.data.Pos.Y },
  421. Scale: { X: 1, Y: 1, Z: 1 }, // 缩放
  422. Rolate: { X: 0, Y: 0, Z: 0 },
  423. Size: { Width: 0, Height: 0 }, // 大小
  424. Type: val.age.Type,
  425. Properties: {
  426. IconUrl: '/serve/topology-wanda/Picture/query/' + val.age.Url,
  427. Url: '/serve/topology-wanda/Picture/query/' + val.age.Url,
  428. Num: 1, // 此num与信息工程化得num无关
  429. sWidth: 32, //icon 的宽
  430. sHeight: 32, //icon 的高
  431. font: 14, //font
  432. color: "#1F2429", //字体颜色
  433. GraphCategoryId: val.age.GraphCategoryId,
  434. InfoSystemId: val.age.InfoSystemId?val.age.InfoSystemId:'', //信息工程话分类ID分类
  435. FID: t.data.SourceId,
  436. InfoTypeId:val.age.InfoTypeId.length? val.age.InfoTypeId :[],
  437. InfoLocal:val.age.InfoLocal.length ?val.age.InfoLocal :[]
  438. },
  439. };
  440. const item = new SImageLegendItem(null, data)
  441. item.selectable = true;
  442. item.moveable = true;
  443. this.scene.addItem(item);
  444. this.scene.Nodes.push(item);
  445. return item
  446. }
  447. }
  448. }).filter(item => item);
  449. this.scene.AddListCommand(list);
  450. bus.$emit("elementDataChange", this.scene);
  451. } else if (val.type == "Zone") {
  452. const list = this.fParser.spaceList
  453. .map(t => {
  454. if (t.data.Type == val.key && val.age.Url) {
  455. if (!t.isExtracted) {
  456. t.isExtracted = true;
  457. return {
  458. ID: uuid(),
  459. Name: val.age.Name,
  460. GraphElementType: val.age.Type,
  461. GraphElementId: val.age.Id,
  462. AttachObjectIds: [],
  463. Pos: { x: t.x, y: t.y },
  464. OutLine: t.pointArr[0],
  465. SubType: "",
  466. Properties: {
  467. IconUrl: '/serve/topology-wanda/Picture/query/' + val.age.Url,
  468. InfoSystemId: val.age.InfoSystemId?val.age.InfoSystemId:'', //信息工程话分类ID分类
  469. StrokeColor: val.age.Color,
  470. FillColor: val.age.FillColor,
  471. LineDash: val.age.LineDash,
  472. font: 20,
  473. color: "#646A73",
  474. TextPos: { X: 0, Y: 0},
  475. FID: t.data.SourceId,
  476. InfoTypeId:val.age.InfoTypeId.length? val.age.InfoTypeId :[],
  477. InfoLocal:val.age.InfoLocal.length ?val.age.InfoLocal :[]
  478. },
  479. Num: 1
  480. };
  481. }
  482. }
  483. })
  484. .filter(item => item);
  485. const parserData = new STopologyParser(null);
  486. parserData.parseData({ Nodes: list });
  487. parserData.zoneLegendList.forEach(t => {
  488. t.$emit('finishCreated')
  489. this.scene.addItem(t);
  490. this.scene.Nodes.push(t);
  491. });
  492. // undo/redo事件
  493. this.scene.AddListCommand(parserData.zoneLegendList);
  494. bus.$emit("elementDataChange", this.scene);
  495. }
  496. });
  497. // 设备图例样式对象
  498. bus.$on("setLenged", obj => {
  499. this.scene.setlegend = obj;
  500. });
  501. // 修改图片url
  502. bus.$on("upadataImageUrl", val => {
  503. this.scene.upadataImageUrl(val);
  504. });
  505. // 改变边框样式
  506. bus.$on("changeBorder", val => {
  507. this.scene.upadataBorder(val);
  508. });
  509. // 改变图例名称
  510. bus.$on("changeLengedName", val => {
  511. this.scene.upadataLengedName(val);
  512. });
  513. // 改变图例名称
  514. bus.$on("changeImageNum", val => {
  515. this.scene.upadatImageNum(val);
  516. });
  517. // 修改填充色
  518. bus.$on("changefillColor", val => {
  519. this.scene.upadatfillColor(val);
  520. });
  521. // 修改当前得状态是否为编辑状态
  522. bus.$on("OpenEditStatus", () => {
  523. ` `; // 获取焦点item (必须选中且仅选中一个)
  524. if (
  525. this.chiceItemList &&
  526. this.chiceItemList.length &&
  527. this.chiceItemList.length == 1
  528. ) {
  529. if (this.scene.grabItem) {
  530. this.view.tryDbclick();
  531. } else {
  532. this.scene.grabItem = this.chiceItemList[0];
  533. this.view.tryDbclick();
  534. }
  535. }
  536. });
  537. //修改图例说明
  538. bus.$on("changeitemExplain", val => {
  539. this.scene.upadatitemExplain(val);
  540. });
  541. //发布图
  542. bus.$on("publishGraph", val => {
  543. publishGraph({ graphId: this.graphId, pubUser: "" }).then(res => {
  544. if (res.Result == "success") {
  545. this.$message.success(res.Message);
  546. } else {
  547. this.$message.error(res.Message);
  548. }
  549. });
  550. });
  551. //创建区域是否点选
  552. bus.$on("changeDrawType", val => {
  553. this.scene.isSelecting = val == "select";
  554. }),
  555. //发布图
  556. bus.$on("publishMap", () => {
  557. const loading = Message({
  558. message: "保存中,切勿关闭窗口!",
  559. type: "warning"
  560. });
  561. // 发布信息时必须保存数据
  562. this.saveMsg()
  563. .then(res => {
  564. loading.close();
  565. if (res) {
  566. this.publishBtn();
  567. }
  568. })
  569. .catch(() => {
  570. loading.close();
  571. });
  572. });
  573. /**
  574. * @name changeScale缩放底图
  575. * @param { Number } zoom 缩放比例
  576. *
  577. */
  578. // TODO: changeScale缩放底图
  579. bus.$on("changeScale", zoom => {
  580. if (zoom == 1) {
  581. this.view.fitSceneToView();
  582. return;
  583. }
  584. const { scale } = this.view;
  585. this.changeScaleByClick = true;
  586. this.view.scaleByPoint(
  587. zoom,
  588. this.canvasWidth / 2,
  589. this.canvasHeight / 2
  590. );
  591. this.changeScaleByClick = false;
  592. });
  593. // 更改图例数据工程化数据
  594. bus.$on("changeAttachObjectIds", arr => {
  595. this.scene.upadatAttachObjectIds(arr);
  596. });
  597. // redo
  598. bus.$on("changeRedo", () => {
  599. this.scene.redo();
  600. });
  601. // uodo/
  602. bus.$on("changeUndo", () => {
  603. this.scene.undo();
  604. });
  605. // 选中状态
  606. bus.$on("toggleItem", (item) => {
  607. this.scene.toggleItem(item);
  608. });
  609. },
  610. // 读取数据
  611. readGroup() {
  612. const data = {
  613. categoryId: this.urlMsg.categoryId,
  614. projectId: this.urlMsg.projectId,
  615. BuildingID: this.urlMsg.BuildingID, // 建筑ID
  616. FloorID: this.urlMsg.FloorID // 楼层id
  617. };
  618. return readGroup(data);
  619. },
  620. //发布
  621. publishBtn() {
  622. const loadings = Loading.service({
  623. lock: true,
  624. text: "Loading",
  625. spinner: "el-icon-loading",
  626. background: "rgba(0, 0, 0, 0.7)"
  627. });
  628. const data = {
  629. BuildingID: this.urlMsg.BuildingID,
  630. CategoryID: this.urlMsg.categoryId,
  631. FloorID: this.urlMsg.FloorID,
  632. GraphId: this.graphId,
  633. ProjectID: this.urlMsg.projectId,
  634. PubUser: ""
  635. };
  636. publishGraph(data).then(res => {
  637. loadings.close();
  638. if (res.Result == "success") {
  639. Message({
  640. message: "发布成功!",
  641. type: "success"
  642. });
  643. setTimeout(() => {
  644. /* const token = this.$store.getters["token"];
  645. const data = `categoryId=${this.urlMsg.categoryId}&projectId=${this.urlMsg.projectId}&BuildingID=${this.urlMsg.BuildingID}&FloorID=${this.urlMsg.FloorID}&fmapID=${this.urlMsg.fmapID}&token=${token}`;
  646. const url =
  647. window.location.origin +
  648. "/wandaEditer/drafts?" +
  649. encodeURIComponent(data);
  650. window.open(url, true); */
  651. // // 发布成功跳转草稿箱
  652. const token = this.$store.getters["token"];
  653. this.$router.push({ path: 'drafts', query: { projectId:this.urlMsg.projectId,BuildingID:this.urlMsg.BuildingID,fmapID:this.urlMsg.fmapID,token:token}})
  654. }, 2000);
  655. } else {
  656. Message({
  657. message: res.Message,
  658. type: "error"
  659. });
  660. }
  661. });
  662. },
  663. // 获取typeid
  664. getTypeId() {
  665. const data = {
  666. categoryId: this.urlMsg.categoryId
  667. };
  668. queryTypeGraph(data).then(res => {
  669. this.hasTypeList = res.Data.map(t => Number(t));
  670. });
  671. },
  672. saveMsg() {
  673. const Elements = this.scene.saveMsgItem();
  674. const Seq = Number(this.urlMsg.seq);
  675. const data = {
  676. Elements,
  677. Name: this.appName, // 名称
  678. CategoryId: this.urlMsg.categoryId,
  679. ProjectID: this.urlMsg.projectId, // 项目ID
  680. BuildingID: this.urlMsg.BuildingID, // 建筑ID
  681. FloorID: this.urlMsg.FloorID, // 楼层id
  682. Seq // 楼层id
  683. };
  684. return new Promise(resolve => {
  685. saveGroup(data)
  686. .then(res => {
  687. if (res.Result == "success") {
  688. this.graphId = res.Data;
  689. Message({
  690. message: "保存成功!",
  691. type: "success"
  692. });
  693. resolve(true);
  694. } else {
  695. Message({
  696. message: "保存失败!",
  697. type: "error"
  698. });
  699. resolve(false);
  700. }
  701. })
  702. .catch(err => {
  703. Message({
  704. message: "保存失败!",
  705. type: "error"
  706. });
  707. resolve(false);
  708. });
  709. });
  710. },
  711. // 自动保存接口
  712. saveMsgNoMessage() {
  713. const Elements = this.scene.saveMsgItem();
  714. const Seq = Number(this.urlMsg.seq);
  715. const data = {
  716. Elements,
  717. Name: this.appName, // 名称
  718. CategoryId: this.urlMsg.categoryId,
  719. ProjectID: this.urlMsg.projectId, // 项目ID
  720. BuildingID: this.urlMsg.BuildingID, // 建筑ID
  721. FloorID: this.urlMsg.FloorID, // 楼层id
  722. Seq // 楼层id
  723. };
  724. saveGroup(data)
  725. .then(res => {
  726. if (res.Result == "success") {
  727. this.graphId = res.Data;
  728. console.log("自动保存成功");
  729. } else {
  730. console.log("自动保存失败");
  731. }
  732. })
  733. .catch(err => {
  734. console.log("自动保存失败");
  735. });
  736. }
  737. },
  738. watch: {
  739. cmdType: {
  740. handler(cmd) {
  741. if (cmd == null || cmd == "") {
  742. cmd = "choice";
  743. }
  744. this.scene.setCmd = cmd;
  745. },
  746. deep: true
  747. },
  748. "scene.cmd": {
  749. handler(cmd) {
  750. this.$emit("setCmdType", cmd);
  751. },
  752. deep: true
  753. },
  754. // 监听scale的变化
  755. "view.scale": {
  756. handler(scale) {
  757. // 滚轮触发的缩放
  758. if (!this.changeScaleByClick) {
  759. bus.$emit("mouseScale", scale / this.initScale);
  760. }
  761. }
  762. }
  763. },
  764. created() {
  765. // // 禁用鼠标右键菜单
  766. // window.oncontextmenu=(e) => {
  767. // console.log("#############",e);
  768. // this.menuStyle.top = `${e.clientY}px`
  769. // this.menuStyle.left = `${e.clientX}px`
  770. // //取消默认的浏览器自带右键 很重要!!
  771. // e.preventDefault();
  772. // }
  773. const href = window.location.href;
  774. // 路由
  775. // const route = href.split("?")[0];
  776. // 参数处理
  777. let params = href.split("?")[1];
  778. if (!params) {
  779. // 参数有问题
  780. return false;
  781. }
  782. params = decodeURIComponent(params);
  783. // params = "categoryId=NTXT&ProjectID=5&BuildingID=1&FloorID=1"; // mock 参数
  784. const paramsArr = params.split("&");
  785. console.log("paramsArr", paramsArr);
  786. const obj = {};
  787. paramsArr.map(item => {
  788. const arr = item.split("=");
  789. obj[arr[0]] = arr[1];
  790. });
  791. this.urlMsg = obj;
  792. },
  793. beforeDestroy() {
  794. // 销毁自动保存
  795. clearInterval(this.autoSave);
  796. }
  797. };
  798. </script>
  799. <style lang="less" scoped>
  800. #baseEditer {
  801. background: #f7f9fa;
  802. width: 100%;
  803. height: 100%;
  804. // overflow: hidden;
  805. // position: relative;
  806. #fengMap {
  807. position: absolute;
  808. width: 100px;
  809. height: 100px;
  810. z-index: -1;
  811. }
  812. .canvas-container {
  813. width: 100%;
  814. height: 100%;
  815. }
  816. }
  817. </style>