You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.8 KiB
JavaScript
71 lines
1.8 KiB
JavaScript
(function () {
|
|
var grid = null;
|
|
|
|
/** 初始化 */
|
|
var init = function () {
|
|
grid = GridStack.init({
|
|
// 一行高度
|
|
cellHeight: 80,
|
|
// 间距
|
|
margin: 5,
|
|
minRow: 5,
|
|
acceptWidgets: true,
|
|
});
|
|
GridStack.setupDragIn('#components-panel > .component-item', undefined, [
|
|
{ w: 12, h: 2, content: '轮播图' },
|
|
{ w: 2, h: 1, content: '搜索' },
|
|
]);
|
|
console.log(grid, 'grid实例');
|
|
|
|
var initData = [
|
|
// {
|
|
// x: 0,
|
|
// y: 0,
|
|
// w: 2,
|
|
// h: 2,
|
|
// content: 'item 1',
|
|
// data: {
|
|
// name: 'item 1',
|
|
// },
|
|
// },
|
|
// {
|
|
// x: 2,
|
|
// y: 3,
|
|
// w: 3,
|
|
// content: 'item 2',
|
|
// data: {
|
|
// name: 'item 2',
|
|
// },
|
|
// },
|
|
];
|
|
// grid.load(initData);
|
|
|
|
grid.engine.nodes.forEach((item) => {
|
|
item.el.firstChild.addEventListener('click', () => {
|
|
console.log(item);
|
|
});
|
|
});
|
|
|
|
grid.on('added', function (_event, itemArray) {
|
|
console.log(itemArray, '这里触发了添加了added事件');
|
|
itemArray.forEach((item) => {
|
|
item.el.firstChild.addEventListener('click', () => {
|
|
console.log(item);
|
|
});
|
|
});
|
|
});
|
|
};
|
|
|
|
$('.save').click(function () {
|
|
grid.addWidget({ w: 2, content: 'item 1' });
|
|
grid.engine.nodes[0].data.name += '_test';
|
|
console.log(grid.save());
|
|
console.log(grid);
|
|
});
|
|
|
|
/** 执行方法 */
|
|
$(function () {
|
|
init();
|
|
});
|
|
})();
|