You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WebCAD/src/index.tsx

355 lines
8.8 KiB

7 years ago
import { ApplicationService } from "./Application";
import * as React from "react";
7 years ago
import * as ReactDOM from 'react-dom';
7 years ago
import { AppUi, CommandComponent, Contain } from './UI/AppUI';
7 years ago
import { Dialog, Terminal } from './UI/Dialog';
7 years ago
import '../node_modules/golden-layout/src/css/goldenlayout-base.css';
import '../node_modules/golden-layout/src/css/goldenlayout-dark-theme.css';
import "./UI/test.less"
7 years ago
import { Props } from './UI/demo';
7 years ago
import GoldenLayout = require('golden-layout')
7 years ago
// window.onload = function ()
// {
// var root = document.createElement('div');
// root.style.height = "100%";
// root.style.widows = "100%";
// document.body.appendChild(root);
// ReactDOM.render(<AppUi />,
// root
// );
7 years ago
7 years ago
// document.onselectstart = () =>
// {
// return false;
// }
7 years ago
7 years ago
// // let command = new Dialog("commands");
// // new Terminal(command);
7 years ago
7 years ago
// //test2();
// //test3();
// //test4()
// test5()
// // new ApplicationService();
7 years ago
// };
7 years ago
function test2()
{
7 years ago
var config = {
7 years ago
settings: {
hasHeaders: false,
showMaximiseIcon: true,
showCloseIcon: true
},
7 years ago
content: [{
type: 'column',
content: [{
type: 'component',
componentName: 'example',
componentState: { startCount: 6 }
}, {
type: 'stack',
content: [{
type: 'component',
componentName: 'example',
componentState: { startCount: 1 }
}, {
type: 'component',
componentName: 'example',
componentState: { startCount: 2 }
}]
}]
}]
};
let el = document.getElementById("webgl")
7 years ago
var myLayout = new GoldenLayout(config, document.body);
7 years ago
7 years ago
myLayout.registerComponent('example', function (container, state)
{
7 years ago
var counter = $('<div class="messageCounter">' + state.startCount + '</div>'),
btnContainer = $('<div class="btnContainer"></div>'),
count = state.startCount;
container.getElement().append(btnContainer);
7 years ago
function makeButton(label, increment)
{
7 years ago
var button = $('<button class="button">' + label + '</button>');
7 years ago
button.click(function ()
{
7 years ago
count += increment;
counter.text(count);
});
btnContainer.append(button);
}
// Add the counter element whenever a tab is created
7 years ago
container.on('tab', function (tab)
{
7 years ago
tab.element.append(counter);
});
7 years ago
container.on("resize", function ()
{
console.log("resize")
})
7 years ago
makeButton('+', 1);
makeButton('-', -1);
});
myLayout.init();
/*
* Since our layout is not a direct child
* of the body we need to tell it when to resize
*/
7 years ago
$(window).resize(function ()
{
7 years ago
myLayout.updateSize();
})
}
7 years ago
function test3()
{
7 years ago
var config = {
content: [{
type: 'row',
content: [
{
title: 'A react component',
type: 'react-component',
component: 'testItem',
7 years ago
props: { value: 'I\'m on the left 121' }
7 years ago
},
{
title: 'Another react component',
type: 'react-component',
component: 'testItem'
}
]
}]
};
let el = document.getElementById("webgl")
var myLayout = new GoldenLayout(config, el);
myLayout.registerComponent('testItem', React.createClass({
7 years ago
getInitialState: function ()
{
7 years ago
return { value: this.props.value || 'bla' };
},
7 years ago
setValue: function (e)
{
7 years ago
this.setState({ value: e.target.value });
},
7 years ago
setContainerTitle: function ()
{
7 years ago
this.props.glContainer.setTitle(this.state.value);
},
7 years ago
render: function ()
{
7 years ago
return (
<div>
<input type="text" value={this.state.value} onChange={this.setValue} />
<button onClick={this.setContainerTitle}>set title</button>
</div>
)
}
}));
myLayout.init()
7 years ago
}
//绘制无标题
function test4()
{
var config = {
settings: {
hasHeaders: false,
showMaximiseIcon: true,
showCloseIcon: true
},
dimensions: { borderWidth: 1 },
content: [{
type: 'column',
content: [{
type: 'row',
height: 8,
content: [{
type: 'react-component',
component: 'Contain',
props: { id: "webgl2" }
}],
},
{
type: 'row',
height: 2,
content: [{
type: 'react-component',
component: 'CommandComponent',
}]
}
]
}]
};
let el = document.getElementById("webgl")
var myLayout = new GoldenLayout(config, el);
myLayout.registerComponent('Contain', Contain);
myLayout.registerComponent('CommandComponent', CommandComponent);
myLayout.init()
myLayout.container.on("resize", (v) =>
{
console.log("test")
})
myLayout.eventHub.on("resize", () =>
{
console.log("ddd")
})
/*
* Since our layout is not a direct child
* of the body we need to tell it when to resize
*/
$(window).resize(function ()
{
myLayout.updateSize();
})
}
function test5()
{
var config = {
content: [{
type: 'column',
content: [{
type: 'component',
componentName: 'example',
componentState: { startCount: 6 }
}, {
type: 'stack',
content: [{
type: 'component',
componentName: 'example',
componentState: { startCount: 1 }
}, {
type: 'component',
componentName: 'example',
componentState: { startCount: 2 }
}]
}]
}]
};
let el = document.getElementById("webgl")
var myLayout = new GoldenLayout(config, el);
myLayout.registerComponent('example', function (container, state)
{
var counter = $('<div class="messageCounter">' + state.startCount + 'hello</div>');
container.on('tab', function (tab)
{
tab.element.append(counter);
});
container.on("resize", function ()
{
console.log("resize")
})
});
myLayout.init();
}
function test6()
{
var config = {
settings: {
hasHeaders: false,
showMaximiseIcon: true,
showCloseIcon: true
},
dimensions: { borderWidth: 1 },
content: [{
type: 'column',
content: [{
type: 'row',
height: 8,
content: [{
type: 'component',
componentName: 'container',
props: { id: "webgl2" }
}],
},
{
type: 'row',
height: 2,
content: [{
type: 'component',
componentName: 'container',
props: { id: "webgl" }
}]
}
]
}]
};
var myLayout = new GoldenLayout(config, document.body);
myLayout.registerComponent('container', function (container, state)
{
var counter = $('<div>' + state.startCount + '</div>'),
btnContainer = $(`<div id=${state.id} class="btnContainer"></div>`),
count = state.startCount;
container.getElement().append(btnContainer);
container.getElement().append($("<div>hello word</div>"))
function makeButton(label, increment)
{
var button = $('<button class="button">' + label + '</button>');
button.click(function ()
{
count += increment;
counter.text(count);
});
btnContainer.append(button);
}
// Add the counter element whenever a tab is created
container.on('tab', function (tab)
{
tab.element.append(counter);
});
container.on("resize", function ()
{
console.log("resize")
})
makeButton('+', 1);
makeButton('-', -1);
});
myLayout.init()
}
window.onload = () =>
{
test6()
7 years ago
}