|
@@ -197,9 +197,50 @@ const mutations = {
|
|
|
//pageStatus==2 分类页
|
|
|
if(state.pageStatus == 2){}
|
|
|
//pageStatus==3 列表页
|
|
|
- if(state.pageStatus == 3){}
|
|
|
+ if(state.pageStatus == 3){
|
|
|
+ const targetModuleIndex = state.pageData.list.findIndex(module => module.i === data.id);
|
|
|
+ //判断组件类型 1=普通新闻 2=tabs新闻选项卡 3=广告 4=友情链接 6=静态组件 7=文本 8=评论
|
|
|
+ if(state.editComponentType == 1){
|
|
|
+ state.componentViewData.pid_arr = state.pageData.list[targetModuleIndex].content.componentList[data.sort].componentData.category_id;
|
|
|
+ state.componentViewData.pageSize = state.editComponentSize;
|
|
|
+ }
|
|
|
+ //2=tabs新闻选项卡
|
|
|
+ if(state.editComponentType == 2){
|
|
|
+ state.componentViewData.pid_arr = state.pageData.list[targetModuleIndex].content.componentList[data.sort].componentData.category_id;
|
|
|
+ state.componentViewData.pageSize = state.editComponentSize;
|
|
|
+ }
|
|
|
+ //3=广告名称
|
|
|
+ if(state.editComponentType == 3){
|
|
|
+ state.componentViewData.adName = state.pageData.list[targetModuleIndex].content.componentList[data.sort].componentData.text;
|
|
|
+ }
|
|
|
+ //7=标题
|
|
|
+ if(state.editComponentType == 7){
|
|
|
+ state.componentViewData.titleName = state.pageData.list[targetModuleIndex].content.componentList[data.sort].componentData.text;
|
|
|
+ }
|
|
|
+ }
|
|
|
//pageStatus==4 详情页
|
|
|
- if(state.pageStatus == 4){}
|
|
|
+ if(state.pageStatus == 4){
|
|
|
+
|
|
|
+ const targetModuleIndex = state.pageData.article.findIndex(module => module.i === data.id);
|
|
|
+ //判断组件类型 1=普通新闻 2=tabs新闻选项卡 3=广告 4=友情链接 6=静态组件 7=文本 8=评论
|
|
|
+ if(state.editComponentType == 1){
|
|
|
+ state.componentViewData.pid_arr = state.pageData.article[targetModuleIndex].content.componentList[data.sort].componentData.category_id;
|
|
|
+ state.componentViewData.pageSize = state.editComponentSize;
|
|
|
+ }
|
|
|
+ //2=tabs新闻选项卡
|
|
|
+ if(state.editComponentType == 2){
|
|
|
+ state.componentViewData.pid_arr = state.pageData.article[targetModuleIndex].content.componentList[data.sort].componentData.category_id;
|
|
|
+ state.componentViewData.pageSize = state.editComponentSize;
|
|
|
+ }
|
|
|
+ //3=广告名称
|
|
|
+ if(state.editComponentType == 3){
|
|
|
+ state.componentViewData.adName = state.pageData.article[targetModuleIndex].content.componentList[data.sort].componentData.text;
|
|
|
+ }
|
|
|
+ //7=标题
|
|
|
+ if(state.editComponentType == 7){
|
|
|
+ state.componentViewData.titleName = state.pageData.article[targetModuleIndex].content.componentList[data.sort].componentData.text;
|
|
|
+ }
|
|
|
+ }
|
|
|
//pageStatus==5 搜索页
|
|
|
if(state.pageStatus == 5){}
|
|
|
//pageStatus==6 自定义列表页
|
|
@@ -367,7 +408,78 @@ const mutations = {
|
|
|
//开始复制 end------------------------------------------------------------>
|
|
|
}
|
|
|
//pageStatus==4 详情页 article
|
|
|
- if(state.pageStatus == 4){}
|
|
|
+ if(state.pageStatus == 4){
|
|
|
+ //开始复制 start------------------------------------------------------------>
|
|
|
+ //判断当前一共有多少个模块最多能添加10个
|
|
|
+ if(state.pageData.article.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.article.map(item => item.y), 0);
|
|
|
+ console.log(data);
|
|
|
+ //设置数据在构建json中的位置
|
|
|
+ let dataSort = state.pageData.article.length;
|
|
|
+
|
|
|
+ //添加板块id
|
|
|
+ state.pageData.article.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.article.map(item => item.y), 0);
|
|
|
+ console.log(data);
|
|
|
+ //设置数据在构建json中的位置
|
|
|
+ let dataSort = state.pageData.article.length;
|
|
|
+ //添加板块id
|
|
|
+ state.pageData.article.push({
|
|
|
+ //i: state.pageData.article.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.article);
|
|
|
+ //需要调查一下这里最后的1,1
|
|
|
+ state.gridlayoutObj.dragEvent('dragend', data.i, data.x, data.y, 1,1);
|
|
|
+ try {
|
|
|
+ state.gridlayoutObj.$children[state.pageData.article.length].$refs.item.style.display="block";
|
|
|
+ } catch {}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
+ }
|
|
|
//pageStatus==5 搜索页 search
|
|
|
if(state.pageStatus == 5){}
|
|
|
//pageStatus==6 自定义列表页 aloneList
|
|
@@ -414,7 +526,19 @@ const mutations = {
|
|
|
//开始复制 end------------------------------------------------------------>
|
|
|
}
|
|
|
//pageStatus==4 详情页
|
|
|
- if(state.pageStatus == 4){}
|
|
|
+ if(state.pageStatus == 4){
|
|
|
+ //开始复制 start------------------------------------------------------------>
|
|
|
+ //必须通过重新查找id的方式来删除
|
|
|
+ const indexToRemove = state.pageData.article.findIndex(item => item.i === data.i);
|
|
|
+ if (indexToRemove !== -1) {
|
|
|
+ state.pageData.article.splice(indexToRemove, 1);
|
|
|
+ Message.success('模块已删除!');
|
|
|
+ console.log('模块已删除,当前的页面构建数据为:', state.pageData.article);
|
|
|
+ } else {
|
|
|
+ Message.warning('未找到要删除的模块!');
|
|
|
+ }
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
+ }
|
|
|
//pageStatus==5 搜索页
|
|
|
if(state.pageStatus == 5){}
|
|
|
//pageStatus==6 自定义列表页
|
|
@@ -470,7 +594,24 @@ const mutations = {
|
|
|
//开始复制 end------------------------------------------------------------>
|
|
|
}
|
|
|
//pageStatus==4 详情页
|
|
|
- if(state.pageStatus == 4){}
|
|
|
+ if(state.pageStatus == 4){
|
|
|
+ //开始复制 start------------------------------------------------------------>
|
|
|
+ // 获取当前模块数据并进行深拷贝
|
|
|
+ let module = JSON.parse(JSON.stringify(state.pageData.article[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.article, dataSort, module);
|
|
|
+ console.log("当前的板块数据为:");
|
|
|
+ console.log(state.pageData.article);
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
+ }
|
|
|
//pageStatus==5 搜索页
|
|
|
if(state.pageStatus == 5){}
|
|
|
//pageStatus==6 自定义列表页
|
|
@@ -597,7 +738,53 @@ const mutations = {
|
|
|
//开始复制 end------------------------------------------------------------>
|
|
|
}
|
|
|
//pageStatus==4 详情页
|
|
|
- if(state.pageStatus == 4){}
|
|
|
+ if(state.pageStatus == 4){
|
|
|
+ //开始复制 start------------------------------------------------------------>
|
|
|
+ const targetModuleIndex = state.pageData.article.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.article[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.article, targetModuleIndex, module); // 替换为深拷贝的模块
|
|
|
+ console.log("当前的板块数据为:");
|
|
|
+ console.log(state.pageData.article);
|
|
|
+ }
|
|
|
+ //2=tabs新闻选项卡
|
|
|
+ if(state.editComponentType == 2){
|
|
|
+ // 获取当前模块数据并进行深拷贝
|
|
|
+ let module = JSON.parse(JSON.stringify(state.pageData.article[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.article, targetModuleIndex, module); // 替换为深拷贝的模块
|
|
|
+ console.log("当前的板块数据为:");
|
|
|
+ console.log(state.pageData.article);
|
|
|
+ }
|
|
|
+ //3=广告
|
|
|
+ if(state.editComponentType == 3){;
|
|
|
+ let module = JSON.parse(JSON.stringify(state.pageData.article[targetModuleIndex]));
|
|
|
+ module.content.componentList[data.sort].componentData.text = data.data.adName;
|
|
|
+ Vue.set(state.pageData.article, targetModuleIndex, module);
|
|
|
+ console.log("当前的板块数据为:");
|
|
|
+ console.log(state.pageData.article);
|
|
|
+ }
|
|
|
+ //7=文本
|
|
|
+ if(state.editComponentType == 7){
|
|
|
+ let module = JSON.parse(JSON.stringify(state.pageData.article[targetModuleIndex]));
|
|
|
+ module.content.componentList[data.sort].componentData.text = data.data.titleName;
|
|
|
+ Vue.set(state.pageData.article, targetModuleIndex, module);
|
|
|
+ console.log("当前的板块数据为:");
|
|
|
+ console.log(state.pageData.article);
|
|
|
+ }
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
+ }
|
|
|
//pageStatus==5 搜索页
|
|
|
if(state.pageStatus == 5){}
|
|
|
//pageStatus==6 自定义列表页
|
|
@@ -780,7 +967,49 @@ const mutations = {
|
|
|
//开始复制 end------------------------------------------------------------>
|
|
|
}
|
|
|
// pageStatus == 4 详情页
|
|
|
- if (state.pageStatus == 4) {}
|
|
|
+ if (state.pageStatus == 4) {
|
|
|
+ //开始复制 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.article.findIndex(item => item.i === 'drop')) === -1) {
|
|
|
+ state.pageData.article.push({
|
|
|
+ x: (state.pageData.article.length * 2) % (this.colNum || 12),
|
|
|
+ y: state.pageData.article.length + (this.colNum || 12), // puts it at the bottom
|
|
|
+ w: 12,
|
|
|
+ h: 2,
|
|
|
+ i: 'drop',
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //如果已经存在占位符
|
|
|
+ let index = state.pageData.article.findIndex(item => item.i === 'drop');
|
|
|
+ if (index !== -1) {
|
|
|
+ try {
|
|
|
+ state.gridlayoutObj.$children[state.pageData.article.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.article[index].x;
|
|
|
+ state.DragPos.y = state.pageData.article[index].y;
|
|
|
+ }
|
|
|
+ if (mouseInGrid === false) {
|
|
|
+ state.gridlayoutObj.dragEvent('dragend', 'drop', new_pos.x, new_pos.y, 2, 12);
|
|
|
+ state.pageData.article = state.pageData.article.filter(obj => obj.i !== 'drop');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //开始复制 end------------------------------------------------------------>
|
|
|
+ }
|
|
|
// pageStatus == 5 搜索页
|
|
|
if (state.pageStatus == 5) {}
|
|
|
// pageStatus == 6 自定义列表页
|
|
@@ -867,7 +1096,34 @@ const mutations = {
|
|
|
//开始复制 end------------------------------------------------------------>
|
|
|
}
|
|
|
// pageStatus == 4 详情页
|
|
|
- if (state.pageStatus == 4) {}
|
|
|
+ if (state.pageStatus == 4) {
|
|
|
+ //开始复制 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.article = state.pageData.article.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 == 5 搜索页
|
|
|
if (state.pageStatus == 5) {}
|
|
|
// pageStatus == 6 自定义列表页
|
|
@@ -892,7 +1148,11 @@ const mutations = {
|
|
|
console.log(state.pageData.list[data.i]);
|
|
|
}
|
|
|
// pageStatus == 4 详情页
|
|
|
- if (state.pageStatus == 4) {}
|
|
|
+ if (state.pageStatus == 4) {
|
|
|
+ console.log(data);
|
|
|
+ state.pageData.article[data.i].h = data.h;
|
|
|
+ console.log(state.pageData.article[data.i]);
|
|
|
+ }
|
|
|
// pageStatus == 5 搜索页
|
|
|
if (state.pageStatus == 5) {}
|
|
|
// pageStatus == 6 自定义列表页
|
|
@@ -926,6 +1186,9 @@ const mutations = {
|
|
|
if (data.type == "list") {
|
|
|
state.webSiteData.template.list = websiteData;
|
|
|
}
|
|
|
+ if (data.type == "article") {
|
|
|
+ state.webSiteData.template.article = websiteData;
|
|
|
+ }
|
|
|
},
|
|
|
//保存模板
|
|
|
saveTemplate(state) {
|
|
@@ -936,6 +1199,8 @@ const mutations = {
|
|
|
this.commit('template/formatTemplateInfo',{data:state.pageData.index,type:"index"});
|
|
|
//格式化list的信息
|
|
|
this.commit('template/formatTemplateInfo',{data:state.pageData.list,type:"list"});
|
|
|
+ //格式化article的信息
|
|
|
+ this.commit('template/formatTemplateInfo',{data:state.pageData.article,type:"article"});
|
|
|
console.log(state.webSiteData);
|
|
|
},
|
|
|
//随机生成模板
|