template.js 76 KB

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