edit.vue 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  1. <template>
  2. <div id="divGraphEdit" v-loading.fullscreen.lock="fullscreenLoading">
  3. <div class="firstRow">
  4. <div class="firstOperDivContainer">
  5. <img
  6. class="imgBar"
  7. src="../../assets/images/systemGraph/editLogo.svg"
  8. />
  9. <span class="headerTitle">系统图编辑器</span>
  10. <div class="operBtnDiv" v-if="operState === 0">
  11. <!-- <span>回到首页</span> -->
  12. <span @click="intoEditState">编辑系统图</span>
  13. <span
  14. v-if="(graphInfo.extraProps || {}).state == 'Draft'"
  15. @click="publishGraph"
  16. >上架系统图</span
  17. >
  18. <span
  19. v-if="(graphInfo.extraProps || {}).state == 'Publish'"
  20. @click="draftGraph"
  21. >下架系统图</span
  22. >
  23. </div>
  24. <div class="operBtnDiv" v-if="operState === 1">
  25. <span @click="saveGraph">保存图纸</span>
  26. <span @click="cancelClick">放弃编辑</span>
  27. </div>
  28. <span class="delBtn" @click="delGraph">删除图纸</span>
  29. </div>
  30. <div class="secondOperDivContainer">
  31. <img
  32. @click="toggleLeft"
  33. class="imgBar"
  34. src="../../assets/images/systemGraph/barController.svg"
  35. />
  36. <span
  37. class="sanjiaoBar"
  38. :class="{
  39. 'el-icon-caret-bottom': isVisibleLeft,
  40. 'el-icon-caret-top': !isVisibleLeft,
  41. }"
  42. @click="toggleLeft"
  43. ></span>
  44. <hr class="splitLine" />
  45. <el-select
  46. v-model="selectScale"
  47. value-key="value"
  48. @change="selScaleChange"
  49. >
  50. <el-option
  51. v-for="item in scaleArr"
  52. :key="item.value"
  53. :label="item.name"
  54. :value="item"
  55. >
  56. </el-option>
  57. </el-select>
  58. <span class="el-icon-zoom-in zoomin" @click="scaleZoomin"></span>
  59. <span class="el-icon-zoom-out zoomout" @click="scaleZoomout"></span>
  60. <!-- <hr class="splitLine" v-if="operState == 1" />
  61. <img
  62. v-if="operState == 1"
  63. class="imgLeftTop"
  64. src="../../assets/images/systemGraph/leftTop.svg"
  65. />
  66. <img
  67. v-if="operState == 1"
  68. class="rightLeftTop"
  69. src="../../assets/images/systemGraph/rightTop.svg"
  70. />
  71. <hr class="splitLine" v-if="operState == 1" />
  72. <img
  73. v-if="operState == 1"
  74. class="imgLeftTop"
  75. src="../../assets/images/systemGraph/text.svg"
  76. /> -->
  77. <span class="resetBtn" v-if="operState == 1" @click="resetGraph"
  78. >重置为自动出图样式</span
  79. >
  80. </div>
  81. </div>
  82. <div class="secondRow">
  83. <div
  84. class="graphInfoContainer"
  85. v-if="(operState === 0 || operState === 1) && isVisibleLeft"
  86. >
  87. <div class="graphInfoFirst">
  88. <span class="graphInfoName">系统图名称</span>
  89. <span
  90. class="graphInfoFirstEdit"
  91. @click="intoGraphNameEditState"
  92. v-if="!isEditGraphName"
  93. >编辑</span
  94. >
  95. <span
  96. class="graphInfoFirstEdit"
  97. @click="saveGraphName"
  98. v-if="isEditGraphName"
  99. >保存</span
  100. >
  101. <span
  102. class="graphInfoFirstEdit"
  103. @click="cancelSaveGraphName"
  104. v-if="isEditGraphName"
  105. >取消</span
  106. >
  107. </div>
  108. <div class="graphInfoContent">
  109. <span v-text="graphInfo.name" v-if="!isEditGraphName"
  110. >高压系统1#系统图</span
  111. >
  112. <el-input
  113. v-model="graphInfo.name"
  114. v-if="isEditGraphName"
  115. @change="graphNameChange"
  116. ></el-input>
  117. </div>
  118. <div class="graphInfoName">
  119. <span>系统图类型</span>
  120. </div>
  121. <div class="graphInfoContent">
  122. <span v-text="graphInfo.graphTypeName">高压配电</span>
  123. </div>
  124. <div class="graphInfoName">
  125. <span>系统实例</span>
  126. </div>
  127. <div class="graphInfoContent">
  128. <span v-text="graphInfo.systemInstanceName">实例1</span>
  129. </div>
  130. <div class="graphInfoName">
  131. <span>系统图模版</span>
  132. </div>
  133. <div class="graphInfoContent">
  134. <span v-text="graphInfo.templateName">模版1</span>
  135. </div>
  136. <div class="graphInfoName">
  137. <span>所属项目</span>
  138. </div>
  139. <div class="graphInfoContent">
  140. <span v-text="project.name">银泰中心</span>
  141. </div>
  142. <div class="graphInfoName">
  143. <span>当前状态</span>
  144. </div>
  145. <div class="graphInfoContent">
  146. <span v-text="graphInfo.stateName">草稿</span>
  147. </div>
  148. </div>
  149. <div class="graphRegion">
  150. <graph
  151. ref="graphc"
  152. @click="graphClickCall"
  153. @closeright="closeRight"
  154. ></graph>
  155. </div>
  156. <div class="rightDetail" v-if="selGraphPartType != -1">
  157. <div v-if="selGraphPartType == 1">
  158. <div class="title titleMargin">设备类</div>
  159. <div class="titleText eqName" v-text="selEquip.name">进线柜</div>
  160. <div class="detailSplitLine"></div>
  161. <div class="title titleMargin">
  162. <span>x</span>
  163. <span
  164. class="coridTitleText titleText"
  165. v-text="(selEquip.absolutePosition || {}).x"
  166. >100</span
  167. >
  168. <span class="coridTitle2">y</span>
  169. <span
  170. class="coridTitleText titleText"
  171. v-text="(selEquip.absolutePosition || {}).y"
  172. >100</span
  173. >
  174. </div>
  175. <div class="title titleMargin">
  176. <span>比例</span>
  177. <span class="scaleTitleText titleText">100%</span>
  178. </div>
  179. <div class="detailSplitLine"></div>
  180. <div class="title titleMargin">锚点</div>
  181. <div
  182. class="anchorContainer"
  183. v-for="anchor in selEquip.anchorArr"
  184. :key="anchor.name"
  185. >
  186. <span v-text="anchor.name">T3</span>
  187. <span>已连接</span>
  188. </div>
  189. </div>
  190. <div v-if="selGraphPartType == 2">
  191. <div class="title titleMargin">连线</div>
  192. <div class="detailSplitLine"></div>
  193. <div
  194. v-for="(linePoint, _index) in selLine.path || []"
  195. :key="_index.toString()"
  196. >
  197. <div
  198. class="title titleMargin"
  199. v-text="
  200. _index == 0
  201. ? '起点'
  202. : _index == selLine.path.length - 1
  203. ? '终点'
  204. : '拐点' + _index
  205. "
  206. >
  207. 起点
  208. </div>
  209. <div class="coridGroup title">
  210. <span>x</span>
  211. <span class="coridTitleText titleText" v-text="linePoint.x"
  212. >100</span
  213. >
  214. <span class="coridTitle2">y</span>
  215. <span class="coridTitleText titleText" v-text="linePoint.y"
  216. >100</span
  217. >
  218. </div>
  219. </div>
  220. <!-- <div class="detailSplitLine"></div>
  221. <div class="title titleMargin">连接关系</div>
  222. <div class="titleMargin lianjieguanxi">
  223. <el-select
  224. v-model="selLineStartPoint"
  225. value-key="id"
  226. @change="selStartPointChange"
  227. >
  228. <div slot="prefix" class="selectPrefix">起点</div>
  229. <el-option
  230. v-for="item in lineStartPointArr"
  231. :key="item.id"
  232. :label="item.name"
  233. :value="item"
  234. >
  235. </el-option>
  236. </el-select>
  237. </div>
  238. <div class="titleMargin lianjieguanxi">
  239. <el-select
  240. v-model="selLineEndPoint"
  241. value-key="id"
  242. @change="selEndPointChange"
  243. >
  244. <div slot="prefix" class="selectPrefix">终点</div>
  245. <el-option
  246. v-for="item in lineEndPointArr"
  247. :key="item.id"
  248. :label="item.name"
  249. :value="item"
  250. >
  251. </el-option>
  252. </el-select>
  253. </div> -->
  254. </div>
  255. <div v-if="selGraphPartType == 3">
  256. <div class="title titleMargin">文字</div>
  257. <div class="titleText eqName">
  258. <span v-text="selText.text" v-if="operState == 0"></span>
  259. <el-input
  260. v-model="selText.text"
  261. v-if="operState == 1"
  262. @change="textContentChange"
  263. ></el-input>
  264. </div>
  265. <div class="detailSplitLine"></div>
  266. <div class="title titleMargin" v-if="operState == 0">
  267. <span>x</span>
  268. <span
  269. class="coridTitleText titleText"
  270. v-text="(selText.absolutePosition || {}).x"
  271. >100</span
  272. >
  273. <span class="coridTitle2">y</span>
  274. <span
  275. class="coridTitleText titleText"
  276. v-text="(selText.absolutePosition || {}).y"
  277. >100</span
  278. >
  279. </div>
  280. <div class="title titleMargin" v-if="operState == 1">
  281. <div>
  282. <span>x</span>
  283. <div class="textCrodDiv" v-if="operState == 1">
  284. <el-input
  285. v-model="(selText.absolutePosition || {}).x"
  286. @change="textXChange"
  287. >
  288. </el-input>
  289. </div>
  290. </div>
  291. <div style="margin-top: 10px">
  292. <span>y</span>
  293. <div class="textCrodDiv" v-if="operState == 1">
  294. <el-input
  295. v-model="(selText.absolutePosition || {}).y"
  296. @change="textYChange"
  297. >
  298. </el-input>
  299. </div>
  300. </div>
  301. </div>
  302. <div class="detailSplitLine"></div>
  303. <div class="title titleMargin">字体样式</div>
  304. <div class="titleMargin fontSizeContainer">
  305. <img
  306. src="@/assets/images/systemGraph/fontStyle.svg"
  307. class="fontStyleSvg"
  308. />
  309. <el-select
  310. v-model="selFontSize"
  311. value-key="id"
  312. @change="selFontSizeChange"
  313. placeholder=""
  314. >
  315. <el-option
  316. v-for="item in fontSizeArr"
  317. :key="item.id"
  318. :label="item.name"
  319. :value="item"
  320. >
  321. </el-option>
  322. </el-select>
  323. </div>
  324. <div class="title titleMargin">字体颜色</div>
  325. <div class="titleMargin fontColor">
  326. <input
  327. v-if="operState == 1"
  328. type="color"
  329. v-model="fontColor"
  330. @change="selFontColorChange"
  331. />
  332. <div v-text="fontColor"></div>
  333. <div>100%</div>
  334. </div>
  335. <div class="title titleMargin">背景颜色</div>
  336. <div class="titleMargin fontColor">
  337. <input
  338. v-if="operState == 1"
  339. type="color"
  340. v-model="fontBackColor"
  341. @change="selFontBackColorChange"
  342. />
  343. <div v-text="fontBackColor"></div>
  344. <div>100%</div>
  345. </div>
  346. </div>
  347. <div
  348. class="delBtn"
  349. v-if="selGraphPartType == 1 && operState == 1"
  350. @click="delEquip"
  351. >
  352. 删除设备
  353. </div>
  354. <div
  355. class="delBtn"
  356. v-if="selGraphPartType == 2 && operState == 1"
  357. @click="delLine"
  358. >
  359. 删除管线
  360. </div>
  361. <div
  362. class="delBtn"
  363. v-if="selGraphPartType == 3 && operState == 1"
  364. @click="delText"
  365. >
  366. 删除文字
  367. </div>
  368. </div>
  369. </div>
  370. <addGraph
  371. :isVisible="operState == 2"
  372. v-if="operState == 2"
  373. @graphCreated="createSuccessed"
  374. ></addGraph>
  375. </div>
  376. </template>
  377. <script>
  378. import { graphStateEnum } from "@/controller/systemGraph/graphStateEnum";
  379. import { sysGraphController } from "@/controller/systemGraph/sysGraphController";
  380. import addGraph from "./addGraph.vue";
  381. import graph from "./graph.vue";
  382. import { logicConfig } from "@/logicConfig";
  383. import { Message } from "element-ui";
  384. import Vue from "vue";
  385. import vueStore from "@/store";
  386. import { mapState } from "vuex";
  387. export default {
  388. props: [],
  389. data() {
  390. return {
  391. fullscreenLoading: false,
  392. //缩放范围
  393. scaleArr: [
  394. {
  395. name: "25%",
  396. value: 25,
  397. },
  398. {
  399. name: "50%",
  400. value: 50,
  401. },
  402. {
  403. name: "75%",
  404. value: 75,
  405. },
  406. {
  407. name: "100%",
  408. value: 100,
  409. },
  410. {
  411. name: "150%",
  412. value: 150,
  413. },
  414. ],
  415. //选择的缩放范围
  416. selectScale: {},
  417. //操作状态 0 预览; 1 编辑; 2 新建
  418. operState: -1,
  419. //系统图ID
  420. diagramId: "",
  421. //项目信息
  422. project: {},
  423. /**
  424. * 选择的系统图上的区域的类型
  425. * -1 什么也没选; 1 设备; 2 线; 3 文字
  426. */
  427. selGraphPartType: -1,
  428. //线的起点数组,用于右侧详情选择
  429. lineStartPointArr: [
  430. {
  431. id: "111",
  432. name: "1#设备-B1",
  433. },
  434. {
  435. id: "222",
  436. name: "1#设备-B2",
  437. },
  438. ],
  439. //选择的线的起点,用于右侧详情选择
  440. selLineStartPoint: {
  441. id: "111",
  442. name: "1#设备-B1",
  443. },
  444. //线的终点数组,用于右侧详情选择
  445. lineEndPointArr: [
  446. {
  447. id: "111",
  448. name: "2#设备-B1",
  449. },
  450. {
  451. id: "222",
  452. name: "2#设备-B2",
  453. },
  454. ],
  455. //选择的线的终点,用于右侧详情选择
  456. selLineEndPoint: {
  457. id: "111",
  458. name: "2#设备-B1",
  459. },
  460. //字号数组
  461. fontSizeArr: [
  462. {
  463. id: 12,
  464. name: "12px",
  465. },
  466. {
  467. id: 14,
  468. name: "14px",
  469. },
  470. {
  471. id: 16,
  472. name: "16px",
  473. },
  474. ],
  475. //选择的字号
  476. selFontSize: {},
  477. //字体颜色
  478. fontColor: "#eb5757",
  479. //字体背景颜色
  480. fontBackColor: "#ffffff",
  481. //系统图原始数据
  482. graphOriginInfo: {},
  483. //系统图数据
  484. graphInfo: {},
  485. /**
  486. * 选择的设备,格式如下:
  487. * {
  488. id: "",
  489. name:'',
  490. legendObj: {
  491. content: "图的地址或base64串",
  492. size: {
  493. width: 12,
  494. height: 12,
  495. },
  496. },
  497. //设备的绝对位置
  498. absolutePosition: {
  499. x: 1,
  500. y: 1,
  501. },
  502. anchorArr:[{
  503. name:'锚点名称',
  504. //锚点相对于设备图例的位置
  505. relativePosition:{
  506. x:1,y:1
  507. }
  508. }]
  509. }
  510. */
  511. selEquip: {},
  512. /*选择的文本,格式如下:
  513. {
  514. id:'',
  515. text:'',
  516. style:{
  517. fontColor: '',
  518. fontSize: '',
  519. backColor:'',
  520. fontWeight:1
  521. },
  522. //文本的绝对位置
  523. absolutePosition: {
  524. x: 1,
  525. y: 1,
  526. },
  527. }*/
  528. selText: {},
  529. /**
  530. * 选择的线,格式如下:
  531. * {
  532. id: '',
  533. path:[{x:1,y:1}],
  534. style: {
  535. lineWidth: 4, //线宽
  536. lineColor: '#8D9399', //线的颜色
  537. }
  538. }
  539. */
  540. selLine: {},
  541. //是否展示左侧系统图基础信息
  542. isVisibleLeft: true,
  543. //是否处于编辑系统图名称状态
  544. isEditGraphName: false,
  545. };
  546. },
  547. computed: {
  548. ...mapState(["projects"]),
  549. },
  550. methods: {
  551. /**
  552. * 新建成功后执行的操作
  553. * graphInfo 系统图数据
  554. */
  555. createSuccessed: function (graphInfo) {
  556. //进入编辑状态
  557. this.operState = 1;
  558. this.graphOriginInfo = JSON.parse(JSON.stringify(graphInfo));
  559. this.graphInfo = graphInfo;
  560. this.diagramId = graphInfo.id;
  561. this.$refs.graphc.drawEntry(graphInfo);
  562. for (let i = 0; i < this.projects.length; i++) {
  563. let currProject = this.projects[i];
  564. if (currProject.id == graphInfo.projectId) {
  565. this.project = {
  566. id: currProject.id,
  567. name: currProject.name,
  568. groupCode: currProject.groupCode,
  569. };
  570. vueStore.commit("updateSelectProject", this.project);
  571. break;
  572. }
  573. }
  574. },
  575. //线的起点选择事件
  576. selStartPointChange: function () {
  577. console.log(this.selLineStartPoint);
  578. },
  579. //线的终点选择事件
  580. selEndPointChange: function () {
  581. console.log(this.selLineEndPoint);
  582. },
  583. //字号选择事件
  584. selFontSizeChange: function () {
  585. //更新graphInfo中的数据
  586. this.updateGraphInfo(3, 2, { id: this.selText.id });
  587. //更新图形以及图形数据源
  588. this.$refs.graphc.updateDataAndGraph(3, 2, {
  589. id: this.selText.id,
  590. fontSize: this.selFontSize.id,
  591. });
  592. },
  593. //字体颜色改变事件
  594. selFontColorChange: function () {
  595. //更新graphInfo中的数据
  596. this.updateGraphInfo(3, 3, { id: this.selText.id });
  597. //更新图形以及图形数据源
  598. this.$refs.graphc.updateDataAndGraph(3, 3, {
  599. id: this.selText.id,
  600. fontColor: this.fontColor,
  601. });
  602. },
  603. //字体backColor颜色改变事件
  604. selFontBackColorChange: function () {
  605. //更新graphInfo中的数据
  606. this.updateGraphInfo(3, 4, { id: this.selText.id });
  607. //更新图形以及图形数据源
  608. this.$refs.graphc.updateDataAndGraph(3, 4, {
  609. id: this.selText.id,
  610. fontBackColor: this.fontBackColor,
  611. });
  612. },
  613. //文本X轴坐标变化后事件
  614. textXChange: function () {
  615. this.selText.absolutePosition.x = parseFloat(
  616. this.selText.absolutePosition.x
  617. );
  618. this.selText.oldAbsolutePosition.x = parseFloat(
  619. this.selText.oldAbsolutePosition.x
  620. );
  621. var xChange =
  622. this.selText.absolutePosition.x - this.selText.oldAbsolutePosition.x;
  623. this.selText.oldAbsolutePosition.x = this.selText.absolutePosition.x;
  624. //更新graphInfo中的数据
  625. this.updateGraphInfo(3, 6, {
  626. id: this.selText.id,
  627. text: { xChange: xChange, yChange: 0 },
  628. });
  629. //更新图形以及图形数据源
  630. this.$refs.graphc.updateDataAndGraph(3, 6, {
  631. id: this.selText.id,
  632. text: { xChange: xChange, yChange: 0 },
  633. });
  634. },
  635. //文本Y轴坐标变化后事件
  636. textYChange: function () {
  637. this.selText.absolutePosition.y = parseFloat(
  638. this.selText.absolutePosition.y
  639. );
  640. this.selText.oldAbsolutePosition.y = parseFloat(
  641. this.selText.oldAbsolutePosition.y
  642. );
  643. var yChange =
  644. this.selText.absolutePosition.y - this.selText.oldAbsolutePosition.y;
  645. this.selText.oldAbsolutePosition.y = this.selText.absolutePosition.y;
  646. //更新graphInfo中的数据
  647. this.updateGraphInfo(3, 6, {
  648. id: this.selText.id,
  649. text: { xChange: 0, yChange: yChange },
  650. });
  651. //更新图形以及图形数据源
  652. this.$refs.graphc.updateDataAndGraph(3, 6, {
  653. id: this.selText.id,
  654. text: { xChange: 0, yChange: yChange },
  655. });
  656. },
  657. //文本内容改变后的事件
  658. textContentChange: function () {
  659. //更新graphInfo中的数据
  660. this.updateGraphInfo(3, 7, {
  661. id: this.selText.id,
  662. text: { content: this.selText.text },
  663. });
  664. //更新图形以及图形数据源
  665. this.$refs.graphc.updateDataAndGraph(3, 7, {
  666. id: this.selText.id,
  667. text: { content: this.selText.text },
  668. });
  669. },
  670. //删除选择的文本节点
  671. delText: function () {
  672. this.$refs.graphc.updateDataAndGraph(3, 5, { id: this.selText.id });
  673. this.updateGraphInfo(3, 5, { id: this.selText.id });
  674. },
  675. //根据系统图ID获取系统图数据
  676. getDiagramById: async function () {
  677. this.fullscreenLoading = true;
  678. var resultObj = await sysGraphController.getDiagramById(
  679. this.diagramId,
  680. this.project.groupCode,
  681. this.project.id
  682. );
  683. if (resultObj.result != logicConfig.resultObj.success) {
  684. this.fullscreenLoading = false;
  685. Message.error(resultObj.message);
  686. return;
  687. }
  688. this.graphOriginInfo = JSON.parse(JSON.stringify(resultObj.data));
  689. this.graphInfo = resultObj.data;
  690. this.fullscreenLoading = false;
  691. },
  692. //进入编辑模式
  693. intoEditState: function () {
  694. this.operState = 1;
  695. },
  696. /**
  697. * 设备、线、文本点击事件的回调
  698. * dataObj 解析后的数据
  699. * type 1 设备; 2 线; 3 文本
  700. */
  701. graphClickCall: function (dataObj, type) {
  702. var _this = this;
  703. var oldPartType = this.selGraphPartType;
  704. this.selGraphPartType = type;
  705. switch (type) {
  706. //设备
  707. case 1:
  708. this.selEquip = dataObj || {};
  709. break;
  710. //线
  711. case 2:
  712. this.selLine = dataObj || {};
  713. break;
  714. //文本
  715. case 3:
  716. this.selText = dataObj || {};
  717. this.selFontSize =
  718. _this.fontSizeArr.filter((_c) => {
  719. return _c.id == _this.selText.style.fontSize;
  720. })[0] || {};
  721. this.fontColor = this.selText.style.fontColor;
  722. this.fontBackColor = this.selText.style.backColor;
  723. break;
  724. }
  725. var _this = this;
  726. //oldPartType为-1的时候,说明右侧面板之前是关闭的,那么展示后会导致图形区域变小,所以需要重绘图形
  727. if (oldPartType == -1) {
  728. Vue.nextTick(function () {
  729. _this.$refs.graphc.resetDraw();
  730. });
  731. }
  732. },
  733. //关闭右侧详情框
  734. closeRight: function () {
  735. var _this = this;
  736. this.selGraphPartType = -1;
  737. Vue.nextTick(function () {
  738. _this.$refs.graphc.resetDraw();
  739. });
  740. },
  741. /**
  742. * 保存图纸按钮事件
  743. */
  744. saveGraph: async function () {
  745. this.fullscreenLoading = true;
  746. var saveResultObj = await sysGraphController.saveSysGraph(
  747. this.graphInfo,
  748. this.project.id,
  749. this.project.groupCode
  750. );
  751. switch (saveResultObj.result) {
  752. case logicConfig.resultObj.failure:
  753. this.fullscreenLoading = false;
  754. Message.error("保存失败:" + (saveResultObj.message || ""));
  755. return;
  756. case logicConfig.resultObj.success:
  757. this.graphOriginInfo = JSON.parse(JSON.stringify(this.graphInfo));
  758. //保存成功后,更新系统图状态为下架
  759. var draftResultObj = await sysGraphController.draftGraph(
  760. this.diagramId
  761. );
  762. this.fullscreenLoading = false;
  763. switch (draftResultObj.result) {
  764. case logicConfig.resultObj.success:
  765. Message.success("保存成功");
  766. break;
  767. case logicConfig.resultObj.failure:
  768. Message.error(
  769. "保存成功,更新状态失败,原因:" + (resultObj.message || "")
  770. );
  771. break;
  772. }
  773. break;
  774. }
  775. },
  776. /**
  777. * 放弃编辑按钮事件
  778. */
  779. cancelClick: function () {
  780. var _this = this;
  781. this.graphInfo = JSON.parse(JSON.stringify(this.graphOriginInfo));
  782. this.operState = 0;
  783. this.selGraphPartType = -1;
  784. Vue.nextTick(function () {
  785. _this.$refs.graphc.drawEntry(_this.graphInfo);
  786. });
  787. },
  788. //上架系统图
  789. publishGraph: async function () {
  790. this.fullscreenLoading = true;
  791. var resultObj = await sysGraphController.publishSysGraph(this.diagramId);
  792. this.fullscreenLoading = false;
  793. switch (resultObj.result) {
  794. case logicConfig.resultObj.success:
  795. this.graphOriginInfo.extraProps.state = graphStateEnum.Publish;
  796. this.graphInfo.extraProps.state = graphStateEnum.Publish;
  797. return Message.success("上架成功");
  798. case logicConfig.resultObj.failure:
  799. return Message.error("上架失败,原因:" + (resultObj.message || ""));
  800. }
  801. },
  802. //下架系统图
  803. draftGraph: async function () {
  804. this.fullscreenLoading = true;
  805. var resultObj = await sysGraphController.draftGraph(this.diagramId);
  806. this.fullscreenLoading = false;
  807. switch (resultObj.result) {
  808. case logicConfig.resultObj.success:
  809. this.graphOriginInfo.extraProps.state = graphStateEnum.Draft;
  810. this.graphInfo.extraProps.state = graphStateEnum.Draft;
  811. return Message.success("下架成功");
  812. case logicConfig.resultObj.failure:
  813. return Message.error("下架失败,原因:" + (resultObj.message || ""));
  814. }
  815. },
  816. //删除系统图
  817. delGraph: function () {
  818. this.$confirm("图纸删除后将不可进行查看和编辑, 是否继续?", "提示", {
  819. confirmButtonText: "确定",
  820. cancelButtonText: "取消",
  821. type: "warning",
  822. })
  823. .then(async () => {
  824. this.fullscreenLoading = true;
  825. var resultObj = await sysGraphController.delSysGraph(this.diagramId);
  826. this.fullscreenLoading = false;
  827. switch (resultObj.result) {
  828. case logicConfig.resultObj.success:
  829. this.$confirm("删除成功,页面将关闭", "提示", {
  830. confirmButtonText: "确定",
  831. type: "success",
  832. showCancelButton: false,
  833. closeOnClickModal: false,
  834. showClose: false,
  835. closeOnPressEscape: false,
  836. }).then(async () => {
  837. window.close();
  838. });
  839. return;
  840. case logicConfig.resultObj.failure:
  841. return Message.error(
  842. "删除图纸失败,原因:" + (resultObj.message || "")
  843. );
  844. }
  845. })
  846. .catch(() => {});
  847. },
  848. //左侧系统图基础信息面板打开或隐藏
  849. toggleLeft: function () {
  850. var _this = this;
  851. this.isVisibleLeft = !this.isVisibleLeft;
  852. Vue.nextTick(function () {
  853. _this.$refs.graphc.resetDraw();
  854. });
  855. },
  856. //缩放比例选择事件
  857. selScaleChange: function () {
  858. this.$refs.graphc.graphScale(this.selectScale.value / 100);
  859. },
  860. //比例放大按钮点击事件
  861. scaleZoomin: function () {
  862. var newScale = this.$refs.graphc.graphScaleCompute(0.25);
  863. this.$refs.graphc.graphScale(newScale);
  864. },
  865. //比例缩小按钮点击事件
  866. scaleZoomout: function () {
  867. var newScale = this.$refs.graphc.graphScaleCompute(-0.25);
  868. this.$refs.graphc.graphScale(newScale);
  869. },
  870. //删除选择的设备节点
  871. delEquip: function () {
  872. this.$refs.graphc.updateDataAndGraph(1, 1, { id: this.selEquip.id });
  873. this.updateGraphInfo(1, 1, { id: this.selEquip.id });
  874. },
  875. //删除选择的线
  876. delLine: function () {
  877. this.$refs.graphc.updateDataAndGraph(2, 8, { id: this.selLine.id });
  878. this.updateGraphInfo(2, 8, { id: this.selLine.id });
  879. },
  880. //graphInfo中移出对应的数据
  881. removeFromData: function (id) {
  882. this.graphInfo.template.frame.children = remove(
  883. this.graphInfo.template.frame.children
  884. );
  885. function remove(dataArr) {
  886. for (let i = 0; i < dataArr.length; i++) {
  887. let _dataObj = dataArr[i];
  888. if (_dataObj.id == id) {
  889. dataArr.splice(i, 1);
  890. return dataArr;
  891. }
  892. if (_dataObj.compType == "container") {
  893. var result = remove(_dataObj.children);
  894. if (result) {
  895. _dataObj.children = result;
  896. return dataArr;
  897. }
  898. }
  899. }
  900. return null;
  901. }
  902. },
  903. /**
  904. * 更新graphInfo中的数据
  905. * dataType 1 设备; 2 线; 3 文本
  906. * operType 1 移除设备节点; 2 更新文本字体大小; 3 更新文本颜色; 4 更新文本背景色; 5 移除文本节点; 6 修改文本位置; 7 修改文本内容; 8删除线
  907. * exprObj 扩展数据,支持:{id:'数据id',text:{xChange:1 新的绝对坐标减去旧的绝对坐标得出的值 ,yChange:1 新的绝对坐标减去旧的绝对坐标得出的值,content:'文本内容'}}
  908. */
  909. updateGraphInfo: function (dataType, operType, exprObj) {
  910. var _this = this;
  911. switch (dataType) {
  912. case 2:
  913. operLine();
  914. break;
  915. default:
  916. _each(this.graphInfo.template.frame.children);
  917. break;
  918. }
  919. function operLine() {
  920. var arr = _this.graphInfo.lines;
  921. for (let i = 0; i < arr.length; i++) {
  922. if (arr[i].id == exprObj.id) {
  923. switch (operType) {
  924. case 8:
  925. arr.splice(i, 1);
  926. break;
  927. }
  928. break;
  929. }
  930. }
  931. }
  932. function _each(dataArr) {
  933. for (let i = 0; i < dataArr.length; i++) {
  934. let _dataObj = dataArr[i];
  935. var _id =
  936. dataType == 1
  937. ? _dataObj.id
  938. : dataType == 3
  939. ? (_dataObj.label || {}).id
  940. : "";
  941. if (_id == exprObj.id) {
  942. switch (operType) {
  943. case 1:
  944. dataArr.splice(i, 1);
  945. break;
  946. case 2:
  947. _dataObj.label.style.fontSize = _this.selFontSize.id;
  948. break;
  949. case 3:
  950. _dataObj.label.style.color = _this.fontColor;
  951. break;
  952. case 4:
  953. _dataObj.label.style.backColor = _this.fontBackColor;
  954. break;
  955. case 5:
  956. _dataObj.label.content = "";
  957. break;
  958. case 6:
  959. _dataObj.label.location.x =
  960. _dataObj.label.location.x + exprObj.text.xChange;
  961. _dataObj.label.location.y =
  962. _dataObj.label.location.y + exprObj.text.yChange;
  963. break;
  964. case 7:
  965. _dataObj.label.content = exprObj.text.content;
  966. break;
  967. }
  968. return dataArr;
  969. }
  970. if (_dataObj.compType == "container") {
  971. var result = _each(_dataObj.children);
  972. if (result) {
  973. _dataObj.children = result;
  974. return dataArr;
  975. }
  976. }
  977. }
  978. return null;
  979. }
  980. },
  981. //重置为自动出图样式点击事件
  982. resetGraph: async function () {
  983. this.$confirm("重置后将不可进行恢复, 是否继续?", "提示", {
  984. confirmButtonText: "确定",
  985. cancelButtonText: "取消",
  986. type: "warning",
  987. })
  988. .then(async () => {
  989. this.fullscreenLoading = true;
  990. this.selGraphPartType = -1;
  991. var resultObj = await sysGraphController.resetData({
  992. id: this.diagramId,
  993. groupCode: this.project.groupCode,
  994. projectId: this.project.id,
  995. });
  996. if (resultObj.result != logicConfig.resultObj.success) {
  997. this.fullscreenLoading = false;
  998. Message.error("重置失败:" + resultObj.message);
  999. return;
  1000. }
  1001. this.graphOriginInfo = JSON.parse(JSON.stringify(resultObj.data));
  1002. this.graphInfo = resultObj.data;
  1003. this.$refs.graphc.drawEntry(this.graphInfo);
  1004. this.fullscreenLoading = false;
  1005. Message.success("重置成功");
  1006. })
  1007. .catch(() => {});
  1008. },
  1009. //进入系统图名称编辑状态
  1010. intoGraphNameEditState: function () {
  1011. this.isEditGraphName = true;
  1012. },
  1013. //保存系统图名称
  1014. saveGraphName: async function () {
  1015. this.fullscreenLoading = true;
  1016. var resultObj = await sysGraphController.saveGraphName({
  1017. id: this.diagramId,
  1018. name: this.graphInfo.name,
  1019. });
  1020. if (resultObj.result != logicConfig.resultObj.success) {
  1021. this.fullscreenLoading = false;
  1022. Message.error("保存失败");
  1023. return;
  1024. }
  1025. this.graphOriginInfo.name = this.graphInfo.name;
  1026. this.isEditGraphName = false;
  1027. this.fullscreenLoading = false;
  1028. Message.success("保存成功");
  1029. },
  1030. //取消保存系统图名称
  1031. cancelSaveGraphName: function () {
  1032. this.graphInfo.name = this.graphOriginInfo.name;
  1033. this.isEditGraphName = false;
  1034. },
  1035. },
  1036. created() {
  1037. this.operState = !this.$route.query.ost
  1038. ? -1
  1039. : parseInt(this.$route.query.ost);
  1040. this.diagramId = !this.$route.query.did ? -1 : this.$route.query.did;
  1041. this.selectScale = this.scaleArr[3];
  1042. this.project = {
  1043. id: this.$route.query.pri,
  1044. groupCode: this.$route.query.gc,
  1045. name: this.$route.query.prn,
  1046. };
  1047. if (this.operState === 0 || this.operState === 1) {
  1048. vueStore.commit("updateSelectProject", this.project);
  1049. }
  1050. },
  1051. mounted() {
  1052. var _this = this;
  1053. (async function () {
  1054. //操作状态 0 预览; 1 编辑; 2 新建 进来时是预览或编辑状态时需要加载系统图数据并绘图
  1055. if (_this.operState === 0 || _this.operState === 1) {
  1056. await _this.getDiagramById();
  1057. _this.$refs.graphc.drawEntry(_this.graphInfo);
  1058. }
  1059. })();
  1060. },
  1061. components: {
  1062. addGraph,
  1063. graph,
  1064. },
  1065. };
  1066. </script>
  1067. <style>
  1068. #divGraphEdit {
  1069. height: 100%;
  1070. display: flex;
  1071. flex-direction: column;
  1072. }
  1073. #divGraphEdit .firstRow {
  1074. height: 96px;
  1075. background: #ffffff;
  1076. box-shadow: 0px 2px 10px rgb(31 36 41 / 10%);
  1077. display: flex;
  1078. flex-direction: column;
  1079. z-index: 2;
  1080. }
  1081. #divGraphEdit .firstOperDivContainer {
  1082. flex: 1;
  1083. border-bottom: solid 1px #f2f2f2;
  1084. line-height: 48px;
  1085. }
  1086. #divGraphEdit .firstOperDivContainer > span:not(:first-child),
  1087. #divGraphEdit .operBtnDiv span {
  1088. cursor: pointer;
  1089. }
  1090. #divGraphEdit .secondOperDivContainer {
  1091. flex: 1;
  1092. }
  1093. #divGraphEdit .headerTitle {
  1094. font-weight: 600;
  1095. margin-left: 15px;
  1096. }
  1097. #divGraphEdit .operBtnDiv {
  1098. display: inline-block;
  1099. margin-left: 52px;
  1100. font-weight: 500;
  1101. }
  1102. #divGraphEdit .operBtnDiv span {
  1103. margin-left: 20px;
  1104. }
  1105. #divGraphEdit .delBtn {
  1106. float: right;
  1107. margin-right: 49px;
  1108. cursor: pointer;
  1109. }
  1110. #divGraphEdit .imgBar {
  1111. margin-left: 33px;
  1112. }
  1113. #divGraphEdit .sanjiaoBar {
  1114. vertical-align: middle;
  1115. }
  1116. #divGraphEdit .splitLine {
  1117. display: inline-block;
  1118. height: 30px;
  1119. border-left: solid 1px #d8d8d8;
  1120. vertical-align: middle;
  1121. margin-left: 26px;
  1122. border-top: none;
  1123. }
  1124. #divGraphEdit .secondOperDivContainer input {
  1125. border: none !important;
  1126. width: 66px;
  1127. padding: 0;
  1128. }
  1129. #divGraphEdit .secondOperDivContainer .el-select {
  1130. margin-left: 26px;
  1131. }
  1132. #divGraphEdit .zoomin {
  1133. margin-left: 20px;
  1134. }
  1135. #divGraphEdit .zoomout {
  1136. margin-left: 14px;
  1137. }
  1138. #divGraphEdit .imgLeftTop {
  1139. margin-left: 26px;
  1140. }
  1141. #divGraphEdit .rightLeftTop {
  1142. margin-left: 22px;
  1143. }
  1144. #divGraphEdit .resetBtn {
  1145. float: right;
  1146. margin-right: 49px;
  1147. line-height: 48px;
  1148. cursor: pointer;
  1149. }
  1150. #divGraphEdit .secondRow {
  1151. flex: 1;
  1152. display: flex;
  1153. flex-direction: row;
  1154. }
  1155. #divGraphEdit .graphInfoContainer {
  1156. background: #fafafa;
  1157. width: 200px;
  1158. height: 100%;
  1159. box-shadow: 0px 0px 1px rgb(0 0 0 / 25%);
  1160. }
  1161. #divGraphEdit .graphInfoFirst {
  1162. margin-top: 31px;
  1163. }
  1164. #divGraphEdit .graphInfoName {
  1165. margin-left: 12px;
  1166. margin-top: 21px;
  1167. font-size: 12px;
  1168. color:#6F777F;
  1169. }
  1170. #divGraphEdit .graphInfoFirstEdit {
  1171. margin-right: 12px;
  1172. float: right;
  1173. color: #0091ff;
  1174. cursor: pointer;
  1175. }
  1176. #divGraphEdit .graphInfoContent {
  1177. margin-top: 12px;
  1178. margin-left: 36px;
  1179. font-weight: normal;
  1180. }
  1181. #divGraphEdit .graphRegion {
  1182. flex: 1;
  1183. height: 100%;
  1184. overflow: hidden;
  1185. }
  1186. #divGraphEdit .rightDetail {
  1187. width: 200px;
  1188. height: 100%;
  1189. background: #fafafa;
  1190. box-shadow: -1px 0px 1px rgb(0 0 0 / 25%);
  1191. box-sizing: border-box;
  1192. padding: 6px 12px 12px 12px;
  1193. }
  1194. #divGraphEdit .rightDetail > div:first-child {
  1195. height: 100%;
  1196. }
  1197. #divGraphEdit .rightDetail .title {
  1198. color: #6f777f;
  1199. font-size: 12px;
  1200. }
  1201. #divGraphEdit .rightDetail .titleMargin {
  1202. margin-top: 19px;
  1203. }
  1204. #divGraphEdit .rightDetail .coridGroup {
  1205. margin-top: 9px;
  1206. }
  1207. #divGraphEdit .rightDetail .titleText {
  1208. font-size: 14px;
  1209. color: #000000;
  1210. }
  1211. #divGraphEdit .rightDetail .eqName {
  1212. margin-top: 11px;
  1213. }
  1214. #divGraphEdit .rightDetail .detailSplitLine {
  1215. width: 100%;
  1216. height: 0;
  1217. margin-top: 19px;
  1218. border-bottom: 1px solid #979797;
  1219. }
  1220. #divGraphEdit .rightDetail .coridTitle2 {
  1221. margin-left: 45px;
  1222. }
  1223. #divGraphEdit .rightDetail .coridTitleText {
  1224. margin-left: 23px;
  1225. }
  1226. #divGraphEdit .rightDetail .textCrodDiv {
  1227. display: inline-block;
  1228. width: 158px;
  1229. margin-left: 10px;
  1230. }
  1231. #divGraphEdit .rightDetail .textCrodDiv .el-input__inner {
  1232. padding-left: 20px;
  1233. }
  1234. #divGraphEdit .rightDetail .scaleTitleText {
  1235. margin-left: 6px;
  1236. }
  1237. #divGraphEdit .rightDetail .anchorContainer {
  1238. margin-top: 15px;
  1239. }
  1240. #divGraphEdit .rightDetail .anchorContainer > span:last-child {
  1241. margin-left: 22px;
  1242. }
  1243. #divGraphEdit .rightDetail .delBtn {
  1244. color: #eb5757;
  1245. position: absolute;
  1246. bottom: 16px;
  1247. margin-left: 62px;
  1248. cursor: pointer;
  1249. }
  1250. #divGraphEdit .rightDetail .selectPrefix {
  1251. color: #000000;
  1252. font-size: 14px;
  1253. height: 100%;
  1254. line-height: 32px;
  1255. }
  1256. #divGraphEdit .rightDetail .lianjieguanxi .el-input__inner {
  1257. padding-left: 42px;
  1258. }
  1259. #divGraphEdit .rightDetail .fontSizeContainer .el-input__inner {
  1260. padding: 0 15px;
  1261. width: 80px;
  1262. }
  1263. #divGraphEdit .rightDetail .fontSizeContainer .el-select {
  1264. margin-left: 42px;
  1265. }
  1266. #divGraphEdit .rightDetail .fontColor {
  1267. position: relative;
  1268. }
  1269. #divGraphEdit .rightDetail .fontColor input {
  1270. border: none;
  1271. background: none;
  1272. width: 30px;
  1273. height: 31px;
  1274. padding: 0;
  1275. top: 0;
  1276. bottom: 0;
  1277. position: absolute;
  1278. }
  1279. #divGraphEdit .rightDetail .fontColor > div {
  1280. line-height: 31px;
  1281. display: inline-block;
  1282. }
  1283. #divGraphEdit .rightDetail .fontColor div:nth-child(2) {
  1284. margin-left: 43px;
  1285. }
  1286. #divGraphEdit .rightDetail .fontColor div:nth-child(3) {
  1287. margin-left: 16px;
  1288. }
  1289. #divGraphEdit img {
  1290. vertical-align: middle;
  1291. }
  1292. </style>