feat: 拖拽布局-完整demo数据结构

master
lichaojun 2 weeks ago
parent 2645752d85
commit 12e9833c08

@ -0,0 +1,680 @@
{
"layoutId": "simple_buttons_images", //ID
"version": "1.0.0", //
"name": "Test 222222", //
"width": 1920, //
"height": 1080, //
"focusConfig": {
"defaultFocusId": "btn_home" //ID
},
"rootView": {
"id": "root_container", //ID
"type": "LinearLayout", //
"x": 0, //xAbsoluteLayout
"y": 0, //yAbsoluteLayout
"leftMargin": 0, //
"topMargin": 0, //
"rightMargin": 0, //
"bottomMargin": 0, //
"width": -1, //MATCH_PARENT = -1; WRAP_CONTENT = -2;>=0
"height": -1, //MATCH_PARENT = -1; WRAP_CONTENT = -2;>=0
"orientation": 1, //LinearLayout HORIZONTAL=0VERTICAL=1
"background": { //background
"color": "#FFFFFF", //
"imageUrl": "", //
"cornerRadius": { //
"topLeft": 8, //
"topRight": 8, //
"bottomLeft": 8, //
"bottomRight": 8 //
},
"border": { //
"width": 2, //线
"color": "#1976D2" //
}
},
"children": [
{
"id": "header",//ID
"type": "LinearLayout",//
"x": 0,
"y": 10,
"leftMargin": 0,
"topMargin": 0,
"rightMargin": 0,
"bottomMargin": 0,
"width": 1920,
"height": 100,
"orientation": 0,//LinearLayout HORIZONTAL=0VERTICAL=1
"background": {
"color": "#2196F3"
},
"children": [
{
"id": "title_text",
"type": "TextView",
"x": 0,
"y": 20,
"leftMargin": 0,
"topMargin": 0,
"rightMargin": 0,
"bottomMargin": 0,
"width": 1920,
"height": 60,
"text": "Test 33333333333333", //
"textSize": 24, //
"textColor": "#FFFFFF", //
"bold": true, //
"focusable": false //
}
]
},
{
"id": "main_content",//ID
"type": "LinearLayout",//
"x": 0,
"y": 80,
"leftMargin": 0,
"topMargin": 0,
"rightMargin": 0,
"bottomMargin": 0,
"width": 1920,
"height": -2,
"orientation": 1,
"background": {
"color": "#FFFFFF"
},
"children": [
{
"id": "buttons_row",//ID
"type": "LinearLayout",//
"x": 0,
"y": 0,
"leftMargin": 0,
"topMargin": 40,
"rightMargin": 0,
"bottomMargin": 0,
"width": 1920,
"height": 100,
"orientation": 0,
"gravity": 17, //17488035
"background": {
"color": "#673AB7"
},
"children": [
{
"id": "btn_home",
"type": "LinearLayout",
"x": 0,
"y": 0,
"leftMargin": 0,
"topMargin": 0,
"rightMargin": 0,
"bottomMargin": 0,
"width": 100,
"height": 100,
"orientation": 1,
"gravity": 17,
"focusable": true //true
"children": [
{
"id": "btn_home1",
"type": "TextView",
"x": 0,
"y": 0,
"leftMargin": 0,
"topMargin": 0,
"rightMargin": 0,
"bottomMargin": 0,
"width": 100,
"height": 40,
"text": "首页",
"gravity": 17,
"textSize": 20,
"textColor": "#29303f",
"background": {
"color": "#2196F3",
"cornerRadius": {
"topLeft": 8,
"topRight": 8,
"bottomLeft": 8,
"bottomRight": 8
},
"border": {
"width": 2,
"color": "#1976D2"
}
}
},
{
"id": "image_nature1",
"type": "ImageView",
"x": 0,
"y": 0,
"leftMargin": 0,
"topMargin": 0,
"rightMargin": 0,
"bottomMargin": 0,
"width": 50,
"height": 50,
"imageUrl": "https://images.unsplash.com/photo-1501854140801-50d01698950b", //线
"placeholder": "https://via.placeholder.com/400x400/CCCCCC/FFFFFF?text=Nature", //线
"scaleType": "CENTER_CROP", // FIT_XY, FIT_CENTER, CENTER_CROP, CENTER_INSIDE
"background": {
"color": "#E0E0E0",
"cornerRadius": {
"topLeft": 12,
"topRight": 12,
"bottomLeft": 12,
"bottomRight": 12
}
}
}
],
"background": {
"color": "#2196F3",
"cornerRadius": {
"topLeft": 8,
"topRight": 8,
"bottomLeft": 8,
"bottomRight": 8
},
"border": { //
"width": 2, //线
"color": "#1976D2" //
}
},
"focusConfig": { //
"upId": null, //ViewID
"downId": "images_row",//ViewID
"leftId": null, //ViewID
"rightId": "btn_settings",//ViewID
"focusable": true, //
"focusableInTouchMode": false, //
"defaultFocus": true, //
"focusedStyle": { //
"background": {
"color": "#1976D2" //
},
"border": { //
"width": 3, //线
"color": "#0D47A1" //
},
"scale": 1.1, //300
"focusAnimation": "scale", //scalepulse
"animationDuration": 300 //
},
},
"events": [
{
"type": "click",
"action": "custom",
"params": {
"message": "首页按钮被点击"
}
}
]
},
{
"id": "btn_settings",//ID
"type": "TextView",//
"x": 0,
"y": 0,
"leftMargin": 40,
"topMargin": 0,
"rightMargin": 0,
"bottomMargin": 0,
"width": 200,
"height": 80,
"text": "设置",
"gravity": 17,
"textSize": 20,
"textColor": "#29303f",
"background": {
"color": "#FF9800",
"cornerRadius": {
"topLeft": 8,
"topRight": 8,
"bottomLeft": 8,
"bottomRight": 8
}
},
"focusConfig": {
"upId": null,
"downId": "images_row",
"leftId": "btn_home",
"rightId": "btn_info",
"focusable": true,
"focusableInTouchMode": false,
"focusedStyle": {
"background": {
"color": "#F57C00"
},
"border": {
"width": 3,
"color": "#E65100"
},
"scale": 1.1,
"focusAnimation": "scale", //scalepulse
"animationDuration": 300 //
}
},
"events": [ //APP
{
"type": "click",
"action": "custom",
"params": {
"message": "设置按钮被点击"
}
}
]
},
{
"id": "btn_info",//ID
"type": "TextView",//
"x": 0,
"y": 0,
"leftMargin": 40,
"topMargin": 0,
"rightMargin": 0,
"bottomMargin": 0,
"width": 200,
"height": 80,
"text": "信息",
"gravity": 17,
"textSize": 20,
"textColor": "#29303f",
"background": {
"color": "#4CAF50",
"cornerRadius": {
"topLeft": 8,
"topRight": 8,
"bottomLeft": 8,
"bottomRight": 8
}
},
"focusConfig": {
"upId": null,
"downId": "images_row",
"leftId": "btn_settings",
"rightId": "btn_help",
"focusable": true,
"focusableInTouchMode": false,
"focusedStyle": {
"background": {
"color": "#388E3C"
},
"border": {
"width": 3,
"color": "#1B5E20"
},
"scale": 1.1,
"focusAnimation": "scale", //scalepulse
"animationDuration": 300 //
}
},
"events": [
{
"type": "click",
"action": "custom",
"params": {
"message": "信息按钮被点击"
}
}
]
},
{
"id": "btn_help",//ID
"type": "TextView",//
"x": 0,
"y": 0,
"leftMargin": 40,
"topMargin": 0,
"rightMargin": 0,
"bottomMargin": 0,
"width": 200,
"height": 80,
"text": "帮助",
"gravity": 17,
"textSize": 20,
"textColor": "#29303f",
"background": {
"color": "#9C27B0",
"cornerRadius": {
"topLeft": 8,
"topRight": 8,
"bottomLeft": 8,
"bottomRight": 8
}
},
"focusConfig": {
"upId": null,
"downId": "images_row",
"leftId": "btn_info",
"rightId": null,
"focusable": true,
"focusableInTouchMode": false,
"focusedStyle": {
"background": {
"color": "#7B1FA2"
},
"border": {
"width": 3,
"color": "#4A148C"
},
"scale": 1.1,
"focusAnimation": "scale", //scalepulse
"animationDuration": 300 //
}
},
"events": [
{
"type": "click",
"action": "custom",
"params": {
"message": "帮助按钮被点击"
}
}
]
}
]
},
{
"id": "images_row",//ID
"type": "LinearLayout",//
"x": 0,
"y": 0,
"leftMargin": 0,
"topMargin": 80,
"rightMargin": 0,
"bottomMargin": 0,
"width": 1920,
"height": 500,
"orientation": 0,
"gravity": 17,
"background": {
"color": "#FFFFFF"
},
"children": [
{
"id": "image_nature",
"type": "ImageView",
"x": 0,
"y": 0,
"leftMargin": 0,
"topMargin": 0,
"rightMargin": 0,
"bottomMargin": 0,
"width": 400,
"height": 400,
"imageUrl": "https://images.unsplash.com/photo-1501854140801-50d01698950b",
"placeholder": "https://via.placeholder.com/400x400/CCCCCC/FFFFFF?text=Nature",
"scaleType": "CENTER_CROP",
"background": {
"color": "#E0E0E0",
"cornerRadius": { //
"topLeft": 12,
"topRight": 12,
"bottomLeft": 12,
"bottomRight": 12
}
},
"shadow": {//
"radius": 8,
"offsetX": 0,
"offsetY": 4,
"color": "#20000000"
},
"focusConfig": {
"upId": "btn_home",
"downId": null,
"leftId": null,
"rightId": "image_tech",
"focusable": true,
"focusableInTouchMode": false,
"focusedStyle": {
"background": {
"color": "#BBDEFB"
},
"border": {
"width": 4,
"color": "#2196F3"
},
"scale": 1.05,
"focusAnimation": "border",
"animationDuration": 300
}
},
"events": [
{
"type": "click",
"action": "custom",
"params": {
"message": "自然图片被点击",
"imageId": "nature"
}
}
]
},
{
"id": "image_tech",//ID
"type": "ImageView",//
"x": 0,
"y": 0,
"leftMargin": 80,
"topMargin": 0,
"rightMargin": 0,
"bottomMargin": 0,
"width": 400,
"height": 400,
"imageUrl": "https://images.unsplash.com/photo-1518709268805-4e9042af2176",
"placeholder": "https://via.placeholder.com/400x400/CCCCCC/FFFFFF?text=Tech",
"scaleType": "CENTER_CROP",
"background": {
"color": "#E0E0E0",
"cornerRadius": {
"topLeft": 12,
"topRight": 12,
"bottomLeft": 12,
"bottomRight": 12
}
},
"shadow": {
"radius": 8,
"offsetX": 0,
"offsetY": 4,
"color": "#20000000"
},
"focusConfig": {
"upId": "btn_settings",
"downId": null,
"leftId": "image_nature",
"rightId": "image_food",
"focusable": true,
"focusableInTouchMode": false,
"focusedStyle": {
"background": {
"color": "#FFECB3"
},
"border": {
"width": 4,
"color": "#FF9800"
},
"scale": 1.05,
"focusAnimation": "border",
"animationDuration": 300
}
},
"events": [
{
"type": "click",
"action": "custom",
"params": {
"message": "科技图片被点击",
"imageId": "tech"
}
}
]
},
{
"id": "image_food",//ID
"type": "ImageView",//
"x": 0,
"y": 0,
"leftMargin": 80,
"topMargin": 0,
"rightMargin": 0,
"bottomMargin": 0,
"width": 400,
"height": 400,
"imageUrl": "https://images.unsplash.com/photo-1565958011703-44f9829ba187",
"placeholder": "https://via.placeholder.com/400x400/CCCCCC/FFFFFF?text=Food",
"scaleType": "CENTER_CROP",
"background": {
"color": "#E0E0E0",
"cornerRadius": {
"topLeft": 12,
"topRight": 12,
"bottomLeft": 12,
"bottomRight": 12
}
},
"shadow": { //
"radius": 8,
"offsetX": 0,
"offsetY": 4,
"color": "#20000000"
},
"focusConfig": {
"upId": "btn_info",
"downId": null,
"leftId": "image_tech",
"rightId": "image_travel",
"focusable": true,
"focusableInTouchMode": false,
"focusedStyle": {
"background": {
"color": "#C8E6C9"
},
"border": {
"width": 4,
"color": "#4CAF50"
},
"scale": 1.05,
"focusAnimation": "pulse",
"animationDuration": 300
}
},
"events": [
{
"type": "click",
"action": "custom",
"params": {
"message": "美食图片被点击",
"imageId": "food"
}
}
]
},
{
"id": "image_travel",//ID
"type": "ImageView",//
"x": 0,
"y": 0,
"leftMargin": 80,
"topMargin": 0,
"rightMargin": 0,
"bottomMargin": 0,
"width": 400,
"height": 400,
"imageUrl": "https://images.unsplash.com/photo-1488646953014-85cb44e25828",
"placeholder": "https://via.placeholder.com/400x400/CCCCCC/FFFFFF?text=Travel",
"scaleType": "CENTER_CROP",
"background": {
"color": "#E0E0E0",
"cornerRadius": {
"topLeft": 12,
"topRight": 12,
"bottomLeft": 12,
"bottomRight": 12
}
},
"shadow": {
"radius": 8,
"offsetX": 0,
"offsetY": 4,
"color": "#20000000"
},
"focusConfig": {
"upId": "btn_help",
"downId": null,
"leftId": "image_food",
"rightId": null,
"focusable": true,
"focusableInTouchMode": false,
"focusedStyle": {
"background": {
"color": "#E1BEE7"
},
"border": {
"width": 4,
"color": "#9C27B0"
},
"scale": 1.05
}
},
"events": [
{
"type": "click",
"action": "custom",
"params": {
"message": "旅行图片被点击",
"imageId": "travel"
}
}
]
}
]
}
]
},
{
"id": "footer",//ID
"type": "LinearLayout",//
"x": 0,
"y": 0,
"leftMargin": 0,
"topMargin": 80,
"rightMargin": 0,
"bottomMargin": 0,
"width": 1920,
"height": 100,
"orientation": 0,
"gravity": 17,
"background": {
"color": "#263238"
},
"children": [
{
"id": "footer_text",//ID
"type": "TextView",//
"x": 0,
"y": 30,
"leftMargin": 0,
"topMargin": 0,
"rightMargin": 0,
"bottomMargin": 0,
"width": 1920,
"height": 40,
"text": "Test 1111111",
"textSize": 24,
"textColor": "#B0BEC5",
"gravity": 17,
"focusable": false
}
]
}
]
}
}

