index.vue 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  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. console.log(item);
  471. // if (item.name == "nav_bar") {
  472. // return this.$Message.warning("该组件禁止移动");
  473. // }
  474. if (type) {
  475. // if(this.mConfig[index-1].name == "search_box" || this.mConfig[index-1].name == "nav_bar"){
  476. if (this.mConfig[index - 1].name == 'search_box') {
  477. return this.$Message.warning('搜索框必须为顶部');
  478. }
  479. this.swapArray(this.mConfig, index - 1, index);
  480. } else {
  481. this.swapArray(this.mConfig, index, index + 1);
  482. }
  483. let obj = {};
  484. this.rConfig = [];
  485. obj.oldIndex = index;
  486. if (type) {
  487. obj.newIndex = index - 1;
  488. } else {
  489. obj.newIndex = index + 1;
  490. }
  491. this.mConfig.forEach((el, index) => {
  492. el.num = new Date().getTime() * 1000 + index;
  493. });
  494. let tempItem = JSON.parse(JSON.stringify(item));
  495. this.rConfig.push(tempItem);
  496. obj.element = item;
  497. obj.list = this.mConfig;
  498. if (type) {
  499. this.activeIndex = index - 1;
  500. } else {
  501. this.activeIndex = index + 1;
  502. }
  503. this.$store.commit('mobildConfig/SETCONFIGNAME', item.name);
  504. this.$store.commit('mobildConfig/defaultArraySort', obj);
  505. },
  506. // 组件添加
  507. addDomCon(item, type, index) {
  508. if (item.name == 'search_box') {
  509. if (this.isSearch) return this.$Message.error('该组件只能添加一次');
  510. this.isSearch = true;
  511. }
  512. if (item.name == 'nav_bar') {
  513. if (this.isTab) return this.$Message.error('该组件只能添加一次');
  514. this.isTab = true;
  515. }
  516. idGlobal += 1;
  517. let obj = {};
  518. let timestamp = new Date().getTime() * 1000;
  519. item.num = `${timestamp}`;
  520. item.id = `id${timestamp}`;
  521. this.activeConfigName = item.name;
  522. let tempItem = JSON.parse(JSON.stringify(item));
  523. if (item.name == 'search_box') {
  524. this.rConfig = [];
  525. this.mConfig.unshift(tempItem);
  526. this.activeIndex = 0;
  527. this.rConfig.push(tempItem);
  528. }
  529. // else if (item.name == "nav_bar") {
  530. // this.rConfig = [];
  531. // if (this.mConfig[0]&&this.mConfig[0].name === "search_box") {
  532. // this.mConfig.splice(1, 0, tempItem);
  533. // this.activeIndex = 1;
  534. // } else {
  535. // this.mConfig.splice(0, 0, tempItem);
  536. // this.activeIndex = 0;
  537. // }
  538. // this.rConfig.push(tempItem);
  539. // }
  540. else {
  541. if (type) {
  542. this.rConfig = [];
  543. this.mConfig.push(tempItem);
  544. this.activeIndex = this.mConfig.length - 1;
  545. this.rConfig.push(tempItem);
  546. } else {
  547. this.mConfig.splice(index + 1, 0, tempItem);
  548. this.activeIndex = index;
  549. }
  550. }
  551. this.mConfig.forEach((el, index) => {
  552. el.num = new Date().getTime() * 1000 + index;
  553. });
  554. // 保存组件名称
  555. obj.element = item;
  556. obj.list = this.mConfig;
  557. this.$store.commit('mobildConfig/SETCONFIGNAME', item.name);
  558. this.$store.commit('mobildConfig/defaultArraySort', obj);
  559. },
  560. //中间页点击添加模块;
  561. bindAddDom(item, type, index) {
  562. let i = item;
  563. this.lConfig.forEach((j) => {
  564. if (item.name == j.name) {
  565. i = j;
  566. }
  567. });
  568. this.addDomCon(i, type, index);
  569. },
  570. //左边配置模块点击添加;
  571. addDom(item, type) {
  572. this.addDomCon(item, type);
  573. },
  574. // 点击显示相应的配置
  575. bindconfig(item, index) {
  576. this.rConfig = [];
  577. let tempItem = JSON.parse(JSON.stringify(item));
  578. this.rConfig.push(tempItem);
  579. this.activeIndex = index;
  580. this.$store.commit('mobildConfig/SETCONFIGNAME', item.name);
  581. },
  582. // 组件删除
  583. bindDelete(item, key) {
  584. if (item.name == 'search_box') {
  585. this.isSearch = false;
  586. }
  587. if (item.name == 'nav_bar') {
  588. this.isTab = false;
  589. }
  590. this.mConfig.splice(key, 1);
  591. this.rConfig.splice(0, 1);
  592. if (this.mConfig.length != key) {
  593. this.rConfig.push(this.mConfig[key]);
  594. } else {
  595. if (this.mConfig.length) {
  596. this.activeIndex = key - 1;
  597. this.rConfig.push(this.mConfig[key - 1]);
  598. } else {
  599. this.showTitle();
  600. }
  601. }
  602. // 删除第几个配置
  603. this.$store.commit('mobildConfig/DELETEARRAY', item);
  604. },
  605. // 组件返回
  606. config(data) {
  607. let propsObj = this.propsObj;
  608. propsObj.data = data;
  609. propsObj.name = this.activeConfigName;
  610. },
  611. addSort(arr, index1, index2) {
  612. arr[index1] = arr.splice(index2, 1, arr[index1])[0];
  613. return arr;
  614. },
  615. // 数组排序
  616. arraySort() {
  617. let tempArr = [];
  618. let basis = {
  619. title: '基础组件',
  620. list: [],
  621. isOpen: true,
  622. };
  623. let marketing = {
  624. title: '营销组件',
  625. list: [],
  626. isOpen: true,
  627. };
  628. let tool = {
  629. title: '工具组件',
  630. list: [],
  631. isOpen: true,
  632. };
  633. this.lConfig.map((el, index) => {
  634. if (el.type == 0) {
  635. basis.list.push(el);
  636. }
  637. if (el.type == 1) {
  638. marketing.list.push(el);
  639. }
  640. if (el.type == 2) {
  641. tool.list.push(el);
  642. }
  643. });
  644. tempArr.push(basis, marketing, tool);
  645. this.leftMenu = tempArr;
  646. },
  647. // toImage(val){
  648. // html2canvas(this.$refs.imgContainer,{
  649. // useCORS:true,
  650. // logging:true,
  651. // taintTest: false,
  652. // backgroundColor: null
  653. // }).then((canvas) => {
  654. // let imgUrl = canvas.toDataURL('image/jpeg');
  655. // this.diySaveDate(val,imgUrl)
  656. // });
  657. // },
  658. diySaveDate(val) {
  659. diySave(this.pageId, {
  660. type: this.pageType,
  661. value: val,
  662. title: this.titleTxt,
  663. name: this.nameTxt,
  664. is_show: this.showTxt ? 1 : 0,
  665. is_bg_color: this.colorTxt ? 1 : 0,
  666. color_picker: this.colorPickerTxt,
  667. bg_pic: this.picUrlTxt,
  668. bg_tab_val: this.tabValTxt,
  669. is_bg_pic: this.picTxt ? 1 : 0,
  670. })
  671. .then((res) => {
  672. this.loading = false;
  673. this.pageId = res.data.id;
  674. this.$Message.success(res.msg);
  675. })
  676. .catch((res) => {
  677. this.loading = false;
  678. this.$Message.error(res.msg);
  679. });
  680. },
  681. // 保存配置
  682. saveConfig() {
  683. if (this.mConfig.length == 0) {
  684. return this.$Message.error('暂未添加任何组件,保存失败!');
  685. }
  686. this.loading = true;
  687. let val = this.$store.state.mobildConfig.defaultArray;
  688. if (!this.footActive) {
  689. let timestamp = new Date().getTime() * 1000;
  690. val[timestamp] = this.$store.state.mobildConfig.pageFooter;
  691. this.footActive = true;
  692. }
  693. this.$nextTick(function () {
  694. this.diySaveDate(val);
  695. });
  696. },
  697. // 获取默认配置
  698. getDefaultConfig() {
  699. diyGetInfo(this.pageId, {
  700. type: 1,
  701. }).then(({ data }) => {
  702. let obj = {};
  703. let tempARR = [];
  704. this.$store.commit('mobildConfig/titleUpdata', data.info.title);
  705. this.$store.commit('mobildConfig/nameUpdata', data.info.name);
  706. this.$store.commit('mobildConfig/showUpdata', data.info.is_show);
  707. this.$store.commit('mobildConfig/colorUpdata', data.info.is_bg_color || 0);
  708. this.$store.commit('mobildConfig/picUpdata', data.info.is_bg_pic || 0);
  709. this.$store.commit('mobildConfig/pickerUpdata', data.info.color_picker || '#f5f5f5');
  710. this.$store.commit('mobildConfig/radioUpdata', data.info.bg_tab_val || 0);
  711. this.$store.commit('mobildConfig/picurlUpdata', data.info.bg_pic || '');
  712. let newArr = this.objToArr(data.info.value);
  713. function sortNumber(a, b) {
  714. return a.timestamp - b.timestamp;
  715. }
  716. newArr.sort(sortNumber);
  717. newArr.map((el, index) => {
  718. if (el.name == 'headerSerch') {
  719. this.isSearch = true;
  720. }
  721. if (el.name == 'tabNav') {
  722. this.isTab = true;
  723. }
  724. if (el.name == 'goodList') {
  725. let storage = window.localStorage;
  726. storage.setItem(el.timestamp, el.selectConfig.activeValue);
  727. }
  728. el.id = 'id' + el.timestamp;
  729. this.lConfig.map((item, j) => {
  730. if (el.name == item.defaultName) {
  731. item.num = el.timestamp;
  732. item.id = 'id' + el.timestamp;
  733. let tempItem = JSON.parse(JSON.stringify(item));
  734. tempARR.push(tempItem);
  735. obj[el.timestamp] = el;
  736. this.mConfig.push(tempItem);
  737. // 保存默认组件配置
  738. this.$store.commit('mobildConfig/ADDARRAY', {
  739. num: el.timestamp,
  740. val: el,
  741. });
  742. }
  743. });
  744. });
  745. let objs = newArr[newArr.length - 1];
  746. if (objs.name == 'pageFoot') {
  747. this.$store.commit('mobildConfig/footPageUpdata', objs);
  748. }
  749. this.showTitle();
  750. // this.rConfig = [];
  751. // this.activeIndex = 0;
  752. // this.rConfig.push(this.mConfig[0]);
  753. });
  754. },
  755. categoryList() {
  756. categoryList((res) => {
  757. this.category = res.data;
  758. });
  759. },
  760. // 重置
  761. reast() {
  762. if (this.pageId == 0) {
  763. this.$Message.error('新增页面,无法重置');
  764. } else {
  765. this.$Modal.confirm({
  766. title: '提示',
  767. content: '<p>是否重置当前页面数据</p>',
  768. onOk: () => {
  769. this.mConfig = [];
  770. this.rConfig = [];
  771. this.activeIndex = -99;
  772. this.getDefaultConfig();
  773. },
  774. onCancel: () => {},
  775. });
  776. }
  777. },
  778. },
  779. beforeDestroy() {
  780. this.$store.commit('mobildConfig/titleUpdata', '');
  781. this.$store.commit('mobildConfig/nameUpdata', '');
  782. this.$store.commit('mobildConfig/showUpdata', 1);
  783. this.$store.commit('mobildConfig/colorUpdata', 0);
  784. this.$store.commit('mobildConfig/picUpdata', 0);
  785. this.$store.commit('mobildConfig/pickerUpdata', '#f5f5f5');
  786. this.$store.commit('mobildConfig/radioUpdata', 0);
  787. this.$store.commit('mobildConfig/picurlUpdata', '');
  788. this.$store.commit('mobildConfig/SETEMPTY');
  789. },
  790. destroyed() {
  791. this.$store.commit('mobildConfig/titleUpdata', '');
  792. this.$store.commit('mobildConfig/nameUpdata', '');
  793. this.$store.commit('mobildConfig/showUpdata', 1);
  794. this.$store.commit('mobildConfig/colorUpdata', 0);
  795. this.$store.commit('mobildConfig/picUpdata', 0);
  796. this.$store.commit('mobildConfig/pickerUpdata', '#f5f5f5');
  797. this.$store.commit('mobildConfig/radioUpdata', 0);
  798. this.$store.commit('mobildConfig/picurlUpdata', '');
  799. this.$store.commit('mobildConfig/SETEMPTY');
  800. },
  801. };
  802. </script>
  803. <style scoped lang="stylus">
  804. .ysize {
  805. background-size: 100%;
  806. }
  807. .fullsize {
  808. background-size: 100% 100%;
  809. }
  810. .repeat {
  811. background-repeat: repeat;
  812. }
  813. .noRepeat {
  814. background-repeat: no-repeat;
  815. }
  816. .wrapper-con {
  817. /* min-width 700px; */
  818. }
  819. .defaultData {
  820. /* margin-left 20px; */
  821. cursor: pointer;
  822. position: absolute;
  823. left: 50%;
  824. margin-left: 245px;
  825. .data {
  826. margin-top: 20px;
  827. color: #282828;
  828. background-color: #fff;
  829. width: 94px;
  830. text-align: center;
  831. height: 32px;
  832. line-height: 32px;
  833. border-radius: 3px;
  834. font-size: 12px;
  835. }
  836. .data:hover {
  837. background-color: #2d8cf0;
  838. color: #fff;
  839. border: 0;
  840. }
  841. }
  842. .overflowy {
  843. overflow-y: scroll;
  844. .picture {
  845. width: 379px;
  846. height: 20px;
  847. margin: 0 auto;
  848. background-color: #fff;
  849. }
  850. }
  851. .bnt {
  852. width: 80px !important;
  853. }
  854. /* 定义滑块 内阴影+圆角 */
  855. ::-webkit-scrollbar-thumb {
  856. -webkit-box-shadow: inset 0 0 6px #fff;
  857. display: none;
  858. }
  859. .left:hover::-webkit-scrollbar-thumb, .right-box:hover::-webkit-scrollbar-thumb {
  860. display: block;
  861. }
  862. .contxt:hover ::-webkit-scrollbar-thumb {
  863. display: block;
  864. }
  865. ::-webkit-scrollbar {
  866. width: 4px !important; /* 对垂直流动条有效 */
  867. }
  868. .scrollCon {
  869. overflow-y: scroll;
  870. overflow-x: hidden;
  871. }
  872. .scroll-box .position {
  873. display: block !important;
  874. height: 40px;
  875. text-align: center;
  876. line-height: 40px;
  877. border: 1px dashed #1890ff;
  878. color: #1890ff;
  879. background-color: #edf4fb;
  880. }
  881. .scroll-box .conter {
  882. display: none !important;
  883. }
  884. .dragClass {
  885. background-color: #fff;
  886. }
  887. .ivu-mt {
  888. display: flex;
  889. justify-content: space-between;
  890. }
  891. .iconfont-diy {
  892. font-size: 24px;
  893. color: #1890ff;
  894. }
  895. .diy-wrapper {
  896. max-width: 100%;
  897. min-width: 1100px;
  898. display: flex;
  899. justify-content: space-between;
  900. /* height: 84.5vh; */
  901. .left {
  902. min-width: 300px;
  903. max-width: 300px;
  904. /* border 1px solid #DDDDDD */
  905. border-radius: 4px;
  906. height: 100%;
  907. .title-bar {
  908. display: flex;
  909. color: #333;
  910. border-bottom: 1px solid #eee;
  911. border-radius: 4px;
  912. cursor: pointer;
  913. .title-item {
  914. display: flex;
  915. align-items: center;
  916. justify-content: center;
  917. flex: 1;
  918. height: 45px;
  919. &.on {
  920. color: #1890FF;
  921. font-size: 14px;
  922. border-bottom: 1px solid #1890FF;
  923. }
  924. }
  925. }
  926. .wrapper {
  927. padding: 15px;
  928. overflow-y: scroll;
  929. -webkit-overflow-scrolling: touch;
  930. .tips {
  931. display: flex;
  932. justify-content: space-between;
  933. padding-bottom: 15px;
  934. font-size: 13px;
  935. color: #000;
  936. cursor: pointer;
  937. .ivu-icon {
  938. color: #000;
  939. }
  940. }
  941. }
  942. .link-item {
  943. padding: 10px;
  944. border-bottom: 1px solid #F5F5F5;
  945. font-size: 12px;
  946. color: #323232;
  947. .name {
  948. font-size: 14px;
  949. color: #1890FF;
  950. }
  951. .link-txt {
  952. margin-top: 2px;
  953. word-break: break-all;
  954. }
  955. .params {
  956. margin-top: 5px;
  957. color: #1CBE6B;
  958. word-break: break-all;
  959. .txt {
  960. color: #323232;
  961. }
  962. span {
  963. &:last-child i {
  964. display: none;
  965. color: red;
  966. }
  967. }
  968. }
  969. .lable {
  970. display: flex;
  971. margin-top: 5px;
  972. color: #999;
  973. p {
  974. flex: 1;
  975. word-break: break-all;
  976. }
  977. button {
  978. margin-left: 30px;
  979. width: 38px;
  980. }
  981. }
  982. }
  983. .dragArea.list-group {
  984. display: flex;
  985. flex-wrap: wrap;
  986. .list-group-item {
  987. display: flex;
  988. flex-direction: column;
  989. align-items: center;
  990. justify-content: center;
  991. width: 74px;
  992. height: 66px;
  993. margin-right: 17px;
  994. margin-bottom: 10px;
  995. font-size: 12px;
  996. color: #666;
  997. cursor: pointer;
  998. border-radius: 5px;
  999. text-align: center;
  1000. &:hover {
  1001. box-shadow: 0 0 5px 0 rgba(24, 144, 255, 0.3);
  1002. border-right: 5px;
  1003. }
  1004. &:nth-child(3n) {
  1005. margin-right: 0;
  1006. }
  1007. }
  1008. }
  1009. }
  1010. .content {
  1011. position: relative;
  1012. height: 100%;
  1013. width: 100%;
  1014. .page-foot {
  1015. position: relative;
  1016. width: 379px;
  1017. margin: 0 auto 20px auto;
  1018. .delete-box {
  1019. display: none;
  1020. position: absolute;
  1021. left: -2px;
  1022. top: 0;
  1023. width: 383px;
  1024. height: 100%;
  1025. border: 2px dashed #1890ff;
  1026. padding: 10px 0;
  1027. }
  1028. &:hover, &.on {
  1029. /* cursor: move; */
  1030. .delete-box {
  1031. /* display: block; */
  1032. }
  1033. }
  1034. &.on {
  1035. cursor: move;
  1036. .delete-box {
  1037. display: block;
  1038. border: 2px solid #1890ff;
  1039. box-shadow: 0 0 10px 0 rgba(24, 144, 255, 0.3);
  1040. }
  1041. }
  1042. }
  1043. .page-title {
  1044. position: relative;
  1045. height: 35px;
  1046. line-height: 35px;
  1047. background: #fff;
  1048. font-size: 15px;
  1049. color: #333333;
  1050. text-align: center;
  1051. width: 379px;
  1052. margin: 0 auto;
  1053. .delete-box {
  1054. display: none;
  1055. position: absolute;
  1056. left: -2px;
  1057. top: 0;
  1058. width: 383px;
  1059. height: 100%;
  1060. border: 2px dashed #1890ff;
  1061. padding: 10px 0;
  1062. span {
  1063. position: absolute;
  1064. right: 0;
  1065. bottom: 0;
  1066. width: 32px;
  1067. height: 16px;
  1068. line-height: 16px;
  1069. display: inline-block;
  1070. text-align: center;
  1071. font-size: 10px;
  1072. color: #fff;
  1073. background: rgba(0, 0, 0, 0.4);
  1074. margin-left: 2px;
  1075. cursor: pointer;
  1076. z-index: 11;
  1077. }
  1078. }
  1079. &:hover, &.on {
  1080. /* cursor: move; */
  1081. .delete-box {
  1082. /* display: block; */
  1083. }
  1084. }
  1085. &.on {
  1086. cursor: move;
  1087. .delete-box {
  1088. display: block;
  1089. border: 2px solid #1890ff;
  1090. box-shadow: 0 0 10px 0 rgba(24, 144, 255, 0.3);
  1091. }
  1092. }
  1093. }
  1094. .scroll-box {
  1095. flex: 1;
  1096. background-color: #fff;
  1097. width: 379px;
  1098. margin: 0 auto;
  1099. padding-top: 1px;
  1100. }
  1101. .dragArea.list-group {
  1102. width: 100%;
  1103. height: 100%;
  1104. .mConfig-item {
  1105. position: relative;
  1106. cursor: move;
  1107. .delete-box {
  1108. display: none;
  1109. position: absolute;
  1110. left: -2px;
  1111. top: 0;
  1112. width: 383px;
  1113. height: 100%;
  1114. border: 2px dashed #1890ff;
  1115. /* padding: 10px 0; */
  1116. .handleType {
  1117. position: absolute;
  1118. right: -43px;
  1119. top: 0;
  1120. width: 36px;
  1121. height: 143px;
  1122. border-radius: 4px;
  1123. background-color: #1890ff;
  1124. cursor: pointer;
  1125. color: #fff;
  1126. font-weight: bold;
  1127. text-align: center;
  1128. padding: 4px 0;
  1129. .iconfont {
  1130. padding: 5px 0;
  1131. &.on {
  1132. opacity: 0.4;
  1133. }
  1134. }
  1135. }
  1136. }
  1137. &.on {
  1138. cursor: move;
  1139. .delete-box {
  1140. display: block;
  1141. border: 2px solid #1890ff;
  1142. box-shadow: 0 0 10px 0 rgba(24, 144, 255, 0.3);
  1143. }
  1144. }
  1145. }
  1146. }
  1147. }
  1148. .right-box {
  1149. max-width: 400px;
  1150. min-width: 400px;
  1151. height: 100%;
  1152. border-radius: 4px;
  1153. overflow: scroll;
  1154. -webkit-overflow-scrolling: touch;
  1155. .title-bar {
  1156. width: 100%;
  1157. height: 45px;
  1158. line-height: 45px;
  1159. padding-left: 24px;
  1160. color: #000;
  1161. border-radius: 4px;
  1162. border-bottom: 1px solid #eee;
  1163. font-size: 14px;
  1164. }
  1165. }
  1166. ::-webkit-scrollbar {
  1167. width: 6px;
  1168. background-color: transparent;
  1169. }
  1170. ::-webkit-scrollbar-track {
  1171. border-radius: 10px;
  1172. }
  1173. ::-webkit-scrollbar-thumb {
  1174. background-color: #bfc1c4;
  1175. }
  1176. }
  1177. .foot-box {
  1178. position: relative;
  1179. display: flex;
  1180. align-items: center;
  1181. justify-content: center;
  1182. height: 80px;
  1183. background: #fff;
  1184. box-shadow: 0px -2px 4px 0px rgba(0, 0, 0, 0.03);
  1185. button {
  1186. width: 100px;
  1187. height: 32px;
  1188. font-size: 13px;
  1189. &:first-child {
  1190. margin-right: 20px;
  1191. }
  1192. }
  1193. }
  1194. /deep/ .ivu-scroll-loader {
  1195. display: none;
  1196. }
  1197. /deep/ .ivu-card-body {
  1198. width: 100%;
  1199. }
  1200. </style>