template.js 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711
  1. //cms中的接口 获取网站基本信息,网站导航,网站底部导航,网站行政区划,行政职能
  2. import {getSiteInfo,getSiteCategory,getFooterCategoryList,selectWebsiteArea,selectWebsiteDepartment } from '@/api/cms'
  3. //自助建站的接口 用于添加基本信息
  4. import {getWebsiteintel,addWebsiteTemplateintel,getWebsiteTemplateintel,upWebsiteTemplateintel,getAllTemplateClass,getWebsiteTemplateList,addWebsiteTemplateclassintel,
  5. getWebsiteTemplateclassintel,addWebsiteTemplate,getWebsiteTemplateInfo,getWebsiteTemplateData} from '@/api/template'
  6. import { Message } from 'element-ui'; //注意在这里引入是非常不符合规范的
  7. import Vue from 'vue'; //导入Vue 因为我们要进行深层次的json修改,深拷贝的数据无法令视图更新
  8. //所以我们需要使用Vue的$set方法来强制视图更新,在vuex中没有this,这里我们需要通过引入vue来使用vue.$set
  9. //引入随机模板json
  10. //首页 风格1
  11. import randomIndex1 from '@/utils/templateJson/index/style1/1.js';
  12. //首页 风格2
  13. import randomIndex2 from '@/utils/templateJson/index/style1/2.js';
  14. const state = {
  15. //0.全局配置 start------------------------------------------------------------>
  16. editWebsiteId: "",//当前编辑网站的id
  17. editWebsiteClass:"",//当前编辑网站的风格
  18. stepStatus: true,//是否显示现在进行到哪一步:true=显示 false=不显示
  19. //0.全局配置 end------------------------------------------------------------>
  20. //1.画布数据 start------------------------------------------------------------>
  21. pageStatus:1,//当前编辑哪个页面 1=首页 2=分类页 3=列表页 4=详情页 5=搜索页 6=自定义列表页 7=自定义详情页
  22. menuType:1, //当前菜单显示板块还是组件 1=板块 2=组件
  23. previewStatus:false,//是否预览
  24. gridKey:0,//使用gridKey来强制更新视图
  25. loading:false,//是否显示加载中
  26. ad_id:"",//生成储存的广告id
  27. showPage:{ //哪些页面可以被展示
  28. index:true,
  29. class:false,
  30. list:true,
  31. article:true,
  32. search:false,
  33. aloneList:false,
  34. aloneArticle:false
  35. },
  36. pageData: { //自助建站拖拽板块的数据,注意,这里并不是提交到后台的数据
  37. index:[
  38. ],//首页
  39. class:[],//分类页
  40. list:[],//列表页
  41. article:[],//详情页
  42. search:[],//搜索页
  43. aloneList:[],//自定义列表页
  44. aloneArticle:[],//自定义详情页
  45. },
  46. // layout: [
  47. // // i = id
  48. // // w = 最大宽度是12
  49. // // { i: "0", x: 0, y: 0, w: 12, h: 2, content:""},
  50. // // { i: "1", x: 0, y: 0, w: 12, h: 2, content:""},
  51. // ],
  52. //1.画布数据 end------------------------------------------------------------>
  53. //2.站点数据 start------------------------------------------------------------>
  54. webSiteInfo:"",//网站信息
  55. webSiteMenu:"",//网站包含的导航池
  56. area:{//地区
  57. economize:[],//省区
  58. market:[],//市区
  59. county:[]//县区
  60. },
  61. departmentList:[],//职能部门
  62. //2.站点数据 end------------------------------------------------------------>
  63. //3.画布构造 start------------------------------------------------------------>
  64. editSectorY:0,//当前组件在画布中的位置
  65. mouseXY:{//鼠标位置
  66. "x": 12,
  67. "y": 33
  68. },
  69. DragPos:{//创建的占位符大小
  70. "x": null,
  71. "y": null,
  72. "w": 12,
  73. "h": 2,
  74. "i": null
  75. },
  76. //获得gridlayout对象
  77. gridlayoutObj:null,
  78. //3.画布构造 end------------------------------------------------------------>
  79. //4.构造的网站数据 start------------------------------------------------------------>
  80. editWindowStatus:false,//编辑组件弹出框是否显示
  81. editComponentWindowStatus:false,//选择组件样式弹出框是否显示
  82. editWebsiteTemplateJsonWindow:false,//当前准备提交的数据 后期删除
  83. editWindowTitle:"",//编辑弹出框标题
  84. editSectorId:0,//当前正在编辑的板块id
  85. editDataSort:0,//当前正在编辑的数据位置
  86. editComponentSort:0,//当前正在编辑的组件id
  87. editComponentType:0,//当前正在编辑的组件类型
  88. editComponentSize:0,//当前组件展示的条数
  89. editComponentStyle:0,//当前编辑的组件样式
  90. editWebsiteCategory:[],//当前网站全部关联导航
  91. webSiteData:{
  92. //1.base网站基本信息
  93. base:{
  94. websiteId:"",//网站id
  95. },
  96. //2.style信息
  97. style:{
  98. styleId:"",//风格id
  99. },
  100. //3.板块信息 header,menu,footer 是页面自带的无需构建
  101. template:{
  102. //index = 首页 class=分类页 list=列表页 article=详情页 search=搜索页 aloneList=自定义列表页 aloneArticle=自定义详情页
  103. index:[],
  104. class:[],//分类页
  105. list:[],//列表页
  106. article:[],//详情页
  107. search:[],//搜索页
  108. aloneList:[],//自定义列表页
  109. aloneArticle:[],//自定义详情页
  110. }
  111. },
  112. canSubmit:false,//当前数据是否可以被提交
  113. //4.构造的网站数据 end------------------------------------------------------------>
  114. //5.组件回显数据 start------------------------------------------------------------>
  115. componentViewData:{
  116. pid_arr:[],//导航池
  117. pageSize:"",//展示条数
  118. adName:"",//广告名称
  119. titleName:"",//标题名称
  120. }
  121. //5.组件回显数据 start------------------------------------------------------------>
  122. }
  123. const mutations = {
  124. //0.全局配置 start------------------------------------------------------------>
  125. //设置网站的id
  126. setEditWebsiteId(state,id){
  127. state.editWebsiteId = id;
  128. },
  129. //设置网站的风格
  130. setClassNumber(state,id){
  131. state.editWebsiteClass = id;
  132. },
  133. //展示步骤
  134. showStepStatus(state){
  135. state.stepStatus = true;
  136. },
  137. //隐藏步骤
  138. hiddenStepStatus(state){
  139. state.stepStatus = false;
  140. },
  141. //设置步骤
  142. setPageStatus(state,num){
  143. state.pageStatus = num;
  144. },
  145. //设置预览状态
  146. setPreviewStatus(state){
  147. state.previewStatus = !state.previewStatus;
  148. },
  149. //打开编辑组件弹出框
  150. setEditWindowStatus(state,data){
  151. state.editWindowStatus = true;
  152. state.editSectorId = data.id;
  153. state.editSectorY = data.y;
  154. state.editDataSort = data.dataSort;
  155. state.editComponentSort = data.sort;
  156. state.editComponentType = data.type;
  157. state.editComponentSize = data.size;
  158. },
  159. //关闭编辑组件弹出框
  160. closeEditWindowStatus(state){
  161. state.editWindowStatus = false;
  162. },
  163. //打开选择组件样式弹出框
  164. setComponentStyleStatus(state,data){
  165. state.editComponentWindowStatus = true;
  166. state.editSectorId = data.id;
  167. state.editDataSort = data.dataSort;
  168. state.editComponentSort = data.sort;
  169. state.editComponentType = data.type;
  170. state.editComponentStyle = data.style;
  171. },
  172. //关闭选择组件样式弹出框
  173. closeComponentStyleStatus(state){
  174. state.editComponentWindowStatus = false;
  175. },
  176. //关闭提交数据弹出框
  177. closeEditWebsiteTemplateJsonWindow(state){
  178. state.editWebsiteTemplateJsonWindow = false;
  179. },
  180. //选择组件样式
  181. selectComponentStyleNumber(state,data){
  182. state.editComponentStyle = data;
  183. },
  184. //设置组件回显数据
  185. setComponentViewData(state,data){
  186. //首页
  187. if(state.pageStatus == 1){
  188. //找到要修改的板块
  189. const targetModuleIndex = state.pageData.index.findIndex(module => module.i === data.id);
  190. //判断组件类型 1=普通新闻 2=tabs新闻选项卡 3=广告 4=友情链接 6=静态组件 7=文本 8=评论
  191. if(state.editComponentType == 1){
  192. state.componentViewData.pid_arr = state.pageData.index[targetModuleIndex].content.componentList[data.sort].componentData.category_id;
  193. state.componentViewData.pageSize = state.editComponentSize;
  194. }
  195. //2=tabs新闻选项卡
  196. if(state.editComponentType == 2){
  197. state.componentViewData.pid_arr = state.pageData.index[targetModuleIndex].content.componentList[data.sort].componentData.category_id;
  198. state.componentViewData.pageSize = state.editComponentSize;
  199. }
  200. //3=广告名称
  201. if(state.editComponentType == 3){
  202. state.componentViewData.adName = state.pageData.index[targetModuleIndex].content.componentList[data.sort].componentData.text;
  203. }
  204. //7=标题
  205. if(state.editComponentType == 7){
  206. state.componentViewData.titleName = state.pageData.index[targetModuleIndex].content.componentList[data.sort].componentData.text;
  207. }
  208. }
  209. //pageStatus==2 分类页
  210. if(state.pageStatus == 2){}
  211. //pageStatus==3 列表页
  212. if(state.pageStatus == 3){
  213. const targetModuleIndex = state.pageData.list.findIndex(module => module.i === data.id);
  214. //判断组件类型 1=普通新闻 2=tabs新闻选项卡 3=广告 4=友情链接 6=静态组件 7=文本 8=评论
  215. if(state.editComponentType == 1){
  216. state.componentViewData.pid_arr = state.pageData.list[targetModuleIndex].content.componentList[data.sort].componentData.category_id;
  217. state.componentViewData.pageSize = state.editComponentSize;
  218. }
  219. //2=tabs新闻选项卡
  220. if(state.editComponentType == 2){
  221. state.componentViewData.pid_arr = state.pageData.list[targetModuleIndex].content.componentList[data.sort].componentData.category_id;
  222. state.componentViewData.pageSize = state.editComponentSize;
  223. }
  224. //3=广告名称
  225. if(state.editComponentType == 3){
  226. state.componentViewData.adName = state.pageData.list[targetModuleIndex].content.componentList[data.sort].componentData.text;
  227. }
  228. //7=标题
  229. if(state.editComponentType == 7){
  230. state.componentViewData.titleName = state.pageData.list[targetModuleIndex].content.componentList[data.sort].componentData.text;
  231. }
  232. }
  233. //pageStatus==4 详情页
  234. if(state.pageStatus == 4){
  235. const targetModuleIndex = state.pageData.article.findIndex(module => module.i === data.id);
  236. //判断组件类型 1=普通新闻 2=tabs新闻选项卡 3=广告 4=友情链接 6=静态组件 7=文本 8=评论
  237. if(state.editComponentType == 1){
  238. state.componentViewData.pid_arr = state.pageData.article[targetModuleIndex].content.componentList[data.sort].componentData.category_id;
  239. state.componentViewData.pageSize = state.editComponentSize;
  240. }
  241. //2=tabs新闻选项卡
  242. if(state.editComponentType == 2){
  243. state.componentViewData.pid_arr = state.pageData.article[targetModuleIndex].content.componentList[data.sort].componentData.category_id;
  244. state.componentViewData.pageSize = state.editComponentSize;
  245. }
  246. //3=广告名称
  247. if(state.editComponentType == 3){
  248. state.componentViewData.adName = state.pageData.article[targetModuleIndex].content.componentList[data.sort].componentData.text;
  249. }
  250. //7=标题
  251. if(state.editComponentType == 7){
  252. state.componentViewData.titleName = state.pageData.article[targetModuleIndex].content.componentList[data.sort].componentData.text;
  253. }
  254. }
  255. //pageStatus==5 搜索页
  256. if(state.pageStatus == 5){}
  257. //pageStatus==6 自定义列表页
  258. if(state.pageStatus == 6){}
  259. //pageStatus==7 自定义详情页
  260. if(state.pageStatus == 7){}
  261. },
  262. //生成一个随机的广告id
  263. getRandomAdid(state){
  264. //网站id
  265. const websiteId = state.editWebsiteId;
  266. // 生成 3 个随机字母 (a-z)
  267. const randomLettersOne = Math.random().toString(36).substring(2, 5); // 生成随机字母并去除前面的 "0."
  268. // 获取当前时间戳(毫秒级)
  269. const timestamp = Date.now();
  270. // 生成 5 个随机字母 (a-z)
  271. const randomLettersTwo = Math.random().toString(36).substring(2, 7); // 生成随机字母并去除前面的 "0."
  272. // 拼接时间戳和随机字母生成唯一 ID
  273. const ad_id = `${websiteId}${randomLettersOne}${timestamp}${randomLettersTwo}`;
  274. state.ad_id = ad_id;
  275. },
  276. //0.全局配置 start------------------------------------------------------------>
  277. //1.配置模块 start------------------------------------------------------------>
  278. //获得gridlayout对象
  279. setGridlayoutObj(state,data){
  280. state.gridlayoutObj = data;
  281. },
  282. //添加板块
  283. addModule(state,data){
  284. //pageStatus==1 首页 index
  285. if(state.pageStatus == 1){
  286. //开始复制 start------------------------------------------------------------>
  287. //判断当前一共有多少个模块最多能添加10个
  288. if(state.pageData.index.length >= 10){
  289. Message.error('最多只能添加10个模块!');
  290. return;
  291. }else{
  292. console.log(data.jsonData)
  293. //判断是拖拽的还是点击添加进来的 click=点击
  294. if(data.source == "click"){
  295. console.log("通过点击添加一个板块");
  296. //通过时间戳生成id
  297. const currentTimestamp = Date.now();
  298. let id = currentTimestamp;
  299. //data.type 组件名称 data.h 模块高度
  300. //计算当前布局的最大 y 值
  301. const maxY = Math.max(...state.pageData.index.map(item => item.y), 0);
  302. console.log(data);
  303. //设置数据在构建json中的位置
  304. let dataSort = state.pageData.index.length;
  305. //判断添加的是否为广告模块 如果是 添加一个ad_id
  306. if(data.jsonData.componentList[0].component_type==3){
  307. this.commit("template/getRandomAdid")
  308. //添加板块id
  309. state.pageData.index.push({
  310. //i: state.pageData.index.length, //base 0.0.1 此方法会导致重复的id出现
  311. i: id,
  312. x: 0,
  313. y: maxY + 1,
  314. w: 12,
  315. h: data.h,
  316. type: data.type,
  317. adid: state.ad_id,
  318. //sectorData:data.jsonData //base 0.0.1 此问题导致深层数据无法被视图渲染
  319. content:data.jsonData,
  320. dataSort:dataSort,
  321. });
  322. }else{
  323. state.pageData.index.push({
  324. //i: state.pageData.index.length, //base 0.0.1 此方法会导致重复的id出现
  325. i: id,
  326. x: 0,
  327. y: maxY + 1,
  328. w: 12,
  329. h: data.h,
  330. type: data.type,
  331. //sectorData:data.jsonData //base 0.0.1 此问题导致深层数据无法被视图渲染
  332. content:data.jsonData,
  333. dataSort:dataSort,
  334. });
  335. }
  336. console.log("当前添加模块的dataSort为:" + dataSort);
  337. //当前的页面构建数据
  338. console.log(state.pageData.index);
  339. }
  340. //drag=拖拽
  341. if(data.source == "drag"){
  342. //拖拽添加
  343. console.log("通过拖拽添加一个板块");
  344. //通过时间戳生成id
  345. const currentTimestamp = Date.now();
  346. let id = currentTimestamp;
  347. //data.type 组件名称 data.h 模块高度
  348. //计算当前布局的最大 y 值
  349. const maxY = Math.max(...state.pageData.index.map(item => item.y), 0);
  350. console.log(data);
  351. //设置数据在构建json中的位置
  352. let dataSort = state.pageData.index.length;
  353. //判断添加的是否为广告模块 如果是 添加一个ad_id
  354. if(data.jsonData.componentList[0].component_type==3){
  355. this.commit("template/getRandomAdid")
  356. //添加板块id
  357. state.pageData.index.push({
  358. //i: state.pageData.index.length, //base 0.0.1 此方法会导致重复的id出现
  359. i: id,
  360. x: 0,
  361. y: maxY + 1,
  362. w: 12,
  363. h: data.h,
  364. type: data.type,
  365. adid: state.ad_id,
  366. //sectorData:data.jsonData //base 0.0.1 此问题导致深层数据无法被视图渲染
  367. content:data.jsonData,
  368. dataSort:dataSort,
  369. });
  370. }else{
  371. state.pageData.index.push({
  372. //i: state.pageData.index.length, //base 0.0.1 此方法会导致重复的id出现
  373. i: id,
  374. x: 0,
  375. y: maxY + 1,
  376. w: 12,
  377. h: data.h,
  378. type: data.type,
  379. //sectorData:data.jsonData //base 0.0.1 此问题导致深层数据无法被视图渲染
  380. content:data.jsonData,
  381. dataSort:dataSort,
  382. });
  383. }
  384. console.log("当前添加模块的dataSort为:" + dataSort);
  385. //当前的页面构建数据
  386. console.log(state.pageData.index);
  387. //需要调查一下这里最后的1,1
  388. state.gridlayoutObj.dragEvent('dragend', data.i, data.x, data.y, 1,1);
  389. try {
  390. state.gridlayoutObj.$children[state.pageData.index.length].$refs.item.style.display="block";
  391. } catch {}
  392. }
  393. }
  394. //开始复制 end------------------------------------------------------------>
  395. }
  396. //pageStatus==2 分类页 class
  397. if(state.pageStatus == 2){}
  398. //pageStatus==3 列表页 list
  399. if(state.pageStatus == 3){
  400. //开始复制 start------------------------------------------------------------>
  401. //判断当前一共有多少个模块最多能添加10个
  402. if(state.pageData.list.length >= 10){
  403. Message.error('最多只能添加10个模块!');
  404. return;
  405. }else{
  406. //判断是拖拽的还是点击添加进来的 click=点击
  407. if(data.source == "click"){
  408. console.log("通过点击添加一个板块");
  409. //通过时间戳生成id
  410. const currentTimestamp = Date.now();
  411. let id = currentTimestamp;
  412. //data.type 组件名称 data.h 模块高度
  413. //计算当前布局的最大 y 值
  414. const maxY = Math.max(...state.pageData.list.map(item => item.y), 0);
  415. console.log(data);
  416. //设置数据在构建json中的位置
  417. let dataSort = state.pageData.list.length;
  418. //判断添加的是否为广告模块 如果是 添加一个ad_id
  419. if(data.jsonData.componentList[0].component_type==3){
  420. this.commit("template/getRandomAdid")
  421. //添加板块id
  422. state.pageData.list.push({
  423. //i: state.pageData.index.length, //base 0.0.1 此方法会导致重复的id出现
  424. i: id,
  425. x: 0,
  426. y: maxY + 1,
  427. w: 12,
  428. h: data.h,
  429. type: data.type,
  430. adid: state.ad_id,
  431. //sectorData:data.jsonData //base 0.0.1 此问题导致深层数据无法被视图渲染
  432. content:data.jsonData,
  433. dataSort:dataSort,
  434. });
  435. }else{
  436. state.pageData.list.push({
  437. //i: state.pageData.index.length, //base 0.0.1 此方法会导致重复的id出现
  438. i: id,
  439. x: 0,
  440. y: maxY + 1,
  441. w: 12,
  442. h: data.h,
  443. type: data.type,
  444. //sectorData:data.jsonData //base 0.0.1 此问题导致深层数据无法被视图渲染
  445. content:data.jsonData,
  446. dataSort:dataSort,
  447. });
  448. }
  449. }
  450. //drag=拖拽
  451. if(data.source == "drag"){
  452. //拖拽添加
  453. console.log("通过拖拽添加一个板块");
  454. //通过时间戳生成id
  455. const currentTimestamp = Date.now();
  456. let id = currentTimestamp;
  457. //data.type 组件名称 data.h 模块高度
  458. //计算当前布局的最大 y 值
  459. const maxY = Math.max(...state.pageData.list.map(item => item.y), 0);
  460. console.log(data);
  461. //设置数据在构建json中的位置
  462. let dataSort = state.pageData.list.length;
  463. //判断添加的是否为广告模块 如果是 添加一个ad_id
  464. if(data.jsonData.componentList[0].component_type==3){
  465. this.commit("template/getRandomAdid")
  466. //添加板块id
  467. state.pageData.list.push({
  468. //i: state.pageData.index.length, //base 0.0.1 此方法会导致重复的id出现
  469. i: id,
  470. x: 0,
  471. y: maxY + 1,
  472. w: 12,
  473. h: data.h,
  474. type: data.type,
  475. adid: state.ad_id,
  476. //sectorData:data.jsonData //base 0.0.1 此问题导致深层数据无法被视图渲染
  477. content:data.jsonData,
  478. dataSort:dataSort,
  479. });
  480. }else{
  481. state.pageData.list.push({
  482. //i: state.pageData.index.length, //base 0.0.1 此方法会导致重复的id出现
  483. i: id,
  484. x: 0,
  485. y: maxY + 1,
  486. w: 12,
  487. h: data.h,
  488. type: data.type,
  489. //sectorData:data.jsonData //base 0.0.1 此问题导致深层数据无法被视图渲染
  490. content:data.jsonData,
  491. dataSort:dataSort,
  492. });
  493. }
  494. console.log("当前添加模块的dataSort为:" + dataSort);
  495. //当前的页面构建数据
  496. console.log(state.pageData.list);
  497. //需要调查一下这里最后的1,1
  498. state.gridlayoutObj.dragEvent('dragend', data.i, data.x, data.y, 1,1);
  499. try {
  500. state.gridlayoutObj.$children[state.pageData.list.length].$refs.item.style.display="block";
  501. } catch {}
  502. }
  503. }
  504. //开始复制 end------------------------------------------------------------>
  505. }
  506. //pageStatus==4 详情页 article
  507. if(state.pageStatus == 4){
  508. //开始复制 start------------------------------------------------------------>
  509. //判断当前一共有多少个模块最多能添加10个
  510. if(state.pageData.article.length >= 10){
  511. Message.error('最多只能添加10个模块!');
  512. return;
  513. }else{
  514. //判断添加的是否为广告模块 如果是 添加一个ad_id
  515. if(data.jsonData.componentList[0].component_type==3){
  516. //生成一个随机的ad_id给广告模块
  517. this.commit("template/getRandomAdid");
  518. console.log("添加广告模块!id为:" + state.ad_id)
  519. data.jsonData.componentList[0].componentData.ad_id = state.ad_id;
  520. }
  521. //判断是拖拽的还是点击添加进来的 click=点击
  522. if(data.source == "click"){
  523. console.log("通过点击添加一个板块");
  524. //通过时间戳生成id
  525. const currentTimestamp = Date.now();
  526. let id = currentTimestamp;
  527. //data.type 组件名称 data.h 模块高度
  528. //计算当前布局的最大 y 值
  529. const maxY = Math.max(...state.pageData.article.map(item => item.y), 0);
  530. console.log(data);
  531. //设置数据在构建json中的位置
  532. let dataSort = state.pageData.article.length;
  533. //判断添加的是否为广告模块 如果是 添加一个ad_id
  534. if(data.jsonData.componentList[0].component_type==3){
  535. this.commit("template/getRandomAdid")
  536. //添加板块id
  537. state.pageData.article.push({
  538. //i: state.pageData.index.length, //base 0.0.1 此方法会导致重复的id出现
  539. i: id,
  540. x: 0,
  541. y: maxY + 1,
  542. w: 12,
  543. h: data.h,
  544. type: data.type,
  545. adid: state.ad_id,
  546. //sectorData:data.jsonData //base 0.0.1 此问题导致深层数据无法被视图渲染
  547. content:data.jsonData,
  548. dataSort:dataSort,
  549. });
  550. }else{
  551. state.pageData.article.push({
  552. //i: state.pageData.index.length, //base 0.0.1 此方法会导致重复的id出现
  553. i: id,
  554. x: 0,
  555. y: maxY + 1,
  556. w: 12,
  557. h: data.h,
  558. type: data.type,
  559. //sectorData:data.jsonData //base 0.0.1 此问题导致深层数据无法被视图渲染
  560. content:data.jsonData,
  561. dataSort:dataSort,
  562. });
  563. }
  564. }
  565. //drag=拖拽
  566. if(data.source == "drag"){
  567. //拖拽添加
  568. console.log("通过拖拽添加一个板块");
  569. //通过时间戳生成id
  570. const currentTimestamp = Date.now();
  571. let id = currentTimestamp;
  572. //data.type 组件名称 data.h 模块高度
  573. //计算当前布局的最大 y 值
  574. const maxY = Math.max(...state.pageData.article.map(item => item.y), 0);
  575. console.log(data);
  576. //设置数据在构建json中的位置
  577. let dataSort = state.pageData.article.length;
  578. //判断添加的是否为广告模块 如果是 添加一个ad_id
  579. if(data.jsonData.componentList[0].component_type==3){
  580. this.commit("template/getRandomAdid")
  581. //添加板块id
  582. state.pageData.article.push({
  583. //i: state.pageData.index.length, //base 0.0.1 此方法会导致重复的id出现
  584. i: id,
  585. x: 0,
  586. y: maxY + 1,
  587. w: 12,
  588. h: data.h,
  589. type: data.type,
  590. adid: state.ad_id,
  591. //sectorData:data.jsonData //base 0.0.1 此问题导致深层数据无法被视图渲染
  592. content:data.jsonData,
  593. dataSort:dataSort,
  594. });
  595. }else{
  596. state.pageData.article.push({
  597. //i: state.pageData.index.length, //base 0.0.1 此方法会导致重复的id出现
  598. i: id,
  599. x: 0,
  600. y: maxY + 1,
  601. w: 12,
  602. h: data.h,
  603. type: data.type,
  604. //sectorData:data.jsonData //base 0.0.1 此问题导致深层数据无法被视图渲染
  605. content:data.jsonData,
  606. dataSort:dataSort,
  607. });
  608. }
  609. console.log("当前添加模块的dataSort为:" + dataSort);
  610. //当前的页面构建数据
  611. console.log(state.pageData.article);
  612. //需要调查一下这里最后的1,1
  613. state.gridlayoutObj.dragEvent('dragend', data.i, data.x, data.y, 1,1);
  614. try {
  615. state.gridlayoutObj.$children[state.pageData.article.length].$refs.item.style.display="block";
  616. } catch {}
  617. }
  618. }
  619. //开始复制 end------------------------------------------------------------>
  620. }
  621. //pageStatus==5 搜索页 search
  622. if(state.pageStatus == 5){}
  623. //pageStatus==6 自定义列表页 aloneList
  624. if(state.pageStatus == 6){}
  625. //pageStatus==7 自定义详情页 aloneArticle
  626. if(state.pageStatus == 7){}
  627. },
  628. //删除板块
  629. deleteModule(state,data){
  630. //data.i = id
  631. //data.dataSort = dataSort
  632. //pageStatus==1 首页
  633. if(state.pageStatus == 1){
  634. //开始复制 start------------------------------------------------------------>
  635. //必须通过重新查找id的方式来删除
  636. const indexToRemove = state.pageData.index.findIndex(item => item.i === data.i);
  637. if (indexToRemove !== -1) {
  638. state.pageData.index.splice(indexToRemove, 1);
  639. Message.success('模块已删除!');
  640. console.log('模块已删除,当前的页面构建数据为:', state.pageData.index);
  641. } else {
  642. Message.warning('未找到要删除的模块!');
  643. }
  644. //开始复制 end------------------------------------------------------------>
  645. // base 0.0.2 如果使用splice方法删除sort,当你就剩下最后一个的时候,会出现找不到那个元素的问题
  646. // state.pageData.index.splice(data.dataSort,1);
  647. // Message.success('模块已删除!');
  648. // console.log(state.pageData.index);
  649. }
  650. //pageStatus==2 分类页
  651. if(state.pageStatus == 2){}
  652. //pageStatus==3 列表页
  653. if(state.pageStatus == 3){
  654. //开始复制 start------------------------------------------------------------>
  655. //必须通过重新查找id的方式来删除
  656. const indexToRemove = state.pageData.list.findIndex(item => item.i === data.i);
  657. if (indexToRemove !== -1) {
  658. state.pageData.list.splice(indexToRemove, 1);
  659. Message.success('模块已删除!');
  660. console.log('模块已删除,当前的页面构建数据为:', state.pageData.list);
  661. } else {
  662. Message.warning('未找到要删除的模块!');
  663. }
  664. //开始复制 end------------------------------------------------------------>
  665. }
  666. //pageStatus==4 详情页
  667. if(state.pageStatus == 4){
  668. //开始复制 start------------------------------------------------------------>
  669. //必须通过重新查找id的方式来删除
  670. const indexToRemove = state.pageData.article.findIndex(item => item.i === data.i);
  671. if (indexToRemove !== -1) {
  672. state.pageData.article.splice(indexToRemove, 1);
  673. Message.success('模块已删除!');
  674. console.log('模块已删除,当前的页面构建数据为:', state.pageData.article);
  675. } else {
  676. Message.warning('未找到要删除的模块!');
  677. }
  678. //开始复制 end------------------------------------------------------------>
  679. }
  680. //pageStatus==5 搜索页
  681. if(state.pageStatus == 5){}
  682. //pageStatus==6 自定义列表页
  683. if(state.pageStatus == 6){}
  684. //pageStatus==7 自定义详情页
  685. if(state.pageStatus == 7){}
  686. },
  687. //设置组件样式
  688. setComponentStyleNumber(state,data){
  689. let id = state.editSectorId;
  690. let dataSort = state.editDataSort;
  691. let sort = state.editComponentSort;
  692. let num = state.editComponentStyle;
  693. console.log(id,dataSort,sort,num);
  694. //pageStatus==1 首页
  695. if(state.pageStatus == 1){
  696. //开始复制 start------------------------------------------------------------>
  697. // 获取当前模块数据并进行深拷贝
  698. let module = JSON.parse(JSON.stringify(state.pageData.index[dataSort]));
  699. //module.content.componentList[sort].component_style = num;
  700. //确保修改属性时 Vue 能监控到变化
  701. Vue.set(module.content.componentList, sort, {
  702. ...module.content.componentList[sort],
  703. component_style: num
  704. });
  705. // 拷贝后直接替换原来的板块
  706. //state.pageData.index[id] = module;
  707. // 使用Vue.set来强制视图更新
  708. Vue.set(state.pageData.index, dataSort, module);
  709. console.log("当前的板块数据为:");
  710. console.log(state.pageData.index);
  711. //开始复制 end------------------------------------------------------------>
  712. }
  713. //pageStatus==2 分类页
  714. if(state.pageStatus == 2){}
  715. //pageStatus==3 列表页
  716. if(state.pageStatus == 3){
  717. //开始复制 start------------------------------------------------------------>
  718. // 获取当前模块数据并进行深拷贝
  719. let module = JSON.parse(JSON.stringify(state.pageData.list[dataSort]));
  720. //module.content.componentList[sort].component_style = num;
  721. //确保修改属性时 Vue 能监控到变化
  722. Vue.set(module.content.componentList, sort, {
  723. ...module.content.componentList[sort],
  724. component_style: num
  725. });
  726. // 拷贝后直接替换原来的板块
  727. //state.pageData.index[id] = module;
  728. // 使用Vue.set来强制视图更新
  729. Vue.set(state.pageData.list, dataSort, module);
  730. console.log("当前的板块数据为:");
  731. console.log(state.pageData.list);
  732. //开始复制 end------------------------------------------------------------>
  733. }
  734. //pageStatus==4 详情页
  735. if(state.pageStatus == 4){
  736. //开始复制 start------------------------------------------------------------>
  737. // 获取当前模块数据并进行深拷贝
  738. let module = JSON.parse(JSON.stringify(state.pageData.article[dataSort]));
  739. //module.content.componentList[sort].component_style = num;
  740. //确保修改属性时 Vue 能监控到变化
  741. Vue.set(module.content.componentList, sort, {
  742. ...module.content.componentList[sort],
  743. component_style: num
  744. });
  745. // 拷贝后直接替换原来的板块
  746. //state.pageData.index[id] = module;
  747. // 使用Vue.set来强制视图更新
  748. Vue.set(state.pageData.article, dataSort, module);
  749. console.log("当前的板块数据为:");
  750. console.log(state.pageData.article);
  751. //开始复制 end------------------------------------------------------------>
  752. }
  753. //pageStatus==5 搜索页
  754. if(state.pageStatus == 5){}
  755. //pageStatus==6 自定义列表页
  756. if(state.pageStatus == 6){}
  757. //pageStatus==7 自定义详情页
  758. if(state.pageStatus == 7){}
  759. },
  760. //保存组件设置的数据
  761. saveComponentData(state,data){
  762. //传入的板块id
  763. console.log("当前编辑板块:" + data.id)
  764. //pageStatus==1 首页
  765. if(state.pageStatus == 1){
  766. //开始复制 start------------------------------------------------------------>
  767. const targetModuleIndex = state.pageData.index.findIndex(module => module.i === data.id);
  768. console.log("要修改的模块id为:") //找到要修改的板块
  769. console.log(data.sort) //找到要修改的板块
  770. console.log(targetModuleIndex) //找到要修改的板块
  771. //console.log(targetModuleIndex) //找到要修改的板块
  772. //state.pageData.index[targetModuleIndex].content.componentList[data.sort] //当前编辑的组件
  773. //data.data.pid_arr //导航池
  774. //state.editComponentSize //展示条数
  775. //判断数据的类型 1=普通新闻 2=tabs新闻选项卡 3=广告 4=友情链接 6=静态组件 7=文本 8=评论
  776. //1=普通新闻
  777. //注意,vue有一个bug就是,当你修改复杂对象的时候,如果对象的内部是数组
  778. //vue可能无法检测到变化,而当你修改无法被检测变化的数据时,就会把所有数据都修改成相同的值
  779. //解决办法是通过vue的set方法将整个对象,即你的数组外层那个对象进行深拷贝,然后修改完再替换回去
  780. if(state.editComponentType == 1){
  781. // 获取当前模块数据并进行深拷贝
  782. let module = JSON.parse(JSON.stringify(state.pageData.index[targetModuleIndex])); // 深拷贝整个模块
  783. // 更新 category_id 和 pageSize
  784. module.content.componentList[data.sort].componentData.category_id = data.data.pid_arr; // 设置 category_id
  785. module.content.componentList[data.sort].componentData.pageSize = state.editComponentSize; // 设置 pageSize
  786. // 使用Vue.set来强制视图更新
  787. Vue.set(state.pageData.index, targetModuleIndex, module); // 替换为深拷贝的模块
  788. console.log("当前的板块数据为:");
  789. console.log(state.pageData.index);
  790. }
  791. //2=tabs新闻选项卡
  792. if(state.editComponentType == 2){
  793. // 获取当前模块数据并进行深拷贝
  794. let module = JSON.parse(JSON.stringify(state.pageData.index[targetModuleIndex])); // 深拷贝整个模块
  795. // 更新 category_id 和 pageSize
  796. module.content.componentList[data.sort].componentData.category_id = data.data.pid_arr; // 设置 category_id
  797. module.content.componentList[data.sort].componentData.pageSize = state.editComponentSize; // 设置 pageSize
  798. // 使用Vue.set来强制视图更新
  799. Vue.set(state.pageData.index, targetModuleIndex, module); // 替换为深拷贝的模块
  800. console.log("当前的板块数据为:");
  801. console.log(state.pageData.index);
  802. }
  803. //3=广告
  804. if(state.editComponentType == 3){;
  805. let module = JSON.parse(JSON.stringify(state.pageData.index[targetModuleIndex]));
  806. module.content.componentList[data.sort].componentData.text = data.data.adName;
  807. Vue.set(state.pageData.index, targetModuleIndex, module);
  808. console.log("当前的板块数据为:");
  809. console.log(state.pageData.index);
  810. }
  811. //4=友情链接
  812. //if(state.editComponentType == 4){}
  813. //6=静态组件
  814. //if(state.editComponentType == 6){}
  815. //7=文本
  816. if(state.editComponentType == 7){
  817. let module = JSON.parse(JSON.stringify(state.pageData.index[targetModuleIndex]));
  818. module.content.componentList[data.sort].componentData.text = data.data.titleName;
  819. Vue.set(state.pageData.index, targetModuleIndex, module);
  820. console.log("当前的板块数据为:");
  821. console.log(state.pageData.index);
  822. }
  823. //8=评论
  824. //if(state.editComponentType == 8){}
  825. //开始复制 end------------------------------------------------------------>
  826. }
  827. //pageStatus==2 分类页
  828. if(state.pageStatus == 2){}
  829. //pageStatus==3 列表页
  830. if(state.pageStatus == 3){
  831. //开始复制 start------------------------------------------------------------>
  832. const targetModuleIndex = state.pageData.list.findIndex(module => module.i === data.id);
  833. console.log("要修改的模块id为:") //找到要修改的板块
  834. console.log(data.sort) //找到要修改的板块
  835. console.log(targetModuleIndex) //找到要修改的板块
  836. if(state.editComponentType == 1){
  837. // 获取当前模块数据并进行深拷贝
  838. let module = JSON.parse(JSON.stringify(state.pageData.list[targetModuleIndex])); // 深拷贝整个模块
  839. // 更新 category_id 和 pageSize
  840. module.content.componentList[data.sort].componentData.category_id = data.data.pid_arr; // 设置 category_id
  841. module.content.componentList[data.sort].componentData.pageSize = state.editComponentSize; // 设置 pageSize
  842. // 使用Vue.set来强制视图更新
  843. Vue.set(state.pageData.list, targetModuleIndex, module); // 替换为深拷贝的模块
  844. console.log("当前的板块数据为:");
  845. console.log(state.pageData.list);
  846. }
  847. //2=tabs新闻选项卡
  848. if(state.editComponentType == 2){
  849. // 获取当前模块数据并进行深拷贝
  850. let module = JSON.parse(JSON.stringify(state.pageData.list[targetModuleIndex])); // 深拷贝整个模块
  851. // 更新 category_id 和 pageSize
  852. module.content.componentList[data.sort].componentData.category_id = data.data.pid_arr; // 设置 category_id
  853. module.content.componentList[data.sort].componentData.pageSize = state.editComponentSize; // 设置 pageSize
  854. // 使用Vue.set来强制视图更新
  855. Vue.set(state.pageData.list, targetModuleIndex, module); // 替换为深拷贝的模块
  856. console.log("当前的板块数据为:");
  857. console.log(state.pageData.list);
  858. }
  859. //3=广告
  860. if(state.editComponentType == 3){;
  861. let module = JSON.parse(JSON.stringify(state.pageData.list[targetModuleIndex]));
  862. module.content.componentList[data.sort].componentData.text = data.data.adName;
  863. Vue.set(state.pageData.list, targetModuleIndex, module);
  864. console.log("当前的板块数据为:");
  865. console.log(state.pageData.list);
  866. }
  867. //7=文本
  868. if(state.editComponentType == 7){
  869. let module = JSON.parse(JSON.stringify(state.pageData.list[targetModuleIndex]));
  870. module.content.componentList[data.sort].componentData.text = data.data.titleName;
  871. Vue.set(state.pageData.list, targetModuleIndex, module);
  872. console.log("当前的板块数据为:");
  873. console.log(state.pageData.list);
  874. }
  875. //开始复制 end------------------------------------------------------------>
  876. }
  877. //pageStatus==4 详情页
  878. if(state.pageStatus == 4){
  879. //开始复制 start------------------------------------------------------------>
  880. const targetModuleIndex = state.pageData.article.findIndex(module => module.i === data.id);
  881. console.log("要修改的模块id为:") //找到要修改的板块
  882. console.log(data.sort) //找到要修改的板块
  883. console.log(targetModuleIndex) //找到要修改的板块
  884. if(state.editComponentType == 1){
  885. // 获取当前模块数据并进行深拷贝
  886. let module = JSON.parse(JSON.stringify(state.pageData.article[targetModuleIndex])); // 深拷贝整个模块
  887. // 更新 category_id 和 pageSize
  888. module.content.componentList[data.sort].componentData.category_id = data.data.pid_arr; // 设置 category_id
  889. module.content.componentList[data.sort].componentData.pageSize = state.editComponentSize; // 设置 pageSize
  890. // 使用Vue.set来强制视图更新
  891. Vue.set(state.pageData.article, targetModuleIndex, module); // 替换为深拷贝的模块
  892. console.log("当前的板块数据为:");
  893. console.log(state.pageData.article);
  894. }
  895. //2=tabs新闻选项卡
  896. if(state.editComponentType == 2){
  897. // 获取当前模块数据并进行深拷贝
  898. let module = JSON.parse(JSON.stringify(state.pageData.article[targetModuleIndex])); // 深拷贝整个模块
  899. // 更新 category_id 和 pageSize
  900. module.content.componentList[data.sort].componentData.category_id = data.data.pid_arr; // 设置 category_id
  901. module.content.componentList[data.sort].componentData.pageSize = state.editComponentSize; // 设置 pageSize
  902. // 使用Vue.set来强制视图更新
  903. Vue.set(state.pageData.article, targetModuleIndex, module); // 替换为深拷贝的模块
  904. console.log("当前的板块数据为:");
  905. console.log(state.pageData.article);
  906. }
  907. //3=广告
  908. if(state.editComponentType == 3){;
  909. let module = JSON.parse(JSON.stringify(state.pageData.article[targetModuleIndex]));
  910. module.content.componentList[data.sort].componentData.text = data.data.adName;
  911. Vue.set(state.pageData.article, targetModuleIndex, module);
  912. console.log("当前的板块数据为:");
  913. console.log(state.pageData.article);
  914. }
  915. //7=文本
  916. if(state.editComponentType == 7){
  917. let module = JSON.parse(JSON.stringify(state.pageData.article[targetModuleIndex]));
  918. module.content.componentList[data.sort].componentData.text = data.data.titleName;
  919. Vue.set(state.pageData.article, targetModuleIndex, module);
  920. console.log("当前的板块数据为:");
  921. console.log(state.pageData.article);
  922. }
  923. //开始复制 end------------------------------------------------------------>
  924. }
  925. //pageStatus==5 搜索页
  926. if(state.pageStatus == 5){}
  927. //pageStatus==6 自定义列表页
  928. if(state.pageStatus == 6){}
  929. //pageStatus==7 自定义详情页
  930. if(state.pageStatus == 7){}
  931. },
  932. //通过按钮移动板块 (暂时停用)
  933. moveModule(state, data) {
  934. Message.error("该功能暂时禁用")
  935. // pageStatus == 1 首页
  936. // if (state.pageStatus == 1) {
  937. // const moveType = data.moveType;
  938. // const moduleId = data.i;
  939. // const modules = state.pageData.index;
  940. // // 深拷贝 modules,避免直接操作原数据
  941. // const newModules = JSON.parse(JSON.stringify(modules));
  942. // // 查找模块在数组中的实际索引
  943. // const thisIndex = newModules.findIndex(module => module.i === moduleId);
  944. // if (thisIndex === -1) {
  945. // Message.error('模块未找到!');
  946. // return;
  947. // }
  948. // const thisY = newModules[thisIndex].y;
  949. // let thatY;
  950. // if (moveType === 'up') {
  951. // thatY = Math.max(
  952. // ...newModules.filter(item => item.y < thisY).map(item => item.y)
  953. // );
  954. // if (thatY === -Infinity) {
  955. // Message.error('已经是顶部了!');
  956. // return;
  957. // }
  958. // const thatIndex = newModules.findIndex(item => item.y === thatY);
  959. // if (thatIndex === -1) {
  960. // Message.error('上方模块未找到!');
  961. // return;
  962. // }
  963. // // 交换y值
  964. // [newModules[thisIndex].y, newModules[thatIndex].y] = [newModules[thatIndex].y, newModules[thisIndex].y];
  965. // } else if (moveType === 'down') {
  966. // thatY = Math.min(
  967. // ...newModules.filter(item => item.y > thisY).map(item => item.y)
  968. // );
  969. // if (thatY === Infinity) {
  970. // Message.error('已经是底部了!');
  971. // return;
  972. // }
  973. // const thatIndex = newModules.findIndex(item => item.y === thatY);
  974. // if (thatIndex === -1) {
  975. // Message.error('下方模块未找到!');
  976. // return;
  977. // }
  978. // // 交换y值
  979. // [newModules[thisIndex].y, newModules[thatIndex].y] = [newModules[thatIndex].y, newModules[thisIndex].y];
  980. // } else {
  981. // Message.error('未知的移动类型!');
  982. // return;
  983. // }
  984. // // 交换后对模块进行排序以确保顺序一致
  985. // newModules.sort((a, b) => a.y - b.y);
  986. // // 使用 Vue.set 强制更新数组,确保视图更新
  987. // //Vue.set(state.pageData, 'index', newModules); // 这里更新整个数组
  988. // state.pageData.index = newModules;
  989. // //state.gridKey+=1;
  990. // console.log(state.pageData.index); // 打印查看是否已修改
  991. // }
  992. // // pageStatus == 2 分类页
  993. // if (state.pageStatus == 2) {}
  994. // // pageStatus == 3 列表页
  995. // if (state.pageStatus == 3) {}
  996. // // pageStatus == 4 详情页
  997. // if (state.pageStatus == 4) {}
  998. // // pageStatus == 5 搜索页
  999. // if (state.pageStatus == 5) {}
  1000. // // pageStatus == 6 自定义列表页
  1001. // if (state.pageStatus == 6) {}
  1002. // // pageStatus == 7 自定义详情页
  1003. // if (state.pageStatus == 7) {}
  1004. },
  1005. //从外部拖拽板块
  1006. drag(state, data) {
  1007. // pageStatus == 1 首页
  1008. if (state.pageStatus == 1) {
  1009. //开始复制 start------------------------------------------------------------>
  1010. let parentRect = document.getElementById('content').getBoundingClientRect();
  1011. //console.log(parentRect); 获取画布
  1012. let mouseInGrid = false;
  1013. if (((state.mouseXY.x > parentRect.left) && (state.mouseXY.x < parentRect.right)) && ((state.mouseXY.y > parentRect.top) && (state.mouseXY.y < parentRect.bottom))) {
  1014. mouseInGrid = true;
  1015. }
  1016. //state.gridlayoutObj
  1017. //如果没有占位符就创建一个
  1018. if (mouseInGrid === true && (state.pageData.index.findIndex(item => item.i === 'drop')) === -1) {
  1019. state.pageData.index.push({
  1020. x: (state.pageData.index.length * 2) % (this.colNum || 12),
  1021. y: state.pageData.index.length + (this.colNum || 12), // puts it at the bottom
  1022. w: 12,
  1023. h: 2,
  1024. i: 'drop',
  1025. });
  1026. }
  1027. //如果已经存在占位符
  1028. let index = state.pageData.index.findIndex(item => item.i === 'drop');
  1029. if (index !== -1) {
  1030. try {
  1031. state.gridlayoutObj.$children[state.pageData.index.length].$refs.item.style.display = "none";
  1032. } catch {
  1033. }
  1034. let el = state.gridlayoutObj.$children[index];
  1035. el.dragging = {"top": state.mouseXY.y - parentRect.top, "left": state.mouseXY.x - parentRect.left};
  1036. let new_pos = el.calcXY(state.mouseXY.y - parentRect.top, state.mouseXY.x - parentRect.left);
  1037. if (mouseInGrid === true) {
  1038. state.gridlayoutObj.dragEvent('dragstart', 'drop', new_pos.x, new_pos.y, 2, 12);
  1039. state.DragPos.i = String(index);
  1040. state.DragPos.x = state.pageData.index[index].x;
  1041. state.DragPos.y = state.pageData.index[index].y;
  1042. }
  1043. if (mouseInGrid === false) {
  1044. state.gridlayoutObj.dragEvent('dragend', 'drop', new_pos.x, new_pos.y, 2, 12);
  1045. state.pageData.index = state.pageData.index.filter(obj => obj.i !== 'drop');
  1046. }
  1047. }
  1048. //开始复制 end------------------------------------------------------------>
  1049. }
  1050. // pageStatus == 2 分类页
  1051. if (state.pageStatus == 2) {}
  1052. // pageStatus == 3 列表页
  1053. if (state.pageStatus == 3) {
  1054. //开始复制 start------------------------------------------------------------>
  1055. let parentRect = document.getElementById('content').getBoundingClientRect();
  1056. //console.log(parentRect); 获取画布
  1057. let mouseInGrid = false;
  1058. if (((state.mouseXY.x > parentRect.left) && (state.mouseXY.x < parentRect.right)) && ((state.mouseXY.y > parentRect.top) && (state.mouseXY.y < parentRect.bottom))) {
  1059. mouseInGrid = true;
  1060. }
  1061. //如果没有占位符就创建一个
  1062. if (mouseInGrid === true && (state.pageData.list.findIndex(item => item.i === 'drop')) === -1) {
  1063. state.pageData.list.push({
  1064. x: (state.pageData.list.length * 2) % (this.colNum || 12),
  1065. y: state.pageData.list.length + (this.colNum || 12), // puts it at the bottom
  1066. w: 12,
  1067. h: 2,
  1068. i: 'drop',
  1069. });
  1070. }
  1071. //如果已经存在占位符
  1072. let index = state.pageData.list.findIndex(item => item.i === 'drop');
  1073. if (index !== -1) {
  1074. try {
  1075. state.gridlayoutObj.$children[state.pageData.list.length].$refs.item.style.display = "none";
  1076. } catch {
  1077. }
  1078. let el = state.gridlayoutObj.$children[index];
  1079. el.dragging = {"top": state.mouseXY.y - parentRect.top, "left": state.mouseXY.x - parentRect.left};
  1080. let new_pos = el.calcXY(state.mouseXY.y - parentRect.top, state.mouseXY.x - parentRect.left);
  1081. if (mouseInGrid === true) {
  1082. state.gridlayoutObj.dragEvent('dragstart', 'drop', new_pos.x, new_pos.y, 2, 12);
  1083. state.DragPos.i = String(index);
  1084. state.DragPos.x = state.pageData.list[index].x;
  1085. state.DragPos.y = state.pageData.list[index].y;
  1086. }
  1087. if (mouseInGrid === false) {
  1088. state.gridlayoutObj.dragEvent('dragend', 'drop', new_pos.x, new_pos.y, 2, 12);
  1089. state.pageData.list = state.pageData.list.filter(obj => obj.i !== 'drop');
  1090. }
  1091. }
  1092. //开始复制 end------------------------------------------------------------>
  1093. }
  1094. // pageStatus == 4 详情页
  1095. if (state.pageStatus == 4) {
  1096. //开始复制 start------------------------------------------------------------>
  1097. let parentRect = document.getElementById('content').getBoundingClientRect();
  1098. //console.log(parentRect); 获取画布
  1099. let mouseInGrid = false;
  1100. if (((state.mouseXY.x > parentRect.left) && (state.mouseXY.x < parentRect.right)) && ((state.mouseXY.y > parentRect.top) && (state.mouseXY.y < parentRect.bottom))) {
  1101. mouseInGrid = true;
  1102. }
  1103. //如果没有占位符就创建一个
  1104. if (mouseInGrid === true && (state.pageData.article.findIndex(item => item.i === 'drop')) === -1) {
  1105. state.pageData.article.push({
  1106. x: (state.pageData.article.length * 2) % (this.colNum || 12),
  1107. y: state.pageData.article.length + (this.colNum || 12), // puts it at the bottom
  1108. w: 12,
  1109. h: 2,
  1110. i: 'drop',
  1111. });
  1112. }
  1113. //如果已经存在占位符
  1114. let index = state.pageData.article.findIndex(item => item.i === 'drop');
  1115. if (index !== -1) {
  1116. try {
  1117. state.gridlayoutObj.$children[state.pageData.article.length].$refs.item.style.display = "none";
  1118. } catch {
  1119. }
  1120. let el = state.gridlayoutObj.$children[index];
  1121. el.dragging = {"top": state.mouseXY.y - parentRect.top, "left": state.mouseXY.x - parentRect.left};
  1122. let new_pos = el.calcXY(state.mouseXY.y - parentRect.top, state.mouseXY.x - parentRect.left);
  1123. if (mouseInGrid === true) {
  1124. state.gridlayoutObj.dragEvent('dragstart', 'drop', new_pos.x, new_pos.y, 2, 12);
  1125. state.DragPos.i = String(index);
  1126. state.DragPos.x = state.pageData.article[index].x;
  1127. state.DragPos.y = state.pageData.article[index].y;
  1128. }
  1129. if (mouseInGrid === false) {
  1130. state.gridlayoutObj.dragEvent('dragend', 'drop', new_pos.x, new_pos.y, 2, 12);
  1131. state.pageData.article = state.pageData.article.filter(obj => obj.i !== 'drop');
  1132. }
  1133. }
  1134. //开始复制 end------------------------------------------------------------>
  1135. }
  1136. // pageStatus == 5 搜索页
  1137. if (state.pageStatus == 5) {}
  1138. // pageStatus == 6 自定义列表页
  1139. if (state.pageStatus == 6) {}
  1140. // pageStatus == 7 自定义详情页
  1141. if (state.pageStatus == 7) {}
  1142. },
  1143. //拖拽结束 定位落点
  1144. dragend(state, data) {
  1145. // pageStatus == 1 首页
  1146. if (state.pageStatus == 1) {
  1147. //开始复制 start------------------------------------------------------------>
  1148. //获取画布尺寸
  1149. let parentRect = document.getElementById('content').getBoundingClientRect();
  1150. //判断是否在画布内
  1151. let mouseInGrid = false;
  1152. if (((state.mouseXY.x > parentRect.left) && (state.mouseXY.x < parentRect.right)) && ((state.mouseXY.y > parentRect.top) && (state.mouseXY.y < parentRect.bottom))) {
  1153. mouseInGrid = true;
  1154. }
  1155. //如果在画布内,开始创建元素
  1156. if (mouseInGrid === true) {
  1157. alert(`Dropped element props:\n${JSON.stringify(state.DragPos, ['x', 'y', 'w', 'h'], 2)}`);
  1158. state.gridlayoutObj.dragEvent('dragend', 'drop', state.DragPos.x, state.DragPos.y, 1, 1);
  1159. state.pageData.index = state.pageData.index.filter(obj => obj.i !== 'drop');
  1160. // UNCOMMENT below if you want to add a grid-item
  1161. /*
  1162. this.layout.push({
  1163. x: DragPos.x,
  1164. y: DragPos.y,
  1165. w: 1,
  1166. h: 1,
  1167. i: DragPos.i,
  1168. });
  1169. this.$refs.gridLayout.dragEvent('dragend', DragPos.i, DragPos.x,DragPos.y,1,1);
  1170. try {
  1171. this.$refs.gridLayout.$children[this.layout.length].$refs.item.style.display="block";
  1172. } catch {
  1173. }
  1174. */
  1175. let sendData = {
  1176. source:"drag",//添加时判断此模块来自外部拖拽,而不是点击
  1177. type:data.type,
  1178. h:data.h,
  1179. jsonData:data.jsonData,
  1180. x: state.DragPos.x,
  1181. y: state.DragPos.y,
  1182. w: 12,
  1183. }
  1184. //开发到这里了,注意我可能还需要上面那个 this.$refs.gridLayout.dragEvent方法
  1185. this.commit('template/addModule',sendData);
  1186. }
  1187. //开始复制 end------------------------------------------------------------>
  1188. }
  1189. // pageStatus == 2 分类页
  1190. if (state.pageStatus == 2) {}
  1191. // pageStatus == 3 列表页
  1192. if (state.pageStatus == 3) {
  1193. //开始复制 start------------------------------------------------------------>
  1194. //获取画布尺寸
  1195. let parentRect = document.getElementById('content').getBoundingClientRect();
  1196. //判断是否在画布内
  1197. let mouseInGrid = false;
  1198. if (((state.mouseXY.x > parentRect.left) && (state.mouseXY.x < parentRect.right)) && ((state.mouseXY.y > parentRect.top) && (state.mouseXY.y < parentRect.bottom))) {
  1199. mouseInGrid = true;
  1200. }
  1201. //如果在画布内,开始创建元素
  1202. if (mouseInGrid === true) {
  1203. alert(`Dropped element props:\n${JSON.stringify(state.DragPos, ['x', 'y', 'w', 'h'], 2)}`);
  1204. state.gridlayoutObj.dragEvent('dragend', 'drop', state.DragPos.x, state.DragPos.y, 1, 1);
  1205. state.pageData.list = state.pageData.list.filter(obj => obj.i !== 'drop');
  1206. let sendData = {
  1207. source:"drag",//添加时判断此模块来自外部拖拽,而不是点击
  1208. type:data.type,
  1209. h:data.h,
  1210. jsonData:data.jsonData,
  1211. x: state.DragPos.x,
  1212. y: state.DragPos.y,
  1213. w: 12,
  1214. }
  1215. this.commit('template/addModule',sendData);
  1216. }
  1217. //开始复制 end------------------------------------------------------------>
  1218. }
  1219. // pageStatus == 4 详情页
  1220. if (state.pageStatus == 4) {
  1221. //开始复制 start------------------------------------------------------------>
  1222. //获取画布尺寸
  1223. let parentRect = document.getElementById('content').getBoundingClientRect();
  1224. //判断是否在画布内
  1225. let mouseInGrid = false;
  1226. if (((state.mouseXY.x > parentRect.left) && (state.mouseXY.x < parentRect.right)) && ((state.mouseXY.y > parentRect.top) && (state.mouseXY.y < parentRect.bottom))) {
  1227. mouseInGrid = true;
  1228. }
  1229. //如果在画布内,开始创建元素
  1230. if (mouseInGrid === true) {
  1231. alert(`Dropped element props:\n${JSON.stringify(state.DragPos, ['x', 'y', 'w', 'h'], 2)}`);
  1232. state.gridlayoutObj.dragEvent('dragend', 'drop', state.DragPos.x, state.DragPos.y, 1, 1);
  1233. state.pageData.article = state.pageData.article.filter(obj => obj.i !== 'drop');
  1234. let sendData = {
  1235. source:"drag",//添加时判断此模块来自外部拖拽,而不是点击
  1236. type:data.type,
  1237. h:data.h,
  1238. jsonData:data.jsonData,
  1239. x: state.DragPos.x,
  1240. y: state.DragPos.y,
  1241. w: 12,
  1242. }
  1243. this.commit('template/addModule',sendData);
  1244. }
  1245. //开始复制 end------------------------------------------------------------>
  1246. }
  1247. // pageStatus == 5 搜索页
  1248. if (state.pageStatus == 5) {}
  1249. // pageStatus == 6 自定义列表页
  1250. if (state.pageStatus == 6) {}
  1251. // pageStatus == 7 自定义详情页
  1252. if (state.pageStatus == 7) {}
  1253. },
  1254. //修改首页板块高度
  1255. setModuleHeight(state,data){
  1256. // pageStatus == 1 首页
  1257. if (state.pageStatus == 1) {
  1258. console.log(data);
  1259. state.pageData.index[data.i].h = data.h;
  1260. console.log(state.pageData.index[data.i]);
  1261. }
  1262. // pageStatus == 2 分类页
  1263. if (state.pageStatus == 2) {}
  1264. // pageStatus == 3 列表页
  1265. if (state.pageStatus == 3) {
  1266. console.log(data);
  1267. state.pageData.list[data.i].h = data.h;
  1268. console.log(state.pageData.list[data.i]);
  1269. }
  1270. // pageStatus == 4 详情页
  1271. if (state.pageStatus == 4) {
  1272. console.log(data);
  1273. state.pageData.article[data.i].h = data.h;
  1274. console.log(state.pageData.article[data.i]);
  1275. }
  1276. // pageStatus == 5 搜索页
  1277. if (state.pageStatus == 5) {}
  1278. // pageStatus == 6 自定义列表页
  1279. if (state.pageStatus == 6) {}
  1280. // pageStatus == 7 自定义详情页
  1281. if (state.pageStatus == 7) {}
  1282. },
  1283. //格式化模板信息
  1284. formatTemplateInfo(state, data) {
  1285. // 深拷贝数据,避免直接修改原数据
  1286. let clonedData = JSON.parse(JSON.stringify(data));
  1287. // 把ad_id传进去
  1288. for(let item of clonedData.data){
  1289. if(item.adid){
  1290. item.content.componentList[0].componentData.ad_id = item.adid;
  1291. }
  1292. }
  1293. // 按照 clonedData.data.y 的大小排序
  1294. clonedData.data.sort((a, b) => a.y - b.y);
  1295. //console.log(clonedData, clonedData);
  1296. let websiteData = [];
  1297. // 获取板块的 sort
  1298. for (let index = 0; index < clonedData.data.length; index++) {
  1299. console.log(clonedData.data[index].content);
  1300. // 使用 Vue.set 来确保属性变更能被 Vue 追踪
  1301. Vue.set(clonedData.data[index].content, 'sort', Number(index) + 1);
  1302. // if (data.type == "index") {
  1303. // // 不要把数据直接保存到 state.webSiteData.template 中,否则无法删除
  1304. // websiteData.push(clonedData.data[index].content);
  1305. // }
  1306. websiteData.push(clonedData.data[index].content);
  1307. }
  1308. // 保存到对应的页面 json 中
  1309. if (data.type == "index") {
  1310. state.webSiteData.template.index = websiteData;
  1311. }
  1312. if (data.type == "list") {
  1313. state.webSiteData.template.list = websiteData;
  1314. }
  1315. if (data.type == "article") {
  1316. state.webSiteData.template.article = websiteData;
  1317. }
  1318. },
  1319. //保存模板
  1320. saveTemplate(state) {
  1321. //临时展示保存的数据 后期移除
  1322. state.editWebsiteTemplateJsonWindow = true;
  1323. //调用mutations中的方法无需使用$store
  1324. //格式化index的信息
  1325. this.commit('template/formatTemplateInfo',{data:state.pageData.index,type:"index"});
  1326. //格式化list的信息
  1327. this.commit('template/formatTemplateInfo',{data:state.pageData.list,type:"list"});
  1328. //格式化article的信息
  1329. this.commit('template/formatTemplateInfo',{data:state.pageData.article,type:"article"});
  1330. // console.log(state.webSiteData);
  1331. // console.log(state.editWebsiteId)
  1332. //给与网站id和模板风格id
  1333. state.webSiteData.base.websiteId = state.editWebsiteId;
  1334. state.webSiteData.style.styleId = state.editWebsiteClass;
  1335. },
  1336. //随机生成模板
  1337. randomTemplate(state){
  1338. state.loading = true;
  1339. const randomIndex = Math.floor(Math.random() * 2); // Generates a random number between 1 and 2
  1340. console.log(`随机生成的数字是: ${randomIndex}`);
  1341. //console.log(randomIndex1)
  1342. //console.log(randomIndex2)
  1343. //Message.warning("该功能研发中");
  1344. // pageStatus == 1 首页
  1345. if (state.pageStatus == 1) {
  1346. // 先清空里面的内容
  1347. Vue.set(state.pageData, 'index', []);
  1348. // 深拷贝 randomIndex1 和 randomIndex2
  1349. const newData1 = JSON.parse(JSON.stringify(randomIndex1));
  1350. const newData2 = JSON.parse(JSON.stringify(randomIndex2));
  1351. if (randomIndex == 0) {
  1352. Vue.set(state.pageData, 'index', newData1);
  1353. }
  1354. if (randomIndex == 1) {
  1355. Vue.set(state.pageData, 'index', newData2);
  1356. }
  1357. state.loading = false;
  1358. }
  1359. // pageStatus == 2 分类页
  1360. if (state.pageStatus == 2) {}
  1361. // pageStatus == 3 列表页
  1362. if (state.pageStatus == 3) {
  1363. Message.warning("暂无模板可用!");
  1364. state.loading = false;
  1365. }
  1366. // pageStatus == 4 详情页
  1367. if (state.pageStatus == 4) {
  1368. Message.warning("暂无模板可用!");
  1369. state.loading = false;
  1370. }
  1371. // pageStatus == 5 搜索页
  1372. if (state.pageStatus == 5) {}
  1373. // pageStatus == 6 自定义列表页
  1374. if (state.pageStatus == 6) {}
  1375. // pageStatus == 7 自定义详情页
  1376. if (state.pageStatus == 7) {}
  1377. },
  1378. //提交数据之前执行完整度检查
  1379. IntegrityCheck(state){
  1380. //先设置为true看能否通过判断
  1381. state.canSubmit = true;
  1382. //先判断当前有哪几个板块可用
  1383. //state.canSubmit == false 不可以提交
  1384. //state.canSubmit == true 可以提交
  1385. //首页
  1386. if(state.showPage.index == true){
  1387. if(state.template.index == []){
  1388. state.canSubmit = false;
  1389. }
  1390. }
  1391. //分类页
  1392. if(state.showPage.class == true){
  1393. if(state.template.class == []){
  1394. state.canSubmit = false;
  1395. }
  1396. }
  1397. //列表页
  1398. if(state.showPage.list == true){
  1399. if(state.template.list == []){
  1400. state.canSubmit = false;
  1401. }
  1402. }
  1403. //详情页
  1404. if(state.showPage.article == true){
  1405. if(state.template.article == []){
  1406. state.canSubmit = false;
  1407. }
  1408. }
  1409. //搜索页
  1410. if(state.showPage.search == true){
  1411. if(state.template.search == []){
  1412. state.canSubmit = false;
  1413. }
  1414. }
  1415. //自定义列表页
  1416. if(state.showPage.aloneList == true){
  1417. if(state.template.aloneList == []){
  1418. state.canSubmit = false;
  1419. }
  1420. }
  1421. //自定义详情页
  1422. if(state.showPage.aloneArticle == true){
  1423. if(state.template.aloneArticle == []){
  1424. state.canSubmit = false;
  1425. }
  1426. }
  1427. //最后判断一下是否可以提交
  1428. if(state.canSubmit == ture){
  1429. }else{
  1430. Message.error('您还有未构建的页面,请检查!');
  1431. }
  1432. },
  1433. //1.配置模块 end------------------------------------------------------------>
  1434. //2.获取站点信息 start------------------------------------------------------------>
  1435. //获取站点详情
  1436. setWebsiteInfo(state,data){
  1437. state.webSiteInfo = data;
  1438. },
  1439. //获取站点导航池
  1440. setGetSiteCategory(state,data) {
  1441. state.webSiteMenu = data;
  1442. },
  1443. //设置地区
  1444. setArea(state,data){
  1445. //都没有的时候返回的是省
  1446. if(data.province==undefined){
  1447. state.area.economize = data;
  1448. }
  1449. //没有region的时候返回的是市
  1450. if(data.province!=undefined&&data.city!=undefined&&data.region==undefined){
  1451. state.area.market = data.city;
  1452. }
  1453. //有region的时候返回的是县
  1454. if(data.province!=undefined&&data.city!=undefined&&data.region!=undefined){
  1455. state.area.county = data.region;
  1456. }
  1457. },
  1458. //设置职能
  1459. setDepartment(state,data){
  1460. for(let item of data){
  1461. let options = {
  1462. value: item.id,
  1463. label: item.name
  1464. }
  1465. state.departmentList.push(options)
  1466. }
  1467. console.log(state.departmentList)
  1468. },
  1469. //获取全部导航
  1470. setWebsiteCategory(state,data){
  1471. let arrayData = []
  1472. for(let item of data){
  1473. let options = {
  1474. key:item.id,
  1475. label:item.name,
  1476. value:item.id
  1477. }
  1478. arrayData.push(options);
  1479. }
  1480. state.editWebsiteCategory = arrayData;
  1481. },
  1482. //2.获取站点信息 end------------------------------------------------------------>
  1483. //3.提示信息 start------------------------------------------------------------>
  1484. alertMessage(state,data){
  1485. Message({
  1486. message: "配置阶段仅展示,无法真实调用该功能!",
  1487. type: 'warning',
  1488. duration: 0,
  1489. showClose: true
  1490. });
  1491. }
  1492. //3.提示信息 end------------------------------------------------------------>
  1493. }
  1494. const actions = {
  1495. //1.显示画板组件数据 start------------------------------------------------------------>
  1496. //1.1 获取网站基本信息
  1497. getSiteInfo({commit},data){
  1498. return new Promise((resolve, reject) => {
  1499. getSiteInfo(data).then(response => {
  1500. commit('setWebsiteInfo', response.data);
  1501. resolve(response)
  1502. }).catch(error => {
  1503. reject(error)
  1504. })
  1505. })
  1506. },
  1507. //1.2 获取网站导航池
  1508. getSiteCategory({commit},data){
  1509. return new Promise((resolve, reject) => {
  1510. getSiteCategory(data).then(response => {
  1511. commit('setGetSiteCategory', response.data);
  1512. resolve(response)
  1513. }).catch(error => {
  1514. reject(error)
  1515. })
  1516. })
  1517. },
  1518. //1.3 获取网站底部导航
  1519. getFooterCategoryList({commit},data){
  1520. return new Promise((resolve, reject) => {
  1521. getFooterCategoryList(data).then(response => {
  1522. resolve(response)
  1523. }).catch(error => {
  1524. reject(error)
  1525. })
  1526. })
  1527. },
  1528. //1.4 获取行政区划
  1529. selectWebsiteArea({commit},data){
  1530. return new Promise((resolve, reject) => {
  1531. selectWebsiteArea(data).then(response => {
  1532. commit('setArea', response.data);
  1533. resolve(response)
  1534. }).catch(error => {
  1535. reject(error)
  1536. })
  1537. })
  1538. },
  1539. //1.5 获取所有职能部门
  1540. selectWebsiteDepartment({commit},data){
  1541. return new Promise((resolve, reject) => {
  1542. selectWebsiteDepartment(data).then(response => {
  1543. commit('setDepartment', response.data);
  1544. resolve(response)
  1545. }).catch(error => {
  1546. reject(error)
  1547. })
  1548. })
  1549. },
  1550. //1.显示画板组件数据 end------------------------------------------------------------>
  1551. //2.构建网站json start------------------------------------------------------------>
  1552. //2.1 搜索网站
  1553. getWebsiteintel({commit},data){
  1554. return new Promise((resolve, reject) => {
  1555. getWebsiteintel(data).then(response => {
  1556. resolve(response)
  1557. }).catch(error => {
  1558. reject(error)
  1559. })
  1560. })
  1561. },
  1562. //2.2 添加网站基本信息 如果只传入website_id,则验证是否已经关联导航池
  1563. addWebsiteTemplateintel({commit},data){
  1564. return new Promise((resolve, reject) => {
  1565. addWebsiteTemplateintel(data).then(response => {
  1566. resolve(response)
  1567. }).catch(error => {
  1568. reject(error)
  1569. })
  1570. })
  1571. },
  1572. //2.3 获取网站基本信息
  1573. getWebsiteTemplateintel({commit},data){
  1574. return new Promise((resolve, reject) => {
  1575. getWebsiteTemplateintel(data).then(response => {
  1576. resolve(response)
  1577. }).catch(error => {
  1578. reject(error)
  1579. })
  1580. })
  1581. },
  1582. //2.4 修改网站基本信息
  1583. upWebsiteTemplateintel({commit},data){
  1584. return new Promise((resolve, reject) => {
  1585. upWebsiteTemplateintel(data).then(response => {
  1586. resolve(response)
  1587. }).catch(error => {
  1588. reject(error)
  1589. })
  1590. })
  1591. },
  1592. //2.5 获取所有风格
  1593. getAllTemplateClass({commit},data){
  1594. return new Promise((resolve, reject) => {
  1595. getAllTemplateClass(data).then(response => {
  1596. resolve(response)
  1597. }).catch(error => {
  1598. reject(error)
  1599. })
  1600. })
  1601. },
  1602. //2.6 搜索并获取所有网站风格
  1603. getWebsiteTemplateList({commit},data){
  1604. return new Promise((resolve, reject) => {
  1605. getWebsiteTemplateList(data).then(response => {
  1606. resolve(response)
  1607. }).catch(error => {
  1608. reject(error)
  1609. })
  1610. })
  1611. },
  1612. //2.7 保存用户选择的风格
  1613. addWebsiteTemplateclassintel({commit},data){
  1614. return new Promise((resolve, reject) => {
  1615. addWebsiteTemplateclassintel(data).then(response => {
  1616. resolve(response)
  1617. }).catch(error => {
  1618. reject(error)
  1619. })
  1620. })
  1621. },
  1622. //2.8 获取用户选择的风格
  1623. getWebsiteTemplateclassintel({commit},data){
  1624. return new Promise((resolve, reject) => {
  1625. getWebsiteTemplateclassintel(data).then(response => {
  1626. resolve(response)
  1627. }).catch(error => {
  1628. reject(error)
  1629. })
  1630. })
  1631. },
  1632. //2.9 保存模板
  1633. addWebsiteTemplate({commit},data){
  1634. return new Promise((resolve, reject) => {
  1635. addWebsiteTemplate(data).then(response => {
  1636. resolve(response)
  1637. }).catch(error => {
  1638. reject(error)
  1639. })
  1640. })
  1641. },
  1642. //2.10 获取模板配置
  1643. getWebsiteTemplateInfo({commit},data){
  1644. return new Promise((resolve, reject) => {
  1645. getWebsiteTemplateInfo(data).then(response => {
  1646. resolve(response)
  1647. }).catch(error => {
  1648. reject(error)
  1649. })
  1650. })
  1651. },
  1652. //2.11 预览模板信息
  1653. getWebsiteTemplateData({commit},data){
  1654. return new Promise((resolve, reject) => {
  1655. getWebsiteTemplateData(data).then(response => {
  1656. resolve(response)
  1657. }).catch(error => {
  1658. reject(error)
  1659. })
  1660. })
  1661. },
  1662. //2.构建网站json end------------------------------------------------------------>
  1663. }
  1664. export default {
  1665. namespaced: true,
  1666. state,
  1667. mutations,
  1668. actions
  1669. }