@ -229,6 +229,10 @@ form {
border-color: #007bff;
}
.form-item select {
width: 100%;
}
.form-actions {
display: flex;
justify-content: space-between;

Binary file not shown.

After

Width:  |  Height:  |  Size: 462 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

@ -38,22 +38,10 @@
</div>
<div class="components-list">
<div class="component-item grid-stack-item">
<div class="grid-stack-item-content"><i class="fas fa-images"></i><span>轮播</span></div>
<div class="grid-stack-item-content"><span></span></div>
</div>
<div class="component-item grid-stack-item">
<div class="grid-stack-item-content"><i class="fas fa-search"></i><span>搜索</span></div>
</div>
<div class="component-item grid-stack-item">
<div class="grid-stack-item-content"><i class="fas fa-tv"></i><span>热门频道</span></div>
</div>
<div class="component-item grid-stack-item">
<div class="grid-stack-item-content"><i class="fas fa-video"></i><span>直播</span></div>
</div>
<div class="component-item grid-stack-item">
<div class="grid-stack-item-content"><i class="fas fa-thumbs-up"></i><span>推荐内容</span></div>
</div>
<div class="component-item grid-stack-item">
<div class="grid-stack-item-content"><i class="fas fa-link"></i><span>快捷入口</span></div>
<div class="grid-stack-item-content"><span>文字</span></div>
</div>
</div>
<div
@ -85,12 +73,29 @@
<div class="wait-box">请选择组件</div>
<form class="hidden">
<div class="form-item">
<label for="name">名称</label>
<label for="childrenType">组件子类型</label>
<input
type="text"
id="childrenType"
/>
</div>
<div class="form-item">
<label for="name">组件名称</label>
<input
type="text"
id="name"
/>
</div>
<div class="form-item">
<label for="image">背景图片</label>
<select id="image">
<option value="">请选择</option>
<option value="./image/1.png">图片一</option>
<option value="./image/2.jpg">图片二</option>
<option value="./image/3.jpg">图片三</option>
<option value="./image/4.jpg">图片四</option>
</select>
</div>
<div class="form-item">
<label for="background">背景颜色</label>
<input
@ -113,23 +118,65 @@
/>
</div>
<div class="form-item">
<label for="icon">图标名称</label>
<label for="text">文字内容</label>
<input
type="text"
id="text"
/>
</div>
<div class="form-item">
<label for="fontWeight">文字宽度</label>
<input
type="text"
id="icon"
id="fontWeight"
/>
</div>
<div class="form-item">
<label for="detail">描述</label>
<textarea id="detail"></textarea>
<label for="eventsType">事件类型</label>
<input
type="text"
id="eventsType"
/>
</div>
<div class="form-item">
<label for="eventsAction">事件动作</label>
<input
type="text"
id="eventsAction"
/>
</div>
<div class="form-item">
<label for="link">跳转链接</label>
<label for="defaultFocus">默认聚焦</label>
<input
type="text"
id="link"
id="defaultFocus"
/>
</div>
<div class="form-item">
<label for="leftId">向左侧移动组件ID</label>
<select id="leftId">
<option value="">请选择</option>
</select>
</div>
<div class="form-item">
<label for="rightId">向右侧移动组件ID</label>
<select id="rightId">
<option value="">请选择</option>
</select>
</div>
<div class="form-item">
<label for="upId">向上侧移动组件ID</label>
<select id="upId">
<option value="">请选择</option>
</select>
</div>
<div class="form-item">
<label for="downId">向下侧移动组件ID</label>
<select id="downId">
<option value="">请选择</option>
</select>
</div>
<!-- <div class="form-actions">
<button
type="button"

@ -18,9 +18,13 @@
initData = {
id: `grid_${generateUniqueId()}`,
children: [],
version: '1.0.0',
width: 1920,
height: 1080,
};
} else {
initData = JSON.parse(initDataStorage);
conputedInitData('init');
}
console.log(initData, 'initData');
@ -43,18 +47,38 @@
});
GridStack.setupDragIn('#components-panel .component-item', undefined, [
{
w: 12,
h: 1,
type: 'banner',
name: '我是轮播图',
fontSize: 14,
color: '#333',
w: 2,
h: 4,
type: 'image',
name: '图片',
image: '',
eventsType: 'click',
eventsAction: '',
defaultFocus: false,
leftId: '',
rightId: '',
upId: '',
downId: '',
},
{
w: 2,
h: 2,
type: 'text',
childrenType: '',
name: '文本',
background: '#fff',
detail: '',
icon: 'fa-image',
link: '',
fontSize: '14px',
color: '#333',
text: '文本',
fontWeight: 'normal',
eventsType: 'click',
eventsAction: '',
defaultFocus: false,
leftId: '',
rightId: '',
upId: '',
downId: '',
},
{ w: 2, h: 1 },
]);
console.log(grid, 'grid实例');
@ -98,6 +122,41 @@
}
// 将当前选中组件的属性显示在右侧列表中
setCurrentComponentProps(currentComponent);
// 设置上下左右移动组件ID
setMoveComponentId(currentComponent);
});
};
// 设置上下左右移动组件ID
var setMoveComponentId = function (component) {
const allComponents = grid.save();
if (allComponents.length <= 1) {
return;
}
setMoveComponentHtml('leftId', component, allComponents);
setMoveComponentHtml('rightId', component, allComponents);
setMoveComponentHtml('upId', component, allComponents);
setMoveComponentHtml('downId', component, allComponents);
};
var setMoveComponentHtml = function (idName, component, allComponents) {
let componentsHtml = [{ value: '', text: '请选择' }];
allComponents
.filter((item) => item.id !== component.id)
.map((item) => {
componentsHtml.push({ value: item.id, text: `${item.name}(${item.id})`, selected: item.id === component[idName] });
});
let el = $(`#${idName}`);
el.empty();
componentsHtml.forEach((item) => {
el.append(
$('<option>', {
value: item.value,
text: item.text,
selected: item.selected || false,
})
);
});
};
@ -106,7 +165,6 @@
currentComponent = null;
// 右侧显示请选择组件
if (!$('#props-panel').find('wait-box').is(':visible')) {
console.log('111');
$('#props-panel').find('.wait-box').show();
$('#props-panel').find('form').hide();
}
@ -116,33 +174,74 @@
//将当前选中组件的属性显示在右侧列表中
var setCurrentComponentProps = function (component) {
const form = $('#props-panel').find('form');
if (component.hasOwnProperty('childrenType')) {
form.find('#childrenType').val(component.childrenType);
form.find('#childrenType').parent().show();
} else {
form.find('#childrenType').parent().hide();
}
form.find('#name').val(component.name);
form.find('#background').val(component.background);
form.find('#fontSize').val(component.fontSize);
form.find('#color').val(component.color);
form.find('#icon').val(component.icon);
form.find('#detail').val(component.detail);
form.find('#link').val(component.link);
if (component.hasOwnProperty('image')) {
form.find('#image').val(component.image);
form.find('#image').parent().show();
} else {
form.find('#image').parent().hide();
}
if (component.hasOwnProperty('background')) {
form.find('#background').val(component.background);
form.find('#background').parent().show();
} else {
form.find('#background').parent().hide();
}
if (component.type === 'text') {
form.find('#text').val(component.text);
form.find('#fontSize').val(component.fontSize);
form.find('#color').val(component.color);
form.find('#fontWeight').val(component.fontWeight);
form.find('#text').parent().show();
form.find('#fontSize').parent().show();
form.find('#color').parent().show();
form.find('#fontWeight').parent().show();
} else {
form.find('#text').parent().hide();
form.find('#fontSize').parent().hide();
form.find('#color').parent().hide();
form.find('#fontWeight').parent().hide();
}
form.find('#eventsType').val(component.eventsType);
form.find('#eventsAction').val(component.eventsAction);
form.find('#defaultFocus').val(component.defaultFocus);
form.find('#leftId').val(component.leftId);
form.find('#rightId').val(component.rightId);
form.find('#upId').val(component.upId);
form.find('#downId').val(component.downId);
};
// 定义组件设置配置策略
const componentStrategies = {
name: function (el, value) {
el.find('span').text(value);
},
background: function (el, value) {
el.find('.grid-stack-item-content').css('background', value);
},
image: function (el, value) {
el.find('.grid-stack-item-content').css('background', `url(${value}) no-repeat center center`).css('background-size', 'cover');
},
fontSize: function (el, value) {
el.find('span').css('font-size', value + 'px');
},
color: function (el, value) {
el.find('span').css('color', value);
},
icon: function (el, value) {
el.find('i').attr('class', `fas ${value}`);
text: function (el, value) {
el.find('span').text(value);
},
fontWeight: function (el, value) {
el.find('span').css('font-weight', value);
},
// detail, link不需要反显页面所有不需要修改dom
};
// 设置当前传递组件的视图展示
@ -162,14 +261,20 @@
// 定义映射关系元素ID -> 事件类型 -> 组件属性
const elementMappings = {
name: { event: 'blur', property: 'name' },
childrenType: { event: 'blur', property: 'childrenType' },
background: { event: 'blur', property: 'background' },
image: { event: 'change', property: 'image' },
fontSize: { event: 'blur', property: 'fontSize' },
color: { event: 'blur', property: 'color' },
icon: { event: 'blur', property: 'icon' },
detail: { event: 'blur', property: 'detail' },
link: { event: 'blur', property: 'link' },
// icon: { event: 'change', property: 'icon' }, // select使用change
text: { event: 'blur', property: 'text' },
fontWeight: { event: 'blur', property: 'fontWeight' },
eventsType: { event: 'blur', property: 'eventsType' },
eventsAction: { event: 'blur', property: 'eventsAction' },
defaultFocus: { event: 'blur', property: 'defaultFocus' },
leftId: { event: 'change', property: 'leftId' },
rightId: { event: 'change', property: 'rightId' },
upId: { event: 'change', property: 'upId' },
downId: { event: 'change', property: 'downId' },
};
// 统一绑定函数
@ -189,12 +294,44 @@
});
};
// 保存的时候计算x,y,w,h
var conputedInitData = function (type) {
if (type === 'save') {
let initDataCopy = JSON.parse(JSON.stringify(initData));
initDataCopy.children.forEach((item) => {
item.xCopy = item.x;
item.x = item.x * (1920 / 12);
item.yCopy = item.y;
item.y = item.y * cellHeight;
item.wCopy = item.w;
item.w = item.w * (1920 / 12);
if (!item.hasOwnProperty('h')) {
item.h = 1;
}
item.hCopy = item.h;
item.h = item.h * cellHeight;
});
console.log(initDataCopy);
return initDataCopy;
}
if (type === 'init') {
initData.children.forEach((item) => {
item.x = item.xCopy;
item.y = item.yCopy;
item.w = item.wCopy;
item.h = item.hCopy;
});
}
};
$('.save-container').click(function () {
// grid.addWidget({ w: 2, content: 'item 1' });
console.log(grid.save());
console.log(grid);
// console.log(grid.save());
// console.log(grid);
initData.children = grid.save();
localStorage.setItem('initData', JSON.stringify(initData));
console.log(initData);
localStorage.setItem('initData', JSON.stringify(conputedInitData('save')));
});
/** 执行方法 */

Loading…
Cancel
Save