template.js 60 KB

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