baseEditer.vue 29 KB

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