style.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /**
  2. * [魔方]属性组件
  3. * 修改时间:2018年9月13日19:08:50
  4. */
  5. //预览自定义魔方组件
  6. var diyHtml = "<div v-html='html' style='position:relative;padding:1px;background:#ffffff;'></div>";//1px用于解决定位偏差问题
  7. Vue.component("rubik-cube-diy-html",{
  8. props : ["diyHtml"],
  9. template : diyHtml,
  10. created : function(){
  11. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  12. this.$parent.data.verify.push(this.verify);//加载验证方法
  13. this.html = this.diyHtml.replace(/&quot;/g,'"');
  14. // console.log(this.html);
  15. },
  16. data : function(){
  17. return {
  18. html : ""
  19. };
  20. },
  21. watch : {
  22. diyHtml : function(v){
  23. this.html = v.toString().replace(/&quot;/g,'"');
  24. // console.log(this.html);
  25. }
  26. },
  27. methods: {
  28. verify : function () {
  29. var res = { code : true, message : "" };
  30. return res;
  31. },
  32. },
  33. });
  34. //编辑属性组件
  35. var rubikCubeHtml = '<div class="layui-form-item">';
  36. rubikCubeHtml += '<div class="selected-template-intro layui-form-item">';
  37. rubikCubeHtml += '<label class="layui-form-label sm">选择模板</label>';
  38. rubikCubeHtml += '<div class="layui-input-block">';
  39. rubikCubeHtml += '<span v-for="(item,i) in templateList" v-bind:class="[item.className == $parent.data.selectedTemplate ? \'\' : \'layui-hide\']">{{item.name}}</span>';
  40. rubikCubeHtml += '</div>';
  41. rubikCubeHtml += '</div>';
  42. rubikCubeHtml += '<div class="selected-template-list layui-form-item">';
  43. rubikCubeHtml += '<ul>';
  44. rubikCubeHtml += '<li v-for="(item,i) in templateList" v-bind:class="[(item.className == $parent.data.selectedTemplate) ? \'ns-text-color ns-border-color ns-bg-color-diaphaneity\' : \'\' ]" v-on:click="changeTemplateList(i)">';
  45. rubikCubeHtml += '<img v-if="item.className == $parent.data.selectedTemplate" v-bind:src="item.subsrc" />';
  46. rubikCubeHtml += '<img v-else v-bind:src="item.src" />';
  47. rubikCubeHtml += '</li>';
  48. rubikCubeHtml += '</ul>';
  49. rubikCubeHtml += '</div>';
  50. rubikCubeHtml += '<div v-if="isShowCustomRubikCube" class="layui-form-item">';
  51. rubikCubeHtml += '<label class="layui-form-label sm">魔方密度</label>';
  52. rubikCubeHtml += '<div class="layui-input-block">';
  53. rubikCubeHtml += '<div v-bind:class="{ \'layui-unselect layui-form-select\' : true, \'layui-form-selected\' : isShowRubikCubeDensity }" v-on:click="isShowRubikCubeDensity=!isShowRubikCubeDensity;">';
  54. rubikCubeHtml += '<div class="layui-select-title">';
  55. rubikCubeHtml += '<input type="text" placeholder="请选择" v-bind:value="customRubikCubeList[selectIndex].text" readonly="readonly" class="layui-input layui-unselect">';
  56. rubikCubeHtml += '<i class="layui-edge"></i>';
  57. rubikCubeHtml += '</div>';
  58. rubikCubeHtml += '<dl class="layui-anim layui-anim-upbit">';
  59. rubikCubeHtml += '<dd v-for="(item,index) in customRubikCubeList" v-bind:class="{ \'layui-this\' : (customRubikCube==item.value) }" v-on:click.stop="customRubikCube=item.value;isShowRubikCubeDensity=false;selectIndex=index;" >{{item.text}}</dd>';
  60. rubikCubeHtml += '</dl>';
  61. rubikCubeHtml += '</div>';
  62. rubikCubeHtml += '</div>';
  63. rubikCubeHtml += '</div>';
  64. rubikCubeHtml += '<div class="layui-form-item">';
  65. rubikCubeHtml += '<label class="layui-form-label sm">魔方布局</label>';
  66. rubikCubeHtml += '</div>';
  67. // rubikCubeHtml += '<p class="ns-word-aux">选定布局区域,在下方添加图片,建议添加比例一致的图片</p>';
  68. rubikCubeHtml += '<div class="layui-form-item selected-template-layout">';
  69. rubikCubeHtml += '<div class="layui-input-block layout" v-for="item in templateList" v-if="(item.className == $parent.data.selectedTemplate) && !isShowCustomRubikCube">';
  70. rubikCubeHtml += '<ul>';
  71. rubikCubeHtml += '<li v-for="(li,i) in item.dimensionScale" v-bind:class="[item.className]">';
  72. rubikCubeHtml += '<div class="empty" v-bind:class="[item.className]" v-show="currentList.length>0 && !currentList[i].imageUrl">';
  73. rubikCubeHtml += '<p>{{li.name}}</p>';
  74. rubikCubeHtml += '<p>{{li.desc}}</p>';
  75. // rubikCubeHtml += '<p>{{li.size}}</p>';
  76. rubikCubeHtml += '</div>';
  77. rubikCubeHtml += '<div class="have-preview-image" v-show="currentList.length>0 && currentList[i].imageUrl">';
  78. rubikCubeHtml += '<img v-bind:src="$parent.$parent.changeImgUrl(currentList[i].imageUrl)"/>';
  79. rubikCubeHtml += '</div>';
  80. rubikCubeHtml += '</li>';
  81. rubikCubeHtml += '</ul>';
  82. //魔方
  83. rubikCubeHtml += '<ul v-if="isShowCustomRubikCube">';
  84. rubikCubeHtml += '<li ref="rubikCube" class="custom-rubik-cube" v-for="(item,i) in customRubikCubeArray" v-bind:class="{ \'ns-border-color\' : item.selected,\'border-left\': (i%customRubikCube==0), \'border-bottom\' : (item.row == customRubikCube ) }" v-on:click="customRubikCubeClick(i)" v-on:mousemove="customRubikCubeMouseMove(i)" v-bind:style="{ width : (100/parseInt(customRubikCube)) + \'%\', height : $parent.data.heightArray[customRubikCube-4], lineHeight : $parent.data.heightArray[customRubikCube-4] }">';
  85. rubikCubeHtml += '<div v-if="!item.selected">+</div>';
  86. rubikCubeHtml += '</li>';
  87. rubikCubeHtml += '</ul>';
  88. //魔方
  89. rubikCubeHtml += '<template v-if="isShowCustomRubikCube && currentList.length>0">';
  90. rubikCubeHtml += '<div ref="selectedRubikCube" v-for="(item,i) in selectedRubikCubeArray" class="selected-rubik-cube" v-bind:style="{ top : item.top,left : item.left, width : item.width, height : item.height, lineHeight : item.height + \'px\', zIndex:(item.selected)?1:0, position : \'absolute\',textAlign : \'center\' }" v-bind:class="{ \'ns-border-color\' : item.selected, \'have-image\' : currentList[i].imageUrl }"';
  91. rubikCubeHtml += ' v-on:click="selectedRubikCubeClick(i)"';
  92. rubikCubeHtml += ' >';
  93. rubikCubeHtml += '<div class="image-url" v-show="currentList[i].imageUrl" v-bind:style="{ lineHeight : item.lineHeight, width : \'100%\', height : \'100%\' }">';
  94. rubikCubeHtml += '<a v-bind:href="(currentList[i].link) ? currentList[i].link.h5_url : \'javascript:;\' "><img v-bind:src="$parent.$parent.changeImgUrl(currentList[i].imageUrl)" style="width: auto;height: auto;max-width: 100%;max-height: 100%;"></a>';
  95. rubikCubeHtml += '</div>';
  96. rubikCubeHtml += '<span v-show="!currentList[i].imageUrl">{{item.proportion}}<template v-if="customRubikCube==4">比例</template></span>';
  97. rubikCubeHtml += '<i class="del" v-on:click.stop="deleteSelectedRubikCubeClick(i)" data-disabled="1">x</i>';
  98. rubikCubeHtml += '</div>';
  99. rubikCubeHtml += '</template>';
  100. rubikCubeHtml += '<div class="image-ad-list" v-if="currentList.length>0 && currentIndex<currentList.length">';
  101. rubikCubeHtml += '<ul>';
  102. rubikCubeHtml += '<li v-for="(li,i) in item.dimensionScale">';
  103. rubikCubeHtml += '<img-sec-upload v-bind:data="{ data : currentList[i], callback : refreshDiyHtml }"></img-sec-upload>';
  104. rubikCubeHtml += '<div class="content-block">';
  105. rubikCubeHtml += '<span style="padding-left: 2px;">{{li.name}}</span>';
  106. rubikCubeHtml += '<sel-link v-bind:data="{ field : $parent.data.list[i].link }" v-bind:callback="linkCallBack" v-bind:refresh="$parent.data.list[i].link"></sel-link>';
  107. rubikCubeHtml += '</div>';
  108. rubikCubeHtml += '</li>';
  109. rubikCubeHtml += '</ul>';
  110. rubikCubeHtml += '</div>';
  111. rubikCubeHtml += '</div>';
  112. rubikCubeHtml += '</div>';
  113. rubikCubeHtml += '</div>';
  114. Vue.component("rubik-cube",{
  115. props : {},
  116. data : function(){
  117. return {
  118. //是否显示魔方密度
  119. isShowCustomRubikCube : false,
  120. //布局密度
  121. customRubikCube : this.$parent.data.customRubikCube,
  122. //自定义区域集合
  123. customRubikCubeArray : [],
  124. //已设定好的自定义区域集合
  125. selectedRubikCubeArray : this.$parent.data.selectedRubikCubeArray,
  126. //当前选中的布局下标
  127. selectIndex : 0,
  128. //控制魔方密度下拉框的显示隐藏
  129. isShowRubikCubeDensity : false,
  130. //可选择的魔方模板
  131. templateList : [],
  132. customRubikCubeList : [
  133. {value : 4,text : "4x4"},
  134. {value : 5,text : "5x5"},
  135. {value : 6,text : "6x6"},
  136. {value : 7,text : "7x7"}
  137. ],
  138. //当前编辑图片的链接地址
  139. currentIndex : 0,
  140. data : this.$parent.data,
  141. currentList : this.$parent.data.list,
  142. }
  143. },
  144. template : rubikCubeHtml,
  145. created : function(){
  146. this.initCustomRubikCubeArray();
  147. this.initTemplateList();
  148. //选中当前编辑的自定义布局下标
  149. for(var i=0;i<this.selectedRubikCubeArray.length;i++){
  150. if(this.selectedRubikCubeArray[i].selected){
  151. this.changeCurrentIndex(i);
  152. break;
  153. }
  154. }
  155. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  156. this.$parent.data.verify.push(this.verify);//加载验证方法
  157. },
  158. methods : {
  159. //初始化自定义区域集合
  160. initCustomRubikCubeArray : function(){
  161. for(var i=0;i<this.customRubikCube;i++){
  162. for(var j=0;j<this.customRubikCube;j++){
  163. var obj = {
  164. coordinates : (i+1) + ":" + (j+1),
  165. row : (i+1), //行
  166. column : (j+1), //列
  167. selected : false, //是否已选择
  168. start : false, //开始
  169. finish : false, //是否已设定
  170. ranksNumber : "", //行列数量
  171. selectedCoordinates : [] //已选择的行列
  172. };
  173. this.customRubikCubeArray.push(obj);
  174. }
  175. }
  176. // console.log(JSON.stringify(this.customRubikCubeArray));
  177. },
  178. //初始化可选择的模板集合
  179. initTemplateList : function(){
  180. var prefix = rubikCubeResourcePath + "/rubik_cube/img";
  181. this.templateList.push({ name : "1行2个", src : prefix + "/rubik_cube_row1_of2.png", subsrc : prefix + "/rubik_cube_row1_of2_2.png", className : "row1-of2", dimensionScale : [{desc: "宽度50%", size: "200px * 200px", name: "图一"}, {desc: "宽度50%", size: "200px * 200px", name: "图二"}], descAux: "选定布局区域,在下方添加图片,建议添加尺寸一致的图片,宽度最小建议为:200px" });
  182. this.templateList.push({ name : "1行3个", src : prefix + "/rubik_cube_row1_of3.png", subsrc : prefix + "/rubik_cube_row1_of3_2.png", className : "row1-of3", dimensionScale : [{desc: "宽度33.33%", size: "200px * 200px", name: "图一"}, {desc: "宽度33.33%", size: "200px * 200px", name: "图二"}, {desc: "宽度33.33%", size: "200px * 200px", name: "图三"}], descAux: "选定布局区域,在下方添加图片,建议添加尺寸一致的图片,宽度最小建议为:130px" });
  183. this.templateList.push({ name : "1行4个", src : prefix + "/rubik_cube_row1_of4.png", subsrc : prefix + "/rubik_cube_row1_of4_2.png", className : "row1-of4", dimensionScale : [{desc: "宽度25%", size: "200px * 200px", name: "图一"},{desc: "宽度25%", size: "200px * 200px", name: "图二"},{desc: "宽度25%", size: "200px * 200px", name: "图三"}, {desc: "宽度25%", size: "200px * 200px", name: "图四"},], descAux: "选定布局区域,在下方添加图片,建议添加尺寸一致的图片,宽度最小建议为:100px" });
  184. this.templateList.push({ name : "2左2右", src : prefix + "/rubik_cube_row2_lt_of2_rt.png", subsrc : prefix + "/rubik_cube_row2_lt_of2_rt_2.png", className : "row2-lt-of2-rt", dimensionScale : [{desc: "宽度50%", size: "200px * 200px", name: "图一"}, {desc: "宽度50%", size: "200px * 200px", name: "图二"}, {desc: "宽度50%", size: "200px * 200px", name: "图三"}, {desc: "宽度50%", size: "200px * 200px", name: "图四"}], descAux: "选定布局区域,在下方添加图片,建议添加尺寸一致的图片,宽度最小建议为:200px" });
  185. this.templateList.push({ name : "1左2右", src : prefix + "/rubik_cube_row1_lt_of2_rt.png", subsrc : prefix + "/rubik_cube_row1_lt_of2_rt_2.png", className : "row1-lt-of2-rt", dimensionScale : [{desc: "宽度50% * 高度100%", size: "200px * 400px", name: "图一"}, {desc: "宽度50% * 高度50%", size: "200px * 200px", name: "图二"}, {desc: "宽度50% * 高度50%", size: "200px * 200px", name: "图三"}], descAux: "选定布局区域,在下方添加图片,宽度最小建议为:200px,右侧两张图片高度一致,左侧图片高度为右侧两张图片高度之和(例:左侧图片尺寸:200px * 300px,右侧两张图片尺寸:200px * 150px)" });
  186. this.templateList.push({ name : "1上2下", src : prefix + "/rubik_cube_row1_tp_of2_bm.png", subsrc : prefix + "/rubik_cube_row1_tp_of2_bm_2.png", className : "row1-tp-of2-bm", dimensionScale : [{desc: "宽度100% * 高度50%", size: "400px * 200px", name: "图一"}, {desc: "宽度50% * 高度50%", size: "200px * 200px", name: "图二"}, {desc: "宽度50% * 高度500%", size: "200px * 200px", name: "图三"}], descAux: "选定布局区域,在下方添加图片,上方一张图片的宽度为下方两张图片宽度之和,下放两张图片尺寸一致,高度可根据实际需求自行确定(例:上方图片尺寸:400px * 150px,下方两张图片尺寸:200px * 150px)" });
  187. this.templateList.push({ name : "1左3右", src : prefix + "/rubik_cube_row1_lt_of1_tp_of2_bm.png", subsrc : prefix + "/rubik_cube_row1_lt_of1_tp_of2_bm_2.png", className : "row1-lt-of1-tp-of2-bm",dimensionScale : [{desc: "宽度50% * 高度100%", size: "200px * 400px", name: "图一"}, {desc: "宽度50% * 高度50%", size: "200px * 200px", name: "图二"}, {desc: "宽度25% * 高度50%", size: "100px * 200px", name: "图三"}, {desc: "宽度25% * 高度50%", size: "100px * 200px", name: "图四"}], descAux: "选定布局区域,在下方添加图片,左右两侧内容宽高相同,右侧上下区域高度各占50%,右侧内容下半部分两张图片的宽度相同,各占右侧内容宽度的50%(例:左侧图片尺寸:200px * 400px,右侧上半部分图片尺寸:200px * 200px,右侧下半部分两张图片尺寸:100px * 200px)" });
  188. // this.templateList.push({ name : "自定义", src : prefix + "/rubik_cube_diy.png", className : "custom-rubik-cube", dimensionScale : [] });
  189. //初始化加载时
  190. for(var i=0;i<this.templateList.length;i++){
  191. if(this.templateList[i].className == this.$parent.data.selectedTemplate){
  192. //判断当前选中模板是否为自定义区域,然后进行特殊处理
  193. if(this.templateList[i].dimensionScale.length == 0){
  194. this.isShowCustomRubikCube = true;//显示自定义
  195. }
  196. }
  197. }
  198. },
  199. //切换选中模板
  200. changeTemplateList : function(v){
  201. this.isShowCustomRubikCube = false;
  202. for(var i=0;i<this.templateList.length;i++){
  203. if(i==v){
  204. this.$parent.data.selectedTemplate = this.templateList[i].className;
  205. //自定义区域特殊处理
  206. if(this.templateList[i].dimensionScale.length == 0){
  207. this.isShowCustomRubikCube = true;
  208. //清空链接地址的数据
  209. this.currentList.length = 0;
  210. this.selectedRubikCubeArray.length = 0;
  211. }else{
  212. var count = this.templateList[i].dimensionScale.length;
  213. //重置当前编辑的图片集合
  214. //数量不够,进行添加
  215. if(count>this.currentList.length){
  216. for(var j=0;j<count;j++){
  217. if((j + 1) > this.currentList.length) this.currentList.push({ imageUrl : "", link : {} });
  218. }
  219. }else{
  220. //数量不相同时,并且数量超出,减去
  221. if(count != this.currentList.length){
  222. for(var j=0;j<this.currentList.length;j++){
  223. if((j+1)>count){
  224. // console.log(j);
  225. this.currentList.splice(j,1);
  226. j=0;
  227. }
  228. }
  229. //设置当前选中为最后一个
  230. this.currentIndex = this.currentList.length - 1;
  231. }
  232. }
  233. }
  234. }
  235. }
  236. this.templateList.push({});
  237. this.templateList.pop();
  238. },
  239. //选中当前编辑的布局
  240. changeCurrentIndex : function(index){
  241. this.currentIndex = index;
  242. },
  243. //自定义魔方区域点击事件
  244. customRubikCubeClick : function(position){
  245. if(this.customRubikCubeArray[position].start && !this.customRubikCubeArray[position].selected){
  246. // console.log("当前操作还没有结束,不能继续操作哦");
  247. return;
  248. }
  249. //再次点击确定
  250. if(this.customRubikCubeArray[position].selected){
  251. var ranksNumber = "";
  252. var selectedCoordinates = "";
  253. var positionXY = "";
  254. for(var i=0;i<this.customRubikCubeArray.length;i++){
  255. if(this.customRubikCubeArray[i].selected && this.customRubikCubeArray[i].start){
  256. ranksNumber = this.customRubikCubeArray[i].ranksNumber;//行列数量
  257. selectedCoordinates = this.customRubikCubeArray[i].selectedCoordinates;//已选中的坐标集合
  258. }
  259. if(this.customRubikCubeArray[i].selected && !this.customRubikCubeArray[i].finish){
  260. if(positionXY == "") positionXY = $(this.$refs.rubikCube[i]).position();
  261. }
  262. }
  263. var rowCount = ranksNumber.split(":")[0];//选中的总行数
  264. var columnCount = ranksNumber.split(":")[1];//选中的总列数
  265. //按照百分比计算宽高
  266. var width = (100/this.customRubikCube) * columnCount;
  267. var height = (100/this.customRubikCube) * rowCount;
  268. //left值采用百分比计算,公式:(同一行中当前魔方位置之前的宽度总和)
  269. //公式:(当前列-1) * (100/魔方密度)
  270. var left = (selectedCoordinates[0].split(":")[1]-1) * (100/this.customRubikCube);
  271. //1:4 2:4 第四列 left = (4-1)*25 = 75
  272. //3:3 4:3 第三列 left = (3-1)*25 = 50
  273. //3:2 3:3 4:2 4:3 第二列、第三列
  274. //2:3 2:4 3:3 3:4 第三列、第四列
  275. //1:3 1:4 2:3 2:4 3:3 3:4 4:3 4:4 第三列、第四列
  276. var selectedRubikCube = {
  277. proportion : rowCount + ":" + columnCount,
  278. selected : true,
  279. top : positionXY.top + "px",
  280. left : left + "%",
  281. width : (width + 0.0) + "%",
  282. height : (height + 0.0) + "%",
  283. lineHeight : 0 + "px",
  284. selectedCoordinates : selectedCoordinates
  285. };
  286. for(var i=0;i<this.selectedRubikCubeArray.length;i++){
  287. this.selectedRubikCubeArray[i].selected = false;
  288. }
  289. this.selectedRubikCubeArray.push(selectedRubikCube);
  290. for(var i=0;i<this.customRubikCubeArray.length;i++){
  291. //将当前选中的设置为已完成(表示不可操作了)
  292. if(this.customRubikCubeArray[i].selected){
  293. this.customRubikCubeArray[i].finish = true;
  294. }
  295. //删除开始位置
  296. if(this.customRubikCubeArray[i].selected && this.customRubikCubeArray[i].start){
  297. this.customRubikCubeArray[i].start = false;
  298. }
  299. }
  300. this.currentList.push({ imageUrl : "", link : {} });
  301. //默认选择当前添加的下标
  302. this.changeCurrentIndex(this.currentList.length-1);
  303. //计算当前添加的自定义魔方区域的行高,用于将图片进行垂直居中
  304. setTimeout(function(){
  305. selectedRubikCube.lineHeight = $(".draggable-element.selected .rubik-cube .layout div.selected-rubik-cube.selected").outerHeight() + "px";
  306. },100);
  307. }else{
  308. //设置当前自定义模块的开始位置,并且设定好它可以如何选中
  309. for(var i=0;i<this.customRubikCubeArray.length;i++){
  310. if(i==position){
  311. this.customRubikCubeArray[i].start = true;
  312. this.customRubikCubeArray[i].selected = true;
  313. }else{
  314. this.customRubikCubeArray[i].start = false;
  315. }
  316. }
  317. }
  318. },
  319. //自定义魔方区域
  320. customRubikCubeMouseMove : function(position){
  321. //当前坐标
  322. var currentMoveCoordinates = this.customRubikCubeArray[position].coordinates;
  323. var coordinates = "";
  324. for(var i=0;i<this.customRubikCubeArray.length;i++){
  325. //找到开始位置
  326. if(this.customRubikCubeArray[i].selected && this.customRubikCubeArray[i].start){
  327. coordinates = this.customRubikCubeArray[i].coordinates;
  328. break;
  329. }
  330. }
  331. //清空
  332. for(var j=0;j<this.customRubikCubeArray.length;j++){
  333. if(this.customRubikCubeArray[j].coordinates != coordinates && !this.customRubikCubeArray[j].finish){
  334. this.customRubikCubeArray[j].selected = false;
  335. }
  336. }
  337. if(coordinates != "") {
  338. //开始行列
  339. var rowStart = coordinates.split(":")[0];
  340. var columnStart = coordinates.split(":")[1];
  341. //结束行列
  342. var rowEnd = parseInt(currentMoveCoordinates.split(":")[0]);
  343. var columnEnd = parseInt(currentMoveCoordinates.split(":")[1]);
  344. var tempRow = rowStart;
  345. //如果开始行大于结束行,则开始行用结束行,结束行用开始行
  346. if(rowStart > rowEnd) {
  347. rowStart = rowEnd;
  348. rowEnd = tempRow;
  349. }
  350. var tempColumn = columnStart;
  351. //如果开始列大于结束列,则开始列用结束列,结束列用开始列
  352. if(columnStart > columnEnd) {
  353. columnStart = columnEnd;
  354. columnEnd = tempColumn;
  355. }
  356. var rowCount = 0; //总行数
  357. var columnCount = new Array(); //总列数
  358. var isAdd = true;
  359. var selectedCoordinates = new Array();
  360. //遍历行
  361. for(rowStart; rowStart <= rowEnd; rowStart++) {
  362. rowCount++;
  363. //遍历列
  364. for(var i = columnStart; i <= columnEnd; i++) {
  365. //当前行列坐标
  366. var currentCoordinates = rowStart + ":" + i;
  367. //检测当前的模块是否被占用,如果被占用,那么整个都不能选择
  368. for(var j=0;j<this.customRubikCubeArray.length;j++){
  369. if(this.customRubikCubeArray[j].coordinates == currentCoordinates && this.customRubikCubeArray[j].finish){
  370. isAdd = false;
  371. break;
  372. }
  373. }
  374. if($.inArray(i, columnCount) == -1) columnCount.push(i);
  375. selectedCoordinates.push(currentCoordinates);
  376. for(var j=0;j<this.customRubikCubeArray.length;j++){
  377. if(this.customRubikCubeArray[j].coordinates == currentCoordinates){
  378. this.customRubikCubeArray[j].selected = true;
  379. }
  380. }
  381. }
  382. }
  383. if(!isAdd) {
  384. for(var j=0;j<this.customRubikCubeArray.length;j++){
  385. if(this.customRubikCubeArray[j].selected && !this.customRubikCubeArray[j].finish){
  386. this.customRubikCubeArray[j].selected = false;
  387. }
  388. }
  389. for(var j=0;j<this.customRubikCubeArray.length;j++){
  390. if(this.customRubikCubeArray[j].start){
  391. this.customRubikCubeArray[j].selected = true;
  392. }
  393. }
  394. }
  395. for(var j=0;j<this.customRubikCubeArray.length;j++){
  396. if(this.customRubikCubeArray[j].selected && this.customRubikCubeArray[j].start){
  397. this.customRubikCubeArray[j].ranksNumber = rowCount + ":" + columnCount.length;
  398. this.customRubikCubeArray[j].selectedCoordinates = selectedCoordinates;
  399. }
  400. }
  401. this.customRubikCubeArray.push({});
  402. this.customRubikCubeArray.pop();
  403. }
  404. },
  405. //点击已设定好的自定义区域
  406. selectedRubikCubeClick : function(position){
  407. for(var i=0;i<this.selectedRubikCubeArray.length;i++){
  408. if(i==position){
  409. this.selectedRubikCubeArray[i].selected = true;
  410. }else{
  411. this.selectedRubikCubeArray[i].selected = false;
  412. }
  413. }
  414. this.changeCurrentIndex(position);
  415. },
  416. //删除已设定好的自定义区域
  417. deleteSelectedRubikCubeClick : function(position){
  418. var selectedCoordinates = this.selectedRubikCubeArray[position].selectedCoordinates;
  419. for(var i=0;i<selectedCoordinates.length;i++){
  420. for(var j=0;j<this.customRubikCubeArray.length;j++){
  421. if(this.customRubikCubeArray[j].coordinates == selectedCoordinates[i]){
  422. this.customRubikCubeArray[j].selected = false;
  423. this.customRubikCubeArray[j].finish = false;
  424. this.customRubikCubeArray[j].ranksNumber = "";
  425. }
  426. }
  427. }
  428. this.currentList.splice(position,1);
  429. //删除后应该选择最后一个
  430. this.changeCurrentIndex(this.currentList.length-1);
  431. for(var i=0;i<this.selectedRubikCubeArray.length;i++){
  432. if(this.currentIndex == i){
  433. this.selectedRubikCubeArray[i].selected = true;
  434. break;
  435. }
  436. }
  437. this.customRubikCubeArray.push({});
  438. this.customRubikCubeArray.pop();
  439. this.selectedRubikCubeArray.splice(position,1);
  440. },
  441. //刷新自定义区域Html代码
  442. refreshDiyHtml : function(){
  443. if(this.isShowCustomRubikCube) {
  444. var self = this;
  445. setTimeout(function () {
  446. var height = $(".draggable-element.selected .rubik-cube .layout div.selected-rubik-cube.have-image").parent().outerHeight() + "px";
  447. var diy = $(".draggable-element.selected .rubik-cube .layout div.selected-rubik-cube.have-image").clone();
  448. var diyHtml = '<div style="background:#ffffff;height:' + height + ';">';
  449. diy.each(function () {
  450. $(this).find(".del").remove();
  451. $(this).find("span").remove();
  452. diyHtml += $(this).prop("outerHTML");
  453. });
  454. diyHtml += "</div>";
  455. self.$parent.data.diyHtml = diyHtml.replace(/"/g, "&quot;").replace(/z-index: 1/g, "");
  456. }, 100);
  457. }
  458. },
  459. //监听链接地址回调,更新diyHtml
  460. linkCallBack : function(index){
  461. this.refreshDiyHtml();
  462. },
  463. verify :function () {
  464. var res = {code: true, message: ""};
  465. if (this.$parent.data.selectedTemplate == "custom-rubik-cube") {
  466. //自定义魔方,不能有空缺
  467. var customRubikCubeArray = new Array();
  468. var selectedCount = 0;//选择数量
  469. for (var i = 0; i < this.customRubikCube; i++) {
  470. for (var j = 0; j < this.customRubikCube; j++) {
  471. customRubikCubeArray.push((i + 1) + ":" + (j + 1));
  472. }
  473. }
  474. for (var i = 0; i < this.customRubikCube; i++) {
  475. for (var j = 0; j < this.customRubikCube; j++) {
  476. customRubikCubeArray.push((i + 1) + ":" + (j + 1));
  477. }
  478. }
  479. for (var i = 0; i < customRubikCubeArray.length; i++) {
  480. for (var j = 0; j < this.selectedRubikCubeArray.length; j++) {
  481. var selectedCoordinates = this.selectedRubikCubeArray[j].selectedCoordinates;
  482. for (var k = 0; k < selectedCoordinates.length; k++) {
  483. if (customRubikCubeArray[i] == selectedCoordinates[k]) {
  484. selectedCount++;
  485. }
  486. }
  487. }
  488. }
  489. if (selectedCount != customRubikCubeArray.length) {
  490. res.code = false;
  491. res.message = "自定义魔方必须填满,不能有空缺哦";
  492. }
  493. }
  494. for (var i = 0; i < this.currentList.length; i++) {
  495. var item = this.currentList[i];
  496. if (!item.imageUrl) {
  497. res.code = false;
  498. res.message = "请上传图片";
  499. break;
  500. }
  501. }
  502. return res;
  503. }
  504. },
  505. watch : {
  506. customRubikCube : function(v){
  507. //自定义区域集合
  508. this.customRubikCubeArray.splice(0,this.customRubikCubeArray.length);
  509. this.selectedRubikCubeArray.splice(0,this.selectedRubikCubeArray.length);
  510. this.initCustomRubikCubeArray();
  511. },
  512. /**
  513. * 监听集合,更新自定义区域Html代码
  514. */
  515. currentList : function(){
  516. this.refreshDiyHtml();
  517. }
  518. }
  519. });