@steedos/steedos-plugin-schema-builder 2.3.0-beta.8 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/objects.action.js +5 -0
- package/src/objects.object.yml +6 -0
- package/webapp/src/g6/behavior/activate-relations/index.tsx +160 -0
- package/webapp/src/g6/behavior/darg/index.tsx +146 -0
- package/webapp/src/g6/behavior/index.tsx +5 -0
- package/webapp/src/g6/model/editor-background.png +0 -0
- package/webapp/src/g6/model/index.tsx +574 -0
- package/webapp/src/g6/model/model-node.tsx +1080 -0
- package/webapp/src/g6/model/model.scss +163 -0
- package/webapp/src/g6/model/toolbar.tsx +360 -0
- package/webapp/src/g6/shape/base-sharp/index.tsx +19 -0
- package/webapp/src/g6/shape/index.tsx +0 -0
- package/webapp/src/g6/util/graph.tsx +60 -0
- package/webapp/src/g6/util/hooks.tsx +26 -0
- package/webapp/src/g6/util/index.tsx +20 -0
- package/webapp/src/hook/index.tsx +47 -0
- package/webapp/src/index.tsx +25 -0
- package/webapp/src/page/dva-model/index.tsx +70 -0
- package/webapp/src/page/dva-model/reducer/arrange.tsx +16 -0
- package/webapp/src/page/dva-model/reducer/index.tsx +7 -0
- package/webapp/src/page/dva-model/reducer/init.tsx +61 -0
- package/webapp/src/page/dva-model/reducer/model.tsx +126 -0
- package/webapp/src/page/dva-model/reducer/on-expand.tsx +27 -0
- package/webapp/src/page/dva-model/style.tsx +88 -0
- package/webapp/src/page/hooks/callback.tsx +54 -0
- package/webapp/src/page/hooks/fullscreen.tsx +34 -0
- package/webapp/src/page/hooks/pagehooks.tsx +127 -0
- package/webapp/src/page/hooks/resize.tsx +20 -0
- package/webapp/src/page/index.tsx +393 -0
- package/webapp/src/page/model-navi/index.tsx +329 -0
- package/webapp/src/page/model-navi/style.scss +111 -0
- package/webapp/src/page/util/index.tsx +234 -0
- package/webapp/src/page/util/layout-nodes/index.tsx +185 -0
- package/webapp/src/pdm/index.tsx +50 -0
- package/webapp/src/pdm/pdm-json/index.js +224 -0
- package/webapp/src/pdm/pdm-json/removeDiacritics.js +96 -0
- package/webapp/src/style.less +14 -0
- package/webapp/src/tree/index.tsx +46 -0
- package/webapp/src/tree/style.scss +26 -0
- package/webapp/src/type/field.tsx +10 -0
- package/webapp/src/type/index.tsx +3 -0
- package/webapp/src/type/model.tsx +12 -0
- package/webapp/src/type/module.tsx +4 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import WebPdmPage from './page'
|
|
3
|
+
import Pdm from './pdm'
|
|
4
|
+
import { Tree } from './tree'
|
|
5
|
+
export * from './type'
|
|
6
|
+
import DvaModel from './page/dva-model'
|
|
7
|
+
import { ErdPage } from './g6/model'
|
|
8
|
+
import './style.less'
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
DvaModel,
|
|
12
|
+
ErdPage
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const useAppContext = () => ({
|
|
16
|
+
tabsRouteContext: {
|
|
17
|
+
current: '/',
|
|
18
|
+
},
|
|
19
|
+
shellContext: {
|
|
20
|
+
setState: () => ({}),
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
export default (props) => {
|
|
24
|
+
return <WebPdmPage ErdPage={ErdPage} Pdm={Pdm} Tree={Tree} useAppContext={useAppContext} {...props} />
|
|
25
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
|
|
2
|
+
import { arrangeShow, init, load , modelEdit, modelReducers, onExpand } from './reducer'
|
|
3
|
+
import { initStyle } from './style'
|
|
4
|
+
export interface IDict<T> {
|
|
5
|
+
[name: string]: T
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const fieldMap = (m) => ({
|
|
9
|
+
key: m.key,
|
|
10
|
+
name: m.name,
|
|
11
|
+
moduleKey: m.moduleKey,
|
|
12
|
+
fields: Object.entries(m.fields).map(([k, v]: [string, any]) => ({
|
|
13
|
+
type: v.type,
|
|
14
|
+
key: v.key,
|
|
15
|
+
name: v.name,
|
|
16
|
+
originalKey: v.originalKey,
|
|
17
|
+
required: v.required,
|
|
18
|
+
|
|
19
|
+
typeMeta: v.typeMeta && {
|
|
20
|
+
type: v.typeMeta.type,
|
|
21
|
+
relationModel: v.typeMeta.relationModel,
|
|
22
|
+
},
|
|
23
|
+
})),
|
|
24
|
+
originalKey: m.originalKey,
|
|
25
|
+
aggregateRoot: m.aggregateRoot,
|
|
26
|
+
belongAggregate: m.belongAggregate,
|
|
27
|
+
// aggregateRoot: m.aggregateRoot,
|
|
28
|
+
aggregateModelKey: m.aggregateModelKey,
|
|
29
|
+
type: m.type,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
export default (({
|
|
33
|
+
namespace,
|
|
34
|
+
}) => {
|
|
35
|
+
const { style, colors } = initStyle({primaryColor: 'black'})
|
|
36
|
+
const state = {
|
|
37
|
+
modules: [],
|
|
38
|
+
models: [],
|
|
39
|
+
showModel: null,
|
|
40
|
+
lockMinZoom: false,
|
|
41
|
+
showInsertModel: null,
|
|
42
|
+
currentModel: null,
|
|
43
|
+
expandedKeys: [],
|
|
44
|
+
checkedKeys: [],
|
|
45
|
+
centerModel: null,
|
|
46
|
+
search: null,
|
|
47
|
+
layouting : false,
|
|
48
|
+
isArrangeLayout: false,
|
|
49
|
+
fieldMap,
|
|
50
|
+
showNameOrLabel: false,
|
|
51
|
+
config : {
|
|
52
|
+
style,
|
|
53
|
+
namespace: 'erd',
|
|
54
|
+
topHeight: 48,
|
|
55
|
+
colors,
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
namespace,
|
|
60
|
+
state,
|
|
61
|
+
reducers: {
|
|
62
|
+
onExpand,
|
|
63
|
+
modelEdit,
|
|
64
|
+
...modelReducers,
|
|
65
|
+
arrangeShow,
|
|
66
|
+
init,
|
|
67
|
+
load,
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const getLayerRootModel = (models, rootKey, roots = []) => {
|
|
2
|
+
const rootModel = models.find((a) => a.key === rootKey)
|
|
3
|
+
const rootsRes = rootModel ? [...roots, rootKey] : roots
|
|
4
|
+
const isRoot = (rootModel.aggregateModelKey && rootModel.aggregateModelKey !== rootKey)
|
|
5
|
+
const rootsResList = isRoot ? getLayerRootModel(models, rootModel.aggregateModelKey, rootsRes) : rootsRes
|
|
6
|
+
return rootsResList
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const arrangeShow = (ss, {model}) => {
|
|
10
|
+
// alert(model)
|
|
11
|
+
const roots = getLayerRootModel(ss.models, model, [])
|
|
12
|
+
// alert(JSON.stringify(roots))
|
|
13
|
+
const list = ss.models.filter((a) => (a.key === model || roots.indexOf(a.aggregateModelKey) >= 0)).map((a) => 'model-' + a.key)
|
|
14
|
+
return {...ss , checkedKeys: list, currentModel: model, isArrangeLayout: true}
|
|
15
|
+
|
|
16
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import Immer from 'immer'
|
|
2
|
+
import { initStyle } from '../style'
|
|
3
|
+
|
|
4
|
+
// const modules_name = 'modules'
|
|
5
|
+
// const models_name = 'models'
|
|
6
|
+
// const model_key = 'key'
|
|
7
|
+
// const module_key = 'key'
|
|
8
|
+
|
|
9
|
+
export const init = (ss, {
|
|
10
|
+
models,
|
|
11
|
+
modules,
|
|
12
|
+
currentModel,
|
|
13
|
+
primaryColor,
|
|
14
|
+
}) => {
|
|
15
|
+
// tslint:disable-next-line: ban-comma-operator
|
|
16
|
+
return Immer(ss, (s) => {
|
|
17
|
+
s.currentModel = currentModel
|
|
18
|
+
|
|
19
|
+
if (models) {
|
|
20
|
+
s.models = models
|
|
21
|
+
s.checkedKeys = models.map((m) => 'model-' + m.key)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (modules) {
|
|
25
|
+
s.modules = modules
|
|
26
|
+
s.expandedKeys = ['allmodels', ...modules.map((module) => 'module-' + module.key)]
|
|
27
|
+
}
|
|
28
|
+
if (primaryColor) {
|
|
29
|
+
const { style , colors } = initStyle({primaryColor})
|
|
30
|
+
s.config.style = style
|
|
31
|
+
s.config.colors = colors
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const load = (ss, {
|
|
37
|
+
models,
|
|
38
|
+
modules,
|
|
39
|
+
currentModel,
|
|
40
|
+
primaryColor,
|
|
41
|
+
}) => {
|
|
42
|
+
// tslint:disable-next-line: ban-comma-operator
|
|
43
|
+
return Immer(ss, (s) => {
|
|
44
|
+
s.currentModel = currentModel
|
|
45
|
+
|
|
46
|
+
if (models) {
|
|
47
|
+
s.models = [...s.models, ...models]
|
|
48
|
+
s.checkedKeys = [...models.map((m) => 'model-' + m.key), ...s.checkedKeys]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (modules) {
|
|
52
|
+
s.modules = [...s.modules, ...modules]
|
|
53
|
+
s.expandedKeys = [...s.expandedKeys, 'allmodels', ...modules.map((module) => 'module-' + module.key)]
|
|
54
|
+
}
|
|
55
|
+
if (primaryColor) {
|
|
56
|
+
const { style , colors } = initStyle({primaryColor})
|
|
57
|
+
s.config.style = style
|
|
58
|
+
s.config.colors = colors
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import _ from 'lodash'
|
|
2
|
+
export const layouting = (sss, arg) => {
|
|
3
|
+
return { ...sss, layouting: arg.layouting }
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export const setArrangeLayout = (sss, { isArrangeLayout }) => {
|
|
7
|
+
return { ...sss, isArrangeLayout }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const openInsertModel = (ss) => {
|
|
11
|
+
return { ...ss, showInsertModel: 'new' }
|
|
12
|
+
}
|
|
13
|
+
export const centerModel = (ss, { model }) => {
|
|
14
|
+
|
|
15
|
+
if (!ss.checkedKeys.find((a) => a === model)) {
|
|
16
|
+
return { ...ss, currentModel: model, checkedKeys : [...ss.checkedKeys, model ], centerModel: model }
|
|
17
|
+
} else {
|
|
18
|
+
// alert(model)
|
|
19
|
+
return { ...ss, currentModel: model , centerModel: model }
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export const currentModel = (ss, { model }) => {
|
|
23
|
+
// return ss
|
|
24
|
+
// alert(JSON.stringify(ss.checkedKeys))
|
|
25
|
+
if (!ss.checkedKeys.find((a) => a === model)) {
|
|
26
|
+
return { ...ss, currentModel: model, checkedKeys : [...ss.checkedKeys, model ] }
|
|
27
|
+
} else {
|
|
28
|
+
// alert(model)
|
|
29
|
+
return { ...ss, currentModel: model }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export const closeModel = (ss) => {
|
|
33
|
+
return { ...ss, showModel: null }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const delModel = (ss, { model }) => {
|
|
37
|
+
// alert(model)
|
|
38
|
+
// if( model === ss.currentModel) {
|
|
39
|
+
// return { ...ss }
|
|
40
|
+
// }
|
|
41
|
+
// return { ...ss, showModel: null }
|
|
42
|
+
|
|
43
|
+
const models = ss.models.filter((a) => (('model-' + a.key) !== model))
|
|
44
|
+
return { ...ss , models , checkedKeys : ss.checkedKeys.filter((a) => a !== model), currentModel : undefined}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const delModule = (ss, { model }) => {
|
|
49
|
+
// alert(model)
|
|
50
|
+
// if( model === ss.currentModel) {
|
|
51
|
+
// return { ...ss }
|
|
52
|
+
// }
|
|
53
|
+
// return { ...ss, showModel: null }
|
|
54
|
+
const modules = ss.modules.filter((a) => ('module-' + a.key) !== model)
|
|
55
|
+
const models = ss.models.filter((a) => (('module-' + a.moduleKey) !== model))
|
|
56
|
+
return { ...ss , models , modules, checkedKeys : ss.checkedKeys.filter((a) => a !== model), currentModel : undefined}
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const closeInsertModel = (ss) => {
|
|
61
|
+
return { ...ss, showInsertModel: null }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const onCheck = (ss, { checkKeys }) => {
|
|
65
|
+
if (checkKeys && checkKeys.find && checkKeys.find((ck) => ck === ss.currentModel)) {
|
|
66
|
+
return { ...ss,
|
|
67
|
+
checkedKeys: checkKeys,
|
|
68
|
+
currentModel: null,
|
|
69
|
+
}
|
|
70
|
+
} else return { ...ss,
|
|
71
|
+
checkedKeys: checkKeys,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export const search = (ss, { text }) => {
|
|
75
|
+
return { ...ss,
|
|
76
|
+
search: text,
|
|
77
|
+
currentModel: null,
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const onCheckByModule = (ss, { checkKeys, moduleKey}) => {
|
|
82
|
+
const modelsElse = ss.models.filter((a) => !!moduleKey && ((a.moduleKey) !== moduleKey)).map(a=>'model-'+a.key)
|
|
83
|
+
const modelFIlterElse = _.intersection(ss.checkedKeys, modelsElse)
|
|
84
|
+
const checkedKeys = [...modelFIlterElse, ...checkKeys]
|
|
85
|
+
return { ...ss,
|
|
86
|
+
checkedKeys,
|
|
87
|
+
currentModel: checkedKeys.find(k => k === ss.currentModel) ? ss.currentModel : null,
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const onCheckByModuleAll = (ss, { moduleKey }) => {
|
|
92
|
+
const modelsElse = ss.models.filter((a) => !!moduleKey && ((a.moduleKey) !== moduleKey)).map(a=>'model-'+a.key)
|
|
93
|
+
const modelFIlterElse = _.intersection(ss.checkedKeys, modelsElse)
|
|
94
|
+
const modelsKeys = ss.models.filter((a) => !moduleKey || ((a.moduleKey) === moduleKey)).map(a=>'model-'+a.key)
|
|
95
|
+
const checkedKeys = [...modelFIlterElse, ...modelsKeys]
|
|
96
|
+
return { ...ss,
|
|
97
|
+
checkedKeys,
|
|
98
|
+
currentModel: checkedKeys.find(k => k === ss.currentModel) ? ss.currentModel : null,
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const onCheckByModuleAllCancle = (ss, { moduleKey }) => {
|
|
103
|
+
const modelsElse = ss.models.filter((a) => !!moduleKey && ((a.moduleKey) !== moduleKey)).map(a=>'model-'+a.key)
|
|
104
|
+
const modelFIlterElse = _.intersection(ss.checkedKeys, modelsElse)
|
|
105
|
+
// const modelsKeys = ss.models.filter((a) => !moduleKey || ((a.moduleKey) === moduleKey)).map(a=>'model-'+a.key)
|
|
106
|
+
const checkedKeys = [...modelFIlterElse]
|
|
107
|
+
return { ...ss,
|
|
108
|
+
checkedKeys,
|
|
109
|
+
currentModel: checkedKeys.find(k => k === ss.currentModel) ? ss.currentModel : null,
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const lockMinZoom = (ss, { lockMinZoom }) => {
|
|
114
|
+
// alert(lockMinZoom)
|
|
115
|
+
return {
|
|
116
|
+
...ss,
|
|
117
|
+
lockMinZoom
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export const showNameOrLabel = (ss, {showNameOrLabel}) => {
|
|
122
|
+
return {
|
|
123
|
+
...ss,
|
|
124
|
+
showNameOrLabel
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Immer from 'immer'
|
|
2
|
+
|
|
3
|
+
export const onExpand = (ss, { expanded, node }) => {
|
|
4
|
+
const resData = Immer(ss, (s) => {
|
|
5
|
+
// tslint:disable-next-line: prefer-conditional-expression
|
|
6
|
+
if (expanded) {
|
|
7
|
+
s.expandedKeys = [...s.expandedKeys, node.props.eventKey]
|
|
8
|
+
} else {
|
|
9
|
+
s.expandedKeys = s.expandedKeys.filter((a) => a !== node.props.eventKey)
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
return resData
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const openModel = (ss) => {
|
|
16
|
+
return { ...ss,
|
|
17
|
+
showModel: ss.currentModel,
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const modelEdit = (ss, {
|
|
22
|
+
model,
|
|
23
|
+
}) => {
|
|
24
|
+
return { ...ss,
|
|
25
|
+
showModel: model,
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
|
|
2
|
+
export const initStyle = ({primaryColor}) => {
|
|
3
|
+
const colors = {
|
|
4
|
+
// blue : '#495D9E',
|
|
5
|
+
|
|
6
|
+
// get blue() {
|
|
7
|
+
// const res = (window.SYS_backEndConfig && window.SYS_backEndConfig.STYLE_PRIMARY_COLOR) || '#495D9E'
|
|
8
|
+
// if (_styleConfigLazy) {
|
|
9
|
+
// _styleConfigLazy.selected.node.stroke = res
|
|
10
|
+
// _styleConfigLazy.default.edge.stroke = res
|
|
11
|
+
// }
|
|
12
|
+
// return res
|
|
13
|
+
// // #0083EE
|
|
14
|
+
// },
|
|
15
|
+
// blue : window.SYS_backEndConfig && window.SYS_backEndConfig.PRESET_CSS_URL ? '#0083EE' : '#495D9E',
|
|
16
|
+
// #0083EE
|
|
17
|
+
blue: primaryColor,
|
|
18
|
+
white: '#FFFFFF',
|
|
19
|
+
head: 'rgba(7,10,26,0.06)',
|
|
20
|
+
black: 'black',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const style = {
|
|
24
|
+
naviWidth: 370,
|
|
25
|
+
default: {
|
|
26
|
+
node: {
|
|
27
|
+
fill: '#FFFFFF',
|
|
28
|
+
// shadowColor: 'rgba(0,0,0,0.06)',
|
|
29
|
+
shadowBlur: 15,
|
|
30
|
+
shadowOffsetX: 8,
|
|
31
|
+
shadowOffsetY: 8,
|
|
32
|
+
radius: 10,
|
|
33
|
+
// stroke: undefined,
|
|
34
|
+
lineWidth: 4 ,
|
|
35
|
+
opacity: 0.8,
|
|
36
|
+
stroke: 'black',
|
|
37
|
+
},
|
|
38
|
+
edge: {
|
|
39
|
+
lineWidth: 2,
|
|
40
|
+
size: 2,
|
|
41
|
+
lineAppendWidth: 4,
|
|
42
|
+
endArrow: {
|
|
43
|
+
path: 'M 6,0 L -6,-6 L -3,0 L -6,6 Z',
|
|
44
|
+
d: 4,
|
|
45
|
+
},
|
|
46
|
+
opacity: 0.2,
|
|
47
|
+
radius: 5,
|
|
48
|
+
labelCfg: {
|
|
49
|
+
autoRotate: true, // 使文本随边旋转
|
|
50
|
+
style: {
|
|
51
|
+
fontSize: 34,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
stroke: 'rgba(11,108,149)',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
inactive: {
|
|
58
|
+
edge: {
|
|
59
|
+
stroke: 'red',
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
selected: {
|
|
63
|
+
node: {
|
|
64
|
+
stroke: 'rgba(11,108,149)',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
active: {
|
|
68
|
+
edge: {
|
|
69
|
+
stroke: 'red',
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
noSelected: {
|
|
73
|
+
node: {
|
|
74
|
+
stroke: 'red',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
isNoModule : {
|
|
78
|
+
node: {
|
|
79
|
+
opacity: 0.2,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
colors,
|
|
86
|
+
style,
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react'
|
|
2
|
+
import Stats from 'stats.js'
|
|
3
|
+
export const useLoadData = ({
|
|
4
|
+
dispatch,
|
|
5
|
+
namespace,
|
|
6
|
+
getModels,
|
|
7
|
+
getModules,
|
|
8
|
+
primaryColor,
|
|
9
|
+
}) => {
|
|
10
|
+
const loadData = useCallback(() => {
|
|
11
|
+
if (getModels && getModules) {
|
|
12
|
+
const fun = async () => {
|
|
13
|
+
const data = await getModels({})
|
|
14
|
+
const modules = await getModules({})
|
|
15
|
+
dispatch({
|
|
16
|
+
type: `${namespace}/init`,
|
|
17
|
+
modules: modules.res,
|
|
18
|
+
models: data.res,
|
|
19
|
+
primaryColor,
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
fun()
|
|
24
|
+
}
|
|
25
|
+
}, [dispatch, getModels, getModules])
|
|
26
|
+
return {
|
|
27
|
+
loadData,
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export const useFpsHook = () => {
|
|
31
|
+
const fpsRef = useRef(null)
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (fpsRef.current && window.SYS_backEndConfig && window.SYS_backEndConfig.ERD_FPS) {
|
|
34
|
+
const stats = new Stats() // alert(stats.dom)
|
|
35
|
+
|
|
36
|
+
stats.showPanel(0) // 0: fps, 1: ms, 2: mb, 3+: custom
|
|
37
|
+
|
|
38
|
+
fpsRef.current.appendChild(stats.dom)
|
|
39
|
+
stats.dom.style.position = 'relative'
|
|
40
|
+
|
|
41
|
+
function animate() {
|
|
42
|
+
stats.begin() // monitored code goes here
|
|
43
|
+
|
|
44
|
+
stats.end()
|
|
45
|
+
requestAnimationFrame(animate)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
requestAnimationFrame(animate)
|
|
49
|
+
}
|
|
50
|
+
}, [])
|
|
51
|
+
return {
|
|
52
|
+
fpsRef,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
import React, {
|
|
3
|
+
useCallback,
|
|
4
|
+
useEffect,
|
|
5
|
+
useMemo,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react'
|
|
9
|
+
|
|
10
|
+
export const usefullScreen = (useAppContext) => {
|
|
11
|
+
const { shellContext, tabsRouteContext } = useAppContext()
|
|
12
|
+
const [layouted, setLayouted] = useState(false)
|
|
13
|
+
const [change, setChange] = useState(false)
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
shellContext.setState({
|
|
16
|
+
fullScreen: true,
|
|
17
|
+
})
|
|
18
|
+
setLayouted(true)
|
|
19
|
+
}, [])
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
shellContext.setState({
|
|
22
|
+
fullScreen: tabsRouteContext.current === '/model-map',
|
|
23
|
+
})
|
|
24
|
+
return () => {
|
|
25
|
+
shellContext.setState({
|
|
26
|
+
fullScreen: false,
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
}, [tabsRouteContext.current === '/model-map'])
|
|
30
|
+
return {
|
|
31
|
+
layouted,
|
|
32
|
+
change,
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { useDispatch, useSelector } from '../../hook'
|
|
2
|
+
import React, {
|
|
3
|
+
useCallback,
|
|
4
|
+
useEffect,
|
|
5
|
+
useMemo,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react'
|
|
9
|
+
// import { modelConfig } from '../config'
|
|
10
|
+
import { createLinks, getNodes, layOutNodesByG6 } from '../util'
|
|
11
|
+
import { usefullScreen } from './fullscreen'
|
|
12
|
+
|
|
13
|
+
export const useLocalHooks = ({namespace, useAppContext}) => {
|
|
14
|
+
const graphRef = useRef(null)
|
|
15
|
+
// const { shellContext } = useAppContext()
|
|
16
|
+
// const { loadData } = useLoadData({dispatch , getTrantorMetaAllModels, getTrantorMetaModules})
|
|
17
|
+
|
|
18
|
+
const { layouted, change } = usefullScreen(useAppContext)
|
|
19
|
+
const {
|
|
20
|
+
models,
|
|
21
|
+
modules,
|
|
22
|
+
checkedKeys,
|
|
23
|
+
showModel,
|
|
24
|
+
currentModel,
|
|
25
|
+
showInsertModel,
|
|
26
|
+
search,
|
|
27
|
+
layouting,
|
|
28
|
+
isArrangeLayout,
|
|
29
|
+
fieldMap,
|
|
30
|
+
config: { topHeight, style, colors },
|
|
31
|
+
} = useSelector((s) => s[namespace])
|
|
32
|
+
const newModels = useMemo(() => models.map(fieldMap).map((a) => ({...a, isShow: (!search || a.name.indexOf(search) >= 0)})), [
|
|
33
|
+
models, search, checkedKeys,
|
|
34
|
+
])
|
|
35
|
+
|
|
36
|
+
const [height] = useState(
|
|
37
|
+
document.documentElement.clientHeight ||
|
|
38
|
+
document.body.clientHeight - topHeight,
|
|
39
|
+
)
|
|
40
|
+
const [nodeState, setNodeState] = useState([])
|
|
41
|
+
const [edgeState, setEdgeState] = useState([])
|
|
42
|
+
const nodes = getNodes(newModels, checkedKeys, style)
|
|
43
|
+
|
|
44
|
+
const edgesRes = createLinks(
|
|
45
|
+
newModels,
|
|
46
|
+
nodes,
|
|
47
|
+
checkedKeys,
|
|
48
|
+
style,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
const edges =
|
|
52
|
+
nodes.length >= 0 ? edgesRes.concat(nodes.filter((a) => !a.isSys).map((a) => ({
|
|
53
|
+
key:
|
|
54
|
+
// 'model-' +
|
|
55
|
+
a.id +
|
|
56
|
+
'~' +
|
|
57
|
+
+'~' +
|
|
58
|
+
'model-SYS-CENTER-POINT',
|
|
59
|
+
|
|
60
|
+
source : a.id,
|
|
61
|
+
visible: false,
|
|
62
|
+
isSys : true,
|
|
63
|
+
style: {
|
|
64
|
+
visible: false,
|
|
65
|
+
},
|
|
66
|
+
target: 'model-SYS-CENTER-POINT',
|
|
67
|
+
type: 'console-line',
|
|
68
|
+
|
|
69
|
+
}))) :
|
|
70
|
+
edgesRes
|
|
71
|
+
const dispatch = useDispatch()
|
|
72
|
+
const setLayouting = useCallback((layoutingSet) => {
|
|
73
|
+
dispatch({
|
|
74
|
+
type: `${namespace}/layouting`,
|
|
75
|
+
layouting: layoutingSet,
|
|
76
|
+
})
|
|
77
|
+
}, [])
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
// alert(1)
|
|
80
|
+
setLayouting(true)
|
|
81
|
+
setImmediate(() => {
|
|
82
|
+
// layOutNodesByG6(nodes, edges, modules, setNodeState, setEdgeState, setLayouting, isArrangeLayout)
|
|
83
|
+
setEdgeState(edges)
|
|
84
|
+
setNodeState(nodes)
|
|
85
|
+
|
|
86
|
+
setLayouting(false)
|
|
87
|
+
}, 10)
|
|
88
|
+
}, [newModels, checkedKeys, isArrangeLayout, search])
|
|
89
|
+
|
|
90
|
+
const graph = useMemo(() => ({
|
|
91
|
+
edges : edgeState,
|
|
92
|
+
nodes : nodeState,
|
|
93
|
+
}), [nodeState])
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
height,
|
|
97
|
+
graph,
|
|
98
|
+
models: newModels,
|
|
99
|
+
checkedKeys,
|
|
100
|
+
graphRef,
|
|
101
|
+
showModel,
|
|
102
|
+
currentModel,
|
|
103
|
+
layouted,
|
|
104
|
+
change,
|
|
105
|
+
showInsertModel,
|
|
106
|
+
search,
|
|
107
|
+
modules,
|
|
108
|
+
layouting,
|
|
109
|
+
style,
|
|
110
|
+
colors,
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// const createGroups = (modules) => {
|
|
115
|
+
// return modules.map((m) => {
|
|
116
|
+
// return {
|
|
117
|
+
// id: `module-${m.key}`,
|
|
118
|
+
// title: {
|
|
119
|
+
// text: m.name,
|
|
120
|
+
// fontSize: 35,
|
|
121
|
+
// stroke: '#444',
|
|
122
|
+
// offsetX: 0,
|
|
123
|
+
// offsetY: 0,
|
|
124
|
+
// },
|
|
125
|
+
// }
|
|
126
|
+
// })
|
|
127
|
+
// }
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
import { useCallback, useEffect, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
export const useResizeUpdate = () => {
|
|
5
|
+
|
|
6
|
+
const [_, update] = useState(0)
|
|
7
|
+
|
|
8
|
+
const onResize = useCallback(() => {
|
|
9
|
+
// alert()
|
|
10
|
+
update(+new Date())
|
|
11
|
+
}, [])
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
window.addEventListener('resize', onResize)
|
|
15
|
+
return (() => {
|
|
16
|
+
window.removeEventListener('resize', onResize)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
})
|
|
20
|
+
}
|