/** * [魔方]属性组件 * 修改时间:2018年9月13日19:08:50 */ //预览自定义魔方组件 var diyHtml = "
";//1px用于解决定位偏差问题 Vue.component("rubik-cube-diy-html",{ props : ["diyHtml"], template : diyHtml, created : function(){ if(!this.$parent.data.verify) this.$parent.data.verify = []; this.$parent.data.verify.push(this.verify);//加载验证方法 this.html = this.diyHtml.replace(/"/g,'"'); // console.log(this.html); }, data : function(){ return { html : "" }; }, watch : { diyHtml : function(v){ this.html = v.toString().replace(/"/g,'"'); // console.log(this.html); } }, methods: { verify : function () { var res = { code : true, message : "" }; return res; }, }, }); //编辑属性组件 var rubikCubeHtml = '
'; rubikCubeHtml += '
'; rubikCubeHtml += ''; rubikCubeHtml += '
'; rubikCubeHtml += '{{item.name}}'; rubikCubeHtml += '
'; rubikCubeHtml += '
'; rubikCubeHtml += '
'; rubikCubeHtml += ''; rubikCubeHtml += '
'; rubikCubeHtml += '
'; rubikCubeHtml += ''; rubikCubeHtml += '
'; rubikCubeHtml += '
'; rubikCubeHtml += '
'; rubikCubeHtml += ''; rubikCubeHtml += ''; rubikCubeHtml += '
'; rubikCubeHtml += '
'; rubikCubeHtml += '
{{item.text}}
'; rubikCubeHtml += '
'; rubikCubeHtml += '
'; rubikCubeHtml += '
'; rubikCubeHtml += '
'; rubikCubeHtml += '
'; rubikCubeHtml += ''; rubikCubeHtml += '
'; // rubikCubeHtml += '

选定布局区域,在下方添加图片,建议添加比例一致的图片

'; rubikCubeHtml += '
'; rubikCubeHtml += '
'; rubikCubeHtml += '
    '; rubikCubeHtml += '
  • '; rubikCubeHtml += '
    '; rubikCubeHtml += '

    {{li.name}}

    '; rubikCubeHtml += '

    {{li.desc}}

    '; // rubikCubeHtml += '

    {{li.size}}

    '; rubikCubeHtml += '
    '; rubikCubeHtml += '
    '; rubikCubeHtml += ''; rubikCubeHtml += '
    '; rubikCubeHtml += '
  • '; rubikCubeHtml += '
'; //魔方 rubikCubeHtml += '
    '; rubikCubeHtml += '
  • '; rubikCubeHtml += '
    +
    '; rubikCubeHtml += '
  • '; rubikCubeHtml += '
'; //魔方 rubikCubeHtml += ''; rubikCubeHtml += '
'; rubikCubeHtml += '
    '; rubikCubeHtml += '
  • '; rubikCubeHtml += ''; rubikCubeHtml += '
    '; rubikCubeHtml += '{{li.name}}'; rubikCubeHtml += ''; rubikCubeHtml += '
    '; rubikCubeHtml += '
  • '; rubikCubeHtml += '
