|
@@ -193,7 +193,6 @@ const mutations = {
|
|
|
if(state.editComponentType == 7){
|
|
|
state.componentViewData.titleName = state.pageData.index[targetModuleIndex].content.componentList[data.sort].componentData.text;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
//pageStatus==2 分类页
|
|
|
if(state.pageStatus == 2){}
|
|
@@ -216,8 +215,9 @@ const mutations = {
|
|
|
},
|
|
|
//添加板块
|
|
|
addModule(state,data){
|
|
|
- //pageStatus==1 首页
|
|
|
+ //pageStatus==1 首页 index
|
|
|
if(state.pageStatus == 1){
|
|
|
+ //开始复制 start------------------------------------------------------------>
|
|
|
//判断当前一共有多少个模块最多能添加10个
|
|
|
if(state.pageData.index.length >= 10){
|
|
|
Message.error('最多只能添加10个模块!');
|
|
@@ -288,20 +288,91 @@ const mutations = {
|
|
|
state.gridlayoutObj.$children[state.pageData.index.length].$refs.item.style.display="block";
|
|
|
} catch {}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
}
|
|
|
- //pageStatus==2 分类页
|
|
|
+ //pageStatus==2 分类页 class
|
|
|
if(state.pageStatus == 2){}
|
|
|
- //pageStatus==3 列表页
|
|
|
- if(state.pageStatus == 3){}
|
|
|
- //pageStatus==4 详情页
|
|
|
+ //pageStatus==3 列表页 list
|
|
|
+ if(state.pageStatus == 3){
|
|
|
+ //开始复制 start------------------------------------------------------------>
|
|
|
+ //判断当前一共有多少个模块最多能添加10个
|
|
|
+ if(state.pageData.list.length >= 10){
|
|
|
+ Message.error('最多只能添加10个模块!');
|
|
|
+ return;
|
|
|
+ }else{
|
|
|
+ //判断是拖拽的还是点击添加进来的 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.list.map(item => item.y), 0);
|
|
|
+ console.log(data);
|
|
|
+ //设置数据在构建json中的位置
|
|
|
+ let dataSort = state.pageData.list.length;
|
|
|
+
|
|
|
+ //添加板块id
|
|
|
+ state.pageData.list.push({
|
|
|
+ i: id,
|
|
|
+ x: 0,
|
|
|
+ y: maxY + 1,
|
|
|
+ w: 12,
|
|
|
+ h: data.h,
|
|
|
+ type: data.type,
|
|
|
+ content:data.jsonData,
|
|
|
+ dataSort:dataSort
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //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.list.map(item => item.y), 0);
|
|
|
+ console.log(data);
|
|
|
+ //设置数据在构建json中的位置
|
|
|
+ let dataSort = state.pageData.list.length;
|
|
|
+ //添加板块id
|
|
|
+ state.pageData.list.push({
|
|
|
+ //i: state.pageData.list.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.list);
|
|
|
+ //需要调查一下这里最后的1,1
|
|
|
+ state.gridlayoutObj.dragEvent('dragend', data.i, data.x, data.y, 1,1);
|
|
|
+ try {
|
|
|
+ state.gridlayoutObj.$children[state.pageData.list.length].$refs.item.style.display="block";
|
|
|
+ } catch {}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
+ }
|
|
|
+ //pageStatus==4 详情页 article
|
|
|
if(state.pageStatus == 4){}
|
|
|
- //pageStatus==5 搜索页
|
|
|
+ //pageStatus==5 搜索页 search
|
|
|
if(state.pageStatus == 5){}
|
|
|
- //pageStatus==6 自定义列表页
|
|
|
+ //pageStatus==6 自定义列表页 aloneList
|
|
|
if(state.pageStatus == 6){}
|
|
|
- //pageStatus==7 自定义详情页
|
|
|
+ //pageStatus==7 自定义详情页 aloneArticle
|
|
|
if(state.pageStatus == 7){}
|
|
|
},
|
|
|
//删除板块
|
|
@@ -310,6 +381,7 @@ const mutations = {
|
|
|
//data.dataSort = dataSort
|
|
|
//pageStatus==1 首页
|
|
|
if(state.pageStatus == 1){
|
|
|
+ //开始复制 start------------------------------------------------------------>
|
|
|
//必须通过重新查找id的方式来删除
|
|
|
const indexToRemove = state.pageData.index.findIndex(item => item.i === data.i);
|
|
|
if (indexToRemove !== -1) {
|
|
@@ -319,6 +391,7 @@ const mutations = {
|
|
|
} else {
|
|
|
Message.warning('未找到要删除的模块!');
|
|
|
}
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
// base 0.0.2 如果使用splice方法删除sort,当你就剩下最后一个的时候,会出现找不到那个元素的问题
|
|
|
// state.pageData.index.splice(data.dataSort,1);
|
|
|
// Message.success('模块已删除!');
|
|
@@ -327,7 +400,19 @@ const mutations = {
|
|
|
//pageStatus==2 分类页
|
|
|
if(state.pageStatus == 2){}
|
|
|
//pageStatus==3 列表页
|
|
|
- if(state.pageStatus == 3){}
|
|
|
+ if(state.pageStatus == 3){
|
|
|
+ //开始复制 start------------------------------------------------------------>
|
|
|
+ //必须通过重新查找id的方式来删除
|
|
|
+ const indexToRemove = state.pageData.list.findIndex(item => item.i === data.i);
|
|
|
+ if (indexToRemove !== -1) {
|
|
|
+ state.pageData.list.splice(indexToRemove, 1);
|
|
|
+ Message.success('模块已删除!');
|
|
|
+ console.log('模块已删除,当前的页面构建数据为:', state.pageData.list);
|
|
|
+ } else {
|
|
|
+ Message.warning('未找到要删除的模块!');
|
|
|
+ }
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
+ }
|
|
|
//pageStatus==4 详情页
|
|
|
if(state.pageStatus == 4){}
|
|
|
//pageStatus==5 搜索页
|
|
@@ -346,6 +431,7 @@ const mutations = {
|
|
|
console.log(id,dataSort,sort,num);
|
|
|
//pageStatus==1 首页
|
|
|
if(state.pageStatus == 1){
|
|
|
+ //开始复制 start------------------------------------------------------------>
|
|
|
// 获取当前模块数据并进行深拷贝
|
|
|
let module = JSON.parse(JSON.stringify(state.pageData.index[dataSort]));
|
|
|
//module.content.componentList[sort].component_style = num;
|
|
@@ -360,11 +446,29 @@ const mutations = {
|
|
|
Vue.set(state.pageData.index, dataSort, module);
|
|
|
console.log("当前的板块数据为:");
|
|
|
console.log(state.pageData.index);
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
}
|
|
|
//pageStatus==2 分类页
|
|
|
if(state.pageStatus == 2){}
|
|
|
//pageStatus==3 列表页
|
|
|
- if(state.pageStatus == 3){}
|
|
|
+ if(state.pageStatus == 3){
|
|
|
+ //开始复制 start------------------------------------------------------------>
|
|
|
+ // 获取当前模块数据并进行深拷贝
|
|
|
+ let module = JSON.parse(JSON.stringify(state.pageData.list[dataSort]));
|
|
|
+ //module.content.componentList[sort].component_style = num;
|
|
|
+ //确保修改属性时 Vue 能监控到变化
|
|
|
+ Vue.set(module.content.componentList, sort, {
|
|
|
+ ...module.content.componentList[sort],
|
|
|
+ component_style: num
|
|
|
+ });
|
|
|
+ // 拷贝后直接替换原来的板块
|
|
|
+ //state.pageData.index[id] = module;
|
|
|
+ // 使用Vue.set来强制视图更新
|
|
|
+ Vue.set(state.pageData.list, dataSort, module);
|
|
|
+ console.log("当前的板块数据为:");
|
|
|
+ console.log(state.pageData.list);
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
+ }
|
|
|
//pageStatus==4 详情页
|
|
|
if(state.pageStatus == 4){}
|
|
|
//pageStatus==5 搜索页
|
|
@@ -380,6 +484,7 @@ const mutations = {
|
|
|
console.log("当前编辑板块:" + data.id)
|
|
|
//pageStatus==1 首页
|
|
|
if(state.pageStatus == 1){
|
|
|
+ //开始复制 start------------------------------------------------------------>
|
|
|
const targetModuleIndex = state.pageData.index.findIndex(module => module.i === data.id);
|
|
|
console.log("要修改的模块id为:") //找到要修改的板块
|
|
|
console.log(data.sort) //找到要修改的板块
|
|
@@ -439,11 +544,58 @@ const mutations = {
|
|
|
}
|
|
|
//8=评论
|
|
|
//if(state.editComponentType == 8){}
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
}
|
|
|
//pageStatus==2 分类页
|
|
|
if(state.pageStatus == 2){}
|
|
|
//pageStatus==3 列表页
|
|
|
- if(state.pageStatus == 3){}
|
|
|
+ if(state.pageStatus == 3){
|
|
|
+ //开始复制 start------------------------------------------------------------>
|
|
|
+ const targetModuleIndex = state.pageData.list.findIndex(module => module.i === data.id);
|
|
|
+ console.log("要修改的模块id为:") //找到要修改的板块
|
|
|
+ console.log(data.sort) //找到要修改的板块
|
|
|
+ console.log(targetModuleIndex) //找到要修改的板块
|
|
|
+ if(state.editComponentType == 1){
|
|
|
+ // 获取当前模块数据并进行深拷贝
|
|
|
+ let module = JSON.parse(JSON.stringify(state.pageData.list[targetModuleIndex])); // 深拷贝整个模块
|
|
|
+ // 更新 category_id 和 pageSize
|
|
|
+ module.content.componentList[data.sort].componentData.category_id = data.data.pid_arr; // 设置 category_id
|
|
|
+ module.content.componentList[data.sort].componentData.pageSize = state.editComponentSize; // 设置 pageSize
|
|
|
+ // 使用Vue.set来强制视图更新
|
|
|
+ Vue.set(state.pageData.list, targetModuleIndex, module); // 替换为深拷贝的模块
|
|
|
+ console.log("当前的板块数据为:");
|
|
|
+ console.log(state.pageData.list);
|
|
|
+ }
|
|
|
+ //2=tabs新闻选项卡
|
|
|
+ if(state.editComponentType == 2){
|
|
|
+ // 获取当前模块数据并进行深拷贝
|
|
|
+ let module = JSON.parse(JSON.stringify(state.pageData.list[targetModuleIndex])); // 深拷贝整个模块
|
|
|
+ // 更新 category_id 和 pageSize
|
|
|
+ module.content.componentList[data.sort].componentData.category_id = data.data.pid_arr; // 设置 category_id
|
|
|
+ module.content.componentList[data.sort].componentData.pageSize = state.editComponentSize; // 设置 pageSize
|
|
|
+ // 使用Vue.set来强制视图更新
|
|
|
+ Vue.set(state.pageData.list, targetModuleIndex, module); // 替换为深拷贝的模块
|
|
|
+ console.log("当前的板块数据为:");
|
|
|
+ console.log(state.pageData.list);
|
|
|
+ }
|
|
|
+ //3=广告
|
|
|
+ if(state.editComponentType == 3){;
|
|
|
+ let module = JSON.parse(JSON.stringify(state.pageData.list[targetModuleIndex]));
|
|
|
+ module.content.componentList[data.sort].componentData.text = data.data.adName;
|
|
|
+ Vue.set(state.pageData.list, targetModuleIndex, module);
|
|
|
+ console.log("当前的板块数据为:");
|
|
|
+ console.log(state.pageData.list);
|
|
|
+ }
|
|
|
+ //7=文本
|
|
|
+ if(state.editComponentType == 7){
|
|
|
+ let module = JSON.parse(JSON.stringify(state.pageData.list[targetModuleIndex]));
|
|
|
+ module.content.componentList[data.sort].componentData.text = data.data.titleName;
|
|
|
+ Vue.set(state.pageData.list, targetModuleIndex, module);
|
|
|
+ console.log("当前的板块数据为:");
|
|
|
+ console.log(state.pageData.list);
|
|
|
+ }
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
+ }
|
|
|
//pageStatus==4 详情页
|
|
|
if(state.pageStatus == 4){}
|
|
|
//pageStatus==5 搜索页
|
|
@@ -538,6 +690,7 @@ const mutations = {
|
|
|
drag(state, data) {
|
|
|
// pageStatus == 1 首页
|
|
|
if (state.pageStatus == 1) {
|
|
|
+ //开始复制 start------------------------------------------------------------>
|
|
|
let parentRect = document.getElementById('content').getBoundingClientRect();
|
|
|
//console.log(parentRect); 获取画布
|
|
|
let mouseInGrid = false;
|
|
@@ -578,11 +731,54 @@ const mutations = {
|
|
|
state.pageData.index = state.pageData.index.filter(obj => obj.i !== 'drop');
|
|
|
}
|
|
|
}
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
}
|
|
|
// pageStatus == 2 分类页
|
|
|
if (state.pageStatus == 2) {}
|
|
|
// pageStatus == 3 列表页
|
|
|
- if (state.pageStatus == 3) {}
|
|
|
+ if (state.pageStatus == 3) {
|
|
|
+ //开始复制 start------------------------------------------------------------>
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ //如果没有占位符就创建一个
|
|
|
+ if (mouseInGrid === true && (state.pageData.list.findIndex(item => item.i === 'drop')) === -1) {
|
|
|
+ state.pageData.list.push({
|
|
|
+ x: (state.pageData.list.length * 2) % (this.colNum || 12),
|
|
|
+ y: state.pageData.list.length + (this.colNum || 12), // puts it at the bottom
|
|
|
+ w: 12,
|
|
|
+ h: 2,
|
|
|
+ i: 'drop',
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //如果已经存在占位符
|
|
|
+ let index = state.pageData.list.findIndex(item => item.i === 'drop');
|
|
|
+ if (index !== -1) {
|
|
|
+ try {
|
|
|
+ state.gridlayoutObj.$children[state.pageData.list.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.list[index].x;
|
|
|
+ state.DragPos.y = state.pageData.list[index].y;
|
|
|
+ }
|
|
|
+ if (mouseInGrid === false) {
|
|
|
+ state.gridlayoutObj.dragEvent('dragend', 'drop', new_pos.x, new_pos.y, 2, 12);
|
|
|
+ state.pageData.list = state.pageData.list.filter(obj => obj.i !== 'drop');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
+ }
|
|
|
// pageStatus == 4 详情页
|
|
|
if (state.pageStatus == 4) {}
|
|
|
// pageStatus == 5 搜索页
|
|
@@ -594,9 +790,9 @@ const mutations = {
|
|
|
},
|
|
|
//拖拽结束 定位落点
|
|
|
dragend(state, data) {
|
|
|
-
|
|
|
// pageStatus == 1 首页
|
|
|
if (state.pageStatus == 1) {
|
|
|
+ //开始复制 start------------------------------------------------------------>
|
|
|
//获取画布尺寸
|
|
|
let parentRect = document.getElementById('content').getBoundingClientRect();
|
|
|
//判断是否在画布内
|
|
@@ -636,13 +832,40 @@ const mutations = {
|
|
|
}
|
|
|
//开发到这里了,注意我可能还需要上面那个 this.$refs.gridLayout.dragEvent方法
|
|
|
this.commit('template/addModule',sendData);
|
|
|
-
|
|
|
}
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
}
|
|
|
// pageStatus == 2 分类页
|
|
|
if (state.pageStatus == 2) {}
|
|
|
// pageStatus == 3 列表页
|
|
|
- if (state.pageStatus == 3) {}
|
|
|
+ if (state.pageStatus == 3) {
|
|
|
+ //开始复制 start------------------------------------------------------------>
|
|
|
+ //获取画布尺寸
|
|
|
+ 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.list = state.pageData.list.filter(obj => obj.i !== 'drop');
|
|
|
+
|
|
|
+ let sendData = {
|
|
|
+ source:"drag",//添加时判断此模块来自外部拖拽,而不是点击
|
|
|
+ type:data.type,
|
|
|
+ h:data.h,
|
|
|
+ jsonData:data.jsonData,
|
|
|
+ x: state.DragPos.x,
|
|
|
+ y: state.DragPos.y,
|
|
|
+ w: 12,
|
|
|
+ }
|
|
|
+ this.commit('template/addModule',sendData);
|
|
|
+ }
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
+ }
|
|
|
// pageStatus == 4 详情页
|
|
|
if (state.pageStatus == 4) {}
|
|
|
// pageStatus == 5 搜索页
|
|
@@ -663,7 +886,11 @@ const mutations = {
|
|
|
// pageStatus == 2 分类页
|
|
|
if (state.pageStatus == 2) {}
|
|
|
// pageStatus == 3 列表页
|
|
|
- if (state.pageStatus == 3) {}
|
|
|
+ if (state.pageStatus == 3) {
|
|
|
+ console.log(data);
|
|
|
+ state.pageData.list[data.i].h = data.h;
|
|
|
+ console.log(state.pageData.list[data.i]);
|
|
|
+ }
|
|
|
// pageStatus == 4 详情页
|
|
|
if (state.pageStatus == 4) {}
|
|
|
// pageStatus == 5 搜索页
|
|
@@ -686,15 +913,19 @@ const mutations = {
|
|
|
console.log(clonedData.data[index].content);
|
|
|
// 使用 Vue.set 来确保属性变更能被 Vue 追踪
|
|
|
Vue.set(clonedData.data[index].content, 'sort', Number(index) + 1);
|
|
|
- if (data.type == "index") {
|
|
|
- // 不要把数据直接保存到 state.webSiteData.template 中,否则无法删除
|
|
|
- websiteData.push(clonedData.data[index].content);
|
|
|
- }
|
|
|
+ // if (data.type == "index") {
|
|
|
+ // // 不要把数据直接保存到 state.webSiteData.template 中,否则无法删除
|
|
|
+ // websiteData.push(clonedData.data[index].content);
|
|
|
+ // }
|
|
|
+ websiteData.push(clonedData.data[index].content);
|
|
|
}
|
|
|
// 保存到对应的页面 json 中
|
|
|
if (data.type == "index") {
|
|
|
state.webSiteData.template.index = websiteData;
|
|
|
}
|
|
|
+ if (data.type == "list") {
|
|
|
+ state.webSiteData.template.list = websiteData;
|
|
|
+ }
|
|
|
},
|
|
|
//保存模板
|
|
|
saveTemplate(state) {
|
|
@@ -703,6 +934,8 @@ const mutations = {
|
|
|
//调用mutations中的方法无需使用$store
|
|
|
//格式化index的信息
|
|
|
this.commit('template/formatTemplateInfo',{data:state.pageData.index,type:"index"});
|
|
|
+ //格式化list的信息
|
|
|
+ this.commit('template/formatTemplateInfo',{data:state.pageData.list,type:"list"});
|
|
|
console.log(state.webSiteData);
|
|
|
},
|
|
|
//随机生成模板
|