process-setting.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. <template>
  2. <div class="main-div" style="width:100%;height:100%;" ref="mainDiv">
  3. <Layout>
  4. <!-- 左侧工具栏 -->
  5. <Sider :width="180">
  6. <div id="stencil"></div>
  7. </Sider>
  8. <Layout>
  9. <!-- 中间流程图 -->
  10. <Content>
  11. <div id="container" ref="container" style="width:100%;height:100%"/>
  12. </Content>
  13. <!-- 底部按钮 -->
  14. <Footer class="footer">
  15. <div class="tools">
  16. <Poptip trigger="hover" >
  17. <Button icon="ios-options"></Button>
  18. <div slot="content" style="background: #f8f8f9">
  19. <Card title="快捷键说明" icon="ios-options" :padding="0" shadow style="width: 350px;">
  20. <CellGroup>
  21. <Cell title="复制">
  22. <div slot="extra" style="display: flex">
  23. <div class="key">Ctrl</div>
  24. <div class="key">C</div>
  25. </div>
  26. </Cell>
  27. <Cell title="剪切">
  28. <div slot="extra" style="display: flex">
  29. <div class="key">Ctrl</div>
  30. <div class="key">X</div>
  31. </div>
  32. </Cell>
  33. <Cell title="粘贴">
  34. <div slot="extra" style="display: flex">
  35. <div class="key">Ctrl</div>
  36. <div class="key">V</div>
  37. </div>
  38. </Cell>
  39. <Cell title="撤销">
  40. <div slot="extra" style="display: flex">
  41. <div class="key">Ctrl</div>
  42. <div class="key">Z</div>
  43. </div>
  44. </Cell>
  45. <Cell title="撤回撤销">
  46. <div slot="extra" style="display: flex">
  47. <div class="key">Ctrl</div>
  48. <div class="key">Shift</div>
  49. <div class="key">Z</div>
  50. </div>
  51. </Cell>
  52. <Cell title="全选">
  53. <div slot="extra" style="display: flex">
  54. <div class="key">Ctrl</div>
  55. <div class="key">Alt</div>
  56. <div class="key">A</div>
  57. </div>
  58. </Cell>
  59. <Cell title="删除">
  60. <div slot="extra" style="display: flex">
  61. <div class="key">Del</div>
  62. </div>
  63. </Cell>
  64. <Cell title="放大">
  65. <div slot="extra" style="display: flex;align-items: center">
  66. <div class="key">Ctrl</div>
  67. <div class="key">Alt</div>
  68. <div class="key">+</div>
  69. <div style="padding-left:3px">或</div>
  70. <div class="key">Ctrl</div>
  71. <div style="padding-left:3px">+ 鼠标滚轮</div>
  72. </div>
  73. </Cell>
  74. <Cell title="缩小">
  75. <div slot="extra" style="display: flex">
  76. <div class="key">Ctrl</div>
  77. <div class="key">Alt</div>
  78. <div class="key">-</div>
  79. <div style="padding-left:3px">或</div>
  80. <div class="key">Ctrl</div>
  81. <div style="padding-left:3px">+ 鼠标滚轮</div>
  82. </div>
  83. </Cell>
  84. <Cell title="整体移动画布" extra="鼠标右键按住空白处拖动" />
  85. <Cell title="多选" extra="鼠标左键按住空白处框选" />
  86. <Cell title="移入节点组" extra="鼠标左键按住节点拖入" />
  87. <Cell title="移出节点组">
  88. <div slot="extra" style="display: flex;align-items: center">
  89. <div>按住</div>
  90. <div class="key">Ctrl</div>
  91. <div style="padding-left:3px">+ 鼠标左键按住节点拖出</div>
  92. </div>
  93. </Cell>
  94. </CellGroup>
  95. </Card>
  96. </div>
  97. </Poptip>
  98. <Tooltip content="节点居中">
  99. <Button icon="md-contract" @click="()=>{this.graph.zoomToFit({ maxScale: 1 });this.graph.centerContent(); this.graph.cleanSelection()}"></Button>
  100. </Tooltip>
  101. <Tooltip content="导出PNG">
  102. <Button icon="md-images" @click="()=>{this.graph.exportPNG('',{padding:50})}"></Button>
  103. </Tooltip>
  104. <Tooltip content="导出JSON">
  105. <Button icon="ios-cloud-download" @click="exportJson"></Button>
  106. </Tooltip>
  107. <Tooltip content="导入JSON">
  108. <Upload action="" accept=".json" :before-upload="uploadJson">
  109. <Button icon="ios-cloud-upload"></Button>
  110. </Upload>
  111. </Tooltip>
  112. </div>
  113. <div>
  114. <DkButton style="margin-right: 10px;" ref="save" type="primary" @click="save">{{ $t('save') }}</DkButton>
  115. <DkButton ref="close" @click="close('/process/process-flow/index')">{{ $t('close') }}</DkButton>
  116. </div>
  117. </Footer>
  118. </Layout>
  119. </Layout>
  120. <transition-group name="fade">
  121. <!-- 节点弹窗 -->
  122. <NodeModal key="node" v-if="process.nodeModal.display"
  123. :dataKindList="dataKindList"
  124. :productGradeList="productGradeList"
  125. :jobList="jobList"
  126. :shopList="shopList"
  127. :dictionaryDataList="dictionaryDataList"/>
  128. <!-- 连线弹窗 -->
  129. <EdgeModal key="edge" v-if="process.edgeModal.display"
  130. :dataKindList="dataKindList"
  131. :productGradeList="productGradeList.filter(it=>![$config.gradeKindType.decrease,$config.gradeKindType.inferior].includes(it.gradeKind))"/>
  132. </transition-group>
  133. </div>
  134. </template>
  135. <script>
  136. import { mapState, mapMutations } from 'vuex'
  137. import NodeModal from '_c/business/process/node-modal/node-modal'
  138. import EdgeModal from '_c/business/process/edge-modal/edge-modal'
  139. const insertCss = require('insert-css')
  140. const zt1 = require('./data/zt1.json')
  141. import Process from '@/view/process/process-flow/config/ProcessConfig'
  142. import { formMixin } from '@/mixins/form'
  143. import FileSaver from 'file-saver'
  144. export default {
  145. name: 'process-setting',
  146. mixins: [formMixin],
  147. components: { NodeModal, EdgeModal },
  148. props: {
  149. type: {
  150. type: String,
  151. default: 'edit'
  152. },
  153. },
  154. data() {
  155. return {
  156. graph: null,//图形对象
  157. exportData: undefined,
  158. importValue: undefined,
  159. dataKindList: [],//基础数据
  160. productGradeList: [],//产品等级
  161. jobList: [],//工种
  162. dictionaryDataList:[],//数据字典
  163. shopList:[],//车间
  164. }
  165. },
  166. created() {
  167. this.setCurrentNodeId(undefined)
  168. this.setCurrentEdgeId(undefined)
  169. this.setProcessNodeModalDisplay(null)
  170. this.setProcessEdgeModalDisplay(null)
  171. },
  172. mounted() {
  173. //创建流程图对象
  174. this.graph = Process.init(this.$refs.container)
  175. //监听删除节点
  176. this.bindDeleteNodes()
  177. // this.graph.zoomToFit({ maxScale: 1 });// 将画布中元素缩小或者放大一定级别,让画布正好容纳所有元素,可以通过 maxScale 配置最大缩放级别
  178. // this.graph.centerContent(); // 将画布中元素居中展示
  179. },
  180. computed: {
  181. ...mapState(['process']),
  182. },
  183. methods: {
  184. ...mapMutations(['setProcessNodeModalDisplay', 'setProcessEdgeModalDisplay', 'setCurrentNodeId', 'setCurrentEdgeId']),
  185. /**
  186. * @desc : 导出json方法
  187. * @author : 张潇木
  188. * @date : 2023/5/10 9:52
  189. */
  190. exportJson(){
  191. // JSON.stringify(data, null, 2): 格式化json数据 方便阅读
  192. FileSaver.saveAs(new Blob([JSON.stringify(this.graph.toJSON(),null,2)], {type: 'application/json'}), 'flow.json')
  193. },
  194. /**
  195. * @desc : 导入json
  196. * @author : 张潇木
  197. * @date : 2023/5/10 10:17
  198. */
  199. uploadJson(file){
  200. //检验文件类型
  201. if(file.type!='application/json'){
  202. console.log('file.type',file.type)
  203. this.$Message.error('导入失败,请上传JSON类型的文件')
  204. return false
  205. }
  206. //读取json
  207. let reader = new FileReader()
  208. reader.readAsText(file)
  209. reader.onload = ((e) => {
  210. console.log('e',e)
  211. let uploadData = JSON.parse(e.target.result)
  212. console.log('uploadData',uploadData)
  213. if(!uploadData.cells){
  214. //校验数据结构
  215. this.$Message.error('导入失败,请检查JSON文件数据结构')
  216. }else{
  217. //根据数据绘制图形
  218. this.graph.fromJSON(uploadData)
  219. // region 暂时不考虑复杂场景,导入数据不需处理
  220. // let allCells=this.graph.getCells()
  221. // this.graph.cut(allCells)
  222. // this.graph.paste({ offset: 0 })
  223. // this.graph.cleanSelection()
  224. // endregion
  225. this.$Message.success('导入成功')
  226. }
  227. })
  228. return false
  229. },
  230. /**
  231. * @desc : 获取基础数据
  232. * @author : 张潇木
  233. * @date : 2023/1/31 13:42
  234. */
  235. initData() {
  236. // 获取数据类别
  237. this.excute(this.$service.commonService, this.$service.commonService.getDataKind, {}).then(res => {
  238. if (res.code === this.$config.SUCCESS_CODE) {
  239. this.dataKindList = res.data
  240. }
  241. })
  242. // 获取产品等级
  243. this.excute(this.$service.productGradeService, this.$service.productGradeService.selectByCond, {
  244. flgValid: true,
  245. ftyId: this.$store.state.user.ftyId
  246. }).then(res => {
  247. if (res.code === this.$config.SUCCESS_CODE) {
  248. this.productGradeList = res.data.list
  249. }
  250. })
  251. // 获取工种信息
  252. this.excute(this.$service.jobService, this.$service.jobService.selectByCond, {
  253. flgValid: true,
  254. ftyId: this.$store.state.user.ftyId
  255. }).then(res => {
  256. if (res.code === this.$config.SUCCESS_CODE) {
  257. this.jobList = res.data.list
  258. }
  259. })
  260. //数据字典
  261. this.excute(this.$service.commonService, this.$service.commonService.getDictionaryData, {
  262. ftyId: this.$store.state.user.ftyId,
  263. }).then(res => {
  264. if (res.code === this.$config.SUCCESS_CODE) {
  265. this.dictionaryDataList = res.data
  266. }
  267. })
  268. //数据字典
  269. this.excute(this.$service.commonService, this.$service.commonService.getFactorySpace, {
  270. ftyId: this.$store.state.user.ftyId,
  271. spaceKind: this.$config.factorySpace.shop
  272. }).then(res => {
  273. if (res.code === this.$config.SUCCESS_CODE) {
  274. this.shopList = res.data
  275. }
  276. })
  277. },
  278. /**
  279. * @desc : 提交保存
  280. * @author : 张潇木
  281. * @date : 2023/2/3 9:30
  282. */
  283. save() {
  284. //节点组大小和是否展开存在data中
  285. this.graph.getNodes().filter(it => it.shape == 'groupNode').forEach((it) => {
  286. //如果是收起状态,存展开大小,如果展开,存当时的实际大小
  287. it.setData({
  288. 'expandSize': it.isCollapsed() ? it.getExpandSize() : it.getSize(),
  289. 'isCollapsed': it.isCollapsed()
  290. })
  291. })
  292. //转json
  293. this.formData.flowLayout = this.graph.toJSON()
  294. //流程整体校验
  295. if (!this.validData()) return false
  296. //发送保存网络请求
  297. this.excute(this.$service.processService, this.$service.processService.processSetting, this.formData).then(res => {
  298. if (res.code === this.$config.SUCCESS_CODE) {
  299. // 提示信息
  300. this.$Message.success(this.$t('I_001', { 'param': this.$v(this.type) }))
  301. // 编辑关闭窗体
  302. this.close()
  303. } else {
  304. // 如果不成功就提示错误信息
  305. this.$Message.warning(res.message)
  306. }
  307. })
  308. },
  309. /**
  310. * @desc : 校验数据
  311. * @author : 张潇木
  312. * @date : 2023/2/27 11:12
  313. */
  314. validData() {
  315. let allNodes = this.graph.getNodes().filter(it => it.shape == 'custom-image')
  316. let allEdges = this.graph.getEdges()
  317. let startNodes = allNodes.filter(it=>it.getData()?.flowKind===this.$config.flowKind.start)
  318. let endNodes = allNodes.filter(it=>it.getData()?.flowKind===this.$config.flowKind.end)
  319. //成检交接节点
  320. let nodeSysTagsCheck =allNodes.filter(it=>it.getData()?.nodeSysTags?.includes(this.$config.nodeSysTags.check))
  321. if(allNodes.length<2){
  322. this.$Message.warning('流程中应至少包含2个节点')
  323. return false
  324. }
  325. if(allEdges.length<1){
  326. this.$Message.warning('流程中应至少包含1条线')
  327. return false
  328. }
  329. if(startNodes.length<1){
  330. this.$Message.warning('流程中应至少包含1个开始节点')
  331. return false
  332. }
  333. if(endNodes.length<1){
  334. this.$Message.warning('流程中应至少包含1个结束节点')
  335. return false
  336. }
  337. if(nodeSysTagsCheck.length<1){
  338. this.$Message.warning('流程中应至少包含1个 [工序标签] 为 [成检交接] 的节点')
  339. return false
  340. }
  341. console.log('allNodes',allNodes)
  342. //检查所有开始节点是否能够连接到结束节点
  343. let startNodesNoCloseLoop=startNodes.filter(it=>{
  344. let endCount = this.graph.getSuccessors(it)?.filter(it=>it.getData()?.flowKind===this.$config.flowKind.end)
  345. if (endCount<1) {
  346. this.$Message.warning('开始节点为 [' + it.getData()?.nodeName + '] 的流程未闭环,请检查')
  347. return true
  348. }
  349. })
  350. if (startNodesNoCloseLoop.length > 0) return false
  351. //检查所有结束节点是否都有开始节点(回收不校验)
  352. let endNodesNoCloseLoop=endNodes.filter(it=>it.getData()?.nodeKind!==this.$config.nodeKind.recover).filter(it=>{
  353. let startCount = this.graph.getPredecessors(it)?.filter(it=>it.getData()?.flowKind===this.$config.flowKind.start)
  354. if (startCount<1) {
  355. this.$Message.warning('结束节点为 [' + it.getData()?.nodeName + '] 的流程未闭环,请检查')
  356. return true
  357. }
  358. })
  359. if (endNodesNoCloseLoop.length > 0) return false
  360. //节点的单个校验未通过
  361. let invalidNodes =allNodes.filter(it => {
  362. if (!it.getData().isValid) {
  363. this.$Message.warning('[' + it.getData()?.nodeName + '] 节点设置有误,请检查')
  364. return true
  365. }
  366. })
  367. if (invalidNodes.length > 0) return false
  368. return true
  369. },
  370. /**
  371. * @desc : 删除节点特殊控制,如果是成型模型,且被成型线绑定了,则不能删除
  372. * @author : 张潇木
  373. * @date : 2023/3/29 13:26
  374. */
  375. bindDeleteNodes(){
  376. this.graph.bindKey(['backspace','del'], () => {
  377. const cells = this.graph.getSelectedCells()
  378. if (cells.length) {
  379. //取成型节点id
  380. let shapingNodes=cells.filter(it=>it.getData()?.nodeKind === this.$config.nodeKind.shaping).map(it=> {return it.getData()?.nodeId})
  381. if(shapingNodes.length){
  382. //查询是否存在绑定的成型线
  383. this.excute(this.$service.processService, this.$service.processService.getBindMolding, shapingNodes).then(res => {
  384. if (res.code === this.$config.SUCCESS_CODE&&res.data.length) {
  385. this.$Message.warning('无法删除已被成型线绑定的节点')
  386. }
  387. else{
  388. this.graph.removeCells(cells)
  389. }
  390. })
  391. }else{
  392. this.graph.removeCells(cells)
  393. }
  394. }
  395. })
  396. },
  397. /**
  398. * @desc : 查询明细
  399. * @author : 张潇木
  400. * @date : 2023/2/3 16:47
  401. */
  402. detail(id) {
  403. return this.excuteNoParam(this.$service.processService, this.$service.processService.selectById, [id], false)
  404. },
  405. /**
  406. * @desc : 初始化
  407. * @author : 张潇木
  408. * @date : 2023/2/7 8:50
  409. */
  410. setValuesByEdit(data) {
  411. this.formData = data
  412. //初始化数据
  413. this.graph.fromJSON(this.formData.flowLayout || { cells: [] })
  414. //再重新渲染群组大小
  415. this.graph.getNodes().filter(it => it.shape == 'groupNode').forEach((it) => {
  416. // console.log('group-data',it.getData())
  417. //解构
  418. let { isCollapsed, expandSize } = it.getData()
  419. //设置展开大小
  420. it.setExpandSize(expandSize)
  421. //如果不是收起的,展开并还原大小
  422. if (!isCollapsed) {
  423. it.toggleCollapse(isCollapsed)
  424. }
  425. })
  426. },
  427. }
  428. }
  429. </script>
  430. <style scoped>
  431. #container {
  432. display: flex;
  433. border: 1px solid #dfe3e8;
  434. }
  435. #stencil {
  436. width: 180px;
  437. height: 100%;
  438. position: relative;
  439. border-right: 1px solid #dfe3e8;
  440. }
  441. #graph-container {
  442. width: calc(100% - 180px);
  443. height: 100%;
  444. }
  445. .x6-widget-stencil {
  446. background-color: #fff;
  447. }
  448. .x6-widget-stencil-title {
  449. background-color: #fff;
  450. }
  451. .x6-widget-stencil-group-title {
  452. background-color: #fff !important;
  453. }
  454. /deep/ .x6-widget-transform {
  455. margin: -1px 0 0 -1px;
  456. padding: 0px;
  457. border: 1px solid #239edd;
  458. }
  459. /deep/ .x6-widget-transform > div {
  460. border: 1px solid #239edd;
  461. }
  462. /deep/ .x6-widget-transform > div:hover {
  463. background-color: #3dafe4;
  464. }
  465. /deep/ .x6-widget-transform-active-handle {
  466. background-color: #3dafe4;
  467. }
  468. /deep/ .x6-widget-transform-resize {
  469. border-radius: 0;
  470. }
  471. /deep/ .x6-widget-selection-inner {
  472. border: 1px solid #239edd;
  473. }
  474. /deep/ .x6-widget-selection-box {
  475. border: 0 !important;
  476. }
  477. /*@keyframes ant-line {*/
  478. /* to {*/
  479. /* stroke-dashoffset: -1000*/
  480. /* }*/
  481. /*}*/
  482. .snap-line-color {
  483. color: black !important;
  484. background: black !important;
  485. }
  486. .ivu-layout-has-sider {
  487. height: 100%;
  488. }
  489. .header {
  490. height: 30px;
  491. background: #ededed;
  492. display: flex;
  493. align-items: center;
  494. justify-content: space-between;
  495. }
  496. /deep/ .ivu-layout-header {
  497. height: 52px !important;
  498. line-height: 52px !important;
  499. }
  500. .footer {
  501. /*background: #fff;*/
  502. display: flex;
  503. justify-content: space-between;
  504. align-items: center;
  505. padding: 10px 30px;
  506. }
  507. .key{
  508. align-items: center;
  509. background-image: linear-gradient(180deg,#f2f4f5,#fff);
  510. border: 1px solid #d1d5d9;
  511. border-radius: 4px;
  512. box-shadow: 0 1px 0 0 #b8bfc4, inset 0 2px 0 0 #fff;
  513. color: #666;
  514. display: flex;
  515. font-size: 12px;
  516. font-weight: 500;
  517. height: 20px;
  518. justify-content: center;
  519. margin-left: 5px;
  520. min-width: 20px;
  521. padding: 0 5px;
  522. }
  523. /deep/ .ivu-card-head{
  524. padding: 7px 8px!important;
  525. }
  526. /deep/ .ivu-cell{
  527. padding: 3px 8px!important;
  528. }
  529. /deep/ .ivu-cell-group{
  530. padding: 2px 0 !important;
  531. }
  532. /deep/ .ivu-btn-icon-only{
  533. padding: 0 !important;
  534. font-size: 28px!important;
  535. width: 48px!important;
  536. height: 48px!important;
  537. border: none!important;
  538. outline:none!important; /*去除点击时的蓝色边框*/
  539. box-shadow:none!important; /*同时去除阴影的蓝色边框*/
  540. /*border-radius:0px!important;*/
  541. }
  542. /deep/ .ivu-tooltip{
  543. height: 48px!important;
  544. }
  545. /deep/ .custom-html{
  546. height: 100%;
  547. width: 100%;
  548. display: flex;
  549. border:solid 1px #E9F1FF;
  550. }
  551. /deep/ .custom-html-left{
  552. background: #E9F1FF;
  553. height: 100%;
  554. width: 40%;
  555. border: solid 2px #E9F1FF;
  556. border-right: none;
  557. border-top-left-radius: 10px;
  558. border-bottom-left-radius: 10px;
  559. display: flex;
  560. align-items: center;
  561. justify-content: center;
  562. box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.1);
  563. }
  564. /deep/ .custom-html-right{
  565. background: #fff;
  566. height: 100%;
  567. /*width: 60%;*/
  568. border: solid 2px #fff;
  569. border-left: none;
  570. border-top-right-radius: 10px;
  571. border-bottom-right-radius: 10px;
  572. box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.1);
  573. overflow: hidden;
  574. flex: 1;
  575. }
  576. /deep/ .custom-html-right-title{
  577. font-size: 14px;
  578. font-weight: bold;
  579. padding-left: 10px;
  580. width: 100%;
  581. height: 50%;
  582. padding-top: 6px;
  583. align-items: center;
  584. color: #4C4C4C;
  585. overflow: hidden;
  586. text-overflow:ellipsis;
  587. white-space: nowrap;
  588. }
  589. /deep/ .custom-html-right-text{
  590. padding: 3px 0 0 10px ;
  591. width: 100%;
  592. height: 50%;
  593. font-size: 10px;
  594. display: flex;
  595. align-items: self-start;
  596. color: #B6B6B6;
  597. }
  598. .tools{
  599. background: #F2F7FA;
  600. }
  601. </style>