|
@@ -19,12 +19,13 @@ const state = {
|
|
|
pageStatus:1,//当前编辑哪个页面 1=首页 2=分类页 3=列表页 4=详情页 5=搜索页 6=自定义列表页 7=自定义详情页
|
|
|
menuType:1, //当前菜单显示板块还是组件 1=板块 2=组件
|
|
|
previewStatus:false,//是否预览
|
|
|
+ gridKey:0,//使用gridKey来强制更新视图
|
|
|
pageData: { //自助建站拖拽板块的数据,注意,这里并不是提交到后台的数据
|
|
|
index:[
|
|
|
|
|
|
],//首页
|
|
|
class:[],//分类页
|
|
|
- list:[],//列表页
|
|
|
+ list:[],//列表页bang
|
|
|
article:[],//详情页
|
|
|
search:[],//搜索页
|
|
|
aloneList:[],//自定义列表页
|
|
@@ -49,7 +50,24 @@ const state = {
|
|
|
departmentList:"",//职能部门
|
|
|
//2.站点数据 end------------------------------------------------------------>
|
|
|
|
|
|
- //3.网站数据 start------------------------------------------------------------>
|
|
|
+ //3.画布构造 start------------------------------------------------------------>
|
|
|
+ editSectorY:0,//当前组件在画布中的位置
|
|
|
+ mouseXY:{//鼠标位置
|
|
|
+ "x": 12,
|
|
|
+ "y": 33
|
|
|
+ },
|
|
|
+ DragPos:{//创建的占位符大小
|
|
|
+ "x": null,
|
|
|
+ "y": null,
|
|
|
+ "w": 12,
|
|
|
+ "h": 2,
|
|
|
+ "i": null
|
|
|
+ },
|
|
|
+ //获得gridlayout对象
|
|
|
+ gridlayoutObj:null,
|
|
|
+ //3.画布构造 end------------------------------------------------------------>
|
|
|
+
|
|
|
+ //4.构造的网站数据 start------------------------------------------------------------>
|
|
|
editWindowStatus:false,//编辑组件弹出框是否显示
|
|
|
editComponentWindowStatus:false,//选择组件样式弹出框是否显示
|
|
|
editWindowTitle:"",//编辑弹出框标题
|
|
@@ -60,7 +78,6 @@ const state = {
|
|
|
editComponentSize:0,//当前组件展示的条数
|
|
|
editComponentStyle:0,//当前编辑的组件样式
|
|
|
editWebsiteCategory:[],//当前网站全部关联导航
|
|
|
-
|
|
|
webSiteData:{
|
|
|
//1.base网站基本信息
|
|
|
base:{
|
|
@@ -82,16 +99,16 @@ const state = {
|
|
|
aloneArticle:[],//自定义详情页
|
|
|
}
|
|
|
},
|
|
|
- //3.网站数据 end------------------------------------------------------------>
|
|
|
+ //4.构造的网站数据 end------------------------------------------------------------>
|
|
|
|
|
|
- //4.组件回显数据 start------------------------------------------------------------>
|
|
|
+ //5.组件回显数据 start------------------------------------------------------------>
|
|
|
componentViewData:{
|
|
|
pid_arr:[],//导航池
|
|
|
pageSize:"",//展示条数
|
|
|
adName:"",//广告名称
|
|
|
titleName:"",//标题名称
|
|
|
}
|
|
|
- //4.组件回显数据 start------------------------------------------------------------>
|
|
|
+ //5.组件回显数据 start------------------------------------------------------------>
|
|
|
}
|
|
|
|
|
|
const mutations = {
|
|
@@ -120,6 +137,7 @@ const mutations = {
|
|
|
setEditWindowStatus(state,data){
|
|
|
state.editWindowStatus = true;
|
|
|
state.editSectorId = data.id;
|
|
|
+ state.editSectorY = data.y;
|
|
|
state.editDataSort = data.dataSort;
|
|
|
state.editComponentSort = data.sort;
|
|
|
state.editComponentType = data.type;
|
|
@@ -187,6 +205,10 @@ const mutations = {
|
|
|
},
|
|
|
//0.全局配置 start------------------------------------------------------------>
|
|
|
//1.配置模块 start------------------------------------------------------------>
|
|
|
+ //获得gridlayout对象
|
|
|
+ setGridlayoutObj(state,data){
|
|
|
+ state.gridlayoutObj = data;
|
|
|
+ },
|
|
|
//添加板块
|
|
|
addModule(state,data){
|
|
|
//pageStatus==1 首页
|
|
@@ -385,75 +407,161 @@ const mutations = {
|
|
|
//pageStatus==7 自定义详情页
|
|
|
if(state.pageStatus == 7){}
|
|
|
},
|
|
|
- //移动板块 (暂时停用)
|
|
|
+ //通过按钮移动板块 (暂时停用)
|
|
|
moveModule(state, data) {
|
|
|
- // Message.error('移动板块功能暂时停用!');
|
|
|
+ Message.error("该功能暂时禁用")
|
|
|
// pageStatus == 1 首页
|
|
|
- if (state.pageStatus == 1) {
|
|
|
- const moveType = data.moveType;
|
|
|
- const moduleId = data.i;
|
|
|
- const modules = state.pageData.index;
|
|
|
- // 查找模块在数组中的实际索引
|
|
|
- const thisIndex = modules.findIndex(module => module.i === moduleId);
|
|
|
- if (thisIndex === -1) {
|
|
|
- Message.error('模块未找到!');
|
|
|
- return;
|
|
|
+ // if (state.pageStatus == 1) {
|
|
|
+ // const moveType = data.moveType;
|
|
|
+ // const moduleId = data.i;
|
|
|
+ // const modules = state.pageData.index;
|
|
|
+
|
|
|
+ // // 深拷贝 modules,避免直接操作原数据
|
|
|
+ // const newModules = JSON.parse(JSON.stringify(modules));
|
|
|
+
|
|
|
+ // // 查找模块在数组中的实际索引
|
|
|
+ // const thisIndex = newModules.findIndex(module => module.i === moduleId);
|
|
|
+ // if (thisIndex === -1) {
|
|
|
+ // Message.error('模块未找到!');
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // const thisY = newModules[thisIndex].y;
|
|
|
+ // let thatY;
|
|
|
+
|
|
|
+ // if (moveType === 'up') {
|
|
|
+ // thatY = Math.max(
|
|
|
+ // ...newModules.filter(item => item.y < thisY).map(item => item.y)
|
|
|
+ // );
|
|
|
+ // if (thatY === -Infinity) {
|
|
|
+ // Message.error('已经是顶部了!');
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // const thatIndex = newModules.findIndex(item => item.y === thatY);
|
|
|
+ // if (thatIndex === -1) {
|
|
|
+ // Message.error('上方模块未找到!');
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // // 交换y值
|
|
|
+ // [newModules[thisIndex].y, newModules[thatIndex].y] = [newModules[thatIndex].y, newModules[thisIndex].y];
|
|
|
+
|
|
|
+ // } else if (moveType === 'down') {
|
|
|
+ // thatY = Math.min(
|
|
|
+ // ...newModules.filter(item => item.y > thisY).map(item => item.y)
|
|
|
+ // );
|
|
|
+ // if (thatY === Infinity) {
|
|
|
+ // Message.error('已经是底部了!');
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // const thatIndex = newModules.findIndex(item => item.y === thatY);
|
|
|
+ // if (thatIndex === -1) {
|
|
|
+ // Message.error('下方模块未找到!');
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // // 交换y值
|
|
|
+ // [newModules[thisIndex].y, newModules[thatIndex].y] = [newModules[thatIndex].y, newModules[thisIndex].y];
|
|
|
+ // } else {
|
|
|
+ // Message.error('未知的移动类型!');
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // // 交换后对模块进行排序以确保顺序一致
|
|
|
+ // newModules.sort((a, b) => a.y - b.y);
|
|
|
+
|
|
|
+ // // 使用 Vue.set 强制更新数组,确保视图更新
|
|
|
+ // //Vue.set(state.pageData, 'index', newModules); // 这里更新整个数组
|
|
|
+ // state.pageData.index = newModules;
|
|
|
+ // //state.gridKey+=1;
|
|
|
+
|
|
|
+ // console.log(state.pageData.index); // 打印查看是否已修改
|
|
|
+ // }
|
|
|
+
|
|
|
+ // // 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) {}
|
|
|
+ },
|
|
|
+ //从外部拖拽板块
|
|
|
+ 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 {
|
|
|
+
|
|
|
}
|
|
|
- const thisY = modules[thisIndex].y;
|
|
|
- let thatY;
|
|
|
- if (moveType === 'up') {
|
|
|
- thatY = Math.max(
|
|
|
- ...modules.filter(item => item.y < thisY).map(item => item.y)
|
|
|
- );
|
|
|
- if (thatY === -Infinity) {
|
|
|
- Message.error('已经是顶部了!');
|
|
|
- return;
|
|
|
- }
|
|
|
- const thatIndex = modules.findIndex(item => item.y === thatY);
|
|
|
- if (thatIndex === -1) {
|
|
|
- Message.error('上方模块未找到!');
|
|
|
- return;
|
|
|
- }
|
|
|
- [modules[thisIndex].y, modules[thatIndex].y] = [modules[thatIndex].y, modules[thisIndex].y];
|
|
|
+ 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);
|
|
|
|
|
|
- } else if (moveType === 'down') {
|
|
|
- thatY = Math.min(
|
|
|
- ...modules.filter(item => item.y > thisY).map(item => item.y)
|
|
|
- );
|
|
|
- if (thatY === Infinity) {
|
|
|
- Message.error('已经是底部了!');
|
|
|
- return;
|
|
|
- }
|
|
|
- const thatIndex = modules.findIndex(item => item.y === thatY);
|
|
|
- if (thatIndex === -1) {
|
|
|
- Message.error('下方模块未找到!');
|
|
|
- return;
|
|
|
- }
|
|
|
- [modules[thisIndex].y, modules[thatIndex].y] = [modules[thatIndex].y, modules[thisIndex].y];
|
|
|
- } else {
|
|
|
- Message.error('未知的移动类型!');
|
|
|
- return;
|
|
|
+ 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');
|
|
|
}
|
|
|
- // 交换后对模块进行排序以确保顺序一致
|
|
|
- modules.sort((a, b) => a.y - b.y);
|
|
|
- // 使用 Vue.set 强制更新数组,确保视图更新
|
|
|
- Vue.set(state.pageData, 'index', [...modules]);
|
|
|
- console.log(state.pageData.index); //打印查看是否已修改
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- // 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 {
|
|
|
+ }
|
|
|
+ */
|
|
|
+ }
|
|
|
},
|
|
|
//修改首页板块高度
|
|
|
setModuleHeight(state,data){
|