|
@@ -81,7 +81,7 @@ const state = {
|
|
|
|
|
|
const mutations = {
|
|
|
//0.全局配置 start------------------------------------------------------------>
|
|
|
- //设置创建网站的id
|
|
|
+ //设置网站的id
|
|
|
setEditWebsiteId(state,id){
|
|
|
state.editWebsiteId = id;
|
|
|
},
|
|
@@ -93,12 +93,12 @@ const mutations = {
|
|
|
hiddenStepStatus(state){
|
|
|
state.stepStatus = false;
|
|
|
},
|
|
|
+ //设置步骤
|
|
|
setPageStatus(state,num){
|
|
|
state.pageStatus = num;
|
|
|
},
|
|
|
//打开编辑组件弹出框
|
|
|
setEditWindowStatus(state,data){
|
|
|
- console.log(data);
|
|
|
state.editWindowStatus = true;
|
|
|
state.editSectorId = data.id;
|
|
|
state.editComponentSort = data.sort;
|
|
@@ -139,181 +139,196 @@ const mutations = {
|
|
|
let sort = state.editComponentSort;
|
|
|
let num = state.editComponentStyle;
|
|
|
|
|
|
- // 获取当前模块数据并进行深拷贝
|
|
|
- let module = JSON.parse(JSON.stringify(state.pageData.index[id]));
|
|
|
- module.content.componentList[sort].component_style = num;
|
|
|
- // 拷贝后直接替换原来的板块
|
|
|
- //state.pageData.index[id] = module;
|
|
|
- // 使用Vue.set来强制视图更新
|
|
|
- Vue.set(state.pageData.index, id, module);
|
|
|
- console.log("当前的板块数据为:");
|
|
|
- console.log(state.pageData.index);
|
|
|
-
|
|
|
-
|
|
|
+ //pageStatus==1 首页
|
|
|
+ if(state.pageStatus == 1){
|
|
|
+ // 获取当前模块数据并进行深拷贝
|
|
|
+ let module = JSON.parse(JSON.stringify(state.pageData.index[id]));
|
|
|
+ //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.index, id, module);
|
|
|
+ console.log("当前的板块数据为:");
|
|
|
+ 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){}
|
|
|
},
|
|
|
//0.全局配置 start------------------------------------------------------------>
|
|
|
//1.配置模块 start------------------------------------------------------------>
|
|
|
- //添加首页板块
|
|
|
- addIndexModule(state,data){
|
|
|
- //判断当前一共有多少个模块最多能添加10个
|
|
|
- if(state.pageData.index.length >= 10){
|
|
|
- Message.error('最多只能添加10个模块!');
|
|
|
- return;
|
|
|
- }else{
|
|
|
- //data.type 组件名称 data.h 模块高度
|
|
|
- //计算当前布局的最大 y 值
|
|
|
- const maxY = Math.max(...state.pageData.index.map(item => item.y), 0);
|
|
|
- console.log(data);
|
|
|
- //添加板块id
|
|
|
- state.pageData.index.push({
|
|
|
- i: state.pageData.index.length,
|
|
|
- x: 0,
|
|
|
- y: maxY + 1,
|
|
|
- w: 12,
|
|
|
- h: data.h,
|
|
|
- type: data.type,
|
|
|
- //content:"",
|
|
|
- //sectorData:data.jsonData
|
|
|
- content:data.jsonData
|
|
|
- });
|
|
|
- // console.log("当前添加的板块id:" + state.pageData.index.length);
|
|
|
- // data.jsonData.sectorId = state.pageData.index.length;
|
|
|
- // console.log("添加完毕后的数据:");
|
|
|
- // console.log(state.pageData.index);
|
|
|
+ //添加板块
|
|
|
+ addModule(state,data){
|
|
|
+ //pageStatus==1 首页
|
|
|
+ if(state.pageStatus == 1){
|
|
|
+ //判断当前一共有多少个模块最多能添加10个
|
|
|
+ if(state.pageData.index.length >= 10){
|
|
|
+ Message.error('最多只能添加10个模块!');
|
|
|
+ return;
|
|
|
+ }else{
|
|
|
+ //data.type 组件名称 data.h 模块高度
|
|
|
+ //计算当前布局的最大 y 值
|
|
|
+ const maxY = Math.max(...state.pageData.index.map(item => item.y), 0);
|
|
|
+ console.log(data);
|
|
|
+ //添加板块id
|
|
|
+ state.pageData.index.push({
|
|
|
+ i: state.pageData.index.length,
|
|
|
+ x: 0,
|
|
|
+ y: maxY + 1,
|
|
|
+ w: 12,
|
|
|
+ h: data.h,
|
|
|
+ type: data.type,
|
|
|
+ //content:"",
|
|
|
+ //sectorData:data.jsonData
|
|
|
+ content:data.jsonData
|
|
|
+ });
|
|
|
+ // console.log("当前添加的板块id:" + state.pageData.index.length);
|
|
|
+ // data.jsonData.sectorId = state.pageData.index.length;
|
|
|
+ // console.log("添加完毕后的数据:");
|
|
|
+ // 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){}
|
|
|
},
|
|
|
- //删除首页板块
|
|
|
- deleteIndexModule(state,data){
|
|
|
- for(let i = 0; i < state.pageData.index.length; i++) {
|
|
|
- if(state.pageData.index[i].i == data.i) {
|
|
|
- state.pageData.index.splice(i, 1);
|
|
|
+ //删除板块
|
|
|
+ deleteModule(state,data){
|
|
|
+ //pageStatus==1 首页
|
|
|
+ if(state.pageStatus == 1){
|
|
|
+ for(let i = 0; i < state.pageData.index.length; i++) {
|
|
|
+ if(state.pageData.index[i].i == data.i) {
|
|
|
+ state.pageData.index.splice(i, 1);
|
|
|
+ }
|
|
|
}
|
|
|
+ Message.success('模块已删除!');
|
|
|
+ console.log("删除后的数据结构:");
|
|
|
+ console.log(state.pageData.index);
|
|
|
}
|
|
|
- Message.success('模块已删除!');
|
|
|
- console.log("删除后的数据结构:");
|
|
|
- console.log(state.pageData.index);
|
|
|
- },
|
|
|
- //修改首页板块高度
|
|
|
- setIndexModuleHeight(state,data){
|
|
|
- console.log(data);
|
|
|
- state.pageData.index[data.i].h = data.h;
|
|
|
- console.log(state.pageData.index[data.i]);
|
|
|
+ //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){}
|
|
|
},
|
|
|
- moveIndexModule(state, data) {
|
|
|
- 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;
|
|
|
- }
|
|
|
- const thisY = modules[thisIndex].y;
|
|
|
-
|
|
|
- if (moveType === 'up') {
|
|
|
- // 查找比当前模块 y 值小的最大的 y 值
|
|
|
- const thatY = Math.max(
|
|
|
- ...modules
|
|
|
- .filter(item => item.y < thisY)
|
|
|
- .map(item => item.y)
|
|
|
- );
|
|
|
- if (thatY === -Infinity) {
|
|
|
- Message.error('已经是顶部了!');
|
|
|
+ //移动板块 (暂时停用)
|
|
|
+ moveModule(state, data) {
|
|
|
+ // 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;
|
|
|
}
|
|
|
- // 查找具有 thatY 的模块索引
|
|
|
- const thatIndex = modules.findIndex(item => item.y === thatY);
|
|
|
- if (thatIndex === -1) {
|
|
|
- Message.error('上方模块未找到!');
|
|
|
- return;
|
|
|
- }
|
|
|
- // 交换 y 值
|
|
|
- [modules[thisIndex].y, modules[thatIndex].y] = [modules[thatIndex].y, modules[thisIndex].y];
|
|
|
+ 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];
|
|
|
|
|
|
- } else if (moveType === 'down') {
|
|
|
- // 查找比当前模块 y 值大的最小的 y 值
|
|
|
- const thatY = Math.min(
|
|
|
- ...modules
|
|
|
- .filter(item => item.y > thisY)
|
|
|
- .map(item => item.y)
|
|
|
- );
|
|
|
- if (thatY === Infinity) {
|
|
|
- Message.error('已经是底部了!');
|
|
|
- return;
|
|
|
- }
|
|
|
- // 查找具有 thatY 的模块索引
|
|
|
- const thatIndex = modules.findIndex(item => item.y === thatY);
|
|
|
- if (thatIndex === -1) {
|
|
|
- Message.error('下方模块未找到!');
|
|
|
+ } 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;
|
|
|
}
|
|
|
- // 交换 y 值
|
|
|
- [modules[thisIndex].y, modules[thatIndex].y] = [modules[thatIndex].y, modules[thisIndex].y];
|
|
|
-
|
|
|
- } else {
|
|
|
- Message.error('未知的移动类型!');
|
|
|
- return;
|
|
|
+ // 交换后对模块进行排序以确保顺序一致
|
|
|
+ modules.sort((a, b) => a.y - b.y);
|
|
|
+ // 使用 Vue.set 强制更新数组,确保视图更新
|
|
|
+ Vue.set(state.pageData, 'index', [...modules]);
|
|
|
+ console.log(state.pageData.index); //打印查看是否已修改
|
|
|
}
|
|
|
- // 交换后对模块进行排序以确保顺序一致
|
|
|
- state.pageData.index.sort((a, b) => a.y - b.y);
|
|
|
+ // 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) {}
|
|
|
+ },
|
|
|
+ //修改首页板块高度
|
|
|
+ setIndexModuleHeight(state,data){
|
|
|
+ // pageStatus == 1 首页
|
|
|
+ if (state.pageStatus == 1) {
|
|
|
+ console.log(data);
|
|
|
+ state.pageData.index[data.i].h = data.h;
|
|
|
+ console.log(state.pageData.index[data.i]);
|
|
|
+ }
|
|
|
+ // 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) {}
|
|
|
},
|
|
|
- //添加模块
|
|
|
- // addModule(state,data) {
|
|
|
- // //data.type 组件名称 data.h 模块高度
|
|
|
- // // 计算当前布局的最大 y 值
|
|
|
- // const maxY = Math.max(...state.layout.map(item => item.y), 0);
|
|
|
- // state.layout.push({
|
|
|
- // i: state.layout.length,
|
|
|
- // x: 0,
|
|
|
- // y: maxY + 1,
|
|
|
- // w: 12,
|
|
|
- // h: data.h,
|
|
|
- // type: data.type,
|
|
|
- // content:""
|
|
|
- // });
|
|
|
- // },
|
|
|
- //删除模块
|
|
|
- // deleteModule(item) {
|
|
|
- // //找到对应的模块删除掉
|
|
|
- // for(let i = 0; i < state.layout.length; i++) {
|
|
|
- // if(state.layout[i].i == item.i) {
|
|
|
- // state.layout.splice(i, 1);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // },
|
|
|
- //移动模块
|
|
|
- // moveIndexModule(state,data){
|
|
|
- // console.log(state.pageData.index[data.i]);
|
|
|
-
|
|
|
- // if(data.moveType == 'up'){
|
|
|
-
|
|
|
- // }else{
|
|
|
-
|
|
|
- // if(state.pageData.index[data.i].y === Math.max(...state.pageData.index.map(item => item.y))){
|
|
|
- // Message.error('已经是底部了!');
|
|
|
- // }else{
|
|
|
- // console.log(state.pageData.index);
|
|
|
- // //当前选择的模块
|
|
|
- // let thisIndex = data.i;
|
|
|
- // let thisY = state.pageData.index[thisIndex].y;
|
|
|
-
|
|
|
- // //找到下方的模块的y值
|
|
|
- // //注意,这里不能用i去定位,因为模块是通过y值去排序的,跟数据的位置,i的位置都没有关系
|
|
|
- // const thatY = Math.min(...state.pageData.index
|
|
|
- // .filter(item => item.y > thisY)
|
|
|
- // .map(item => item.y),
|
|
|
- // Infinity);
|
|
|
- // //再通过y值找到对应的模块i
|
|
|
- // const thatIndex = state.pageData.index.findIndex(item => item.y === thatY);
|
|
|
-
|
|
|
- // //最后交换位置
|
|
|
- // state.pageData.index[thisIndex].y = thatY;
|
|
|
- // state.pageData.index[thatIndex].y = thisY;
|
|
|
- // }
|
|
|
-
|
|
|
- // }
|
|
|
- // },
|
|
|
//格式化模板信息
|
|
|
formatTemplateInfo(state, data) {
|
|
|
//console.log(data.type);
|