template.js 80 KB

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