home.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <div class="flow_region">
  3. <div class="flow_left" v-if="sourceType == '1'">
  4. <div class="flow_left_item">
  5. <el-scrollbar style="height: 100%">
  6. <div class="nodes-wrap">
  7. <div class="left-tab-container">
  8. <div class="primary-tabs">
  9. <div
  10. v-for="(tab, index) in nodeTypeList"
  11. @click="activePrimary = index; activeSecondary = 0"
  12. :class="{ 'active': activePrimary === index }"
  13. :key="tab.name"
  14. >
  15. {{tab.name}}
  16. </div>
  17. </div>
  18. </div>
  19. </div>
  20. </el-scrollbar>
  21. </div>
  22. <div class="flow_left_item">
  23. <el-scrollbar style="height: 100%">
  24. <div class="nodes-wrap">
  25. <div class="left-tab-container">
  26. <div class="secondary-tabs" v-if="nodeTypeList!= null && nodeTypeList.length > 0">
  27. <div
  28. v-for="(subTab, subIndex) in nodeTypeList[activePrimary].children"
  29. @click="activeSecondary = subIndex"
  30. :class="{ 'active': activeSecondary === subIndex }"
  31. :key="subTab.typeId"
  32. :draggable="true"
  33. @dragstart="drag($event, {nodeName: subTab.name, workTypeId: subTab.typeId, type: subTab.type})"
  34. >
  35. {{subTab.name}}
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. </el-scrollbar>
  41. </div>
  42. </div>
  43. <div
  44. id="flowWrap"
  45. ref="flowWrap"
  46. class="flow-wrap"
  47. @drop="drop($event)"
  48. @dragover="allowDrop($event)"
  49. >
  50. <div id="flow">
  51. <div
  52. v-show="auxiliaryLine.isShowXLine"
  53. class="auxiliary-line-x"
  54. :style="{
  55. width: auxiliaryLinePos.width,
  56. top: auxiliaryLinePos.y + 'px',
  57. left: auxiliaryLinePos.offsetX + 'px'
  58. }"
  59. ></div>
  60. <div
  61. v-show="auxiliaryLine.isShowYLine"
  62. class="auxiliary-line-y"
  63. :style="{
  64. height: auxiliaryLinePos.height,
  65. left: auxiliaryLinePos.x + 'px',
  66. top: auxiliaryLinePos.offsetY + 'px'
  67. }"
  68. ></div>
  69. <flowNode
  70. v-for="item in data.nodeList"
  71. :id="item.id"
  72. :key="item.id"
  73. :node="item"
  74. :disabled="disabled"
  75. :isEdit="isEdit"
  76. :selectOperator="selectOperator"
  77. :sourceType="sourceType"
  78. @setNode="setNode"
  79. @deleteNode="deleteNode"
  80. @changeLineState="changeLineState"
  81. ></flowNode>
  82. </div>
  83. </div>
  84. </div>
  85. </template>
  86. <script>
  87. import cloneDeep from 'lodash/cloneDeep'
  88. import { jsPlumb } from 'jsplumb'
  89. // import { nodeTypeList } from './config/init'
  90. import {
  91. jsplumbSetting,
  92. jsplumbConnectOptions,
  93. jsplumbSourceOptions,
  94. jsplumbTargetOptions
  95. } from './config/commonConfig'
  96. import methods from './config/methods'
  97. import flowNode from './node-item'
  98. export default {
  99. name: 'FlowEdit',
  100. components: {
  101. flowNode
  102. },
  103. props: {
  104. // 节点数据源
  105. nodeData: {
  106. type: Object,
  107. default: {
  108. nodeList: [],
  109. lineList: []
  110. }
  111. },
  112. // 是否仅查看
  113. disabled: {
  114. type: Boolean,
  115. default: false
  116. },
  117. // 是否选择操作人,当选择操作人时,其他字段不可编辑
  118. selectOperator: {
  119. type: Boolean,
  120. default: false
  121. },
  122. isEdit: {
  123. type: Boolean,
  124. default: false
  125. },
  126. // 节点类型
  127. nodeTypeList: {
  128. type: Array,
  129. default: () => []
  130. },
  131. sourceType: {
  132. type: String,
  133. default: ''
  134. }
  135. },
  136. data () {
  137. return {
  138. jsPlumb: null,
  139. currentItem: null,
  140. // nodeTypeList: nodeTypeList,
  141. nodeTypeObj: {},
  142. data: {
  143. nodeList: [],
  144. lineList: []
  145. },
  146. selectedList: [],
  147. jsplumbSetting: jsplumbSetting,
  148. jsplumbConnectOptions: jsplumbConnectOptions,
  149. jsplumbSourceOptions: jsplumbSourceOptions,
  150. jsplumbTargetOptions: jsplumbTargetOptions,
  151. auxiliaryLine: { isShowXLine: false, isShowYLine: false }, // 对齐辅助线是否显示
  152. auxiliaryLinePos: {
  153. width: '100%',
  154. height: '100%',
  155. offsetX: 0,
  156. offsetY: 0,
  157. x: 20,
  158. y: 20
  159. },
  160. commonGrid: [5, 5], // 节点移动最小距离
  161. selectModuleFlag: false, // 多选标识
  162. rectAngle: {
  163. px: '', // 多选框绘制时的起始点横坐标
  164. py: '', // 多选框绘制时的起始点纵坐标
  165. left: 0,
  166. top: 0,
  167. height: 0,
  168. width: 0
  169. },
  170. activePrimary: 0, // 当前激活的一级标签索引
  171. activeSecondary: 0 // 当前激活的二级标签索引
  172. }
  173. },
  174. watch: {
  175. nodeData (val) {
  176. console.log('nodeData watch', val)
  177. this.initNode()
  178. this.fixNodesPosition()
  179. this.$nextTick(() => {
  180. this.jsPlumb.deleteEveryConnection()
  181. // this.jsPlumb.deleteEveryEndpoint();
  182. // this.deleteAllNode();
  183. this.init()
  184. })
  185. },
  186. disabled (val) {
  187. },
  188. isEdit (val) {},
  189. nodeTypeList (val) {
  190. console.log('watch', val)
  191. }
  192. },
  193. mounted () {
  194. // console.log('mounted')
  195. this.jsPlumb = jsPlumb.getInstance()
  196. this.initNodeTypeObj()
  197. this.initNode()
  198. this.fixNodesPosition()
  199. this.$nextTick(() => {
  200. this.init()
  201. })
  202. // window.addEventListener('scroll', this.init)
  203. },
  204. methods: {
  205. ...methods,
  206. // 重置
  207. resetNodeData () {
  208. this.data = {
  209. nodeList: [],
  210. lineList: []
  211. }
  212. },
  213. initNodeTypeObj () {
  214. this.nodeTypeList.map(v => {
  215. this.nodeTypeObj[v.type] = v
  216. })
  217. },
  218. initNode () {
  219. this.resetNodeData()
  220. let tempData = cloneDeep(this.nodeData)
  221. this.data.lineList.push(...tempData.lineList)
  222. this.data.nodeList = []
  223. tempData.nodeList.map(v => {
  224. // v.logImg = this.nodeTypeObj[v.type].logImg
  225. // v.log_bg_color = this.nodeTypeObj[v.type].log_bg_color
  226. this.data.nodeList.push(v)
  227. })
  228. // this.$nextTick(() => {
  229. // this.init()
  230. // })
  231. },
  232. nodeDisabled (node) {
  233. return (
  234. this.disabled ||
  235. this.selectOperator ||
  236. (this.data.nodeList.findIndex(t => t.type === 'start') > -1 &&
  237. node.type === 'start') ||
  238. (this.data.nodeList.findIndex(t => t.type === 'end') > -1 &&
  239. node.type === 'end') ||
  240. false
  241. )
  242. },
  243. // 保存流程图
  244. saveFlow () {
  245. // 去除流程图背景图片logImg和背景颜色字段log_bg_color
  246. // let data = JSON.parse(JSON.stringify(this.data))
  247. // data.nodeList = data.nodeList.map(item => {
  248. // delete item.logImg
  249. // delete item.log_bg_color
  250. // return item
  251. // })
  252. // this.$emit('saveWorkFlow', data)
  253. },
  254. getFlowData () {
  255. let data = JSON.parse(JSON.stringify(this.data))
  256. data.nodeList = data.nodeList.map(item => {
  257. delete item.logImg
  258. delete item.log_bg_color
  259. return item
  260. })
  261. return data
  262. },
  263. dataChange () {
  264. // 通知上层数据变更
  265. this.$emit('dataChange')
  266. }
  267. }
  268. }
  269. </script>
  270. <style lang="less" scoped>
  271. .flow_region {
  272. display: flex;
  273. width: 90%;
  274. height: 90%;
  275. margin: 20px auto;
  276. border: 1px solid #ccc;
  277. position: relative;
  278. text-align: center;
  279. .flow_left {
  280. display: flex;
  281. }
  282. .flow_left_item {
  283. border-right: 1px solid #ccc;
  284. display: flex;
  285. flex-direction: column;
  286. justify-content: space-between;
  287. .help {
  288. position: absolute;
  289. left: 150px;
  290. z-index: 99;
  291. }
  292. }
  293. .nodes-wrap {
  294. width: 100px;
  295. height: 90%;
  296. // border-right: 1px solid #ccc;
  297. .node {
  298. display: flex;
  299. height: 40px;
  300. width: 80%;
  301. margin: 5px auto;
  302. border: 1px solid #ccc;
  303. line-height: 40px;
  304. &:hover {
  305. cursor: grab;
  306. }
  307. &:active {
  308. cursor: grabbing;
  309. }
  310. .log {
  311. width: 40px;
  312. height: 40px;
  313. }
  314. .name {
  315. width: 0;
  316. flex-grow: 1;
  317. }
  318. }
  319. .node-disabled {
  320. &:hover {
  321. cursor: not-allowed;
  322. }
  323. &:active {
  324. cursor: not-allowed;
  325. }
  326. }
  327. }
  328. .flow_operation {
  329. // height: 50px;
  330. display: flex;
  331. justify-content: center;
  332. align-items: center;
  333. border-top: 1px solid #ccc;
  334. padding: 10px 0;
  335. .el-button {
  336. width: 80%;
  337. }
  338. }
  339. .flow-wrap {
  340. height: 100%;
  341. position: relative;
  342. overflow: hidden;
  343. outline: none !important;
  344. flex-grow: 1;
  345. background-image: url("../../assets/point.png");
  346. #flow {
  347. position: relative;
  348. width: 100%;
  349. height: 100%;
  350. .auxiliary-line-x {
  351. position: absolute;
  352. border: 0.5px dashed #2ab1e8;
  353. z-index: 9999;
  354. }
  355. .auxiliary-line-y {
  356. position: absolute;
  357. border: 0.5px dashed #2ab1e8;
  358. z-index: 9999;
  359. }
  360. }
  361. }
  362. }
  363. ::v-deep.el-scrollbar .el-scrollbar__wrap {
  364. overflow-x: hidden;
  365. }
  366. </style>
  367. <style lang="less">
  368. .jtk-connector.active {
  369. z-index: 9999;
  370. path {
  371. stroke: #150042;
  372. stroke-width: 1.5;
  373. animation: ring;
  374. animation-duration: 3s;
  375. animation-timing-function: linear;
  376. animation-iteration-count: infinite;
  377. stroke-dasharray: 5;
  378. }
  379. }
  380. @keyframes ring {
  381. from {
  382. stroke-dashoffset: 50;
  383. }
  384. to {
  385. stroke-dashoffset: 0;
  386. }
  387. }
  388. /* 全局或组件内样式 */
  389. .el-scrollbar__wrap {
  390. overflow-x: hidden !important; /* 隐藏横向滚动条 */
  391. }
  392. .left-tab-container{
  393. display: flex;
  394. }
  395. /* 左侧列:固定宽度,垂直排列 */
  396. .primary-tabs {
  397. width: 100%;
  398. display: flex;
  399. flex-direction: column; /* 垂直布局 */
  400. border-right: 1px solid #ddd;
  401. }
  402. .primary-tabs > div {
  403. padding: 12px;
  404. // cursor: pointer;
  405. margin: 2px 2px;
  406. border-radius: 3px;
  407. }
  408. .primary-tabs > div.active {
  409. color: #ffffff;
  410. background: #f78989 !important;
  411. }
  412. /* 二级标签:水平排列 */
  413. .secondary-tabs {
  414. display: flex;
  415. flex: 1;
  416. flex-direction: column;
  417. }
  418. .secondary-tabs > div {
  419. padding: 12px;
  420. cursor: pointer;
  421. margin: 2px 2px;
  422. background: #85ce61;
  423. border-radius: 3px;
  424. }
  425. .secondary-tabs > div.active {
  426. color: #ffffff;
  427. background: #66b1ff !important;
  428. }
  429. </style>