This repository has been archived by the owner on Sep 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.js
94 lines (83 loc) · 2.49 KB
/
App.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React, { Component } from 'react';
import './app.css';
import 'micro-design-editor/css/index.css';
import Design from 'micro-design-editor/es/index';
import _cloneDeep from 'lodash/cloneDeep';
import navigationBarConf from './components/navigationBar';
import searchConf from './components/search';
import noticeConf from './components/notice';
import { Button, Notify } from 'zent';
const groupedComponents = [
navigationBarConf,
Design.group('基础'),
searchConf,
noticeConf,
Design.group('其他'),
searchConf,
];
class App extends Component {
state = {
value: [
{
type: navigationBarConf.type,
...navigationBarConf.editor.getInitialValue()
}
]
};
onChange = newValue => {
this.setState({ value: newValue });
}
onSettingsChange = newSettings => {
this.setState({ settings: newSettings });
}
/**
* @param {Design} instance - Design 组件的实例, 用于调用组件里的方法
*/
saveDesign = instance => {
this.design = instance && instance.getDecoratedComponentInstance();
// 恢复上一次未保存数据
const cache = this.design && this.design.readCache();
if (Array.isArray(cache)) {
this.setState({ value: cache });
}
}
onFormSubmit = () => {
this.design.validate()
.then(() => {
// 如果需要对数据处理,需要对原数据进行拷贝
let data = _cloneDeep(this.state.value);
const stringify = JSON.stringify(data, null, 2);
console.log(stringify);
// 标记为以保存状态,如果使用了缓存或者离开提示需要手动调用这个函数通知 Design 更改已经保存
// localStorage 将被清除
this.design.markAsSaved();
Notify.success('保存成功');
})
.catch(validations => {
Notify.warning('保存失败, 请检查配置');
});
}
render() {
return (
<div className="design-page">
<Design
ref={this.saveDesign}
cache
cacheId="micro-design"
confirmUnsavedLeave={false}
components={groupedComponents}
value={this.state.value}
onChange={this.onChange}
settings={this.state.settings}
onSettingsChange={this.onSettingsChange}
scrollTopOffset={-270}
globalConfig={window._global}
/>
<div className="design-bottom-action">
<Button type="primary" onClick={this.onFormSubmit}>保存并继续</Button>
</div>
</div>
);
}
}
export default App;