|
@@ -70,6 +70,7 @@ const state = {
|
|
|
//4.构造的网站数据 start------------------------------------------------------------>
|
|
|
editWindowStatus:false,//编辑组件弹出框是否显示
|
|
|
editComponentWindowStatus:false,//选择组件样式弹出框是否显示
|
|
|
+ editWebsiteTemplateJsonWindow:false,//当前准备提交的数据 后期删除
|
|
|
editWindowTitle:"",//编辑弹出框标题
|
|
|
editSectorId:0,//当前正在编辑的板块id
|
|
|
editDataSort:0,//当前正在编辑的数据位置
|
|
@@ -160,6 +161,10 @@ const mutations = {
|
|
|
closeComponentStyleStatus(state){
|
|
|
state.editComponentWindowStatus = false;
|
|
|
},
|
|
|
+ //关闭提交数据弹出框
|
|
|
+ closeEditWebsiteTemplateJsonWindow(state){
|
|
|
+ state.editWebsiteTemplateJsonWindow = false;
|
|
|
+ },
|
|
|
//选择组件样式
|
|
|
selectComponentStyleNumber(state,data){
|
|
|
state.editComponentStyle = data;
|
|
@@ -218,31 +223,72 @@ const mutations = {
|
|
|
Message.error('最多只能添加10个模块!');
|
|
|
return;
|
|
|
}else{
|
|
|
- //通过时间戳生成id
|
|
|
- const currentTimestamp = Date.now();
|
|
|
- let id = currentTimestamp;
|
|
|
- //data.type 组件名称 data.h 模块高度
|
|
|
- //计算当前布局的最大 y 值
|
|
|
- const maxY = Math.max(...state.pageData.index.map(item => item.y), 0);
|
|
|
- console.log(data);
|
|
|
- //设置数据在构建json中的位置
|
|
|
- let dataSort = state.pageData.index.length;
|
|
|
- //添加板块id
|
|
|
- state.pageData.index.push({
|
|
|
- //i: state.pageData.index.length, //base 0.0.1 此方法会导致重复的id出现
|
|
|
- i: id,
|
|
|
- x: 0,
|
|
|
- y: maxY + 1,
|
|
|
- w: 12,
|
|
|
- h: data.h,
|
|
|
- type: data.type,
|
|
|
- //sectorData:data.jsonData //base 0.0.1 此问题导致深层数据无法被视图渲染
|
|
|
- content:data.jsonData,
|
|
|
- dataSort:dataSort
|
|
|
- });
|
|
|
- console.log("当前添加模块的dataSort为:" + dataSort);
|
|
|
- //当前的页面构建数据
|
|
|
- console.log(state.pageData.index);
|
|
|
+ //判断是拖拽的还是点击添加进来的 click=点击
|
|
|
+ if(data.source == "click"){
|
|
|
+ console.log("通过点击添加一个板块");
|
|
|
+ //通过时间戳生成id
|
|
|
+ const currentTimestamp = Date.now();
|
|
|
+ let id = currentTimestamp;
|
|
|
+ //data.type 组件名称 data.h 模块高度
|
|
|
+ //计算当前布局的最大 y 值
|
|
|
+ const maxY = Math.max(...state.pageData.index.map(item => item.y), 0);
|
|
|
+ console.log(data);
|
|
|
+ //设置数据在构建json中的位置
|
|
|
+ let dataSort = state.pageData.index.length;
|
|
|
+ //添加板块id
|
|
|
+ state.pageData.index.push({
|
|
|
+ //i: state.pageData.index.length, //base 0.0.1 此方法会导致重复的id出现
|
|
|
+ i: id,
|
|
|
+ x: 0,
|
|
|
+ y: maxY + 1,
|
|
|
+ w: 12,
|
|
|
+ h: data.h,
|
|
|
+ type: data.type,
|
|
|
+ //sectorData:data.jsonData //base 0.0.1 此问题导致深层数据无法被视图渲染
|
|
|
+ content:data.jsonData,
|
|
|
+ dataSort:dataSort
|
|
|
+ });
|
|
|
+ console.log("当前添加模块的dataSort为:" + dataSort);
|
|
|
+ //当前的页面构建数据
|
|
|
+ console.log(state.pageData.index);
|
|
|
+ }
|
|
|
+
|
|
|
+ //drag=拖拽
|
|
|
+ if(data.source == "drag"){
|
|
|
+ //拖拽添加
|
|
|
+ console.log("通过拖拽添加一个板块");
|
|
|
+ //通过时间戳生成id
|
|
|
+ const currentTimestamp = Date.now();
|
|
|
+ let id = currentTimestamp;
|
|
|
+ //data.type 组件名称 data.h 模块高度
|
|
|
+ //计算当前布局的最大 y 值
|
|
|
+ const maxY = Math.max(...state.pageData.index.map(item => item.y), 0);
|
|
|
+ console.log(data);
|
|
|
+ //设置数据在构建json中的位置
|
|
|
+ let dataSort = state.pageData.index.length;
|
|
|
+ //添加板块id
|
|
|
+ state.pageData.index.push({
|
|
|
+ //i: state.pageData.index.length, //base 0.0.1 此方法会导致重复的id出现
|
|
|
+ i: id,
|
|
|
+ x: data.x,
|
|
|
+ y: data.y,
|
|
|
+ w: 12,
|
|
|
+ h: data.h,
|
|
|
+ type: data.type,
|
|
|
+ //sectorData:data.jsonData //base 0.0.1 此问题导致深层数据无法被视图渲染
|
|
|
+ content:data.jsonData,
|
|
|
+ dataSort:dataSort
|
|
|
+ });
|
|
|
+ console.log("当前添加模块的dataSort为:" + dataSort);
|
|
|
+ //当前的页面构建数据
|
|
|
+ console.log(state.pageData.index);
|
|
|
+ //需要调查一下这里最后的1,1
|
|
|
+ state.gridlayoutObj.dragEvent('dragend', data.i, data.x, data.y, 1,1);
|
|
|
+ try {
|
|
|
+ state.gridlayoutObj.$children[state.pageData.index.length].$refs.item.style.display="block";
|
|
|
+ } catch {}
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
//pageStatus==2 分类页
|
|
@@ -489,79 +535,122 @@ const mutations = {
|
|
|
// if (state.pageStatus == 7) {}
|
|
|
},
|
|
|
//从外部拖拽板块
|
|
|
- drag: function (state, data) {
|
|
|
- let parentRect = document.getElementById('content').getBoundingClientRect();
|
|
|
- //console.log(parentRect); 获取画布
|
|
|
- let mouseInGrid = false;
|
|
|
- if (((state.mouseXY.x > parentRect.left) && (state.mouseXY.x < parentRect.right)) && ((state.mouseXY.y > parentRect.top) && (state.mouseXY.y < parentRect.bottom))) {
|
|
|
- mouseInGrid = true;
|
|
|
- }
|
|
|
- //state.gridlayoutObj
|
|
|
- //如果没有占位符就创建一个
|
|
|
- if (mouseInGrid === true && (state.pageData.index.findIndex(item => item.i === 'drop')) === -1) {
|
|
|
- state.pageData.index.push({
|
|
|
- x: (state.pageData.index.length * 2) % (this.colNum || 12),
|
|
|
- y: state.pageData.index.length + (this.colNum || 12), // puts it at the bottom
|
|
|
- w: 12,
|
|
|
- h: 2,
|
|
|
- i: 'drop',
|
|
|
- });
|
|
|
- }
|
|
|
- //如果已经存在占位符
|
|
|
- let index = state.pageData.index.findIndex(item => item.i === 'drop');
|
|
|
- if (index !== -1) {
|
|
|
- try {
|
|
|
- state.gridlayoutObj.$children[state.pageData.index.length].$refs.item.style.display = "none";
|
|
|
- } catch {
|
|
|
-
|
|
|
+ drag(state, data) {
|
|
|
+ // pageStatus == 1 首页
|
|
|
+ if (state.pageStatus == 1) {
|
|
|
+ let parentRect = document.getElementById('content').getBoundingClientRect();
|
|
|
+ //console.log(parentRect); 获取画布
|
|
|
+ let mouseInGrid = false;
|
|
|
+ if (((state.mouseXY.x > parentRect.left) && (state.mouseXY.x < parentRect.right)) && ((state.mouseXY.y > parentRect.top) && (state.mouseXY.y < parentRect.bottom))) {
|
|
|
+ mouseInGrid = true;
|
|
|
}
|
|
|
- let el = state.gridlayoutObj.$children[index];
|
|
|
- el.dragging = {"top": state.mouseXY.y - parentRect.top, "left": state.mouseXY.x - parentRect.left};
|
|
|
- let new_pos = el.calcXY(state.mouseXY.y - parentRect.top, state.mouseXY.x - parentRect.left);
|
|
|
-
|
|
|
- if (mouseInGrid === true) {
|
|
|
- state.gridlayoutObj.dragEvent('dragstart', 'drop', new_pos.x, new_pos.y, 2, 12);
|
|
|
- state.DragPos.i = String(index);
|
|
|
- state.DragPos.x = state.pageData.index[index].x;
|
|
|
- state.DragPos.y = state.pageData.index[index].y;
|
|
|
+ //state.gridlayoutObj
|
|
|
+ //如果没有占位符就创建一个
|
|
|
+ if (mouseInGrid === true && (state.pageData.index.findIndex(item => item.i === 'drop')) === -1) {
|
|
|
+ state.pageData.index.push({
|
|
|
+ x: (state.pageData.index.length * 2) % (this.colNum || 12),
|
|
|
+ y: state.pageData.index.length + (this.colNum || 12), // puts it at the bottom
|
|
|
+ w: 12,
|
|
|
+ h: 2,
|
|
|
+ i: 'drop',
|
|
|
+ });
|
|
|
}
|
|
|
- if (mouseInGrid === false) {
|
|
|
- state.gridlayoutObj.dragEvent('dragend', 'drop', new_pos.x, new_pos.y, 2, 12);
|
|
|
- state.pageData.index = state.pageData.index.filter(obj => obj.i !== 'drop');
|
|
|
+ //如果已经存在占位符
|
|
|
+ let index = state.pageData.index.findIndex(item => item.i === 'drop');
|
|
|
+ if (index !== -1) {
|
|
|
+ try {
|
|
|
+ state.gridlayoutObj.$children[state.pageData.index.length].$refs.item.style.display = "none";
|
|
|
+ } catch {
|
|
|
+
|
|
|
+ }
|
|
|
+ let el = state.gridlayoutObj.$children[index];
|
|
|
+ el.dragging = {"top": state.mouseXY.y - parentRect.top, "left": state.mouseXY.x - parentRect.left};
|
|
|
+ let new_pos = el.calcXY(state.mouseXY.y - parentRect.top, state.mouseXY.x - parentRect.left);
|
|
|
+
|
|
|
+ if (mouseInGrid === true) {
|
|
|
+ state.gridlayoutObj.dragEvent('dragstart', 'drop', new_pos.x, new_pos.y, 2, 12);
|
|
|
+ state.DragPos.i = String(index);
|
|
|
+ state.DragPos.x = state.pageData.index[index].x;
|
|
|
+ state.DragPos.y = state.pageData.index[index].y;
|
|
|
+ }
|
|
|
+ if (mouseInGrid === false) {
|
|
|
+ state.gridlayoutObj.dragEvent('dragend', 'drop', new_pos.x, new_pos.y, 2, 12);
|
|
|
+ state.pageData.index = state.pageData.index.filter(obj => obj.i !== 'drop');
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ // pageStatus == 2 分类页
|
|
|
+ if (state.pageStatus == 2) {}
|
|
|
+ // pageStatus == 3 列表页
|
|
|
+ if (state.pageStatus == 3) {}
|
|
|
+ // pageStatus == 4 详情页
|
|
|
+ if (state.pageStatus == 4) {}
|
|
|
+ // pageStatus == 5 搜索页
|
|
|
+ if (state.pageStatus == 5) {}
|
|
|
+ // pageStatus == 6 自定义列表页
|
|
|
+ if (state.pageStatus == 6) {}
|
|
|
+ // pageStatus == 7 自定义详情页
|
|
|
+ if (state.pageStatus == 7) {}
|
|
|
},
|
|
|
//拖拽结束 定位落点
|
|
|
- dragend: function (state, data) {
|
|
|
- //获取画布尺寸
|
|
|
- let parentRect = document.getElementById('content').getBoundingClientRect();
|
|
|
- //判断是否在画布内
|
|
|
- let mouseInGrid = false;
|
|
|
- if (((state.mouseXY.x > parentRect.left) && (state.mouseXY.x < parentRect.right)) && ((state.mouseXY.y > parentRect.top) && (state.mouseXY.y < parentRect.bottom))) {
|
|
|
- mouseInGrid = true;
|
|
|
- }
|
|
|
- //如果在画布内,开始创建元素
|
|
|
- if (mouseInGrid === true) {
|
|
|
- alert(`Dropped element props:\n${JSON.stringify(state.DragPos, ['x', 'y', 'w', 'h'], 2)}`);
|
|
|
- state.gridlayoutObj.dragEvent('dragend', 'drop', state.DragPos.x, state.DragPos.y, 1, 1);
|
|
|
- state.pageData.index = state.pageData.index.filter(obj => obj.i !== 'drop');
|
|
|
-
|
|
|
- // UNCOMMENT below if you want to add a grid-item
|
|
|
- /*
|
|
|
- this.layout.push({
|
|
|
- x: DragPos.x,
|
|
|
- y: DragPos.y,
|
|
|
- w: 1,
|
|
|
- h: 1,
|
|
|
- i: DragPos.i,
|
|
|
- });
|
|
|
- this.$refs.gridLayout.dragEvent('dragend', DragPos.i, DragPos.x,DragPos.y,1,1);
|
|
|
- try {
|
|
|
- this.$refs.gridLayout.$children[this.layout.length].$refs.item.style.display="block";
|
|
|
- } catch {
|
|
|
+ dragend(state, data) {
|
|
|
+
|
|
|
+ // pageStatus == 1 首页
|
|
|
+ if (state.pageStatus == 1) {
|
|
|
+ //获取画布尺寸
|
|
|
+ let parentRect = document.getElementById('content').getBoundingClientRect();
|
|
|
+ //判断是否在画布内
|
|
|
+ let mouseInGrid = false;
|
|
|
+ if (((state.mouseXY.x > parentRect.left) && (state.mouseXY.x < parentRect.right)) && ((state.mouseXY.y > parentRect.top) && (state.mouseXY.y < parentRect.bottom))) {
|
|
|
+ mouseInGrid = true;
|
|
|
+ }
|
|
|
+ //如果在画布内,开始创建元素
|
|
|
+ if (mouseInGrid === true) {
|
|
|
+ alert(`Dropped element props:\n${JSON.stringify(state.DragPos, ['x', 'y', 'w', 'h'], 2)}`);
|
|
|
+ state.gridlayoutObj.dragEvent('dragend', 'drop', state.DragPos.x, state.DragPos.y, 1, 1);
|
|
|
+ state.pageData.index = state.pageData.index.filter(obj => obj.i !== 'drop');
|
|
|
+
|
|
|
+ // UNCOMMENT below if you want to add a grid-item
|
|
|
+ /*
|
|
|
+ this.layout.push({
|
|
|
+ x: DragPos.x,
|
|
|
+ y: DragPos.y,
|
|
|
+ w: 1,
|
|
|
+ h: 1,
|
|
|
+ i: DragPos.i,
|
|
|
+ });
|
|
|
+ this.$refs.gridLayout.dragEvent('dragend', DragPos.i, DragPos.x,DragPos.y,1,1);
|
|
|
+ try {
|
|
|
+ this.$refs.gridLayout.$children[this.layout.length].$refs.item.style.display="block";
|
|
|
+ } catch {
|
|
|
+ }
|
|
|
+ */
|
|
|
+ let sendData = {
|
|
|
+ source:"drag",//添加时判断此模块来自外部拖拽,而不是点击
|
|
|
+ type:data.type,
|
|
|
+ h:data.h,
|
|
|
+ jsonData:data.jsonData,
|
|
|
+ x: state.DragPos.x,
|
|
|
+ y: state.DragPos.y,
|
|
|
+ w: 12,
|
|
|
+ }
|
|
|
+ //开发到这里了,注意我可能还需要上面那个 this.$refs.gridLayout.dragEvent方法
|
|
|
+ this.commit('template/addModule',sendData);
|
|
|
+
|
|
|
}
|
|
|
- */
|
|
|
}
|
|
|
+ // pageStatus == 2 分类页
|
|
|
+ if (state.pageStatus == 2) {}
|
|
|
+ // pageStatus == 3 列表页
|
|
|
+ if (state.pageStatus == 3) {}
|
|
|
+ // pageStatus == 4 详情页
|
|
|
+ if (state.pageStatus == 4) {}
|
|
|
+ // pageStatus == 5 搜索页
|
|
|
+ if (state.pageStatus == 5) {}
|
|
|
+ // pageStatus == 6 自定义列表页
|
|
|
+ if (state.pageStatus == 6) {}
|
|
|
+ // pageStatus == 7 自定义详情页
|
|
|
+ if (state.pageStatus == 7) {}
|
|
|
},
|
|
|
//修改首页板块高度
|
|
|
setModuleHeight(state,data){
|
|
@@ -607,6 +696,9 @@ const mutations = {
|
|
|
},
|
|
|
//保存模板
|
|
|
saveTemplate(state) {
|
|
|
+ //临时展示保存的数据 后期移除
|
|
|
+ state.editWebsiteTemplateJsonWindow = true;
|
|
|
+
|
|
|
//调用mutations中的方法无需使用$store
|
|
|
//格式化index的信息
|
|
|
this.commit('template/formatTemplateInfo',{data:state.pageData.index,type:"index"});
|
|
@@ -619,6 +711,8 @@ const mutations = {
|
|
|
const randomIndex = Math.floor(Math.random() * 3); // Generates a random number between 1 and 2
|
|
|
console.log(`随机生成的数字是: ${randomIndex}`);
|
|
|
|
|
|
+ Message.warning("该功能研发中");
|
|
|
+
|
|
|
// pageStatus == 1 首页
|
|
|
if (state.pageStatus == 1) {}
|
|
|
// pageStatus == 2 分类页
|