|
|
@@ -9,6 +9,7 @@ const { Search } = Input
|
|
|
class DashboardMenu extends React.Component {
|
|
|
|
|
|
constructor(props) {
|
|
|
+ console.log('create');
|
|
|
super(props);
|
|
|
this.state = {
|
|
|
editingKey: null,
|
|
|
@@ -22,10 +23,40 @@ class DashboardMenu extends React.Component {
|
|
|
dispatch({ type: 'dashboard/remoteMenuTree' });
|
|
|
}
|
|
|
|
|
|
+ cloneTree = (tree) => {
|
|
|
+ let arr = [];
|
|
|
+ tree.forEach(t => {
|
|
|
+ let obj = { ...t, children: []};
|
|
|
+ if(t.children && t.children.length > 0) {
|
|
|
+ obj.children = this.cloneTree(t.children);
|
|
|
+ }
|
|
|
+ arr.push(obj);
|
|
|
+ });
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
+
|
|
|
+ reduceTree = (tree) => {
|
|
|
+ let arr = [ ...tree ];
|
|
|
+ for(let i = arr.length - 1; i >= 0; i--) {
|
|
|
+ let t = arr[i];
|
|
|
+ if(t.children && t.children.length > 0) {
|
|
|
+ t.children = this.reduceTree(t.children);
|
|
|
+ }
|
|
|
+ if((!t.children || t.children.length === 0) && t.type !== 'dashboard') {
|
|
|
+ arr.splice(i, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
+
|
|
|
generateMenu(tree, regLabel) {
|
|
|
const { mode, dispatch } = this.props;
|
|
|
const { editingKey } = this.state;
|
|
|
- return tree.filter(t => (mode === 'view' || t.type === 'menu')).sort((a, b) => a.index - b.index).map(t => {
|
|
|
+ let ftree = this.cloneTree(tree);
|
|
|
+ if(mode === 'view') {
|
|
|
+ ftree = this.reduceTree(ftree)
|
|
|
+ }
|
|
|
+ return ftree.filter(t => (mode === 'view' || t.type === 'menu')).sort((a, b) => a.index - b.index).map(t => {
|
|
|
let title = <div className='node-title'>
|
|
|
<span>{ (t.code !== editingKey) ?
|
|
|
( regLabel ? ( <span style={{ fontWeight: t.type === 'dashboard' ? 'bold' : 'normal' }}>
|