process-setting.vue 19 KB

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