node-item.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <div
  3. class="node-item"
  4. ref="node"
  5. :class="{
  6. active: isActive || isSelected,
  7. done: node.state === '0',
  8. todo: node.state === '1'
  9. }"
  10. :style="flowNodeContainer"
  11. v-click-outside="setNotActive"
  12. @click="setActive"
  13. @mouseenter="showAnchor"
  14. @mouseleave="hideAnchor"
  15. @dblclick.prevent="editNode"
  16. @contextmenu.prevent="onContextmenu"
  17. >
  18. <el-row>
  19. <!-- <el-col :span="8">
  20. <div class="log-wrap">
  21. <img :src="node.logImg" alt="" />
  22. </div>
  23. </el-col> -->
  24. <el-col :span="24">
  25. <div class="nodeName">{{ node.nodeName }}</div>
  26. </el-col>
  27. </el-row>
  28. <!-- <el-row>
  29. <div class="node-operator">{{ node.operatorName }}</div>
  30. </el-row> -->
  31. <!--连线用--//触发连线的区域-->
  32. <div class="node-anchor anchor-top" v-show="mouseEnter"></div>
  33. <div class="node-anchor anchor-right" v-show="mouseEnter"></div>
  34. <div class="node-anchor anchor-bottom" v-show="mouseEnter"></div>
  35. <div class="node-anchor anchor-left" v-show="mouseEnter"></div>
  36. <el-dialog
  37. :title="disabled ? '节点详情' : '节点编辑'"
  38. :visible.sync="dialog.visible"
  39. :modal="true"
  40. :append-to-body="true"
  41. width="60%"
  42. >
  43. <div style="height:400px;overflow:auto">
  44. <nodeEdit
  45. ref="nodeEdit"
  46. :data="dialog.data"
  47. :disabled="disabled"
  48. :isEdit="isEdit"
  49. :selectOperator="selectOperator"
  50. ></nodeEdit>
  51. </div>
  52. <div slot="footer">
  53. <el-button @click="dialog.visible = false">取 消</el-button>
  54. <el-button v-if="!disabled" type="primary" @click="dialogSubmit"
  55. >确 定</el-button
  56. >
  57. </div>
  58. </el-dialog>
  59. </div>
  60. </template>
  61. <script>
  62. import ClickOutside from 'vue-click-outside'
  63. import nodeEdit from './node-edit'
  64. // import nodeAdd from './node-add'
  65. export default {
  66. name: 'node-item',
  67. components: {
  68. nodeEdit
  69. // nodeAdd
  70. },
  71. props: {
  72. node: {
  73. type: Object,
  74. default: () => {}
  75. },
  76. disabled: {
  77. type: Boolean,
  78. default: false
  79. },
  80. // 是否选择操作人,当选择操作人时,其他字段不可编辑
  81. selectOperator: {
  82. type: Boolean,
  83. default: false
  84. },
  85. isEdit: {
  86. type: Boolean,
  87. default: false
  88. }
  89. },
  90. directives: {
  91. ClickOutside
  92. },
  93. computed: {
  94. // 节点容器样式
  95. flowNodeContainer: {
  96. get () {
  97. return {
  98. top: this.node.top,
  99. left: this.node.left
  100. }
  101. }
  102. }
  103. },
  104. data () {
  105. return {
  106. mouseEnter: false,
  107. isActive: false,
  108. isSelected: false,
  109. // 对话框
  110. dialog: {
  111. visible: false,
  112. data: {}
  113. }
  114. }
  115. },
  116. watch: {
  117. disabled (val) {
  118. // eslint-disable-next-line no-undef
  119. onContextmenu()
  120. }
  121. },
  122. methods: {
  123. showAnchor () {
  124. this.mouseEnter = true
  125. },
  126. hideAnchor () {
  127. this.mouseEnter = false
  128. },
  129. onContextmenu () {
  130. this.$contextmenu({
  131. items: [
  132. {
  133. label: '删除',
  134. disabled: this.disabled,
  135. icon: '',
  136. onClick: () => {
  137. this.deleteNode()
  138. }
  139. }
  140. ],
  141. event,
  142. customClass: 'custom-class',
  143. zIndex: 9999,
  144. minWidth: 180
  145. })
  146. },
  147. setActive () {
  148. if (window.event.ctrlKey) {
  149. this.isSelected = !this.isSelected
  150. return false
  151. }
  152. this.isActive = true
  153. this.isSelected = false
  154. setTimeout(() => {
  155. this.$emit('changeLineState', this.node.id, true)
  156. }, 0)
  157. },
  158. setNotActive () {
  159. if (!window.event.ctrlKey) {
  160. this.isSelected = false
  161. }
  162. if (!this.isActive) {
  163. return
  164. }
  165. this.$emit('changeLineState', this.node.id, false)
  166. this.isActive = false
  167. },
  168. editNode () {
  169. // 编辑节点
  170. this.dialog.data = this.node
  171. this.dialog.visible = true
  172. },
  173. deleteNode () {
  174. this.$emit('deleteNode', this.node)
  175. },
  176. // 节点编辑提交
  177. dialogSubmit () {
  178. this.$refs.nodeEdit
  179. .validateFormData()
  180. .then(() => {
  181. let formData = this.$refs.nodeEdit.formData()
  182. this.$emit('setNode', this.node.id, formData)
  183. this.dialog.visible = false
  184. })
  185. .catch((e) => { console.log(e) })
  186. }
  187. }
  188. }
  189. </script>
  190. <style lang="less" scoped>
  191. @labelColor: #409eff;
  192. @nodeSize: 20px;
  193. @viewSize: 10px;
  194. .node-item {
  195. position: absolute;
  196. // display: flex;
  197. // height: 40px;
  198. width: 120px;
  199. justify-content: center;
  200. align-items: center;
  201. border: 1px solid #b7b6b6;
  202. border-radius: 4px;
  203. // color: #ffffff;
  204. cursor: move;
  205. box-sizing: content-box;
  206. z-index: 9995;
  207. &:hover {
  208. z-index: 9998;
  209. .delete-btn {
  210. display: block;
  211. }
  212. }
  213. .log-wrap {
  214. width: 40px;
  215. height: 40px;
  216. border-right: 1px solid #b7b6b6;
  217. }
  218. .nodeName {
  219. flex-grow: 1;
  220. // width: 80px;
  221. overflow: hidden;
  222. text-overflow: ellipsis;
  223. // white-space: nowrap;
  224. height: 40px;
  225. align-items: center;
  226. justify-content: center;
  227. display: flex;
  228. }
  229. .node-operator {
  230. border-top: 1px solid #b7b6b6;
  231. height: 25px;
  232. overflow: hidden;
  233. text-overflow: ellipsis;
  234. white-space: nowrap;
  235. }
  236. .node-anchor {
  237. display: flex;
  238. position: absolute;
  239. width: @nodeSize;
  240. height: @nodeSize;
  241. align-items: center;
  242. justify-content: center;
  243. border-radius: 10px;
  244. cursor: crosshair;
  245. z-index: 9999;
  246. background: -webkit-radial-gradient(sandybrown 10%, white 30%, #9a54ff 60%);
  247. }
  248. .anchor-top {
  249. top: calc((@nodeSize / 2) * -1);
  250. left: 50%;
  251. margin-left: calc((@nodeSize / 2) * -1);
  252. }
  253. .anchor-right {
  254. top: 50%;
  255. right: calc((@nodeSize / 2) * -1);
  256. margin-top: calc((@nodeSize / 2) * -1);
  257. }
  258. .anchor-bottom {
  259. bottom: calc((@nodeSize / 2) * -1);
  260. left: 50%;
  261. margin-left: calc((@nodeSize / 2) * -1);
  262. }
  263. .anchor-left {
  264. top: 50%;
  265. left: calc((@nodeSize / 2) * -1);
  266. margin-top: calc((@nodeSize / 2) * -1);
  267. }
  268. }
  269. .active {
  270. border: 1px dashed @labelColor;
  271. box-shadow: 0px 5px 9px 0px rgba(0, 0, 0, 0.5);
  272. }
  273. .done {
  274. background-color: #cccccc;
  275. color: #ffffff;
  276. }
  277. .todo {
  278. background-color: #FF3333;
  279. color: #ffffff;
  280. }
  281. </style>