process-setting.vue 20 KB

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