| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467 |
- <template>
- <div class="diy-page">
- <div class="i-layout-page-header header-title">
- <div class="fl_header">
- <!-- <router-link :to="{ path: $routeProStr + '/setting/pages/devise' }"
- ><Button icon="ios-arrow-back" size="small" type="text">返回</Button></router-link
- > -->
- <!-- <Divider type="vertical" /> -->
- <span class="ivu-page-header-title mr20" style="padding: 0" v-text="$route.meta.title"></span>
- <div class="rbtn">
- <!-- <Button v-if="pageId !== 0" class="bnt" @click="setmoren" :loading="loading">保存默认</Button>
- <Button v-if="pageId !== 0" class="bnt ml20" @click="getmoren" :loading="loading">恢复默认</Button> -->
- <!-- <div class="data" @click="setmoren">设置默认</div>
- <div class="data" @click="getmoren">恢复默认</div> -->
- <Button class="bnt ml20" type="info" @click="preview" :loading="loading">预览</Button>
- <Button class="bnt ml20" type="primary" @click="saveConfig(0)" :loading="loading">保存</Button>
- <Button class="ml20" type="error" @click="closeWindow" :loading="loading">关闭</Button>
- </div>
- </div>
- </div>
- <Card :bordered="false" dis-hover class="ivu-mt" style="margin: 0 10px">
- <div class="diy-wrapper">
- <!-- 左侧 -->
- <div class="left">
- <div class="title-bar">
- <div
- class="title-item"
- :class="{ on: tabCur == index }"
- v-for="(item, index) in tabList"
- :key="index"
- @click="bindTab(index)"
- >
- {{ item.title }}
- </div>
- </div>
- <div class="wrapper" v-if="tabCur == 0">
- <div v-for="(item, index) in leftMenu" :key="index">
- <div class="tips" @click="item.isOpen = !item.isOpen">
- {{ item.title }}
- <Icon type="ios-arrow-forward" size="16" v-if="!item.isOpen" />
- <Icon type="ios-arrow-down" size="16" v-else />
- </div>
- <draggable
- class="dragArea list-group"
- :list="item.list"
- :group="{ name: 'people', pull: 'clone', put: false }"
- :clone="cloneDog"
- dragClass="dragClass"
- filter=".search , .navbar"
- >
- <!--filter=".search , .navbar"-->
- <!--:class="{ search: element.cname == '搜索框' , navbar: element.cname == '商品分类' }"-->
- <div
- class="list-group-item"
- :class="{
- search: element.cname == '搜索框',
- navbar: element.cname == '商品分类',
- }"
- v-for="(element, index) in item.list"
- :key="element.id"
- @click="addDom(element, 1)"
- v-show="item.isOpen"
- >
- <div>
- <div class="position" style="display: none">释放鼠标将组建添加到此处</div>
- <span class="conter iconfont-diy" :class="element.icon"></span>
- <p class="conter">{{ element.cname }}</p>
- </div>
- </div>
- </draggable>
- </div>
- </div>
- <!-- <div style="padding: 0 20px"><Button type="primary" style="width: 100%" @click="saveConfig">保存</Button></div>-->
- <div class="wrapper" v-else :style="'height:' + (clientHeight - 200) + 'px;'">
- <div class="link-item" v-for="(item, index) in urlList" :key="index">
- <div class="name">{{ item.name }}</div>
- <div class="link-txt">地址:{{ item.url }}</div>
- <div class="params">
- <span class="txt">参数:</span>
- <span>{{ item.parameter }}</span>
- </div>
- <div class="lable">
- <p class="txt">例如:{{ item.example }}</p>
- <Button size="small" @click="onCopy(item.example)">复制 </Button>
- </div>
- </div>
- </div>
- </div>
- <!-- 中间 -->
- <div
- class="wrapper-con"
- style="flex: 1; background: #f0f2f5; display: flex; justify-content: center; padding-top: 20px; height: 100%"
- >
- <div class="acticon">
- <Button class="bnt mb10" @click="showTitle">页面设置</Button>
- <Button class="bnt mb10" @click="nameModal = true">另存模板</Button>
- <Button class="bnt" @click="reast">重置</Button>
- </div>
- <div class="content">
- <div class="contxt" style="display: flex; flex-direction: column; overflow: hidden; height: 100%">
- <div class="overflowy">
- <div class="picture">
- <img src="@/assets/images/electric.png" />
- </div>
- <div class="page-title" :class="{ on: activeIndex == -100 }" @click="showTitle">
- {{ titleTxt }}
- <div class="delete-box"></div>
- <div class="handle"></div>
- </div>
- </div>
- <div class="scrollCon">
- <div style="width: 460px; margin: 0 auto">
- <div
- class="scroll-box"
- :class="
- picTxt && tabValTxt == 2
- ? 'fullsize noRepeat'
- : picTxt && tabValTxt == 1
- ? 'repeat ysize'
- : 'noRepeat ysize'
- "
- :style="
- 'background-color:' +
- (colorTxt ? colorPickerTxt : '') +
- ';background-image: url(' +
- (picTxt ? picUrlTxt : '') +
- ');height:calc(100vh - 200px)'
- "
- ref="imgContainer"
- >
- <draggable
- class="dragArea list-group"
- :list="mConfig"
- group="people"
- @change="log"
- filter=".top"
- :move="onMove"
- animation="300"
- >
- <div
- class="mConfig-item"
- :class="{
- on: activeIndex == key,
- top: item.name == 'search_box' || item.name == 'nav_bar',
- }"
- v-for="(item, key) in mConfig"
- :key="key"
- @click.stop="bindconfig(item, key)"
- :style="colorTxt ? 'background-color:' + colorPickerTxt + ';' : 'background-color:#fff;'"
- >
- <component
- :is="item.name"
- ref="getComponentData"
- :configData="propsObj"
- :index="key"
- :num="item.num"
- ></component>
- <div class="delete-box">
- <div class="handleType">
- <Tooltip content="删除当前模块" placement="top">
- <div class="iconfont iconshanchu2" @click.stop="bindDelete(item, key)"></div>
- </Tooltip>
- <div class="iconfont iconfuzhi" @click.stop="bindAddDom(item, 0, key)"></div>
- <div
- class="iconfont iconshangyi"
- :class="key === 0 ? 'on' : ''"
- @click.stop="movePage(item, key, 1)"
- ></div>
- <div
- class="iconfont iconxiayi"
- :class="key === mConfig.length - 1 ? 'on' : ''"
- @click.stop="movePage(item, key, 0)"
- ></div>
- </div>
- </div>
- <div class="handle"></div>
- </div>
- </draggable>
- </div>
- </div>
- </div>
- <div class="overflowy">
- <div class="page-foot" @click="showFoot" :class="{ on: activeIndex == -101 }">
- <footPage></footPage>
- <div class="delete-box"></div>
- <div class="handle"></div>
- </div>
- </div>
- <!-- <div class="defaultData" v-if="pageId !== 0">
- <div class="data" @click="setmoren">设置默认</div>
- <div class="data" @click="getmoren">恢复默认</div>
- </div> -->
- </div>
- </div>
- </div>
- <!-- 右侧 -->
- <div class="right-box">
- <div class="mConfig-item" style="background-color: #fff" v-for="(item, key) in rConfig" :key="key">
- <div class="title-bar">{{ item.cname }}</div>
- <component
- :is="item.configName"
- @config="config"
- :activeIndex="activeIndex"
- :num="item.num"
- :index="key"
- ></component>
- </div>
- </div>
- </div>
- </Card>
- <!--<div class="foot-box">-->
- <!--<Button @click="reast">重置</Button>-->
- <!--<Button type="primary" @click="saveConfig" :loading="loading"-->
- <!-->保存-->
- <!--</Button-->
- <!-->-->
- <!--</div>-->
- <Modal v-model="modal" title="预览" footer-hide>
- <div>
- <div v-viewer class="acea-row row-around code">
- <div class="acea-row row-column-around row-between-wrapper">
- <div class="QRpic" ref="qrCodeUrl"></div>
- <span class="mt10">公众号二维码</span>
- </div>
- <div class="acea-row row-column-around row-between-wrapper">
- <div class="QRpic">
- <img v-lazy="qrcodeImg" />
- </div>
- <span class="mt10">小程序二维码</span>
- </div>
- </div>
- </div>
- </Modal>
- <Modal v-model="nameModal" title="设置模版名称" :closable="false" @on-ok="saveModal" @on-cancel="nameModal = false">
- <Input v-model="saveName" placeholder="请输入模版名称"></Input>
- </Modal>
- </div>
- </template>
- <script crossorigin="anonymous">
- import { categoryList, getDiyInfo, saveDiy, getUrl, setDefault, recovery, getRoutineCode } from '@/api/diy';
- import vuedraggable from 'vuedraggable';
- import mPage from '@/components/mobilePageDiy/index.js';
- import mConfig from '@/components/mobileConfigDiy/index.js';
- import footPage from '@/components/pagesFoot';
- import { mapState } from 'vuex';
- import html2canvas from 'html2canvas';
- import QRCode from 'qrcodejs2';
- let idGlobal = 0;
- export default {
- inject: ['reload'],
- name: 'index.vue',
- components: {
- footPage,
- html2canvas,
- draggable: vuedraggable,
- ...mPage,
- ...mConfig,
- },
- filters: {
- filterTxt(val) {
- if (val) {
- return (val = val.substr(0, val.length - 1));
- }
- },
- },
- computed: {
- ...mapState({
- titleTxt: (state) => state.mobildConfig.pageTitle || '首页',
- nameTxt: (state) => state.mobildConfig.pageName || '模板',
- showTxt: (state) => state.mobildConfig.pageShow,
- colorTxt: (state) => state.mobildConfig.pageColor,
- picTxt: (state) => state.mobildConfig.pagePic,
- colorPickerTxt: (state) => state.mobildConfig.pageColorPicker,
- tabValTxt: (state) => state.mobildConfig.pageTabVal,
- picUrlTxt: (state) => state.mobildConfig.pagePicUrl,
- }),
- },
- data() {
- return {
- clientHeight: '', //页面动态高度
- rollHeight: '',
- leftMenu: [], // 左侧菜单
- lConfig: [], // 左侧组件
- mConfig: [], // 中间组件渲染
- rConfig: [], // 右侧组件配置
- activeConfigName: '',
- propsObj: {}, // 组件传递的数据,
- activeIndex: -100, // 选中的下标
- number: 0,
- pageId: '',
- pageName: '',
- pageType: '',
- category: [],
- tabList: [
- {
- title: '组件库',
- key: 0,
- },
- {
- title: '页面链接',
- key: 1,
- },
- ],
- tabCur: 0,
- urlList: [],
- footActive: false,
- loading: false,
- isSearch: false,
- isTab: false,
- isFllow: false,
- qrcodeImg: '',
- modal: false,
- nameModal: false,
- saveName: '',
- };
- },
- beforeRouteLeave(to, from, next) {
- // 导航离开该组件的对应路由时调用
- },
- beforeCreate() {
- this.$store.commit('mobildConfig/titleUpdata', '');
- this.$store.commit('mobildConfig/nameUpdata', '');
- this.$store.commit('mobildConfig/showUpdata', 1);
- this.$store.commit('mobildConfig/colorUpdata', 0);
- this.$store.commit('mobildConfig/picUpdata', 0);
- this.$store.commit('mobildConfig/pickerUpdata', '#f5f5f5');
- this.$store.commit('mobildConfig/radioUpdata', 0);
- this.$store.commit('mobildConfig/picurlUpdata', '');
- this.$store.commit('mobildConfig/SETEMPTY');
- },
- created() {
- window.onbeforeunload = () => {
- return '刷新页面将丢失内容,是否继续?';
- };
- this.categoryList();
- this.getUrlList();
- this.pageId = this.$route.query.id;
- this.pageName = this.$route.query.name;
- this.pageType = this.$route.query.type;
- this.lConfig = this.objToArr(mPage);
- },
- mounted() {
- // window.addEventListener('onbeforeunload', this.beforeUnload);
- let imgList = {
- imgList: [require('@/assets/images/foot-005.png'), require('@/assets/images/foot-006.png')],
- name: '购物车',
- link: '/pages/order_addcart/order_addcart',
- };
- this.$nextTick(() => {
- this.$store.commit('mobildConfig/FOOTER', {
- title: '专题页是否显示',
- name: imgList,
- });
- this.arraySort();
- if (this.pageId != 0) {
- this.getDefaultConfig();
- } else {
- this.showTitle();
- }
- this.clientHeight = `${document.documentElement.clientHeight}`; //获取浏览器可视区域高度
- let H = `${document.documentElement.clientHeight}` - 180;
- this.rollHeight = H > 650 ? 650 : H;
- let that = this;
- window.onresize = function () {
- that.clientHeight = `${document.documentElement.clientHeight}`;
- let H = `${document.documentElement.clientHeight}` - 180;
- that.rollHeight = H > 650 ? 650 : H;
- };
- });
- },
- methods: {
- saveModal() {
- if (!this.saveName) return this.$Message.warning('请先输入模板名称');
- this.saveConfig(1, this.saveName);
- },
- //小程序二维码
- routineCode(id) {
- getRoutineCode(id)
- .then((res) => {
- this.qrcodeImg = res.data.image;
- })
- .catch((err) => {
- this.$Message.error(err);
- });
- },
- preview(row) {
- this.modal = true;
- this.creatQrCode(row.id);
- this.routineCode(this.$route.query.id);
- },
- //生成二维码
- creatQrCode(id) {
- this.$refs.qrCodeUrl.innerHTML = '';
- let url = `${this.BaseURL}pages/annex/special/index?id=${id}`;
- var qrcode = new QRCode(this.$refs.qrCodeUrl, {
- text: url, // 需要转换为二维码的内容
- width: 160,
- height: 160,
- colorDark: '#000000',
- colorLight: '#ffffff',
- correctLevel: QRCode.CorrectLevel.H,
- });
- },
- closeWindow() {
- this.$Modal.confirm({
- title: '确定关闭当前页吗?',
- content: '关闭页面前请先保存数据,未保存的话数据会丢失',
- okText: '确定',
- cancelText: '取消',
- loading: true,
- onOk: () => {
- setTimeout(() => {
- // this.saveConfig();
- this.$Modal.remove();
- window.close();
- }, 1000);
- },
- onCancel: () => {
- this.$Modal.remove();
- },
- });
- },
- leftRemove({ to, from, item, clone, oldIndex, newIndex }) {
- if (this.isSearch && newIndex == 0) {
- if (item._underlying_vm_.name == 'z_wechat_attention') {
- this.isFllow = true;
- } else {
- this.$store.commit('mobildConfig/ARRAYREAST', this.mConfig[0].num);
- this.mConfig.splice(0, 1);
- }
- }
- if ((this.isFllow = true && newIndex >= 1)) {
- this.$store.commit('mobildConfig/ARRAYREAST', this.mConfig[0].num);
- }
- },
- onMove(e) {
- if (e.relatedContext.element.name == 'search_box') return false;
- if (e.relatedContext.element.name == 'nav_bar') return false;
- return true;
- },
- onCopy(copyData) {
- this.$copyText(copyData)
- .then((message) => {
- this.$Message.success('复制成功');
- })
- .catch((err) => {
- this.$Message.error('复制失败');
- });
- },
- onError() {
- this.$Message.error('复制失败');
- },
- //设置默认数据
- setmoren() {
- this.$Modal.confirm({
- title: '保存为默认数据',
- content: '您确定将当前设计设为默认数据吗?',
- onOk: () => {
- setDefault(this.pageId)
- .then((res) => {
- this.$Message.success(res.msg);
- })
- .catch((err) => {
- this.$Message.error(err.msg);
- });
- },
- onCancel: () => {},
- });
- },
- //恢复默认
- getmoren() {
- this.$Modal.confirm({
- title: '恢复默认数据',
- content: '您确定恢复为之前保存的默认数据吗?',
- onOk: () => {
- recovery(this.pageId)
- .then((res) => {
- this.$Message.success(res.msg);
- this.reload();
- })
- .catch((err) => {
- this.$Message.error(err.msg);
- });
- },
- onCancel: () => {},
- });
- },
- // 获取url
- getUrlList() {
- getUrl().then((res) => {
- this.urlList = res.data.url;
- });
- },
- // 左侧tab
- bindTab(index) {
- this.tabCur = index;
- },
- // 页面标题点击
- showTitle() {
- this.activeIndex = -100;
- let obj = {};
- for (var i in mConfig) {
- if (i == 'pageTitle') {
- // this.rConfig = obj
- obj = mConfig[i];
- obj.configName = mConfig[i].name;
- obj.cname = '页面设置';
- }
- }
- let abc = obj;
- this.rConfig = [];
- this.rConfig[0] = JSON.parse(JSON.stringify(obj));
- },
- // 页面底部点击
- showFoot() {
- this.activeIndex = -101;
- let obj = {};
- for (var i in mConfig) {
- if (i == 'pageFoot') {
- // this.rConfig = obj
- obj = mConfig[i];
- obj.configName = mConfig[i].name;
- obj.cname = '底部菜单';
- }
- }
- let abc = obj;
- this.rConfig = [];
- this.rConfig[0] = JSON.parse(JSON.stringify(obj));
- },
- // 对象转数组
- objToArr(data) {
- let obj = Object.keys(data);
- let m = obj.map((key) => data[key]);
- return m;
- },
- log(evt) {
- // 中间拖拽排序
- if (evt.moved) {
- if (evt.moved.element.name == 'search_box' || evt.moved.element.name == 'nav_bar') {
- return this.$Message.warning('该组件禁止拖拽');
- }
- // if (evt.moved.element.name == "nav_bar") {
- // return this.$Message.warning("该组件禁止拖拽");
- // }
- evt.moved.oldNum = this.mConfig[evt.moved.oldIndex].num;
- evt.moved.newNum = this.mConfig[evt.moved.newIndex].num;
- evt.moved.status = evt.moved.oldIndex > evt.moved.newIndex;
- this.mConfig.forEach((el, index) => {
- el.num = new Date().getTime() * 1000 + index;
- });
- evt.moved.list = this.mConfig;
- this.rConfig = [];
- let item = evt.moved.element;
- let tempItem = JSON.parse(JSON.stringify(item));
- this.rConfig.push(tempItem);
- this.activeIndex = evt.moved.newIndex;
- this.$store.commit('mobildConfig/SETCONFIGNAME', item.name);
- this.$store.commit('mobildConfig/defaultArraySort', evt.moved);
- }
- // 从左向右拖拽排序
- if (evt.added) {
- let data = evt.added.element;
- let obj = {};
- let timestamp = new Date().getTime() * 1000;
- data.num = timestamp;
- this.activeConfigName = data.name;
- let tempItem = JSON.parse(JSON.stringify(data));
- tempItem.id = 'id' + tempItem.num;
- this.mConfig[evt.added.newIndex] = tempItem;
- this.rConfig = [];
- this.rConfig.push(tempItem);
- this.mConfig.forEach((el, index) => {
- el.num = new Date().getTime() * 1000 + index;
- });
- evt.added.list = this.mConfig;
- this.activeIndex = evt.added.newIndex;
- // 保存组件名称
- this.$store.commit('mobildConfig/SETCONFIGNAME', data.name);
- this.$store.commit('mobildConfig/defaultArraySort', evt.added);
- }
- },
- cloneDog(data) {
- // this.mConfig.push(tempItem)
- return {
- ...data,
- };
- },
- //数组元素互换位置
- swapArray(arr, index1, index2) {
- arr[index1] = arr.splice(index2, 1, arr[index1])[0];
- return arr;
- },
- //点击上下移动;
- movePage(item, index, type) {
- if (type) {
- if (index == 0) {
- return;
- }
- } else {
- if (index == this.mConfig.length - 1) {
- return;
- }
- }
- if (item.name == 'search_box' || item.name == 'nav_bar') {
- return this.$Message.warning('该组件禁止移动');
- }
- // if (item.name == "nav_bar") {
- // return this.$Message.warning("该组件禁止移动");
- // }
- if (type) {
- // if(this.mConfig[index-1].name == "search_box" || this.mConfig[index-1].name == "nav_bar"){
- if (this.mConfig[index - 1].name == 'search_box') {
- return this.$Message.warning('搜索框必须为顶部');
- }
- this.swapArray(this.mConfig, index - 1, index);
- } else {
- this.swapArray(this.mConfig, index, index + 1);
- }
- let obj = {};
- this.rConfig = [];
- obj.oldIndex = index;
- if (type) {
- obj.newIndex = index - 1;
- } else {
- obj.newIndex = index + 1;
- }
- this.mConfig.forEach((el, index) => {
- el.num = new Date().getTime() * 1000 + index;
- });
- let tempItem = JSON.parse(JSON.stringify(item));
- this.rConfig.push(tempItem);
- obj.element = item;
- obj.list = this.mConfig;
- if (type) {
- this.activeIndex = index - 1;
- } else {
- this.activeIndex = index + 1;
- }
- this.$store.commit('mobildConfig/SETCONFIGNAME', item.name);
- this.$store.commit('mobildConfig/defaultArraySort', obj);
- },
- // 组件添加
- addDomCon(item, type, index) {
- if (item.name == 'search_box') {
- if (this.isSearch) return this.$Message.error('该组件只能添加一次');
- this.isSearch = true;
- }
- if (item.name == 'nav_bar') {
- if (this.isTab) return this.$Message.error('该组件只能添加一次');
- this.isTab = true;
- }
- idGlobal += 1;
- let obj = {};
- let timestamp = new Date().getTime() * 1000;
- item.num = `${timestamp}`;
- item.id = `id${timestamp}`;
- this.activeConfigName = item.name;
- let tempItem = JSON.parse(JSON.stringify(item));
- if (item.name == 'search_box') {
- this.rConfig = [];
- this.mConfig.unshift(tempItem);
- this.activeIndex = 0;
- this.rConfig.push(tempItem);
- }
- // 动态拖动可上传此部分代码
- else if (item.name == 'nav_bar') {
- this.rConfig = [];
- if (this.mConfig[0] && this.mConfig[0].name === 'search_box') {
- this.mConfig.splice(1, 0, tempItem);
- this.activeIndex = 1;
- } else {
- this.mConfig.splice(0, 0, tempItem);
- this.activeIndex = 0;
- }
- this.rConfig.push(tempItem);
- } else {
- if (type) {
- this.rConfig = [];
- this.mConfig.push(tempItem);
- this.activeIndex = this.mConfig.length - 1;
- this.rConfig.push(tempItem);
- } else {
- this.mConfig.splice(index + 1, 0, tempItem);
- this.activeIndex = index;
- }
- }
- this.mConfig.forEach((el, index) => {
- el.num = new Date().getTime() * 1000 + index;
- });
- // 保存组件名称
- obj.element = item;
- obj.list = this.mConfig;
- this.$store.commit('mobildConfig/SETCONFIGNAME', item.name);
- this.$store.commit('mobildConfig/defaultArraySort', obj);
- },
- //中间页点击添加模块;
- bindAddDom(item, type, index) {
- let i = item;
- this.lConfig.forEach((j) => {
- if (item.name == j.name) {
- i = j;
- }
- });
- this.addDomCon(i, type, index);
- },
- //左边配置模块点击添加;
- addDom(item, type) {
- this.addDomCon(item, type);
- },
- // 点击显示相应的配置
- bindconfig(item, index) {
- console.log(item, index);
- this.rConfig = [];
- let tempItem = JSON.parse(JSON.stringify(item));
- this.rConfig.push(tempItem);
- this.activeIndex = index;
- this.$store.commit('mobildConfig/SETCONFIGNAME', item.name);
- },
- // 组件删除
- bindDelete(item, key) {
- if (item.name == 'search_box') {
- this.isSearch = false;
- }
- if (item.name == 'nav_bar') {
- this.isTab = false;
- }
- this.mConfig.splice(key, 1);
- this.rConfig.splice(0, 1);
- if (this.mConfig.length != key) {
- this.rConfig.push(this.mConfig[key]);
- } else {
- if (this.mConfig.length) {
- this.activeIndex = key - 1;
- this.rConfig.push(this.mConfig[key - 1]);
- } else {
- this.showTitle();
- }
- }
- // 删除第几个配置
- this.$store.commit('mobildConfig/DELETEARRAY', item);
- },
- // 组件返回
- config(data) {
- let propsObj = this.propsObj;
- propsObj.data = data;
- propsObj.name = this.activeConfigName;
- },
- addSort(arr, index1, index2) {
- arr[index1] = arr.splice(index2, 1, arr[index1])[0];
- return arr;
- },
- // 数组排序
- arraySort() {
- let tempArr = [];
- let basis = {
- title: '基础组件',
- list: [],
- isOpen: true,
- };
- let marketing = {
- title: '营销组件',
- list: [],
- isOpen: true,
- };
- let tool = {
- title: '工具组件',
- list: [],
- isOpen: true,
- };
- this.lConfig.map((el, index) => {
- if (el.type == 0) {
- basis.list.push(el);
- }
- if (el.type == 1) {
- marketing.list.push(el);
- }
- if (el.type == 2) {
- tool.list.push(el);
- }
- });
- tempArr.push(basis, marketing, tool);
- this.leftMenu = tempArr;
- },
- // toImage(val){
- // html2canvas(this.$refs.imgContainer,{
- // useCORS:true,
- // logging:true,
- // taintTest: false,
- // backgroundColor: null
- // }).then((canvas) => {
- // let imgUrl = canvas.toDataURL('image/jpeg');
- // this.diySaveDate(val,imgUrl)
- // });
- // },
- diySaveDate(val, init, name) {
- console.log(init, name);
- saveDiy(init ? 0 : this.pageId, {
- type: this.pageType,
- value: val,
- title: this.titleTxt,
- name: name || this.nameTxt,
- is_show: this.showTxt ? 1 : 0,
- is_bg_color: this.colorTxt ? 1 : 0,
- color_picker: this.colorPickerTxt,
- bg_pic: this.picUrlTxt,
- bg_tab_val: this.tabValTxt,
- is_bg_pic: this.picTxt ? 1 : 0,
- })
- .then((res) => {
- this.loading = false;
- if (!init) {
- this.pageId = res.data.id;
- }
- this.saveName = '';
- this.$Message.success(res.msg);
- })
- .catch((res) => {
- this.loading = false;
- this.$Message.error(res.msg);
- });
- },
- // 保存配置
- saveConfig(init, name) {
- if (this.mConfig.length == 0) {
- return this.$Message.error('暂未添加任何组件,保存失败!');
- }
- this.loading = true;
- let val = this.$store.state.mobildConfig.defaultArray;
- if (!this.footActive) {
- let timestamp = new Date().getTime() * 1000;
- val[timestamp] = this.$store.state.mobildConfig.pageFooter;
- this.footActive = true;
- }
- this.$nextTick(() => {
- this.diySaveDate(val, init, name);
- });
- },
- // 获取默认配置
- getDefaultConfig() {
- getDiyInfo(this.pageId).then(({ data }) => {
- let obj = {};
- let tempARR = [];
- this.$store.commit('mobildConfig/titleUpdata', data.info.title);
- this.$store.commit('mobildConfig/nameUpdata', data.info.name);
- this.$store.commit('mobildConfig/showUpdata', data.info.is_show);
- this.$store.commit('mobildConfig/colorUpdata', data.info.is_bg_color || 0);
- this.$store.commit('mobildConfig/picUpdata', data.info.is_bg_pic || 0);
- this.$store.commit('mobildConfig/pickerUpdata', data.info.color_picker || '#f5f5f5');
- this.$store.commit('mobildConfig/radioUpdata', data.info.bg_tab_val || 0);
- this.$store.commit('mobildConfig/picurlUpdata', data.info.bg_pic || '');
- let newArr = this.objToArr(data.info.value);
- function sortNumber(a, b) {
- return a.timestamp - b.timestamp;
- }
- newArr.sort(sortNumber);
- newArr.map((el, index) => {
- if (el.name == 'headerSerch') {
- this.isSearch = true;
- }
- if (el.name == 'tabNav') {
- this.isTab = true;
- }
- if (el.name == 'goodList') {
- let storage = window.localStorage;
- storage.setItem(el.timestamp, el.selectConfig.activeValue);
- }
- el.id = 'id' + el.timestamp;
- this.lConfig.map((item, j) => {
- if (el.name == item.defaultName) {
- item.num = el.timestamp;
- item.id = 'id' + el.timestamp;
- let tempItem = JSON.parse(JSON.stringify(item));
- tempARR.push(tempItem);
- obj[el.timestamp] = el;
- this.mConfig.push(tempItem);
- // 保存默认组件配置
- this.$store.commit('mobildConfig/ADDARRAY', {
- num: el.timestamp,
- val: el,
- });
- }
- });
- });
- let objs = newArr[newArr.length - 1];
- if (objs.name == 'pageFoot') {
- this.$store.commit('mobildConfig/footPageUpdata', objs);
- }
- this.showTitle();
- // this.rConfig = [];
- // this.activeIndex = 0;
- // this.rConfig.push(this.mConfig[0]);
- });
- },
- categoryList() {
- categoryList((res) => {
- this.category = res.data;
- });
- },
- // 重置
- reast() {
- if (this.pageId == 0) {
- this.$Message.error('新增页面,无法重置');
- } else {
- this.$Modal.confirm({
- title: '提示',
- content: '<p>重置会恢复到上次保存的数据,确定不保存当前操作吗?</p>',
- onOk: () => {
- this.mConfig = [];
- this.rConfig = [];
- this.activeIndex = -99;
- this.getDefaultConfig();
- },
- onCancel: () => {},
- });
- }
- },
- },
- beforeDestroy() {
- this.$store.commit('mobildConfig/titleUpdata', '');
- this.$store.commit('mobildConfig/nameUpdata', '');
- this.$store.commit('mobildConfig/showUpdata', 1);
- this.$store.commit('mobildConfig/colorUpdata', 0);
- this.$store.commit('mobildConfig/picUpdata', 0);
- this.$store.commit('mobildConfig/pickerUpdata', '#f5f5f5');
- this.$store.commit('mobildConfig/radioUpdata', 0);
- this.$store.commit('mobildConfig/picurlUpdata', '');
- this.$store.commit('mobildConfig/SETEMPTY');
- },
- destroyed() {
- this.$store.commit('mobildConfig/titleUpdata', '');
- this.$store.commit('mobildConfig/nameUpdata', '');
- this.$store.commit('mobildConfig/showUpdata', 1);
- this.$store.commit('mobildConfig/colorUpdata', 0);
- this.$store.commit('mobildConfig/picUpdata', 0);
- this.$store.commit('mobildConfig/pickerUpdata', '#f5f5f5');
- this.$store.commit('mobildConfig/radioUpdata', 0);
- this.$store.commit('mobildConfig/picurlUpdata', '');
- this.$store.commit('mobildConfig/SETEMPTY');
- },
- };
- </script>
- <style scoped lang="stylus">
- .ysize {
- background-size: 100%;
- }
- .fullsize {
- background-size: 100% 100%;
- }
- .repeat {
- background-repeat: repeat;
- }
- .noRepeat {
- background-repeat: no-repeat;
- }
- .wrapper-con {
- position relative
- .acticon{
- position absolute
- right: 20px
- top 20px
- display: flex;
- flex-direction: column;
- z-index: 9;
- }
- /* min-width 700px; */
- }
- .main .content-wrapper{
- padding: 0 !important;
- }
- .defaultData {
- /* margin-left 20px; */
- cursor: pointer;
- position: absolute;
- left: 50%;
- margin-left: 245px;
- .data {
- margin-top: 20px;
- color: #282828;
- background-color: #fff;
- width: 94px;
- text-align: center;
- height: 32px;
- line-height: 32px;
- border-radius: 3px;
- font-size: 12px;
- }
- .data:hover {
- background-color: #2d8cf0;
- color: #fff;
- border: 0;
- }
- }
- .overflowy {
- overflow-y: scroll;
- .picture {
- width: 379px;
- height: 20px;
- margin: 0 auto;
- background-color: #fff;
- }
- }
- .bnt {
- width: 80px !important;
- }
- /* 定义滑块 内阴影+圆角 */
- ::-webkit-scrollbar-thumb {
- -webkit-box-shadow: inset 0 0 6px #fff;
- display: none;
- }
- .left:hover::-webkit-scrollbar-thumb, .right-box:hover::-webkit-scrollbar-thumb {
- display: block;
- }
- .contxt:hover ::-webkit-scrollbar-thumb {
- display: block;
- }
- ::-webkit-scrollbar {
- width: 4px !important; /* 对垂直流动条有效 */
- }
- .scrollCon {
- overflow-y: scroll;
- overflow-x: hidden;
- }
- .scroll-box .position {
- display: block !important;
- height: 40px;
- text-align: center;
- line-height: 40px;
- border: 1px dashed #1890ff;
- color: #1890ff;
- background-color: #edf4fb;
- }
- .scroll-box .conter {
- display: none !important;
- }
- .dragClass {
- background-color: #fff;
- }
- .ivu-mt {
- display: flex;
- justify-content: space-between;
- margin-bottom: 10px;
- }
- .iconfont-diy {
- font-size: 24px;
- color: var(--prev-color-primary);
- }
- .diy-wrapper {
- max-width: 100%;
- min-width: 1100px;
- display: flex;
- justify-content: space-between;
- height: 100%;
- .left {
- min-width: 300px;
- max-width: 300px;
- /* border 1px solid #DDDDDD */
- border-radius: 4px;
- height: 100%;
- .title-bar {
- display: flex;
- color: #333;
- border-bottom: 1px solid #eee;
- border-radius: 4px;
- cursor: pointer;
- .title-item {
- display: flex;
- align-items: center;
- justify-content: center;
- flex: 1;
- height: 45px;
- &.on {
- color: var(--prev-color-primary);
- font-size: 14px;
- border-bottom: 1px solid var(--prev-color-primary);
- }
- }
- }
- .wrapper {
- padding: 15px;
- overflow-y: scroll;
- -webkit-overflow-scrolling: touch;
- .tips {
- display: flex;
- justify-content: space-between;
- padding-bottom: 15px;
- font-size: 13px;
- color: #000;
- cursor: pointer;
- .ivu-icon {
- color: #000;
- }
- }
- }
- .link-item {
- padding: 10px;
- border-bottom: 1px solid #F5F5F5;
- font-size: 12px;
- color: #323232;
- .name {
- font-size: 14px;
- color: #1890FF;
- }
- .link-txt {
- margin-top: 2px;
- word-break: break-all;
- }
- .params {
- margin-top: 5px;
- color: #1CBE6B;
- word-break: break-all;
- .txt {
- color: #323232;
- }
- span {
- &:last-child i {
- display: none;
- color: red;
- }
- }
- }
- .lable {
- display: flex;
- margin-top: 5px;
- color: #999;
- p {
- flex: 1;
- word-break: break-all;
- }
- button {
- margin-left: 30px;
- width: 38px;
- }
- }
- }
- .dragArea.list-group {
- display: flex;
- flex-wrap: wrap;
- .list-group-item {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- width: 74px;
- height: 66px;
- margin-right: 17px;
- margin-bottom: 10px;
- font-size: 12px;
- color: #666;
- cursor: pointer;
- border-radius: 5px;
- text-align: center;
- &:hover {
- box-shadow: 0 0 5px 0 rgba(24, 144, 255, 0.3);
- border-right: 5px;
- transform: scale(1.1);
- transition: all 0.2s;
- }
- &:nth-child(3n) {
- margin-right: 0;
- }
- }
- }
- }
- .content {
- position: relative;
- height: 100%;
- width: 100%;
- .page-foot {
- position: relative;
- width: 379px;
- margin: 0 auto 20px auto;
- .delete-box {
- display: none;
- position: absolute;
- left: -2px;
- top: 0;
- width: 383px;
- height: 100%;
- border: 2px dashed var(--prev-color-primary);
- padding: 10px 0;
- }
- &:hover, &.on {
- /* cursor: move; */
- .delete-box {
- /* display: block; */
- }
- }
- &.on {
- cursor: move;
- .delete-box {
- display: block;
- border: 2px solid var(--prev-color-primary);
- box-shadow: 0 0 10px 0 rgba(24, 144, 255, 0.3);
- }
- }
- }
- .page-title {
- position: relative;
- height: 35px;
- line-height: 35px;
- background: #fff;
- font-size: 15px;
- color: #333333;
- text-align: center;
- width: 379px;
- margin: 0 auto;
- .delete-box {
- display: none;
- position: absolute;
- left: -2px;
- top: 0;
- width: 383px;
- height: 100%;
- border: 2px dashed var(--prev-color-primary);
- padding: 10px 0;
- span {
- position: absolute;
- right: 0;
- bottom: 0;
- width: 32px;
- height: 16px;
- line-height: 16px;
- display: inline-block;
- text-align: center;
- font-size: 10px;
- color: #fff;
- background: rgba(0, 0, 0, 0.4);
- margin-left: 2px;
- cursor: pointer;
- z-index: 11;
- }
- }
- &:hover, &.on {
- /* cursor: move; */
- .delete-box {
- /* display: block; */
- }
- }
- &.on {
- cursor: move;
- .delete-box {
- display: block;
- border: 2px solid var(--prev-color-primary);
- box-shadow: 0 0 10px 0 rgba(24, 144, 255, 0.3);
- }
- }
- }
- .scroll-box {
- flex: 1;
- background-color: #fff;
- width: 379px;
- margin: 0 auto;
- padding-top: 1px;
- }
- .dragArea.list-group {
- width: 100%;
- height: 100%;
- .mConfig-item {
- position: relative;
- cursor: move;
- .delete-box {
- display: none;
- position: absolute;
- left: -2px;
- top: 0;
- width: 383px;
- height: 100%;
- border: 2px dashed var(--prev-color-primary);
- /* padding: 10px 0; */
- .handleType {
- position: absolute;
- right: -43px;
- top: 0;
- width: 36px;
- height: 143px;
- border-radius: 4px;
- background-color: #1890ff;
- cursor: pointer;
- color: #fff;
- font-weight: bold;
- text-align: center;
- padding: 4px 0;
- .iconfont {
- padding: 5px 0;
- &.on {
- opacity: 0.4;
- }
- }
- }
- }
- &.on {
- cursor: move;
- .delete-box {
- display: block;
- border: 2px solid var(--prev-color-primary);
- box-shadow: 0 0 10px 0 rgba(24, 144, 255, 0.3);
- }
- }
- }
- .mConfig-item:hover {
- transform: scale(1.01);
- box-shadow: 0 0 10px 0 rgba(24, 144, 255, 0.3);
- transition: all 0.2s;
- }
- }
- }
- .right-box {
- max-width: 400px;
- min-width: 400px;
- height: 100%;
- border-radius: 4px;
- overflow: scroll;
- -webkit-overflow-scrolling: touch;
- /deep/ .ivu-tabs-bar {
- margin-bottom: 16px;
- }
- .title-bar {
- width: 100%;
- height: 45px;
- line-height: 45px;
- padding-left: 24px;
- color: #000;
- border-radius: 4px;
- border-bottom: 1px solid #eee;
- font-size: 14px;
- }
- }
- ::-webkit-scrollbar {
- width: 6px;
- background-color: transparent;
- }
- ::-webkit-scrollbar-track {
- border-radius: 10px;
- }
- ::-webkit-scrollbar-thumb {
- background-color: #bfc1c4;
- }
- }
- .foot-box {
- position: relative;
- display: flex;
- align-items: center;
- justify-content: center;
- height: 80px;
- background: #fff;
- box-shadow: 0px -2px 4px 0px rgba(0, 0, 0, 0.03);
- button {
- width: 100px;
- height: 32px;
- font-size: 13px;
- &:first-child {
- margin-right: 20px;
- }
- }
- }
- /deep/ .ivu-scroll-loader {
- display: none;
- }
- /deep/ .ivu-card-body {
- width: 100%;
- padding:0;
- height: calc(100vh - 73px);
- }
- .rbtn {
- position: absolute;
- right: 20px;
- }
- .code {
- position: relative;
- }
- .QRpic {
- width: 160px;
- height: 160px;
- img {
- width: 100%;
- height: 100%;
- }
- }
- </style>
|