template.js 59 KB

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