'; rubikCubeHtml += '
'; rubikCubeHtml += '
'; rubikCubeHtml += '
'; rubikCubeHtml += '
'; Vue.component("rubik-cube",{ props : {}, data : function(){ return { //是否显示魔方密度 isShowCustomRubikCube : false, //布局密度 customRubikCube : this.$parent.data.customRubikCube, //自定义区域集合 customRubikCubeArray : [], //已设定好的自定义区域集合 selectedRubikCubeArray : this.$parent.data.selectedRubikCubeArray, //当前选中的布局下标 selectIndex : 0, //控制魔方密度下拉框的显示隐藏 isShowRubikCubeDensity : false, //可选择的魔方模板 templateList : [], customRubikCubeList : [ {value : 4,text : "4x4"}, {value : 5,text : "5x5"}, {value : 6,text : "6x6"}, {value : 7,text : "7x7"} ], //当前编辑图片的链接地址 currentIndex : 0, data : this.$parent.data, currentList : this.$parent.data.list, } }, template : rubikCubeHtml, created : function(){ this.initCustomRubikCubeArray(); this.initTemplateList(); //选中当前编辑的自定义布局下标 for(var i=0;ithis.currentList.length){ for(var j=0;j this.currentList.length) this.currentList.push({ imageUrl : "", link : {} }); } }else{ //数量不相同时,并且数量超出,减去 if(count != this.currentList.length){ for(var j=0;jcount){ // console.log(j); this.currentList.splice(j,1); j=0; } } //设置当前选中为最后一个 this.currentIndex = this.currentList.length - 1; } } } } } this.templateList.push({}); this.templateList.pop(); }, //选中当前编辑的布局 changeCurrentIndex : function(index){ this.currentIndex = index; }, //自定义魔方区域点击事件 customRubikCubeClick : function(position){ if(this.customRubikCubeArray[position].start && !this.customRubikCubeArray[position].selected){ // console.log("当前操作还没有结束,不能继续操作哦"); return; } //再次点击确定 if(this.customRubikCubeArray[position].selected){ var ranksNumber = ""; var selectedCoordinates = ""; var positionXY = ""; for(var i=0;i rowEnd) { rowStart = rowEnd; rowEnd = tempRow; } var tempColumn = columnStart; //如果开始列大于结束列,则开始列用结束列,结束列用开始列 if(columnStart > columnEnd) { columnStart = columnEnd; columnEnd = tempColumn; } var rowCount = 0; //总行数 var columnCount = new Array(); //总列数 var isAdd = true; var selectedCoordinates = new Array(); //遍历行 for(rowStart; rowStart <= rowEnd; rowStart++) { rowCount++; //遍历列 for(var i = columnStart; i <= columnEnd; i++) { //当前行列坐标 var currentCoordinates = rowStart + ":" + i; //检测当前的模块是否被占用,如果被占用,那么整个都不能选择 for(var j=0;j'; diy.each(function () { $(this).find(".del").remove(); $(this).find("span").remove(); diyHtml += $(this).prop("outerHTML"); }); diyHtml += ""; self.$parent.data.diyHtml = diyHtml.replace(/"/g, """).replace(/z-index: 1/g, ""); }, 100); } }, //监听链接地址回调,更新diyHtml linkCallBack : function(index){ this.refreshDiyHtml(); }, verify :function () { var res = {code: true, message: ""}; if (this.$parent.data.selectedTemplate == "custom-rubik-cube") { //自定义魔方,不能有空缺 var customRubikCubeArray = new Array(); var selectedCount = 0;//选择数量 for (var i = 0; i < this.customRubikCube; i++) { for (var j = 0; j < this.customRubikCube; j++) { customRubikCubeArray.push((i + 1) + ":" + (j + 1)); } } for (var i = 0; i < this.customRubikCube; i++) { for (var j = 0; j < this.customRubikCube; j++) { customRubikCubeArray.push((i + 1) + ":" + (j + 1)); } } for (var i = 0; i < customRubikCubeArray.length; i++) { for (var j = 0; j < this.selectedRubikCubeArray.length; j++) { var selectedCoordinates = this.selectedRubikCubeArray[j].selectedCoordinates; for (var k = 0; k < selectedCoordinates.length; k++) { if (customRubikCubeArray[i] == selectedCoordinates[k]) { selectedCount++; } } } } if (selectedCount != customRubikCubeArray.length) { res.code = false; res.message = "自定义魔方必须填满,不能有空缺哦"; } } for (var i = 0; i < this.currentList.length; i++) { var item = this.currentList[i]; if (!item.imageUrl) { res.code = false; res.message = "请上传图片"; break; } } return res; } }, watch : { customRubikCube : function(v){ //自定义区域集合 this.customRubikCubeArray.splice(0,this.customRubikCubeArray.length); this.selectedRubikCubeArray.splice(0,this.selectedRubikCubeArray.length); this.initCustomRubikCubeArray(); }, /** * 监听集合,更新自定义区域Html代码 */ currentList : function(){ this.refreshDiyHtml(); } } });