pcdiy.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. import { defineStore } from 'pinia';
  2. import { toRaw } from 'vue';
  3. import { ElMessage, ElMessageBox } from 'element-plus';
  4. import { cloneDeep } from 'lodash-es';
  5. import { fa } from 'element-plus/es/locale/index.mjs';
  6. const usePcdiyStore = defineStore('pcdiy', {
  7. state: () => {
  8. return {
  9. componentList: [],
  10. uniqueIdCounter: 0,
  11. currentIndex: -99, // 当前正在编辑的组件下标
  12. currentKey: '',
  13. editTab: 'content', // 编辑页面
  14. predefineColors: [
  15. '#F4391c',
  16. '#ff4500',
  17. '#ff8c00',
  18. '#FFD009',
  19. '#ffd700',
  20. '#19C650',
  21. '#90ee90',
  22. '#00ced1',
  23. '#1e90ff',
  24. '#c71585',
  25. '#FF407E',
  26. '#CFAF70',
  27. '#A253FF',
  28. 'rgba(255, 69, 0, 0.68)',
  29. 'rgb(255, 120, 0)',
  30. 'hsl(181, 100%, 37%)',
  31. 'hsla(209, 100%, 56%, 0.73)',
  32. '#c7158577'
  33. ],
  34. global: {
  35. title: '页面',
  36. // 公共模板属性,所有组件都继承,无需重复定义,组件内部根据业务自行调用
  37. template: {
  38. textColor: '#303133', // 文字颜色
  39. pageStartBgColor: '', // 组件底部背景颜色(开始)
  40. pageEndBgColor: '', // 组件底部背景颜色(结束)
  41. pageGradientAngle: 'to bottom', // 渐变角度,从上到下(to bottom)、从左到右(to right)
  42. componentStartBgColor: '', // 组件背景颜色(开始)
  43. componentEndBgColor: '', // 组件背景颜色(结束)
  44. componentGradientAngle: 'to bottom', // 渐变角度,从上到下(to bottom)、从左到右(to right)
  45. topRounded: 0, // 组件上圆角
  46. bottomRounded: 0, // 组件下圆角
  47. padding: {
  48. top: 0, // 上边距
  49. bottom: 0, // 下边距
  50. both: 0 // 左右边距
  51. },
  52. isHidden: false // 是否隐藏该组件 true:是,false:否,增加问号说明:勾选后该组件将隐藏,适用于你不希望看到该组件字段又不希望删除的情况;
  53. }
  54. }
  55. };
  56. },
  57. getters: {
  58. editComponent: (state) => {
  59. if (state.currentIndex == -99) {
  60. return state.global;
  61. } else {
  62. return state.componentList[state.currentIndex];
  63. }
  64. }
  65. },
  66. actions: {
  67. // 添加组件
  68. addComponent(item: any, key: any) {
  69. if (this.componentList.length == 0) {
  70. this.uniqueIdCounter = 0;
  71. }
  72. this.uniqueIdCounter++;
  73. const template = cloneDeep(this.global.template);
  74. const newItem = {
  75. ...item,
  76. ...template,
  77. itemKey: this.uniqueIdCounter,
  78. ignore: []
  79. };
  80. // 头部组件
  81. if (item.id == 1) {
  82. newItem.ignore = ['pageBgColor', 'componentBgUrl', 'componentBgColor', 'componentBgColor', 'topRounded', 'bottomRounded', 'marginBoth'];
  83. newItem.settings = 1;
  84. newItem.carousel = 1;
  85. newItem.topStyle = 1;
  86. newItem.logo = '';
  87. newItem.code = '';
  88. newItem.classifyShow = true;
  89. newItem.topType = 1;
  90. newItem.topNav = [
  91. {
  92. title: '导航名称',
  93. url: '',
  94. id: Date.now()
  95. }
  96. ];
  97. newItem.toplabel = [
  98. {
  99. title: '标签名称',
  100. url: '',
  101. id: Date.now()
  102. }
  103. ];
  104. newItem.leftStyle = 1;
  105. newItem.leftBackground = '#ffffff';
  106. newItem.leftColor1 = '#101828';
  107. newItem.leftColor2 = '#364153';
  108. newItem.carouselStyle = false;
  109. newItem.carouselType = 0;
  110. newItem.carouselRadius = 10;
  111. newItem.carouselInterval = 3000;
  112. newItem.centreType = 1;
  113. newItem.carouselList = [
  114. {
  115. imageUrl: '',
  116. url: '',
  117. imgType: 1,
  118. show: true,
  119. id: Date.now()
  120. }
  121. ];
  122. newItem.advertNum = 0;
  123. newItem.advertList = [
  124. {
  125. imageUrl: '',
  126. url: '',
  127. imgType: 1,
  128. id: Date.now(),
  129. show: false
  130. },
  131. {
  132. imageUrl: '',
  133. url: '',
  134. imgType: 1,
  135. id: Date.now(),
  136. show: false
  137. },
  138. {
  139. imageUrl: '',
  140. url: '',
  141. imgType: 1,
  142. id: Date.now(),
  143. show: false
  144. },
  145. {
  146. imageUrl: '',
  147. url: '',
  148. imgType: 1,
  149. id: Date.now(),
  150. show: false
  151. }
  152. ];
  153. newItem.realType = 1;
  154. newItem.realDataType = 1;
  155. newItem.realNumber = 5;
  156. newItem.realIds = [];
  157. newItem.navlList = [
  158. {
  159. imageUrl: '',
  160. title: '导航名称',
  161. url: '',
  162. imgType: 1,
  163. id: Date.now()
  164. }
  165. ];
  166. newItem.rightRadius = 5;
  167. } else if (item.id == 2) {
  168. // 文本标题
  169. newItem.styleType = 1;
  170. newItem.title = '标题名称';
  171. newItem.titleUrl = '';
  172. newItem.titleAlign = 'left';
  173. newItem.titleSize = 18;
  174. newItem.titleColor = '#101828';
  175. newItem.titleWeight = 'bold';
  176. newItem.subtitle = '副标题';
  177. newItem.subtitleSize = 16;
  178. newItem.subtitleColor = '#b7bcd2';
  179. newItem.more = '更多';
  180. newItem.moreShow = true;
  181. newItem.moreSize = 14;
  182. newItem.moreColor = '#b7bcd2';
  183. newItem.moreUrl = '';
  184. newItem.pageStartBgColor = '#ffffff';
  185. newItem.padding.top = 10;
  186. newItem.padding.bottom = 10;
  187. newItem.padding.both = 20;
  188. } else if (item.id == 3) {
  189. //图文导航
  190. newItem.styleType = 1;
  191. newItem.number = 3;
  192. newItem.count = 1;
  193. newItem.navlList = [
  194. {
  195. imageUrl: '',
  196. title: '标题名称',
  197. subtitle: '副标题名称',
  198. url: '',
  199. imgType: 1,
  200. id: Date.now()
  201. }
  202. ];
  203. newItem.titleSize = 16;
  204. newItem.titleColor = '#101828';
  205. newItem.titleWeight = 'bold';
  206. newItem.subtitleSize = 12;
  207. newItem.subtitleColor = '#364153';
  208. newItem.imageRadius = 10;
  209. newItem.componentStartBgColor = '#ffffff';
  210. newItem.topRounded = 10;
  211. newItem.bottomRounded = 10;
  212. } else if (item.id == 4) {
  213. // 图片魔方
  214. newItem.number = 1;
  215. newItem.imageHeight = 150;
  216. newItem.imagelList = [
  217. {
  218. imageUrl: '',
  219. url: '',
  220. imgType: 1,
  221. id: Date.now()
  222. },
  223. {
  224. imageUrl: '',
  225. url: '',
  226. imgType: 1,
  227. id: Date.now()
  228. },
  229. {
  230. imageUrl: '',
  231. url: '',
  232. imgType: 1,
  233. id: Date.now()
  234. },
  235. {
  236. imageUrl: '',
  237. url: '',
  238. imgType: 1,
  239. id: Date.now()
  240. },
  241. {
  242. imageUrl: '',
  243. url: '',
  244. imgType: 1,
  245. id: Date.now()
  246. }
  247. ];
  248. newItem.gap = 10;
  249. newItem.imageTopRounded = 10;
  250. newItem.imageBottomRoundedRounded = 10;
  251. } else if (item.id == 6) {
  252. //轮播图
  253. newItem.imageHeight = 200;
  254. newItem.imagelList = [
  255. {
  256. imageUrl: '',
  257. imgType: 1,
  258. id: Date.now()
  259. }
  260. ];
  261. newItem.interval = 3000;
  262. newItem.styleType = 1;
  263. newItem.position = 2;
  264. newItem.imageRadius = 10;
  265. newItem.ignore = ['componentBgColor', 'topRounded', 'bottomRounded'];
  266. } else if (item.id == 7) {
  267. //文章咨询
  268. newItem.dataType = 1;
  269. newItem.dataNumber = 4;
  270. newItem.dataIds = [];
  271. newItem.border = 1;
  272. newItem.borderColor = '#ffffff';
  273. newItem.backgroundColor = '#ffffff';
  274. newItem.boxTopRounded = 10;
  275. newItem.boxBottomRounded = 10;
  276. } else if (item.id == 8) {
  277. //品牌组件
  278. newItem.settings = 1;
  279. newItem.imageUrl = '';
  280. newItem.url = '';
  281. newItem.imgType = 1;
  282. newItem.brandList = [
  283. {
  284. imageUrl: '',
  285. title: '品牌名称',
  286. subtitle: '品牌介绍',
  287. url: '',
  288. imgType: 1,
  289. id: Date.now()
  290. }
  291. ];
  292. newItem.titleSize = 14;
  293. newItem.titleColor = '#101828';
  294. newItem.titleWeight = 'bold';
  295. newItem.subtitleSize = 12;
  296. newItem.subtitleColor = '#364153';
  297. newItem.imageRadius = 10;
  298. newItem.boxRadius = 5;
  299. } else if (item.id == 9) {
  300. //图文广告
  301. newItem.styleType = 1;
  302. newItem.number = 3;
  303. newItem.count = 1;
  304. newItem.navlList = [
  305. {
  306. imageUrl: '',
  307. title: '标题名称',
  308. subtitle: '副标题名称',
  309. url: '',
  310. imgType: 1,
  311. id: Date.now()
  312. }
  313. ];
  314. newItem.titleSize = 16;
  315. newItem.titleColor = '#101828';
  316. newItem.titleWeight = 'bold';
  317. newItem.subtitleSize = 12;
  318. newItem.subtitleColor = '#364153';
  319. newItem.imageRadius = 10;
  320. newItem.componentStartBgColor = '#ffffff';
  321. newItem.topRounded = 10;
  322. newItem.bottomRounded = 10;
  323. } else if (item.id == 10) {
  324. //楼层组件
  325. newItem.styleType = 1;
  326. newItem.imageUrl = '';
  327. newItem.imgType = 1;
  328. newItem.imageRadius = 10;
  329. newItem.goodsIds = [];
  330. newItem.goodsShow = [1, 2, 3];
  331. newItem.btnShow = true;
  332. newItem.btnStyle = 1;
  333. newItem.btnText = '购买';
  334. newItem.btnColor = '#ffffff';
  335. newItem.btnbackgroundColor = '#E7000B';
  336. newItem.moreTitle = '更多';
  337. newItem.moreUrl = '';
  338. newItem.moreColor = '#E7000B';
  339. newItem.moreShow = true;
  340. newItem.brandList = [
  341. {
  342. imageUrl: '',
  343. url: '',
  344. imgType: 1,
  345. id: Date.now()
  346. },
  347. {
  348. imageUrl: '',
  349. url: '',
  350. imgType: 1,
  351. id: Date.now()
  352. },
  353. {
  354. imageUrl: '',
  355. url: '',
  356. imgType: 1,
  357. id: Date.now()
  358. },
  359. {
  360. imageUrl: '',
  361. url: '',
  362. imgType: 1,
  363. id: Date.now()
  364. },
  365. {
  366. imageUrl: '',
  367. url: '',
  368. imgType: 1,
  369. id: Date.now()
  370. },
  371. {
  372. imageUrl: '',
  373. url: '',
  374. imgType: 1,
  375. id: Date.now()
  376. }
  377. ];
  378. } else if (item.id == 11) {
  379. // 商品组件
  380. newItem.styleType = 1;
  381. newItem.btnShow = true;
  382. newItem.btnStyle = 1;
  383. newItem.btnText = '购买';
  384. newItem.goodsShow = [1, 2, 3];
  385. newItem.goodsType = 1;
  386. newItem.goodsIds = [];
  387. newItem.goodsClassify = '';
  388. newItem.topCategoryId = '';
  389. newItem.mediumCategoryId = '';
  390. newItem.bottomCategoryId = '';
  391. newItem.goodsNumber = 5;
  392. newItem.goodsSort = 1;
  393. newItem.goodsBrand = '';
  394. newItem.goodsbackgroundColor = '#ffffff';
  395. newItem.goodsTitleType = 1;
  396. newItem.goodsTitleColor = '#101828';
  397. newItem.imageRadius = 10;
  398. newItem.goodstopRounded = 10;
  399. newItem.goodsbottomRounded = 10;
  400. newItem.priceColor = '#E7000B';
  401. newItem.btnColor = '#ffffff';
  402. newItem.btnbackgroundColor = '#E7000B';
  403. } else if (item.id == 12) {
  404. //多商品组件
  405. newItem.btnShow = true;
  406. newItem.btnStyle = 1;
  407. newItem.btnText = '购买';
  408. newItem.goodsShow = [1, 2, 3];
  409. newItem.goodsNumber = 5;
  410. newItem.goodsSort = 1;
  411. newItem.goodsbackgroundColor = '#ffffff';
  412. newItem.goodsTitleType = 1;
  413. newItem.goodsTitleColor = '#101828';
  414. newItem.imageRadius = 10;
  415. newItem.goodstopRounded = 10;
  416. newItem.goodsbottomRounded = 10;
  417. newItem.priceColor = '#E7000B';
  418. newItem.btnColor = '#ffffff';
  419. newItem.btnbackgroundColor = '#E7000B';
  420. newItem.tabColor1 = '#333333';
  421. newItem.tabColor2 = '#ffffff';
  422. newItem.tabbackgroundColor1 = '#ffffff';
  423. newItem.tabbackgroundColor2 = '#E7000B';
  424. newItem.tabRadius = 10;
  425. newItem.tabIndex = 0;
  426. newItem.tabList = [
  427. {
  428. title: '选项卡',
  429. goodsType: 1,
  430. goodsIds: [],
  431. goodsClassify: '',
  432. topCategoryId: '',
  433. mediumCategoryId: '',
  434. bottomCategoryId: '',
  435. id: Date.now()
  436. }
  437. ];
  438. } else if (item.id == 13) {
  439. // 发现组件
  440. newItem.settings = 1;
  441. newItem.title = '标题';
  442. newItem.titleUrl = '';
  443. newItem.titleSize = 18;
  444. newItem.titleColor = '#101828';
  445. newItem.titleWeight = 'bold';
  446. newItem.subtitle = '副标题';
  447. newItem.subtitleSize = 14;
  448. newItem.subtitleColor = '#364153';
  449. newItem.imgType = 1;
  450. newItem.tabList = [
  451. {
  452. title: '导航名称',
  453. url: '',
  454. id: Date.now()
  455. }
  456. ];
  457. newItem.imageUrl = '';
  458. newItem.imageRadius = 10;
  459. newItem.boxRadius = 5;
  460. newItem.boxColor = '#E7000B';
  461. newItem.planList = [
  462. {
  463. imageUrl: '',
  464. title: '',
  465. subtitle: '',
  466. url: '',
  467. imgType: 1,
  468. id: Date.now()
  469. },
  470. {
  471. imageUrl: '',
  472. title: '',
  473. subtitle: '',
  474. url: '',
  475. imgType: 1,
  476. id: Date.now()
  477. },
  478. {
  479. imageUrl: '',
  480. title: '',
  481. subtitle: '',
  482. url: '',
  483. imgType: 1,
  484. id: Date.now()
  485. }
  486. ];
  487. newItem.detectList = [
  488. {
  489. imageUrl: '',
  490. title: '',
  491. subtitle: '',
  492. url: '',
  493. imgType: 1,
  494. id: Date.now()
  495. },
  496. {
  497. imageUrl: '',
  498. title: '',
  499. subtitle: '',
  500. url: '',
  501. imgType: 1,
  502. id: Date.now()
  503. },
  504. {
  505. imageUrl: '',
  506. title: '',
  507. subtitle: '',
  508. url: '',
  509. imgType: 1,
  510. id: Date.now()
  511. }
  512. ];
  513. newItem.labelList = [
  514. {
  515. title: '标签名称',
  516. url: '',
  517. id: Date.now()
  518. }
  519. ];
  520. newItem.goodsIds = [];
  521. }
  522. this.componentList.push(newItem);
  523. this.currentIndex = this.componentList.length - 1;
  524. this.currentKey = newItem.itemKey;
  525. console.log(this.componentList, '4564654');
  526. },
  527. // 上移组件
  528. moveUpComponent() {
  529. if (this.currentIndex <= 0 || this.currentIndex >= this.componentList.length) {
  530. return;
  531. }
  532. [this.componentList[this.currentIndex], this.componentList[this.currentIndex - 1]] = [
  533. this.componentList[this.currentIndex - 1],
  534. this.componentList[this.currentIndex]
  535. ];
  536. },
  537. // 下移组件
  538. moveDownComponent() {
  539. if (this.currentIndex < 0 || this.currentIndex >= this.componentList.length - 1) {
  540. return;
  541. }
  542. [this.componentList[this.currentIndex], this.componentList[this.currentIndex + 1]] = [
  543. this.componentList[this.currentIndex + 1],
  544. this.componentList[this.currentIndex]
  545. ];
  546. },
  547. // 复制
  548. copyComponent() {
  549. // const datas = structuredClone(this.componentList[this.currentIndex]);
  550. // const datas = JSON.parse(JSON.stringify(this.componentList[this.currentIndex]));
  551. // // console.log(datas, '???????')
  552. // this.componentList.splice(this.currentIndex + 1, 0, datas);
  553. },
  554. //删除
  555. delComponent() {
  556. this.componentList.splice(this.currentIndex, 1);
  557. },
  558. //点击组件
  559. onComponent(item: any, index: any) {
  560. this.currentKey = item.itemKey;
  561. this.currentIndex = index;
  562. }
  563. }
  564. });
  565. export default usePcdiyStore;