index.vue 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279
  1. <template>
  2. <div class="diy-page">
  3. <Card :bordered="false" dis-hover class="ivu-mt" style="margin: 0 10px">
  4. <div class="diy-wrapper" :style="'height:' + clientHeight + 'px;'">
  5. <!-- 左侧 -->
  6. <div class="left">
  7. <div class="title-bar">
  8. <div
  9. class="title-item"
  10. :class="{ on: tabCur == index }"
  11. v-for="(item, index) in tabList"
  12. :key="index"
  13. @click="bindTab(index)"
  14. >
  15. {{ item.title }}
  16. </div>
  17. </div>
  18. <div class="wrapper" :style="'height:' + (clientHeight - 46) + 'px;'" v-if="tabCur == 0">
  19. <div v-for="(item, index) in leftMenu" :key="index">
  20. <div class="tips" @click="item.isOpen = !item.isOpen">
  21. {{ item.title }}
  22. <Icon type="ios-arrow-forward" size="16" v-if="!item.isOpen" />
  23. <Icon type="ios-arrow-down" size="16" v-else />
  24. </div>
  25. <draggable
  26. class="dragArea list-group"
  27. :list="item.list"
  28. :group="{ name: 'people', pull: 'clone', put: false }"
  29. :clone="cloneDog"
  30. dragClass="dragClass"
  31. filter=".search"
  32. >
  33. <!--filter=".search , .navbar"-->
  34. <!--:class="{ search: element.cname == '搜索框' , navbar: element.cname == '商品分类' }"-->
  35. <div
  36. class="list-group-item"
  37. :class="{ search: element.cname == '搜索框' }"
  38. v-for="(element, index) in item.list"
  39. :key="element.id"
  40. @click="addDom(element, 1)"
  41. v-show="item.isOpen"
  42. >
  43. <div>
  44. <div class="position" style="display: none">释放鼠标将组建添加到此处</div>
  45. <span class="conter iconfont-diy" :class="element.icon"></span>
  46. <p class="conter">{{ element.cname }}</p>
  47. </div>
  48. </div>
  49. </draggable>
  50. </div>
  51. </div>
  52. <!-- <div style="padding: 0 20px"><Button type="primary" style="width: 100%" @click="saveConfig">保存</Button></div>-->
  53. <div class="wrapper" v-else :style="'height:' + (clientHeight - 46) + 'px;'">
  54. <div class="link-item" v-for="(item, index) in urlList" :key="index">
  55. <div class="name">{{ item.name }}</div>
  56. <div class="link-txt">地址:{{ item.url }}</div>
  57. <div class="params">
  58. <span class="txt">参数:</span>
  59. <span>{{ item.parameter }}</span>
  60. </div>
  61. <div class="lable">
  62. <p class="txt">例如:{{ item.example }}</p>
  63. <Button size="small" @click="onCopy(item.example)">复制 </Button>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. <!-- 中间 -->
  69. <div
  70. class="wrapper-con"
  71. style="flex: 1; background: #f0f2f5; display: flex; justify-content: center; padding-top: 20px; height: 100%"
  72. >
  73. <div class="content">
  74. <div class="contxt" style="display: flex; flex-direction: column; overflow: hidden; height: 100%">
  75. <div class="overflowy">
  76. <div class="picture">
  77. <img src="@/assets/images/electric.png" />
  78. </div>
  79. <div class="page-title" :class="{ on: activeIndex == -100 }" @click="showTitle">
  80. {{ titleTxt }}
  81. <div class="delete-box"></div>
  82. <div class="handle"></div>
  83. </div>
  84. </div>
  85. <div class="scrollCon">
  86. <div style="width: 460px; margin: 0 auto">
  87. <div
  88. class="scroll-box"
  89. :class="
  90. picTxt && tabValTxt == 2
  91. ? 'fullsize noRepeat'
  92. : picTxt && tabValTxt == 1
  93. ? 'repeat ysize'
  94. : 'noRepeat ysize'
  95. "
  96. :style="
  97. 'background-color:' +
  98. (colorTxt ? colorPickerTxt : '') +
  99. ';background-image: url(' +
  100. (picTxt ? picUrlTxt : '') +
  101. ');height:' +
  102. rollHeight +
  103. 'px;'
  104. "
  105. ref="imgContainer"
  106. >
  107. <draggable
  108. class="dragArea list-group"
  109. :list="mConfig"
  110. group="people"
  111. @change="log"
  112. filter=".top"
  113. :move="onMove"
  114. animation="300"
  115. >
  116. <div
  117. class="mConfig-item"
  118. :class="{
  119. on: activeIndex == key,
  120. top: item.name == 'search_box' || item.name == 'nav_bar',
  121. }"
  122. v-for="(item, key) in mConfig"
  123. :key="key"
  124. @click.stop="bindconfig(item, key)"
  125. :style="colorTxt ? 'background-color:' + colorPickerTxt + ';' : 'background-color:#fff;'"
  126. >
  127. <component
  128. :is="item.name"
  129. ref="getComponentData"
  130. :configData="propsObj"
  131. :index="key"
  132. :num="item.num"
  133. ></component>
  134. <div class="delete-box">
  135. <div class="handleType">
  136. <div class="iconfont iconshanchu2" @click.stop="bindDelete(item, key)"></div>
  137. <div class="iconfont iconfuzhi" @click.stop="bindAddDom(item, 0, key)"></div>
  138. <div
  139. class="iconfont iconshangyi"
  140. :class="key === 0 ? 'on' : ''"
  141. @click.stop="movePage(item, key, 1)"
  142. ></div>
  143. <div
  144. class="iconfont iconxiayi"
  145. :class="key === mConfig.length - 1 ? 'on' : ''"
  146. @click.stop="movePage(item, key, 0)"
  147. ></div>
  148. </div>
  149. </div>
  150. <div class="handle"></div>
  151. </div>
  152. </draggable>
  153. </div>
  154. </div>
  155. </div>
  156. <div class="overflowy">
  157. <div class="page-foot" @click="showFoot" :class="{ on: activeIndex == -101 }">
  158. <footPage></footPage>
  159. <div class="delete-box"></div>
  160. <div class="handle"></div>
  161. </div>
  162. </div>
  163. <div class="defaultData" v-if="pageId !== 0">
  164. <div class="data" @click="setmoren">设置默认</div>
  165. <div class="data" @click="getmoren">恢复默认</div>
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. <!-- 右侧 -->
  171. <div class="right-box">
  172. <div class="mConfig-item" style="background-color: #fff" v-for="(item, key) in rConfig" :key="key">
  173. <div class="title-bar">{{ item.cname }}</div>
  174. <component
  175. :is="item.configName"
  176. @config="config"
  177. :activeIndex="activeIndex"
  178. :num="item.num"
  179. :index="key"
  180. ></component>
  181. </div>
  182. </div>
  183. </div>
  184. </Card>
  185. <!--<div class="foot-box">-->
  186. <!--<Button @click="reast">重置</Button>-->
  187. <!--<Button type="primary" @click="saveConfig" :loading="loading"-->
  188. <!--&gt;保存-->
  189. <!--</Button-->
  190. <!--&gt;-->
  191. <!--</div>-->
  192. </div>
  193. </template>
  194. <script crossorigin="anonymous">
  195. import { categoryList, diyGetInfo, diySave, getUrl, setDefault, recovery } from '@/api/diy';
  196. import vuedraggable from 'vuedraggable';
  197. import footPage from '@/components/pagesFoot';
  198. import { mapState } from 'vuex';
  199. import html2canvas from 'html2canvas';
  200. let idGlobal = 0;
  201. export default {
  202. inject: ['reload'],
  203. name: 'index.vue',
  204. components: {
  205. footPage,
  206. html2canvas,
  207. draggable: vuedraggable,
  208. },
  209. filters: {
  210. filterTxt(val) {
  211. if (val) {
  212. return (val = val.substr(0, val.length - 1));
  213. }
  214. },
  215. },
  216. computed: {
  217. ...mapState({
  218. titleTxt: (state) => state.mobildConfig.pageTitle || '首页',
  219. nameTxt: (state) => state.mobildConfig.pageName || '模板',
  220. showTxt: (state) => state.mobildConfig.pageShow,
  221. colorTxt: (state) => state.mobildConfig.pageColor,
  222. picTxt: (state) => state.mobildConfig.pagePic,
  223. colorPickerTxt: (state) => state.mobildConfig.pageColorPicker,
  224. tabValTxt: (state) => state.mobildConfig.pageTabVal,
  225. picUrlTxt: (state) => state.mobildConfig.pagePicUrl,
  226. }),
  227. },
  228. data() {
  229. return {
  230. clientHeight: '', //页面动态高度
  231. rollHeight: '',
  232. leftMenu: [], // 左侧菜单
  233. lConfig: [], // 左侧组件
  234. mConfig: [], // 中间组件渲染
  235. rConfig: [], // 右侧组件配置
  236. activeConfigName: '',
  237. propsObj: {}, // 组件传递的数据,
  238. activeIndex: -100, // 选中的下标
  239. number: 0,
  240. pageId: '',
  241. pageName: '',
  242. pageType: '',
  243. category: [],
  244. tabList: [
  245. {
  246. title: '组件库',
  247. key: 0,
  248. },
  249. {
  250. title: '页面链接',
  251. key: 1,
  252. },
  253. ],
  254. tabCur: 0,
  255. urlList: [],
  256. footActive: false,
  257. loading: false,
  258. isSearch: false,
  259. isTab: false,
  260. isFllow: false,
  261. };
  262. },
  263. created() {
  264. this.categoryList();
  265. this.getUrlList();
  266. this.pageId = this.$route.query.id;
  267. this.pageName = this.$route.query.name;
  268. this.pageType = this.$route.query.type;
  269. this.lConfig = this.objToArr(mPage);
  270. },
  271. mounted() {
  272. let imgList = {
  273. imgList: [require('@/assets/images/foot-005.png'), require('@/assets/images/foot-006.png')],
  274. name: '购物车',
  275. link: '/pages/order_addcart/order_addcart',
  276. };
  277. this.$nextTick(() => {
  278. this.$store.commit('mobildConfig/FOOTER', {
  279. title: '是否自定义',
  280. name: imgList,
  281. });
  282. this.arraySort();
  283. if (this.pageId != 0) {
  284. this.getDefaultConfig();
  285. } else {
  286. this.showTitle();
  287. }
  288. this.clientHeight = `${document.documentElement.clientHeight}` - 65.81; //获取浏览器可视区域高度
  289. let H = `${document.documentElement.clientHeight}` - 180;
  290. this.rollHeight = H > 650 ? 650 : H;
  291. let that = this;
  292. window.onresize = function () {
  293. that.clientHeight = `${document.documentElement.clientHeight}` - 65.81;
  294. let H = `${document.documentElement.clientHeight}` - 180;
  295. that.rollHeight = H > 650 ? 650 : H;
  296. };
  297. });
  298. },
  299. methods: {
  300. leftRemove({ to, from, item, clone, oldIndex, newIndex }) {
  301. if (this.isSearch && newIndex == 0) {
  302. if (item._underlying_vm_.name == 'z_wechat_attention') {
  303. this.isFllow = true;
  304. } else {
  305. this.$store.commit('mobildConfig/ARRAYREAST', this.mConfig[0].num);
  306. this.mConfig.splice(0, 1);
  307. }
  308. }
  309. if ((this.isFllow = true && newIndex >= 1)) {
  310. this.$store.commit('mobildConfig/ARRAYREAST', this.mConfig[0].num);
  311. }
  312. },
  313. onMove(e) {
  314. if (e.relatedContext.element.name == 'search_box') return false;
  315. if (e.relatedContext.element.name == 'nav_bar') return false;
  316. return true;
  317. },
  318. onCopy(copyData) {
  319. this.$copyText(copyData)
  320. .then((message) => {
  321. this.$Message.success('复制成功');
  322. })
  323. .catch((err) => {
  324. this.$Message.error('复制失败');
  325. });
  326. },
  327. onError() {
  328. this.$Message.error('复制失败');
  329. },
  330. //设置默认数据
  331. setmoren() {
  332. setDefault(this.pageId)
  333. .then((res) => {
  334. this.$Message.success(res.msg);
  335. })
  336. .catch((err) => {
  337. this.$Message.error(err.msg);
  338. });
  339. },
  340. //恢复默认
  341. getmoren() {
  342. recovery(this.pageId)
  343. .then((res) => {
  344. this.$Message.success(res.msg);
  345. this.reload();
  346. })
  347. .catch((err) => {
  348. this.$Message.error(err.msg);
  349. });
  350. },
  351. // 获取url
  352. getUrlList() {
  353. getUrl().then((res) => {
  354. this.urlList = res.data.url;
  355. });
  356. },
  357. // 左侧tab
  358. bindTab(index) {
  359. this.tabCur = index;
  360. },
  361. // 页面标题点击
  362. showTitle() {
  363. this.activeIndex = -100;
  364. let obj = {};
  365. for (var i in mConfig) {
  366. if (i == 'pageTitle') {
  367. // this.rConfig = obj
  368. obj = mConfig[i];
  369. obj.configName = mConfig[i].name;
  370. obj.cname = '页面设置';
  371. }
  372. }
  373. let abc = obj;
  374. this.rConfig = [];
  375. this.rConfig[0] = JSON.parse(JSON.stringify(obj));
  376. },
  377. // 页面底部点击
  378. showFoot() {
  379. this.activeIndex = -101;
  380. let obj = {};
  381. for (var i in mConfig) {
  382. if (i == 'pageFoot') {
  383. // this.rConfig = obj
  384. obj = mConfig[i];
  385. obj.configName = mConfig[i].name;
  386. obj.cname = '底部菜单';
  387. }
  388. }
  389. let abc = obj;
  390. this.rConfig = [];
  391. this.rConfig[0] = JSON.parse(JSON.stringify(obj));
  392. },
  393. // 对象转数组
  394. objToArr(data) {
  395. let obj = Object.keys(data);
  396. let m = obj.map((key) => data[key]);
  397. return m;
  398. },
  399. log(evt) {
  400. // 中间拖拽排序
  401. if (evt.moved) {
  402. if (evt.moved.element.name == 'search_box' || evt.moved.element.name == 'nav_bar') {
  403. return this.$Message.warning('该组件禁止拖拽');
  404. }
  405. // if (evt.moved.element.name == "nav_bar") {
  406. // return this.$Message.warning("该组件禁止拖拽");
  407. // }
  408. evt.moved.oldNum = this.mConfig[evt.moved.oldIndex].num;
  409. evt.moved.newNum = this.mConfig[evt.moved.newIndex].num;
  410. evt.moved.status = evt.moved.oldIndex > evt.moved.newIndex;
  411. this.mConfig.forEach((el, index) => {
  412. el.num = new Date().getTime() * 1000 + index;
  413. });
  414. evt.moved.list = this.mConfig;
  415. this.rConfig = [];
  416. let item = evt.moved.element;
  417. let tempItem = JSON.parse(JSON.stringify(item));
  418. this.rConfig.push(tempItem);
  419. this.activeIndex = evt.moved.newIndex;
  420. this.$store.commit('mobildConfig/SETCONFIGNAME', item.name);
  421. this.$store.commit('mobildConfig/defaultArraySort', evt.moved);
  422. }
  423. // 从左向右拖拽排序
  424. if (evt.added) {
  425. let data = evt.added.element;
  426. let obj = {};
  427. let timestamp = new Date().getTime() * 1000;
  428. data.num = timestamp;
  429. this.activeConfigName = data.name;
  430. let tempItem = JSON.parse(JSON.stringify(data));
  431. tempItem.id = 'id' + tempItem.num;
  432. this.mConfig[evt.added.newIndex] = tempItem;
  433. this.rConfig = [];
  434. this.rConfig.push(tempItem);
  435. this.mConfig.forEach((el, index) => {
  436. el.num = new Date().getTime() * 1000 + index;
  437. });
  438. evt.added.list = this.mConfig;
  439. this.activeIndex = evt.added.newIndex;
  440. // 保存组件名称
  441. this.$store.commit('mobildConfig/SETCONFIGNAME', data.name);
  442. this.$store.commit('mobildConfig/defaultArraySort', evt.added);
  443. }
  444. },
  445. cloneDog(data) {
  446. // this.mConfig.push(tempItem)
  447. return {
  448. ...data,
  449. };
  450. },
  451. //数组元素互换位置
  452. swapArray(arr, index1, index2) {
  453. arr[index1] = arr.splice(index2, 1, arr[index1])[0];
  454. return arr;
  455. },
  456. //点击上下移动;
  457. movePage(item, index, type) {
  458. if (type) {
  459. if (index == 0) {
  460. return;
  461. }
  462. } else {
  463. if (index == this.mConfig.length - 1) {
  464. return;
  465. }
  466. }
  467. if (item.name == 'search_box' || item.name == 'nav_bar') {
  468. return this.$Message.warning('该组件禁止移动');
  469. }
  470. // if (item.name == "nav_bar") {
  471. // return this.$Message.warning("该组件禁止移动");
  472. // }
  473. if (type) {
  474. // if(this.mConfig[index-1].name == "search_box" || this.mConfig[index-1].name == "nav_bar"){
  475. if (this.mConfig[index - 1].name == 'search_box') {
  476. return this.$Message.warning('搜索框必须为顶部');
  477. }
  478. this.swapArray(this.mConfig, index - 1, index);
  479. } else {
  480. this.swapArray(this.mConfig, index, index + 1);
  481. }
  482. let obj = {};
  483. this.rConfig = [];
  484. obj.oldIndex = index;
  485. if (type) {
  486. obj.newIndex = index - 1;
  487. } else {
  488. obj.newIndex = index + 1;
  489. }
  490. this.mConfig.forEach((el, index) => {
  491. el.num = new Date().getTime() * 1000 + index;
  492. });
  493. let tempItem = JSON.parse(JSON.stringify(item));
  494. this.rConfig.push(tempItem);
  495. obj.element = item;
  496. obj.list = this.mConfig;
  497. if (type) {
  498. this.activeIndex = index - 1;
  499. } else {
  500. this.activeIndex = index + 1;
  501. }
  502. this.$store.commit('mobildConfig/SETCONFIGNAME', item.name);
  503. this.$store.commit('mobildConfig/defaultArraySort', obj);
  504. },
  505. // 组件添加
  506. addDomCon(item, type, index) {
  507. if (item.name == 'search_box') {
  508. if (this.isSearch) return this.$Message.error('该组件只能添加一次');
  509. this.isSearch = true;
  510. }
  511. if (item.name == 'nav_bar') {
  512. if (this.isTab) return this.$Message.error('该组件只能添加一次');
  513. this.isTab = true;
  514. }
  515. idGlobal += 1;
  516. let obj = {};
  517. let timestamp = new Date().getTime() * 1000;
  518. item.num = `${timestamp}`;
  519. item.id = `id${timestamp}`;
  520. this.activeConfigName = item.name;
  521. let tempItem = JSON.parse(JSON.stringify(item));
  522. if (item.name == 'search_box') {
  523. this.rConfig = [];
  524. this.mConfig.unshift(tempItem);
  525. this.activeIndex = 0;
  526. this.rConfig.push(tempItem);
  527. }
  528. // else if (item.name == "nav_bar") {
  529. // this.rConfig = [];
  530. // if (this.mConfig[0]&&this.mConfig[0].name === "search_box") {
  531. // this.mConfig.splice(1, 0, tempItem);
  532. // this.activeIndex = 1;
  533. // } else {
  534. // this.mConfig.splice(0, 0, tempItem);
  535. // this.activeIndex = 0;
  536. // }
  537. // this.rConfig.push(tempItem);
  538. // }
  539. else {
  540. if (type) {
  541. this.rConfig = [];
  542. this.mConfig.push(tempItem);
  543. this.activeIndex = this.mConfig.length - 1;
  544. this.rConfig.push(tempItem);
  545. } else {
  546. this.mConfig.splice(index + 1, 0, tempItem);
  547. this.activeIndex = index;
  548. }
  549. }
  550. this.mConfig.forEach((el, index) => {
  551. el.num = new Date().getTime() * 1000 + index;
  552. });
  553. // 保存组件名称
  554. obj.element = item;
  555. obj.list = this.mConfig;
  556. this.$store.commit('mobildConfig/SETCONFIGNAME', item.name);
  557. this.$store.commit('mobildConfig/defaultArraySort', obj);
  558. },
  559. //中间页点击添加模块;
  560. bindAddDom(item, type, index) {
  561. let i = item;
  562. this.lConfig.forEach((j) => {
  563. if (item.name == j.name) {
  564. i = j;
  565. }
  566. });
  567. this.addDomCon(i, type, index);
  568. },
  569. //左边配置模块点击添加;
  570. addDom(item, type) {
  571. this.addDomCon(item, type);
  572. },
  573. // 点击显示相应的配置
  574. bindconfig(item, index) {
  575. this.rConfig = [];
  576. let tempItem = JSON.parse(JSON.stringify(item));
  577. this.rConfig.push(tempItem);
  578. this.activeIndex = index;
  579. this.$store.commit('mobildConfig/SETCONFIGNAME', item.name);
  580. },
  581. // 组件删除
  582. bindDelete(item, key) {
  583. if (item.name == 'search_box') {
  584. this.isSearch = false;
  585. }
  586. if (item.name == 'nav_bar') {
  587. this.isTab = false;
  588. }
  589. this.mConfig.splice(key, 1);
  590. this.rConfig.splice(0, 1);
  591. if (this.mConfig.length != key) {
  592. this.rConfig.push(this.mConfig[key]);
  593. } else {
  594. if (this.mConfig.length) {
  595. this.activeIndex = key - 1;
  596. this.rConfig.push(this.mConfig[key - 1]);
  597. } else {
  598. this.showTitle();
  599. }
  600. }
  601. // 删除第几个配置
  602. this.$store.commit('mobildConfig/DELETEARRAY', item);
  603. },
  604. // 组件返回
  605. config(data) {
  606. let propsObj = this.propsObj;
  607. propsObj.data = data;
  608. propsObj.name = this.activeConfigName;
  609. },
  610. addSort(arr, index1, index2) {
  611. arr[index1] = arr.splice(index2, 1, arr[index1])[0];
  612. return arr;
  613. },
  614. // 数组排序
  615. arraySort() {
  616. let tempArr = [];
  617. let basis = {
  618. title: '基础组件',
  619. list: [],
  620. isOpen: true,
  621. };
  622. let marketing = {
  623. title: '营销组件',
  624. list: [],
  625. isOpen: true,
  626. };
  627. let tool = {
  628. title: '工具组件',
  629. list: [],
  630. isOpen: true,
  631. };
  632. this.lConfig.map((el, index) => {
  633. if (el.type == 0) {
  634. basis.list.push(el);
  635. }
  636. if (el.type == 1) {
  637. marketing.list.push(el);
  638. }
  639. if (el.type == 2) {
  640. tool.list.push(el);
  641. }
  642. });
  643. tempArr.push(basis, marketing, tool);
  644. this.leftMenu = tempArr;
  645. },
  646. // toImage(val){
  647. // html2canvas(this.$refs.imgContainer,{
  648. // useCORS:true,
  649. // logging:true,
  650. // taintTest: false,
  651. // backgroundColor: null
  652. // }).then((canvas) => {
  653. // let imgUrl = canvas.toDataURL('image/jpeg');
  654. // this.diySaveDate(val,imgUrl)
  655. // });
  656. // },
  657. diySaveDate(val) {
  658. diySave(this.pageId, {
  659. type: this.pageType,
  660. value: val,
  661. title: this.titleTxt,
  662. name: this.nameTxt,
  663. is_show: this.showTxt ? 1 : 0,
  664. is_bg_color: this.colorTxt ? 1 : 0,
  665. color_picker: this.colorPickerTxt,
  666. bg_pic: this.picUrlTxt,
  667. bg_tab_val: this.tabValTxt,
  668. is_bg_pic: this.picTxt ? 1 : 0,
  669. })
  670. .then((res) => {
  671. this.loading = false;
  672. this.pageId = res.data.id;
  673. this.$Message.success(res.msg);
  674. })
  675. .catch((res) => {
  676. this.loading = false;
  677. this.$Message.error(res.msg);
  678. });
  679. },
  680. // 保存配置
  681. saveConfig() {
  682. if (this.mConfig.length == 0) {
  683. return this.$Message.error('暂未添加任何组件,保存失败!');
  684. }
  685. this.loading = true;
  686. let val = this.$store.state.mobildConfig.defaultArray;
  687. if (!this.footActive) {
  688. let timestamp = new Date().getTime() * 1000;
  689. val[timestamp] = this.$store.state.mobildConfig.pageFooter;
  690. this.footActive = true;
  691. }
  692. this.$nextTick(function () {
  693. this.diySaveDate(val);
  694. });
  695. },
  696. // 获取默认配置
  697. getDefaultConfig() {
  698. diyGetInfo(this.pageId, {
  699. type: 1,
  700. }).then(({ data }) => {
  701. let obj = {};
  702. let tempARR = [];
  703. this.$store.commit('mobildConfig/titleUpdata', data.info.title);
  704. this.$store.commit('mobildConfig/nameUpdata', data.info.name);
  705. this.$store.commit('mobildConfig/showUpdata', data.info.is_show);
  706. this.$store.commit('mobildConfig/colorUpdata', data.info.is_bg_color || 0);
  707. this.$store.commit('mobildConfig/picUpdata', data.info.is_bg_pic || 0);
  708. this.$store.commit('mobildConfig/pickerUpdata', data.info.color_picker || '#f5f5f5');
  709. this.$store.commit('mobildConfig/radioUpdata', data.info.bg_tab_val || 0);
  710. this.$store.commit('mobildConfig/picurlUpdata', data.info.bg_pic || '');
  711. let newArr = this.objToArr(data.info.value);
  712. function sortNumber(a, b) {
  713. return a.timestamp - b.timestamp;
  714. }
  715. newArr.sort(sortNumber);
  716. newArr.map((el, index) => {
  717. if (el.name == 'headerSerch') {
  718. this.isSearch = true;
  719. }
  720. if (el.name == 'tabNav') {
  721. this.isTab = true;
  722. }
  723. if (el.name == 'goodList') {
  724. let storage = window.localStorage;
  725. storage.setItem(el.timestamp, el.selectConfig.activeValue);
  726. }
  727. el.id = 'id' + el.timestamp;
  728. this.lConfig.map((item, j) => {
  729. if (el.name == item.defaultName) {
  730. item.num = el.timestamp;
  731. item.id = 'id' + el.timestamp;
  732. let tempItem = JSON.parse(JSON.stringify(item));
  733. tempARR.push(tempItem);
  734. obj[el.timestamp] = el;
  735. this.mConfig.push(tempItem);
  736. // 保存默认组件配置
  737. this.$store.commit('mobildConfig/ADDARRAY', {
  738. num: el.timestamp,
  739. val: el,
  740. });
  741. }
  742. });
  743. });
  744. let objs = newArr[newArr.length - 1];
  745. if (objs.name == 'pageFoot') {
  746. this.$store.commit('mobildConfig/footPageUpdata', objs);
  747. }
  748. this.showTitle();
  749. // this.rConfig = [];
  750. // this.activeIndex = 0;
  751. // this.rConfig.push(this.mConfig[0]);
  752. });
  753. },
  754. categoryList() {
  755. categoryList((res) => {
  756. this.category = res.data;
  757. });
  758. },
  759. // 重置
  760. reast() {
  761. if (this.pageId == 0) {
  762. this.$Message.error('新增页面,无法重置');
  763. } else {
  764. this.$Modal.confirm({
  765. title: '提示',
  766. content: '<p>重置会恢复到上次保存的数据,确定不保存当前操作吗?</p>',
  767. onOk: () => {
  768. this.mConfig = [];
  769. this.rConfig = [];
  770. this.activeIndex = -99;
  771. this.getDefaultConfig();
  772. },
  773. onCancel: () => {},
  774. });
  775. }
  776. },
  777. },
  778. beforeDestroy() {
  779. this.$store.commit('mobildConfig/titleUpdata', '');
  780. this.$store.commit('mobildConfig/nameUpdata', '');
  781. this.$store.commit('mobildConfig/showUpdata', 1);
  782. this.$store.commit('mobildConfig/colorUpdata', 0);
  783. this.$store.commit('mobildConfig/picUpdata', 0);
  784. this.$store.commit('mobildConfig/pickerUpdata', '#f5f5f5');
  785. this.$store.commit('mobildConfig/radioUpdata', 0);
  786. this.$store.commit('mobildConfig/picurlUpdata', '');
  787. this.$store.commit('mobildConfig/SETEMPTY');
  788. },
  789. destroyed() {
  790. this.$store.commit('mobildConfig/titleUpdata', '');
  791. this.$store.commit('mobildConfig/nameUpdata', '');
  792. this.$store.commit('mobildConfig/showUpdata', 1);
  793. this.$store.commit('mobildConfig/colorUpdata', 0);
  794. this.$store.commit('mobildConfig/picUpdata', 0);
  795. this.$store.commit('mobildConfig/pickerUpdata', '#f5f5f5');
  796. this.$store.commit('mobildConfig/radioUpdata', 0);
  797. this.$store.commit('mobildConfig/picurlUpdata', '');
  798. this.$store.commit('mobildConfig/SETEMPTY');
  799. },
  800. };
  801. </script>
  802. <style scoped lang="stylus">
  803. .ysize {
  804. background-size: 100%;
  805. }
  806. .fullsize {
  807. background-size: 100% 100%;
  808. }
  809. .repeat {
  810. background-repeat: repeat;
  811. }
  812. .noRepeat {
  813. background-repeat: no-repeat;
  814. }
  815. .wrapper-con {
  816. /* min-width 700px; */
  817. }
  818. .defaultData {
  819. /* margin-left 20px; */
  820. cursor: pointer;
  821. position: absolute;
  822. left: 50%;
  823. margin-left: 245px;
  824. .data {
  825. margin-top: 20px;
  826. color: #282828;
  827. background-color: #fff;
  828. width: 94px;
  829. text-align: center;
  830. height: 32px;
  831. line-height: 32px;
  832. border-radius: 3px;
  833. font-size: 12px;
  834. }
  835. .data:hover {
  836. background-color: #2d8cf0;
  837. color: #fff;
  838. border: 0;
  839. }
  840. }
  841. .overflowy {
  842. overflow-y: scroll;
  843. .picture {
  844. width: 379px;
  845. height: 20px;
  846. margin: 0 auto;
  847. background-color: #fff;
  848. }
  849. }
  850. .bnt {
  851. width: 80px !important;
  852. }
  853. /* 定义滑块 内阴影+圆角 */
  854. ::-webkit-scrollbar-thumb {
  855. -webkit-box-shadow: inset 0 0 6px #fff;
  856. display: none;
  857. }
  858. .left:hover::-webkit-scrollbar-thumb, .right-box:hover::-webkit-scrollbar-thumb {
  859. display: block;
  860. }
  861. .contxt:hover ::-webkit-scrollbar-thumb {
  862. display: block;
  863. }
  864. ::-webkit-scrollbar {
  865. width: 4px !important; /* 对垂直流动条有效 */
  866. }
  867. .scrollCon {
  868. overflow-y: scroll;
  869. overflow-x: hidden;
  870. }
  871. .scroll-box .position {
  872. display: block !important;
  873. height: 40px;
  874. text-align: center;
  875. line-height: 40px;
  876. border: 1px dashed #1890ff;
  877. color: #1890ff;
  878. background-color: #edf4fb;
  879. }
  880. .scroll-box .conter {
  881. display: none !important;
  882. }
  883. .dragClass {
  884. background-color: #fff;
  885. }
  886. .ivu-mt {
  887. display: flex;
  888. justify-content: space-between;
  889. }
  890. .iconfont-diy {
  891. font-size: 24px;
  892. color: #1890ff;
  893. }
  894. .diy-wrapper {
  895. max-width: 100%;
  896. min-width: 1100px;
  897. display: flex;
  898. justify-content: space-between;
  899. /* height: 84.5vh; */
  900. .left {
  901. min-width: 300px;
  902. max-width: 300px;
  903. /* border 1px solid #DDDDDD */
  904. border-radius: 4px;
  905. height: 100%;
  906. .title-bar {
  907. display: flex;
  908. color: #333;
  909. border-bottom: 1px solid #eee;
  910. border-radius: 4px;
  911. cursor: pointer;
  912. .title-item {
  913. display: flex;
  914. align-items: center;
  915. justify-content: center;
  916. flex: 1;
  917. height: 45px;
  918. &.on {
  919. color: #1890FF;
  920. font-size: 14px;
  921. border-bottom: 1px solid #1890FF;
  922. }
  923. }
  924. }
  925. .wrapper {
  926. padding: 15px;
  927. overflow-y: scroll;
  928. -webkit-overflow-scrolling: touch;
  929. .tips {
  930. display: flex;
  931. justify-content: space-between;
  932. padding-bottom: 15px;
  933. font-size: 13px;
  934. color: #000;
  935. cursor: pointer;
  936. .ivu-icon {
  937. color: #000;
  938. }
  939. }
  940. }
  941. .link-item {
  942. padding: 10px;
  943. border-bottom: 1px solid #F5F5F5;
  944. font-size: 12px;
  945. color: #323232;
  946. .name {
  947. font-size: 14px;
  948. color: #1890FF;
  949. }
  950. .link-txt {
  951. margin-top: 2px;
  952. word-break: break-all;
  953. }
  954. .params {
  955. margin-top: 5px;
  956. color: #1CBE6B;
  957. word-break: break-all;
  958. .txt {
  959. color: #323232;
  960. }
  961. span {
  962. &:last-child i {
  963. display: none;
  964. color: red;
  965. }
  966. }
  967. }
  968. .lable {
  969. display: flex;
  970. margin-top: 5px;
  971. color: #999;
  972. p {
  973. flex: 1;
  974. word-break: break-all;
  975. }
  976. button {
  977. margin-left: 30px;
  978. width: 38px;
  979. }
  980. }
  981. }
  982. .dragArea.list-group {
  983. display: flex;
  984. flex-wrap: wrap;
  985. .list-group-item {
  986. display: flex;
  987. flex-direction: column;
  988. align-items: center;
  989. justify-content: center;
  990. width: 74px;
  991. height: 66px;
  992. margin-right: 17px;
  993. margin-bottom: 10px;
  994. font-size: 12px;
  995. color: #666;
  996. cursor: pointer;
  997. border-radius: 5px;
  998. text-align: center;
  999. &:hover {
  1000. box-shadow: 0 0 5px 0 rgba(24, 144, 255, 0.3);
  1001. border-right: 5px;
  1002. }
  1003. &:nth-child(3n) {
  1004. margin-right: 0;
  1005. }
  1006. }
  1007. }
  1008. }
  1009. .content {
  1010. position: relative;
  1011. height: 100%;
  1012. width: 100%;
  1013. .page-foot {
  1014. position: relative;
  1015. width: 379px;
  1016. margin: 0 auto 20px auto;
  1017. .delete-box {
  1018. display: none;
  1019. position: absolute;
  1020. left: -2px;
  1021. top: 0;
  1022. width: 383px;
  1023. height: 100%;
  1024. border: 2px dashed #1890ff;
  1025. padding: 10px 0;
  1026. }
  1027. &:hover, &.on {
  1028. /* cursor: move; */
  1029. .delete-box {
  1030. /* display: block; */
  1031. }
  1032. }
  1033. &.on {
  1034. cursor: move;
  1035. .delete-box {
  1036. display: block;
  1037. border: 2px solid #1890ff;
  1038. box-shadow: 0 0 10px 0 rgba(24, 144, 255, 0.3);
  1039. }
  1040. }
  1041. }
  1042. .page-title {
  1043. position: relative;
  1044. height: 35px;
  1045. line-height: 35px;
  1046. background: #fff;
  1047. font-size: 15px;
  1048. color: #333333;
  1049. text-align: center;
  1050. width: 379px;
  1051. margin: 0 auto;
  1052. .delete-box {
  1053. display: none;
  1054. position: absolute;
  1055. left: -2px;
  1056. top: 0;
  1057. width: 383px;
  1058. height: 100%;
  1059. border: 2px dashed #1890ff;
  1060. padding: 10px 0;
  1061. span {
  1062. position: absolute;
  1063. right: 0;
  1064. bottom: 0;
  1065. width: 32px;
  1066. height: 16px;
  1067. line-height: 16px;
  1068. display: inline-block;
  1069. text-align: center;
  1070. font-size: 10px;
  1071. color: #fff;
  1072. background: rgba(0, 0, 0, 0.4);
  1073. margin-left: 2px;
  1074. cursor: pointer;
  1075. z-index: 11;
  1076. }
  1077. }
  1078. &:hover, &.on {
  1079. /* cursor: move; */
  1080. .delete-box {
  1081. /* display: block; */
  1082. }
  1083. }
  1084. &.on {
  1085. cursor: move;
  1086. .delete-box {
  1087. display: block;
  1088. border: 2px solid #1890ff;
  1089. box-shadow: 0 0 10px 0 rgba(24, 144, 255, 0.3);
  1090. }
  1091. }
  1092. }
  1093. .scroll-box {
  1094. flex: 1;
  1095. background-color: #fff;
  1096. width: 379px;
  1097. margin: 0 auto;
  1098. padding-top: 1px;
  1099. }
  1100. .dragArea.list-group {
  1101. width: 100%;
  1102. height: 100%;
  1103. .mConfig-item {
  1104. position: relative;
  1105. cursor: move;
  1106. .delete-box {
  1107. display: none;
  1108. position: absolute;
  1109. left: -2px;
  1110. top: 0;
  1111. width: 383px;
  1112. height: 100%;
  1113. border: 2px dashed #1890ff;
  1114. /* padding: 10px 0; */
  1115. .handleType {
  1116. position: absolute;
  1117. right: -43px;
  1118. top: 0;
  1119. width: 36px;
  1120. height: 143px;
  1121. border-radius: 4px;
  1122. background-color: #1890ff;
  1123. cursor: pointer;
  1124. color: #fff;
  1125. font-weight: bold;
  1126. text-align: center;
  1127. padding: 4px 0;
  1128. .iconfont {
  1129. padding: 5px 0;
  1130. &.on {
  1131. opacity: 0.4;
  1132. }
  1133. }
  1134. }
  1135. }
  1136. &.on {
  1137. cursor: move;
  1138. .delete-box {
  1139. display: block;
  1140. border: 2px solid #1890ff;
  1141. box-shadow: 0 0 10px 0 rgba(24, 144, 255, 0.3);
  1142. }
  1143. }
  1144. }
  1145. }
  1146. }
  1147. .right-box {
  1148. max-width: 400px;
  1149. min-width: 400px;
  1150. height: 100%;
  1151. border-radius: 4px;
  1152. overflow: scroll;
  1153. -webkit-overflow-scrolling: touch;
  1154. .title-bar {
  1155. width: 100%;
  1156. height: 45px;
  1157. line-height: 45px;
  1158. padding-left: 24px;
  1159. color: #000;
  1160. border-radius: 4px;
  1161. border-bottom: 1px solid #eee;
  1162. font-size: 14px;
  1163. }
  1164. }
  1165. ::-webkit-scrollbar {
  1166. width: 6px;
  1167. background-color: transparent;
  1168. }
  1169. ::-webkit-scrollbar-track {
  1170. border-radius: 10px;
  1171. }
  1172. ::-webkit-scrollbar-thumb {
  1173. background-color: #bfc1c4;
  1174. }
  1175. }
  1176. .foot-box {
  1177. position: relative;
  1178. display: flex;
  1179. align-items: center;
  1180. justify-content: center;
  1181. height: 80px;
  1182. background: #fff;
  1183. box-shadow: 0px -2px 4px 0px rgba(0, 0, 0, 0.03);
  1184. button {
  1185. width: 100px;
  1186. height: 32px;
  1187. font-size: 13px;
  1188. &:first-child {
  1189. margin-right: 20px;
  1190. }
  1191. }
  1192. }
  1193. /deep/ .ivu-scroll-loader {
  1194. display: none;
  1195. }
  1196. /deep/ .ivu-card-body {
  1197. width: 100%;
  1198. }
  1199. </style>