NodeUser.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { PolygonNode, PolygonNodeModel, h } from "@logicflow/core";
  2. class UserNode extends PolygonNode {
  3. getIconShape() {
  4. const { model } = this.props
  5. const { stroke } = model.getNodeStyle()
  6. return h(
  7. 'svg',
  8. {
  9. x: 20,
  10. y: 18,
  11. width: 30,
  12. height: 30,
  13. viewBox: '0 0 1126 1024'
  14. },
  15. h(
  16. 'path',
  17. {
  18. fill: stroke,
  19. d: 'M792.576 379.392a25.6 25.6 0 0 0 25.2928 25.8048h283.2384A25.6 25.6 0 0 0 1126.4 379.392a25.6 25.6 0 0 0-25.2928-25.8048h-283.2384a25.6 25.6 0 0 0-25.344 25.8048z m303.9232 80.7424H761.856c-16.5376 0-29.9008 11.6224-29.9008 25.7536 0 14.1824 13.312 25.7536 29.9008 25.7536h334.6432c16.4864 0 29.9008-11.5712 29.9008-25.7536 0-14.1312-13.4144-25.7536-29.9008-25.7536z m4.608 106.496h-283.2384a25.6 25.6 0 0 0-25.344 25.7536 25.6 25.6 0 0 0 25.344 25.7536h283.2384A25.6 25.6 0 0 0 1126.4 592.384a25.6 25.6 0 0 0-25.2928-25.8048zM543.0272 1024H341.6576C150.8352 1024 0 1024 0 923.648v-20.1216c0-188.16 153.2928-341.1968 341.7088-341.1968h201.2672c188.416 0 341.76 153.0368 341.76 341.1968v20.0704C884.6848 1024 726.3232 1024 542.976 1024z m-203.1616-405.1456c-158.464 0-287.4368 128.4096-287.4368 286.208v20.48c0 40.9088 166.0928 40.9088 287.4368 40.9088h204.9536c100.4544 0 287.4368 0 287.4368-40.96v-20.3776c0-157.8496-128.9728-286.208-287.4368-286.208H339.8656z m92.416-76.7488a271.4112 271.4112 0 0 1-271.2064-271.0528A271.36 271.36 0 0 1 432.2816 0a271.36 271.36 0 0 1 271.2064 271.0528 271.4624 271.4624 0 0 1-271.2064 271.0528z m-215.3472-271.872c0 118.1696 96.6144 214.3232 215.3472 214.3232 118.784 0 215.3984-96.1536 215.3984-214.3232 0-118.2208-96.6144-214.3232-215.3984-214.3232S216.9344 152.0128 216.9344 270.2336z'
  20. }
  21. )
  22. )
  23. }
  24. getShape() {
  25. const { model } = this.props
  26. const { width, height, x, y, points } = model
  27. const { fill, fillOpacity, strokeWidth, stroke, strokeOpacity, } = model.getNodeStyle()
  28. const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
  29. const pointsPath = points.map(point => point.join(',')).join(' ')
  30. return h(
  31. 'g',
  32. {
  33. transform
  34. },
  35. [
  36. h(
  37. 'polygon',
  38. {
  39. points: pointsPath,
  40. fill,
  41. stroke,
  42. strokeWidth,
  43. strokeOpacity,
  44. fillOpacity
  45. }
  46. ),
  47. this.getIconShape()
  48. ]
  49. )
  50. }
  51. }
  52. class UserNodeModel extends PolygonNodeModel {
  53. constructor(data, graphModel) {
  54. data.text = {
  55. value: (data.text && data.text.value) || '',
  56. x: data.x,
  57. y: data.y + 50
  58. }
  59. super(data, graphModel)
  60. // 右键菜单自由配置,也可以通过边的properties或者其他属性条件更换不同菜单
  61. this.menu = [
  62. {
  63. className: 'lf-menu-delete',
  64. text: 'delete',
  65. callback(node) {
  66. // const comfirm = window.confirm('你确定要删除吗?')
  67. lf.deleteNode(node.id)
  68. }
  69. },
  70. {
  71. text: 'edit',
  72. className: 'lf-menu-item',
  73. callback(node) {
  74. lf.editText(node.id)
  75. }
  76. },
  77. {
  78. text: 'copy',
  79. className: 'lf-menu-item',
  80. callback(node) {
  81. lf.cloneNode(node.id)
  82. }
  83. }
  84. ]
  85. }
  86. initNodeData(data) {
  87. super.initNodeData(data)
  88. const lenght = 35
  89. this.points = [
  90. [lenght, 0],
  91. [lenght * 2, lenght],
  92. [lenght, lenght * 2],
  93. [0, lenght]
  94. ]
  95. }
  96. // 自定义锚点样式
  97. getAnchorStyle() {
  98. const style = super.getAnchorStyle();
  99. style.hover.r = 8;
  100. style.hover.fill = "rgb(24, 125, 255)";
  101. style.hover.stroke = "rgb(24, 125, 255)";
  102. return style;
  103. }
  104. }
  105. export default {
  106. type: 'user-node',
  107. view: UserNode,
  108. model: UserNodeModel
  109. }