@easyv/react-component-builder 0.19.3 → 0.19.5-beta.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/config/paths.js +24 -24
- package/config/webpack.config.build.js +70 -70
- package/config/webpack.config.common.js +126 -126
- package/config/webpack.config.js +126 -126
- package/launcher/build.js +122 -120
- package/launcher/generate.js +99 -99
- package/launcher/start.js +238 -238
- package/loaders/react-entry-loader.js +470 -430
- package/package.json +76 -76
- package/public/component.ejs +51 -51
- package/public/home.ejs +21 -21
- package/templates/basic/assets/logo.png +0 -0
- package/templates/basic/config/main.data.json +14 -14
- package/templates/basic/config/main.json +6 -6
- package/templates/basic/index.jsx +26 -26
- package/templates/basic/styles/index.module.css +3 -3
- package/templates/basic/utils/bind-children.js +10 -10
- package/templates/basic/utils/reduce-config.js +20 -20
- package/templates/three-component/config/main.data.json +14 -14
- package/templates/three-component/config/main.json +76 -76
- package/templates/three-component/index.jsx +122 -122
- package/templates/three-component/utils/Component.js +274 -274
- package/templates/three-component/utils/OrbitControls.js +1051 -1051
- package/templates/three-component/utils/reduce-config.js +20 -20
- package/utils/auto-assign-port.js +11 -11
- package/utils/index.js +91 -91
- package/utils/openBrowser.js +153 -153
- package/utils/openChrome.applescript +94 -94
|
@@ -1,274 +1,274 @@
|
|
|
1
|
-
// import OrbitControls from 'three-orbitcontrols';
|
|
2
|
-
import OrbitControls from './OrbitControls';
|
|
3
|
-
import { Scene, WebGLRenderer, PerspectiveCamera, OrthographicCamera, Vector3 } from 'three';
|
|
4
|
-
import { dispatch } from 'd3-dispatch';
|
|
5
|
-
import { reduceConfig } from './reduce-config';
|
|
6
|
-
export class EasyVComponent {
|
|
7
|
-
constructor(props) {
|
|
8
|
-
let { configuration, data, id } = props;
|
|
9
|
-
this.id = id;
|
|
10
|
-
this.setConfig(configuration);
|
|
11
|
-
this.setProps(props);
|
|
12
|
-
this.setData(data);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
getConfig() {
|
|
16
|
-
return this.config;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
setConfig(configuration) {
|
|
20
|
-
this.config = reduceConfig(configuration);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
setProps(props) {
|
|
24
|
-
this.props = props;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
setData(data) {
|
|
28
|
-
this.data = data;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
update(configuration, data) {
|
|
32
|
-
this.setConfig(configuration);
|
|
33
|
-
this.setData(data);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
animate() { }
|
|
37
|
-
|
|
38
|
-
destroy() { }
|
|
39
|
-
}
|
|
40
|
-
export class EasyVComponent3d extends EasyVComponent {
|
|
41
|
-
devicePixelRatio = window.devicePixelRatio;
|
|
42
|
-
|
|
43
|
-
childrenComponent = {};
|
|
44
|
-
|
|
45
|
-
initChildren(childrenConfig, childrenData, children) {
|
|
46
|
-
this.setChildrenConfig(childrenConfig);
|
|
47
|
-
this.setChildrenData(childrenData);
|
|
48
|
-
this.setChildren(children);
|
|
49
|
-
}
|
|
50
|
-
setDispath = (...names) => {
|
|
51
|
-
this.dispatch = dispatch(...names);
|
|
52
|
-
};
|
|
53
|
-
setChildrenData(childrenData) {
|
|
54
|
-
this.childrenData = childrenData;
|
|
55
|
-
}
|
|
56
|
-
getTextPosition = (position) => {
|
|
57
|
-
let { width, height } = this.getDimension(),
|
|
58
|
-
{ x, y } = position.clone().project(this.camera),
|
|
59
|
-
halfWidth = Number(width / 2),
|
|
60
|
-
halfHeight = Number(height / 2),
|
|
61
|
-
left = Math.round(x * halfWidth + halfWidth),
|
|
62
|
-
top = Math.round(-y * halfHeight + halfHeight);
|
|
63
|
-
return { left, top };
|
|
64
|
-
};
|
|
65
|
-
setChildrenConfig(childrenConfig) {
|
|
66
|
-
this.childrenConfig = childrenConfig;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
getDimension = () => {
|
|
70
|
-
let { dimension } = this.config.chart,
|
|
71
|
-
{ left, top } = dimension.chartPosition,
|
|
72
|
-
{ width, height } = dimension.chartDimension;
|
|
73
|
-
return { width, height, left, top };
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
init = ({ camera, renderer, scene }) => {
|
|
77
|
-
this.initCamera(camera);
|
|
78
|
-
this.initRenderer(renderer);
|
|
79
|
-
this.initScene(scene);
|
|
80
|
-
this.setRenderSize(
|
|
81
|
-
(this.config.chart.shapeStyle && this.config.chart.shapeStyle.devicePixelRatio) || window.devicePixelRatio
|
|
82
|
-
);
|
|
83
|
-
};
|
|
84
|
-
initCamera = (camera, position, lookAt) => {
|
|
85
|
-
this.camera = camera;
|
|
86
|
-
if (position) {
|
|
87
|
-
this.setCameraPosition(position);
|
|
88
|
-
}
|
|
89
|
-
if (lookAt) {
|
|
90
|
-
this.setCameraLookAt(lookAt);
|
|
91
|
-
}
|
|
92
|
-
(position || lookAt) && this.updateCamera();
|
|
93
|
-
};
|
|
94
|
-
initRenderer = (renderer) => {
|
|
95
|
-
this.renderer = renderer;
|
|
96
|
-
};
|
|
97
|
-
initScene = (scene) => {
|
|
98
|
-
this.scene = scene;
|
|
99
|
-
};
|
|
100
|
-
setChildren = (childrenComponent) => {
|
|
101
|
-
childrenComponent.forEach((item) => {
|
|
102
|
-
var childrenProps = this.getChildren(item.name);
|
|
103
|
-
childrenProps &&
|
|
104
|
-
childrenProps.length > 0 &&
|
|
105
|
-
childrenProps.forEach((props) => {
|
|
106
|
-
this.initChild(props.id, item.child, props);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
initChild = (id, Component, item) => {
|
|
112
|
-
var component = new Component(item, this);
|
|
113
|
-
this.childrenComponent['component_' + id] = component;
|
|
114
|
-
this.scene.add(component.getComponent());
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
getChildren = (type) => {
|
|
118
|
-
var config = this.getChildrenConfig(type);
|
|
119
|
-
return this.getChildrenProps(config);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
getChildrenProps = (config) => {
|
|
123
|
-
return config
|
|
124
|
-
.map((item) => {
|
|
125
|
-
var currentData = this.childrenData.filter(
|
|
126
|
-
(data) => data.id !== undefined && item.id !== undefined && data.id === item.id
|
|
127
|
-
);
|
|
128
|
-
if (currentData && currentData.length > 0) {
|
|
129
|
-
return { ...item, data: currentData[0].data };
|
|
130
|
-
}
|
|
131
|
-
})
|
|
132
|
-
.filter((item) => !!item);
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
getChildrenConfig = (type = '') => {
|
|
136
|
-
var childrenConfig = this.reduceChildrenConfig();
|
|
137
|
-
return childrenConfig
|
|
138
|
-
.filter((item) => type === (item && item.base && item.base.module_name))
|
|
139
|
-
.filter((item) => !!item);
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
reduceChildrenConfig = () => {
|
|
143
|
-
return this.childrenConfig
|
|
144
|
-
? this.childrenConfig.map((item) => {
|
|
145
|
-
return { ...item, config: reduceConfig(item.configuration) };
|
|
146
|
-
})
|
|
147
|
-
: [];
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
initCamera() {
|
|
151
|
-
var { type } = this.camera;
|
|
152
|
-
if (type === '') {
|
|
153
|
-
} else {
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
setCameraAspect = () => {
|
|
158
|
-
let { width, height } = this.getDimension();
|
|
159
|
-
this.camera.aspect = width / height;
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
setCameraFov(fov) {
|
|
163
|
-
this.camera.fov = fov;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
setCameraPosition = (x, y, z) => {
|
|
167
|
-
this.camera.position.set(x, y, z);
|
|
168
|
-
this.cameraPosition = { x, y, z };
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
setOrbitControlsPosition = (x, y, z) => {
|
|
172
|
-
if (this.orbitControls) {
|
|
173
|
-
this.orbitControls.target = new Vector3(x, y, z);
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
setCameraLookAt = (x, y, z) => {
|
|
177
|
-
this.camera.lookAt(new Vector3(x, y, z));
|
|
178
|
-
};
|
|
179
|
-
updateCamera = () => {
|
|
180
|
-
this.camera.updateProjectionMatrix();
|
|
181
|
-
this.camera.updateMatrixWorld();
|
|
182
|
-
if (this.orbitControls) {
|
|
183
|
-
this.orbitControls.update();
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
initOrbitControls = () => {
|
|
187
|
-
this.orbitControls = new OrbitControls(this.camera, this.renderer.domElement);
|
|
188
|
-
};
|
|
189
|
-
setOrbitControlsEnable = (enable) => {
|
|
190
|
-
this.orbitControls.enable = !!enable;
|
|
191
|
-
};
|
|
192
|
-
appendCanvasToDom = (wraper) => {
|
|
193
|
-
wraper.appendChild(this.renderer.domElement);
|
|
194
|
-
};
|
|
195
|
-
render = () => {
|
|
196
|
-
this.renderer.render(this.scene, this.camera);
|
|
197
|
-
};
|
|
198
|
-
setRenderSize = (devicePixelRatio) => {
|
|
199
|
-
var { width, height } = this.getDimension();
|
|
200
|
-
this.renderer.setSize(width, height);
|
|
201
|
-
if (devicePixelRatio) {
|
|
202
|
-
this.devicePixelRatio = devicePixelRatio;
|
|
203
|
-
this.renderer.setPixelRatio(this.devicePixelRatio);
|
|
204
|
-
} else {
|
|
205
|
-
this.renderer.setPixelRatio(this.devicePixelRatio);
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
cameraChanged = () => { };
|
|
209
|
-
setAttribute = (key, value) => {
|
|
210
|
-
this[key] = value;
|
|
211
|
-
};
|
|
212
|
-
updateChildren(props, nextProps) {
|
|
213
|
-
this.setProps(nextProps);
|
|
214
|
-
|
|
215
|
-
var { childrenConfig, childrenData } = props,
|
|
216
|
-
{ childrenConfig: nextChildrenConfig, childrenData: nextChildrenData } = nextProps,
|
|
217
|
-
children = this.getChildrenId(childrenConfig), //props中children的ID组件数组
|
|
218
|
-
nextChildren = this.getChildrenId(nextChildrenConfig), //nextProps中children的ID组件数组
|
|
219
|
-
arr = this.differArr(children, nextChildren), //在children中有,在nextchildren中没有的元素
|
|
220
|
-
nextArr = this.differArr(nextChildren, children); //在nextChildren中有,在children中没有的元素
|
|
221
|
-
|
|
222
|
-
arr &&
|
|
223
|
-
arr.length > 0 &&
|
|
224
|
-
arr.forEach((id) => {
|
|
225
|
-
//如果老组件的ID未在新的组件列表中找到,说明已被删除,就从场景中删除
|
|
226
|
-
this.childrenComponent['component_' + id] && this.childrenComponent['component_' + id].remove(this.scene);
|
|
227
|
-
});
|
|
228
|
-
nextArr &&
|
|
229
|
-
nextArr.length > 0 &&
|
|
230
|
-
nextArr.forEach((id) => {
|
|
231
|
-
//如果组件的ID未在老的组件列表中找到,说明是新增组件
|
|
232
|
-
var currentNextProps = this.filterItem(nextChildrenConfig, 'id', id)[0],
|
|
233
|
-
currentNextData = this.filterItem(nextChildrenData, 'id', id)[0],
|
|
234
|
-
{ base, configuration } = currentNextProps,
|
|
235
|
-
{ child } = this.filterItem(props.children, 'name', base.module_name)[0];
|
|
236
|
-
this.initChild(
|
|
237
|
-
id,
|
|
238
|
-
child,
|
|
239
|
-
Object.assign({}, currentNextProps, { config: reduceConfig(configuration), data: currentNextData.data })
|
|
240
|
-
);
|
|
241
|
-
});
|
|
242
|
-
nextChildren &&
|
|
243
|
-
nextChildren.length > 0 &&
|
|
244
|
-
nextChildren.forEach((id) => {
|
|
245
|
-
if (
|
|
246
|
-
nextArr.indexOf(id) < 0 &&
|
|
247
|
-
children.indexOf(id) > -1 &&
|
|
248
|
-
nextChildren.indexOf(id) > -1 &&
|
|
249
|
-
this.childrenComponent['component_' + id]
|
|
250
|
-
) {
|
|
251
|
-
let config = this.filterItem(nextProps.childrenConfig, 'id', id)[0].configuration,
|
|
252
|
-
data = this.filterItem(nextProps.childrenData, 'id', id)[0].data;
|
|
253
|
-
this.childrenComponent['component_' + id].update(config, data);
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
getChildrenId(children = []) {
|
|
258
|
-
return children.map((item) => item.id);
|
|
259
|
-
}
|
|
260
|
-
differArr(arr, comparedArr) {
|
|
261
|
-
var tmp = [];
|
|
262
|
-
for (var i = 0, j = arr.length; i < j; i++) {
|
|
263
|
-
if (comparedArr.indexOf(arr[i]) < 0) {
|
|
264
|
-
tmp.push(arr[i]);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return tmp;
|
|
268
|
-
}
|
|
269
|
-
filterItem(arr, name, value) {
|
|
270
|
-
return arr.filter((item) => {
|
|
271
|
-
return item[name] === value;
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
}
|
|
1
|
+
// import OrbitControls from 'three-orbitcontrols';
|
|
2
|
+
import OrbitControls from './OrbitControls';
|
|
3
|
+
import { Scene, WebGLRenderer, PerspectiveCamera, OrthographicCamera, Vector3 } from 'three';
|
|
4
|
+
import { dispatch } from 'd3-dispatch';
|
|
5
|
+
import { reduceConfig } from './reduce-config';
|
|
6
|
+
export class EasyVComponent {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
let { configuration, data, id } = props;
|
|
9
|
+
this.id = id;
|
|
10
|
+
this.setConfig(configuration);
|
|
11
|
+
this.setProps(props);
|
|
12
|
+
this.setData(data);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getConfig() {
|
|
16
|
+
return this.config;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
setConfig(configuration) {
|
|
20
|
+
this.config = reduceConfig(configuration);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
setProps(props) {
|
|
24
|
+
this.props = props;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
setData(data) {
|
|
28
|
+
this.data = data;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
update(configuration, data) {
|
|
32
|
+
this.setConfig(configuration);
|
|
33
|
+
this.setData(data);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
animate() { }
|
|
37
|
+
|
|
38
|
+
destroy() { }
|
|
39
|
+
}
|
|
40
|
+
export class EasyVComponent3d extends EasyVComponent {
|
|
41
|
+
devicePixelRatio = window.devicePixelRatio;
|
|
42
|
+
|
|
43
|
+
childrenComponent = {};
|
|
44
|
+
|
|
45
|
+
initChildren(childrenConfig, childrenData, children) {
|
|
46
|
+
this.setChildrenConfig(childrenConfig);
|
|
47
|
+
this.setChildrenData(childrenData);
|
|
48
|
+
this.setChildren(children);
|
|
49
|
+
}
|
|
50
|
+
setDispath = (...names) => {
|
|
51
|
+
this.dispatch = dispatch(...names);
|
|
52
|
+
};
|
|
53
|
+
setChildrenData(childrenData) {
|
|
54
|
+
this.childrenData = childrenData;
|
|
55
|
+
}
|
|
56
|
+
getTextPosition = (position) => {
|
|
57
|
+
let { width, height } = this.getDimension(),
|
|
58
|
+
{ x, y } = position.clone().project(this.camera),
|
|
59
|
+
halfWidth = Number(width / 2),
|
|
60
|
+
halfHeight = Number(height / 2),
|
|
61
|
+
left = Math.round(x * halfWidth + halfWidth),
|
|
62
|
+
top = Math.round(-y * halfHeight + halfHeight);
|
|
63
|
+
return { left, top };
|
|
64
|
+
};
|
|
65
|
+
setChildrenConfig(childrenConfig) {
|
|
66
|
+
this.childrenConfig = childrenConfig;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
getDimension = () => {
|
|
70
|
+
let { dimension } = this.config.chart,
|
|
71
|
+
{ left, top } = dimension.chartPosition,
|
|
72
|
+
{ width, height } = dimension.chartDimension;
|
|
73
|
+
return { width, height, left, top };
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
init = ({ camera, renderer, scene }) => {
|
|
77
|
+
this.initCamera(camera);
|
|
78
|
+
this.initRenderer(renderer);
|
|
79
|
+
this.initScene(scene);
|
|
80
|
+
this.setRenderSize(
|
|
81
|
+
(this.config.chart.shapeStyle && this.config.chart.shapeStyle.devicePixelRatio) || window.devicePixelRatio
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
initCamera = (camera, position, lookAt) => {
|
|
85
|
+
this.camera = camera;
|
|
86
|
+
if (position) {
|
|
87
|
+
this.setCameraPosition(position);
|
|
88
|
+
}
|
|
89
|
+
if (lookAt) {
|
|
90
|
+
this.setCameraLookAt(lookAt);
|
|
91
|
+
}
|
|
92
|
+
(position || lookAt) && this.updateCamera();
|
|
93
|
+
};
|
|
94
|
+
initRenderer = (renderer) => {
|
|
95
|
+
this.renderer = renderer;
|
|
96
|
+
};
|
|
97
|
+
initScene = (scene) => {
|
|
98
|
+
this.scene = scene;
|
|
99
|
+
};
|
|
100
|
+
setChildren = (childrenComponent) => {
|
|
101
|
+
childrenComponent.forEach((item) => {
|
|
102
|
+
var childrenProps = this.getChildren(item.name);
|
|
103
|
+
childrenProps &&
|
|
104
|
+
childrenProps.length > 0 &&
|
|
105
|
+
childrenProps.forEach((props) => {
|
|
106
|
+
this.initChild(props.id, item.child, props);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
initChild = (id, Component, item) => {
|
|
112
|
+
var component = new Component(item, this);
|
|
113
|
+
this.childrenComponent['component_' + id] = component;
|
|
114
|
+
this.scene.add(component.getComponent());
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
getChildren = (type) => {
|
|
118
|
+
var config = this.getChildrenConfig(type);
|
|
119
|
+
return this.getChildrenProps(config);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
getChildrenProps = (config) => {
|
|
123
|
+
return config
|
|
124
|
+
.map((item) => {
|
|
125
|
+
var currentData = this.childrenData.filter(
|
|
126
|
+
(data) => data.id !== undefined && item.id !== undefined && data.id === item.id
|
|
127
|
+
);
|
|
128
|
+
if (currentData && currentData.length > 0) {
|
|
129
|
+
return { ...item, data: currentData[0].data };
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
.filter((item) => !!item);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
getChildrenConfig = (type = '') => {
|
|
136
|
+
var childrenConfig = this.reduceChildrenConfig();
|
|
137
|
+
return childrenConfig
|
|
138
|
+
.filter((item) => type === (item && item.base && item.base.module_name))
|
|
139
|
+
.filter((item) => !!item);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
reduceChildrenConfig = () => {
|
|
143
|
+
return this.childrenConfig
|
|
144
|
+
? this.childrenConfig.map((item) => {
|
|
145
|
+
return { ...item, config: reduceConfig(item.configuration) };
|
|
146
|
+
})
|
|
147
|
+
: [];
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
initCamera() {
|
|
151
|
+
var { type } = this.camera;
|
|
152
|
+
if (type === '') {
|
|
153
|
+
} else {
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
setCameraAspect = () => {
|
|
158
|
+
let { width, height } = this.getDimension();
|
|
159
|
+
this.camera.aspect = width / height;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
setCameraFov(fov) {
|
|
163
|
+
this.camera.fov = fov;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
setCameraPosition = (x, y, z) => {
|
|
167
|
+
this.camera.position.set(x, y, z);
|
|
168
|
+
this.cameraPosition = { x, y, z };
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
setOrbitControlsPosition = (x, y, z) => {
|
|
172
|
+
if (this.orbitControls) {
|
|
173
|
+
this.orbitControls.target = new Vector3(x, y, z);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
setCameraLookAt = (x, y, z) => {
|
|
177
|
+
this.camera.lookAt(new Vector3(x, y, z));
|
|
178
|
+
};
|
|
179
|
+
updateCamera = () => {
|
|
180
|
+
this.camera.updateProjectionMatrix();
|
|
181
|
+
this.camera.updateMatrixWorld();
|
|
182
|
+
if (this.orbitControls) {
|
|
183
|
+
this.orbitControls.update();
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
initOrbitControls = () => {
|
|
187
|
+
this.orbitControls = new OrbitControls(this.camera, this.renderer.domElement);
|
|
188
|
+
};
|
|
189
|
+
setOrbitControlsEnable = (enable) => {
|
|
190
|
+
this.orbitControls.enable = !!enable;
|
|
191
|
+
};
|
|
192
|
+
appendCanvasToDom = (wraper) => {
|
|
193
|
+
wraper.appendChild(this.renderer.domElement);
|
|
194
|
+
};
|
|
195
|
+
render = () => {
|
|
196
|
+
this.renderer.render(this.scene, this.camera);
|
|
197
|
+
};
|
|
198
|
+
setRenderSize = (devicePixelRatio) => {
|
|
199
|
+
var { width, height } = this.getDimension();
|
|
200
|
+
this.renderer.setSize(width, height);
|
|
201
|
+
if (devicePixelRatio) {
|
|
202
|
+
this.devicePixelRatio = devicePixelRatio;
|
|
203
|
+
this.renderer.setPixelRatio(this.devicePixelRatio);
|
|
204
|
+
} else {
|
|
205
|
+
this.renderer.setPixelRatio(this.devicePixelRatio);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
cameraChanged = () => { };
|
|
209
|
+
setAttribute = (key, value) => {
|
|
210
|
+
this[key] = value;
|
|
211
|
+
};
|
|
212
|
+
updateChildren(props, nextProps) {
|
|
213
|
+
this.setProps(nextProps);
|
|
214
|
+
|
|
215
|
+
var { childrenConfig, childrenData } = props,
|
|
216
|
+
{ childrenConfig: nextChildrenConfig, childrenData: nextChildrenData } = nextProps,
|
|
217
|
+
children = this.getChildrenId(childrenConfig), //props中children的ID组件数组
|
|
218
|
+
nextChildren = this.getChildrenId(nextChildrenConfig), //nextProps中children的ID组件数组
|
|
219
|
+
arr = this.differArr(children, nextChildren), //在children中有,在nextchildren中没有的元素
|
|
220
|
+
nextArr = this.differArr(nextChildren, children); //在nextChildren中有,在children中没有的元素
|
|
221
|
+
|
|
222
|
+
arr &&
|
|
223
|
+
arr.length > 0 &&
|
|
224
|
+
arr.forEach((id) => {
|
|
225
|
+
//如果老组件的ID未在新的组件列表中找到,说明已被删除,就从场景中删除
|
|
226
|
+
this.childrenComponent['component_' + id] && this.childrenComponent['component_' + id].remove(this.scene);
|
|
227
|
+
});
|
|
228
|
+
nextArr &&
|
|
229
|
+
nextArr.length > 0 &&
|
|
230
|
+
nextArr.forEach((id) => {
|
|
231
|
+
//如果组件的ID未在老的组件列表中找到,说明是新增组件
|
|
232
|
+
var currentNextProps = this.filterItem(nextChildrenConfig, 'id', id)[0],
|
|
233
|
+
currentNextData = this.filterItem(nextChildrenData, 'id', id)[0],
|
|
234
|
+
{ base, configuration } = currentNextProps,
|
|
235
|
+
{ child } = this.filterItem(props.children, 'name', base.module_name)[0];
|
|
236
|
+
this.initChild(
|
|
237
|
+
id,
|
|
238
|
+
child,
|
|
239
|
+
Object.assign({}, currentNextProps, { config: reduceConfig(configuration), data: currentNextData.data })
|
|
240
|
+
);
|
|
241
|
+
});
|
|
242
|
+
nextChildren &&
|
|
243
|
+
nextChildren.length > 0 &&
|
|
244
|
+
nextChildren.forEach((id) => {
|
|
245
|
+
if (
|
|
246
|
+
nextArr.indexOf(id) < 0 &&
|
|
247
|
+
children.indexOf(id) > -1 &&
|
|
248
|
+
nextChildren.indexOf(id) > -1 &&
|
|
249
|
+
this.childrenComponent['component_' + id]
|
|
250
|
+
) {
|
|
251
|
+
let config = this.filterItem(nextProps.childrenConfig, 'id', id)[0].configuration,
|
|
252
|
+
data = this.filterItem(nextProps.childrenData, 'id', id)[0].data;
|
|
253
|
+
this.childrenComponent['component_' + id].update(config, data);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
getChildrenId(children = []) {
|
|
258
|
+
return children.map((item) => item.id);
|
|
259
|
+
}
|
|
260
|
+
differArr(arr, comparedArr) {
|
|
261
|
+
var tmp = [];
|
|
262
|
+
for (var i = 0, j = arr.length; i < j; i++) {
|
|
263
|
+
if (comparedArr.indexOf(arr[i]) < 0) {
|
|
264
|
+
tmp.push(arr[i]);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return tmp;
|
|
268
|
+
}
|
|
269
|
+
filterItem(arr, name, value) {
|
|
270
|
+
return arr.filter((item) => {
|
|
271
|
+
return item[name] === value;
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|