schangxiang@126.com
2025-05-07 cace264ad9d86a7831099810b079da1141957add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { NODES } from '../../core/enum'
import { width, height, x, y } from './index'
 
// const pngMap = import.meta.glob('../../../../assets/images/*.png', {
//   eager: true,
// })
// const iconMap: Record<string, any> = Object.entries(pngMap).reduce(
//   (acc, [key, value]: any[]) => {
//     const name = key
//       .replace('../../../../assets/images/', '')
//       .replace('.png', '')
//     return {
//       ...acc,
//       [name]: value.default,
//     }
//   },
//   {}
// )
const OrdinaryNode: {
  type: string
  options: Record<string, any>
} = {
  type: NODES.ACTIVITIES,
  options: {
    drawShape(cfg: Record<string, any>, group: any) {
      const type = cfg?.properties?.type
      const isRoot = cfg?.isRoot
      const rect = group.addShape('rect', {
        zIndex: 1,
        attrs: {
          x: -width / 2,
          y: -height / 2,
          width,
          height,
          radius: 1,
          stroke: '#5B8FF9',
          fill: '#C6E5FF',
          lineWidth: 2,
        },
        name: 'rect-shape',
      })
      group.addShape('image', {
        zIndex: 100,
        draggable: false,
        attrs: {
          x: -width / 2 + 1,
          y: -height / 2 + 1,
          radius: 1,
          width: 20,
          height: 20,
          // img: isRoot ? iconMap[NODES.ACTIVITY] : iconMap[type],
          img: `/resources/assets/images/${isRoot ? NODES.ACTIVITY : type}.png`,
        },
        name: 'node-icon',
      })
      return rect
    },
  },
}
 
export default OrdinaryNode