process-setting.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <div class="main-div" style="width:100%;height:100%;" ref="mainDiv">
  3. {{ this.exportData }}
  4. <!-- {{this.importValue}}-->
  5. <!-- {{this.process.currentEdgeId}}-->
  6. <!-- {{this.process.currentNodeId}}-->
  7. <!-- 测试导入初始数据 -->
  8. <Layout>
  9. <!-- 左侧工具栏 -->
  10. <Sider :width="180">
  11. <div id="stencil"></div>
  12. </Sider>
  13. <Layout>
  14. <!-- 顶部工具栏 -->
  15. <Header class="header">
  16. <Button @click="()=>{this.graph.exportPNG('',{padding:50})}">导出PNG</Button>
  17. <Button @click="()=>{this.exportData=this.graph.toJSON()}" style="margin-left:10px;">导出json</Button>
  18. <Button @click="()=>{this.graph.fromJSON(JSON.parse(this.importValue))}" style="margin-left:10px;">导入json
  19. </Button>
  20. <Input v-model="importValue"/>
  21. </Header>
  22. <!-- 中间流程图 -->
  23. <Content>
  24. <div id="container" ref="container" style="width:100%;height:100%"/>
  25. </Content>
  26. <!-- 底部按钮 -->
  27. <Footer class="footer">
  28. <DkButton style="margin-right: 10px;" ref="save" type="primary" @click="save">{{ $t('save') }}</DkButton>
  29. <DkButton ref="close" @click="close('/process/process-flow/index')">{{ $t('close') }}</DkButton>
  30. </Footer>
  31. </Layout>
  32. </Layout>
  33. <transition-group name="fade">
  34. <!-- 节点弹窗 -->
  35. <NodeModal key="node" v-if="process.nodeModal.display"
  36. :dataKindList="dataKindList"
  37. :productGradeList="productGradeList"
  38. :jobList="jobList"
  39. :shopList="shopList"
  40. :dictionaryDataList="dictionaryDataList"/>
  41. <!-- 连线弹窗 -->
  42. <EdgeModal key="edge" v-if="process.edgeModal.display"
  43. :dataKindList="dataKindList"
  44. :productGradeList="productGradeList.filter(it=>![$config.gradeKindType.decrease,$config.gradeKindType.inferior].includes(it.gradeKind))"/>
  45. </transition-group>
  46. </div>
  47. </template>
  48. <script>
  49. import { mapState, mapMutations } from 'vuex'
  50. import NodeModal from '_c/business/process/node-modal/node-modal'
  51. import EdgeModal from '_c/business/process/edge-modal/edge-modal'
  52. const insertCss = require('insert-css')
  53. const zt1 = require('./data/zt1.json')
  54. import Process from '@/view/process/process-flow/config/ProcessConfig'
  55. import { formMixin } from '@/mixins/form'
  56. export default {
  57. name: 'process-setting',
  58. mixins: [formMixin],
  59. components: { NodeModal, EdgeModal },
  60. props: {
  61. type: {
  62. type: String,
  63. default: 'edit'
  64. },
  65. },
  66. data() {
  67. return {
  68. graph: null,//图形对象
  69. exportData: undefined,
  70. importValue: undefined,
  71. dataKindList: [],//基础数据
  72. productGradeList: [],//产品等级
  73. jobList: [],//工种
  74. dictionaryDataList:[],//数据字典
  75. shopList:[],//车间
  76. }
  77. },
  78. created() {
  79. this.setCurrentNodeId(undefined)
  80. this.setCurrentEdgeId(undefined)
  81. this.setProcessNodeModalDisplay(null)
  82. this.setProcessEdgeModalDisplay(null)
  83. },
  84. mounted() {
  85. //创建流程图对象
  86. this.graph = Process.init(this.$refs.container)
  87. //监听删除节点
  88. this.bindDeleteNodes()
  89. // this.graph.zoomToFit({ maxScale: 1 });// 将画布中元素缩小或者放大一定级别,让画布正好容纳所有元素,可以通过 maxScale 配置最大缩放级别
  90. // this.graph.centerContent(); // 将画布中元素居中展示
  91. },
  92. computed: {
  93. ...mapState(['process']),
  94. },
  95. methods: {
  96. ...mapMutations(['setProcessNodeModalDisplay', 'setProcessEdgeModalDisplay', 'setCurrentNodeId', 'setCurrentEdgeId']),
  97. /**
  98. * @desc : 获取基础数据
  99. * @author : 张潇木
  100. * @date : 2023/1/31 13:42
  101. */
  102. initData() {
  103. // 获取数据类别
  104. this.excute(this.$service.commonService, this.$service.commonService.getDataKind, {}).then(res => {
  105. if (res.code === this.$config.SUCCESS_CODE) {
  106. this.dataKindList = res.data
  107. }
  108. })
  109. // 获取产品等级
  110. this.excute(this.$service.productGradeService, this.$service.productGradeService.selectByCond, {
  111. flgValid: true,
  112. ftyId: this.$store.state.user.ftyId
  113. }).then(res => {
  114. if (res.code === this.$config.SUCCESS_CODE) {
  115. this.productGradeList = res.data.list
  116. }
  117. })
  118. // 获取工种信息
  119. this.excute(this.$service.jobService, this.$service.jobService.selectByCond, {
  120. flgValid: true,
  121. ftyId: this.$store.state.user.ftyId
  122. }).then(res => {
  123. if (res.code === this.$config.SUCCESS_CODE) {
  124. this.jobList = res.data.list
  125. }
  126. })
  127. //数据字典
  128. this.excute(this.$service.commonService, this.$service.commonService.getDictionaryData, {
  129. ftyId: this.$store.state.user.ftyId,
  130. }).then(res => {
  131. if (res.code === this.$config.SUCCESS_CODE) {
  132. this.dictionaryDataList = res.data
  133. }
  134. })
  135. //数据字典
  136. this.excute(this.$service.commonService, this.$service.commonService.getFactorySpace, {
  137. ftyId: this.$store.state.user.ftyId,
  138. spaceKind: this.$config.factorySpace.shop
  139. }).then(res => {
  140. if (res.code === this.$config.SUCCESS_CODE) {
  141. this.shopList = res.data
  142. }
  143. })
  144. },
  145. /**
  146. * @desc : 提交保存
  147. * @author : 张潇木
  148. * @date : 2023/2/3 9:30
  149. */
  150. save() {
  151. //节点组大小和是否展开存在data中
  152. this.graph.getNodes().filter(it => it.shape == 'groupNode').forEach((it) => {
  153. //如果是收起状态,存展开大小,如果展开,存当时的实际大小
  154. it.setData({
  155. 'expandSize': it.isCollapsed() ? it.getExpandSize() : it.getSize(),
  156. 'isCollapsed': it.isCollapsed()
  157. })
  158. })
  159. //转json
  160. this.formData.flowLayout = this.graph.toJSON()
  161. //流程整体校验
  162. if (!this.validData()) return false
  163. //发送保存网络请求
  164. this.excute(this.$service.processService, this.$service.processService.processSetting, this.formData).then(res => {
  165. if (res.code === this.$config.SUCCESS_CODE) {
  166. // 提示信息
  167. this.$Message.success(this.$t('I_001', { 'param': this.$v(this.type) }))
  168. // 编辑关闭窗体
  169. this.close()
  170. } else {
  171. // 如果不成功就提示错误信息
  172. this.$Message.warning(res.message)
  173. }
  174. })
  175. },
  176. /**
  177. * @desc : 校验数据
  178. * @author : 张潇木
  179. * @date : 2023/2/27 11:12
  180. */
  181. validData() {
  182. let allNodes = this.graph.getNodes().filter(it => it.shape == 'custom-image')
  183. let allEdges = this.graph.getEdges()
  184. let startNodes = allNodes.filter(it=>it.getData()?.flowKind===this.$config.flowKind.start)
  185. let endNodes = allNodes.filter(it=>it.getData()?.flowKind===this.$config.flowKind.end)
  186. if(allNodes.length<2){
  187. this.$Message.warning('流程中应至少包含2个节点')
  188. return false
  189. }
  190. if(allEdges.length<1){
  191. this.$Message.warning('流程中应至少包含1条线')
  192. return false
  193. }
  194. if(startNodes.length<1){
  195. this.$Message.warning('流程中应至少包含1个开始节点')
  196. return false
  197. }
  198. if(endNodes.length<1){
  199. this.$Message.warning('流程中应至少包含1个结束节点')
  200. return false
  201. }
  202. //检查所有开始节点是否能够连接到结束节点
  203. let startNodesNoCloseLoop=startNodes.filter(it=>{
  204. let endCount = this.graph.getSuccessors(it)?.filter(it=>it.getData()?.flowKind===this.$config.flowKind.end)
  205. if (endCount<1) {
  206. this.$Message.warning('开始节点为 [' + it.getData()?.nodeName + '] 的流程未闭环,请检查')
  207. return true
  208. }
  209. })
  210. if (startNodesNoCloseLoop.length > 0) return false
  211. //检查所有结束节点是否都有开始节点(回收不校验)
  212. let endNodesNoCloseLoop=endNodes.filter(it=>it.getData()?.nodeKind!==this.$config.nodeKind.recover).filter(it=>{
  213. let startCount = this.graph.getPredecessors(it)?.filter(it=>it.getData()?.flowKind===this.$config.flowKind.start)
  214. if (startCount<1) {
  215. this.$Message.warning('结束节点为 [' + it.getData()?.nodeName + '] 的流程未闭环,请检查')
  216. return true
  217. }
  218. })
  219. if (endNodesNoCloseLoop.length > 0) return false
  220. //节点的单个校验未通过
  221. let invalidNodes =allNodes.filter(it => {
  222. if (it.getAttrs()?.body?.stroke === 'red') {
  223. this.$Message.warning('[' + it.getData()?.nodeName + '] 节点设置有误,请检查')
  224. return true
  225. }
  226. })
  227. if (invalidNodes.length > 0) return false
  228. return true
  229. },
  230. /**
  231. * @desc : 删除节点特殊控制,如果是成型模型,且被成型线绑定了,则不能删除
  232. * @author : 张潇木
  233. * @date : 2023/3/29 13:26
  234. */
  235. bindDeleteNodes(){
  236. this.graph.bindKey(['backspace','del'], () => {
  237. const cells = this.graph.getSelectedCells()
  238. if (cells.length) {
  239. //取成型节点id
  240. let shapingNodes=cells.filter(it=>it.getData()?.nodeKind === this.$config.nodeKind.shaping).map(it=> {return it.getData()?.nodeId})
  241. console.log('shapingNodes',shapingNodes)
  242. if(shapingNodes.length){
  243. //查询是否存在绑定的成型线
  244. this.excute(this.$service.processService, this.$service.processService.getBindMolding, shapingNodes).then(res => {
  245. if (res.code === this.$config.SUCCESS_CODE&&res.data.length) {
  246. this.$Message.warning('无法删除已被成型线绑定的节点')
  247. }
  248. else{
  249. this.graph.removeCells(cells)
  250. }
  251. })
  252. }else{
  253. this.graph.removeCells(cells)
  254. }
  255. }
  256. })
  257. },
  258. /**
  259. * @desc : 查询明细
  260. * @author : 张潇木
  261. * @date : 2023/2/3 16:47
  262. */
  263. detail(id) {
  264. return this.excuteNoParam(this.$service.processService, this.$service.processService.selectById, [id], false)
  265. },
  266. /**
  267. * @desc : 初始化
  268. * @author : 张潇木
  269. * @date : 2023/2/7 8:50
  270. */
  271. setValuesByEdit(data) {
  272. this.formData = data
  273. //初始化数据
  274. this.graph.fromJSON(this.formData.flowLayout || { cells: [] })
  275. //再重新渲染群组大小
  276. this.graph.getNodes().filter(it => it.shape == 'groupNode').forEach((it) => {
  277. // console.log('group-data',it.getData())
  278. //解构
  279. let { isCollapsed, expandSize } = it.getData()
  280. //设置展开大小
  281. it.setExpandSize(expandSize)
  282. //如果不是收起的,展开并还原大小
  283. if (!isCollapsed) {
  284. it.toggleCollapse(isCollapsed)
  285. }
  286. })
  287. },
  288. }
  289. }
  290. </script>
  291. <style scoped>
  292. #container {
  293. display: flex;
  294. border: 1px solid #dfe3e8;
  295. }
  296. #stencil {
  297. width: 180px;
  298. height: 100%;
  299. position: relative;
  300. border-right: 1px solid #dfe3e8;
  301. }
  302. #graph-container {
  303. width: calc(100% - 180px);
  304. height: 100%;
  305. }
  306. .x6-widget-stencil {
  307. background-color: #fff;
  308. }
  309. .x6-widget-stencil-title {
  310. background-color: #fff;
  311. }
  312. .x6-widget-stencil-group-title {
  313. background-color: #fff !important;
  314. }
  315. /deep/ .x6-widget-transform {
  316. margin: -1px 0 0 -1px;
  317. padding: 0px;
  318. border: 1px solid #239edd;
  319. }
  320. /deep/ .x6-widget-transform > div {
  321. border: 1px solid #239edd;
  322. }
  323. /deep/ .x6-widget-transform > div:hover {
  324. background-color: #3dafe4;
  325. }
  326. /deep/ .x6-widget-transform-active-handle {
  327. background-color: #3dafe4;
  328. }
  329. /deep/ .x6-widget-transform-resize {
  330. border-radius: 0;
  331. }
  332. /deep/ .x6-widget-selection-inner {
  333. border: 1px solid #239edd;
  334. }
  335. /deep/ .x6-widget-selection-box {
  336. border: 0 !important;
  337. }
  338. /*@keyframes ant-line {*/
  339. /* to {*/
  340. /* stroke-dashoffset: -1000*/
  341. /* }*/
  342. /*}*/
  343. .snap-line-color {
  344. color: black !important;
  345. background: black !important;
  346. }
  347. .ivu-layout-has-sider {
  348. height: 100%;
  349. }
  350. .header {
  351. height: 30px;
  352. background: #ededed;
  353. display: flex;
  354. align-items: center;
  355. }
  356. /deep/ .ivu-layout-header {
  357. height: 52px !important;
  358. line-height: 52px !important;
  359. }
  360. .footer {
  361. background: #ededed;
  362. display: flex;
  363. justify-content: right;
  364. padding: 10px 50px;
  365. }
  366. </style>