design.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  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. },
  15. data : function(){
  16. return {
  17. html : ""
  18. };
  19. },
  20. watch : {
  21. diyHtml : function(v){
  22. this.html = v.toString().replace(/&quot;/g,'"');
  23. }
  24. },
  25. methods: {
  26. verify : function (index) {
  27. var res = { code : true, message : "" };
  28. return res;
  29. },
  30. },
  31. });
  32. //编辑属性组件
  33. var rubikCubeHtml = '<div class="layui-form-item">';
  34. rubikCubeHtml += '<div class="template-edit-title">';
  35. rubikCubeHtml += '<h3>选择风格</h3>';
  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 += '<template v-for="(item,i) in templateList" :keys="i">';
  40. rubikCubeHtml += '<span v-if="item.className == $parent.data.mode">{{item.name}}</span>';
  41. rubikCubeHtml += '</template>';
  42. rubikCubeHtml += '</div>';
  43. rubikCubeHtml += '</div>';
  44. rubikCubeHtml += '<div class="selected-template-list layui-form-item">';
  45. rubikCubeHtml += '<ul>';
  46. rubikCubeHtml += '<li v-for="(item,i) in templateList" :class="[(item.className == $parent.data.mode) ? \'text-color border-color\' : \'\' ]" @click="changeTemplateList(i)">';
  47. rubikCubeHtml += '<i class="iconfont" :class="[{\'text-color\': item.className == $parent.data.mode}, item.src]"></i>';
  48. rubikCubeHtml += '</li>';
  49. rubikCubeHtml += '</ul>';
  50. rubikCubeHtml += '</div>';
  51. rubikCubeHtml += '<div v-if="isShowCustomRubikCube" class="layui-form-item">';
  52. rubikCubeHtml += '<label class="layui-form-label sm">魔方密度</label>';
  53. rubikCubeHtml += '<div class="layui-input-block">';
  54. rubikCubeHtml += '<div :class="{ \'layui-unselect layui-form-select\' : true, \'layui-form-selected\' : isShowRubikCubeDensity }" @click="isShowRubikCubeDensity=!isShowRubikCubeDensity;">';
  55. rubikCubeHtml += '<div class="layui-select-title">';
  56. rubikCubeHtml += '<input type="text" placeholder="请选择" :value="customRubikCubeList[selectIndex].text" readonly="readonly" class="layui-input layui-unselect">';
  57. rubikCubeHtml += '<i class="layui-edge"></i>';
  58. rubikCubeHtml += '</div>';
  59. rubikCubeHtml += '<dl class="layui-anim layui-anim-upbit">';
  60. rubikCubeHtml += '<dd v-for="(item,index) in customRubikCubeList" :class="{ \'layui-this\' : (customRubikCube==item.value) }" @click.stop="customRubikCubeFn(item,index)" >{{item.text}}</dd>';
  61. rubikCubeHtml += '</dl>';
  62. rubikCubeHtml += '</div>';
  63. rubikCubeHtml += '</div>';
  64. rubikCubeHtml += '</div>';
  65. rubikCubeHtml += '</div>';
  66. // rubikCubeHtml += '<div class="template-edit-title">';
  67. // rubikCubeHtml += '<h3>间隙设置</h3>';
  68. // rubikCubeHtml += '<slide :data="{ field : \'imageGap\', label : \'图片间隙\', max: 30, callback : calcRatio }"></slide>';
  69. // rubikCubeHtml += '</div>';
  70. rubikCubeHtml += '<div class="template-edit-title">';
  71. rubikCubeHtml += '<h3>魔方布局</h3>';
  72. // rubikCubeHtml += '<p class="word-aux">选定布局区域,在下方添加图片,建议添加比例一致的图片</p>';
  73. rubikCubeHtml += '<div class="layui-form-item selected-template-layout">';
  74. rubikCubeHtml += '<div class="layui-input-block layout" v-for="item in templateList" v-if="(item.className == $parent.data.mode) && !isShowCustomRubikCube">';
  75. rubikCubeHtml += '<ul>';
  76. // rubikCubeHtml += '<li v-for="(li,i) in item.dimensionScale" :class="[item.className,(currentIndex==i) ? \'border-color\' : \'\']" @click="changeCurrentIndex(i)">';
  77. // rubikCubeHtml += '<div class="empty" :class="[item.className,(currentIndex==i) ? \'text-color\' : \'\']" v-show="currentList.length>0 && !currentList[i].imageUrl" v-html="li"></div>';
  78. rubikCubeHtml += '<li v-for="(li,i) in item.dimensionScale" :class="[item.className]">';
  79. rubikCubeHtml += '<div class="empty" :class="[item.className]" v-show="currentList.length>0 && !currentList[i].imageUrl">';
  80. rubikCubeHtml += '<p>{{li.name}}</p>';
  81. rubikCubeHtml += '<p>{{li.desc}}</p>';
  82. // rubikCubeHtml += '<p>{{li.size}}</p>';
  83. rubikCubeHtml += '</div>';
  84. rubikCubeHtml += '<div class="have-preview-image" v-show="currentList.length>0 && currentList[i].imageUrl">';
  85. rubikCubeHtml += '<img :src="$parent.$parent.changeImgUrl(currentList[i].imageUrl)"/>';
  86. rubikCubeHtml += '</div>';
  87. rubikCubeHtml += '</li>';
  88. rubikCubeHtml += '</ul>';
  89. rubikCubeHtml += '<div class="image-ad-list" v-if="currentList.length>0 && currentIndex<currentList.length">';
  90. rubikCubeHtml += '<ul>';
  91. rubikCubeHtml += '<li v-for="(li,i) in item.dimensionScale">';
  92. rubikCubeHtml += '<img-upload :data="{ data : currentList[i], callback : refreshDiyHtml, isShow:true }"></img-upload>';
  93. rubikCubeHtml += '<div class="content-block">';
  94. rubikCubeHtml += '<span style="padding-left: 2px;">{{li.name}}</span>';
  95. rubikCubeHtml += '<nc-link :data="{ field : $parent.data.list[i].link }" :callback="linkCallBack"></nc-link>';
  96. rubikCubeHtml += '<nc-image-mode :data="$parent.data.list[i]"></nc-image-mode>';
  97. rubikCubeHtml += '</div>';
  98. rubikCubeHtml += '</li>';
  99. rubikCubeHtml += '</ul>';
  100. rubikCubeHtml += '</div>';
  101. rubikCubeHtml += '</div>';
  102. // rubikCubeHtml += '<p class="word-aux">选定布局区域,在下方添加图片,建议添加比例一致的图片</p>';
  103. rubikCubeHtml += '</div>';
  104. rubikCubeHtml += '</div>';
  105. rubikCubeHtml += '</div>';
  106. Vue.component("rubik-cube", {
  107. props: {},
  108. data: function () {
  109. return {
  110. windowWidth: 375,
  111. //是否显示魔方密度
  112. isShowCustomRubikCube: false,
  113. //布局密度
  114. customRubikCube: this.$parent.data.customRubikCube,
  115. //自定义区域集合
  116. customRubikCubeArray: [],
  117. //已设定好的自定义区域集合
  118. selectedRubikCubeArray: this.$parent.data.selectedRubikCubeArray,
  119. //当前选中的布局下标
  120. selectIndex: 0,
  121. //控制魔方密度下拉框的显示隐藏
  122. isShowRubikCubeDensity: false,
  123. //可选择的魔方模板
  124. templateList: [],
  125. customRubikCubeList: [
  126. {value: 4, text: "4x4"},
  127. {value: 5, text: "5x5"},
  128. {value: 6, text: "6x6"},
  129. {value: 7, text: "7x7"}
  130. ],
  131. //当前编辑图片的链接地址
  132. currentIndex: 0,
  133. data: this.$parent.data,
  134. currentList: this.$parent.data.list,
  135. }
  136. },
  137. template: rubikCubeHtml,
  138. created: function () {
  139. this.initCustomRubikCubeArray();
  140. this.initTemplateList();
  141. this.calcRatio();
  142. if (!this.$parent.data.verify) this.$parent.data.verify = [];
  143. this.$parent.data.verify.push(this.verify);//加载验证方法
  144. this.$parent.data.ignore = ['textColor', 'elementBgColor'];//加载忽略内容 -- 其他设置中的属性设置
  145. this.$parent.data.ignoreLoad = true; // 等待忽略数组赋值后加载
  146. },
  147. methods: {
  148. //初始化自定义区域集合
  149. initCustomRubikCubeArray: function () {
  150. for (var i = 0; i < this.customRubikCube; i++) {
  151. for (var j = 0; j < this.customRubikCube; j++) {
  152. var obj = {
  153. coordinates: (i + 1) + ":" + (j + 1),
  154. row: (i + 1), //行
  155. column: (j + 1), //列
  156. selected: false, //是否已选择
  157. start: false, //开始
  158. finish: false, //是否已设定
  159. ranksNumber: "", //行列数量
  160. selectedCoordinates: [] //已选择的行列
  161. };
  162. this.customRubikCubeArray.push(obj);
  163. }
  164. }
  165. // console.log(JSON.stringify(this.customRubikCubeArray));
  166. },
  167. //初始化可选择的模板集合
  168. initTemplateList: function () {
  169. this.templateList.push({
  170. name: "1行2个",
  171. src: 'iconyihangliangge',
  172. className: "row1-of2",
  173. dimensionScale: [{desc: "宽度50%", size: "200px * 200px", name: "图一"}, {
  174. desc: "宽度50%",
  175. size: "200px * 200px",
  176. name: "图二"
  177. }],
  178. descAux: "选定布局区域,在下方添加图片,建议添加尺寸一致的图片,宽度最小建议为:200px"
  179. });
  180. this.templateList.push({
  181. name: "1行3个",
  182. src: 'iconyihangsange',
  183. className: "row1-of3",
  184. dimensionScale: [{desc: "宽度33.33%", size: "200px * 200px", name: "图一"}, {
  185. desc: "宽度33.33%",
  186. size: "200px * 200px",
  187. name: "图二"
  188. }, {desc: "宽度33.33%", size: "200px * 200px", name: "图三"}],
  189. descAux: "选定布局区域,在下方添加图片,建议添加尺寸一致的图片,宽度最小建议为:130px"
  190. });
  191. this.templateList.push({
  192. name: "1行4个",
  193. src: 'iconyihangsige',
  194. className: "row1-of4",
  195. dimensionScale: [{desc: "宽度25%", size: "200px * 200px", name: "图一"}, {
  196. desc: "宽度25%",
  197. size: "200px * 200px",
  198. name: "图二"
  199. }, {desc: "宽度25%", size: "200px * 200px", name: "图三"}, {
  200. desc: "宽度25%",
  201. size: "200px * 200px",
  202. name: "图四"
  203. },],
  204. descAux: "选定布局区域,在下方添加图片,建议添加尺寸一致的图片,宽度最小建议为:100px"
  205. });
  206. this.templateList.push({
  207. name: "2左2右",
  208. src: 'iconmofang-liangzuoliangyou',
  209. className: "row2-lt-of2-rt",
  210. dimensionScale: [{desc: "宽度50%", size: "200px * 200px", name: "图一"}, {
  211. desc: "宽度50%",
  212. size: "200px * 200px",
  213. name: "图二"
  214. }, {desc: "宽度50%", size: "200px * 200px", name: "图三"}, {
  215. desc: "宽度50%",
  216. size: "200px * 200px",
  217. name: "图四"
  218. }],
  219. descAux: "选定布局区域,在下方添加图片,建议添加尺寸一致的图片,宽度最小建议为:200px"
  220. });
  221. this.templateList.push({
  222. name: "1左2右",
  223. src: 'iconmofang-yizuoliangyou',
  224. className: "row1-lt-of2-rt",
  225. dimensionScale: [{desc: "宽度50% * 高度100%", size: "200px * 400px", name: "图一"}, {
  226. desc: "宽度50% * 高度50%",
  227. size: "200px * 200px",
  228. name: "图二"
  229. }, {desc: "宽度50% * 高度50%", size: "200px * 200px", name: "图三"}],
  230. descAux: "选定布局区域,在下方添加图片,宽度最小建议为:200px,右侧两张图片高度一致,左侧图片高度为右侧两张图片高度之和(例:左侧图片尺寸:200px * 300px,右侧两张图片尺寸:200px * 150px)"
  231. });
  232. this.templateList.push({
  233. name: "1上2下",
  234. src: 'iconmofang-yishangliangxia',
  235. className: "row1-tp-of2-bm",
  236. dimensionScale: [{desc: "宽度100% * 高度50%", size: "400px * 200px", name: "图一"}, {
  237. desc: "宽度50% * 高度50%",
  238. size: "200px * 200px",
  239. name: "图二"
  240. }, {desc: "宽度50% * 高度50%", size: "200px * 200px", name: "图三"}],
  241. descAux: "选定布局区域,在下方添加图片,上方一张图片的宽度为下方两张图片宽度之和,下放两张图片尺寸一致,高度可根据实际需求自行确定(例:上方图片尺寸:400px * 150px,下方两张图片尺寸:200px * 150px)"
  242. });
  243. this.templateList.push({
  244. name: "1左3右",
  245. src: 'iconxuanzemoban-yizuosanyou',
  246. className: "row1-lt-of1-tp-of2-bm",
  247. dimensionScale: [{desc: "宽度50% * 高度100%", size: "200px * 400px", name: "图一"}, {
  248. desc: "宽度50% * 高度50%",
  249. size: "200px * 200px",
  250. name: "图二"
  251. }, {desc: "宽度25% * 高度50%", size: "100px * 200px", name: "图三"}, {
  252. desc: "宽度25% * 高度50%",
  253. size: "100px * 200px",
  254. name: "图四"
  255. }],
  256. descAux: "选定布局区域,在下方添加图片,左右两侧内容宽高相同,右侧上下区域高度各占50%,右侧内容下半部分两张图片的宽度相同,各占右侧内容宽度的50%(例:左侧图片尺寸:200px * 400px,右侧上半部分图片尺寸:200px * 200px,右侧下半部分两张图片尺寸:100px * 200px)"
  257. });
  258. // this.templateList.push({ name : "自定义", src : prefix + "/rubik_cube_diy.png", className : "custom-rubik-cube", dimensionScale : [] });
  259. //初始化加载时
  260. for (var i = 0; i < this.templateList.length; i++) {
  261. if (this.templateList[i].className == this.$parent.data.mode) {
  262. //判断当前选中模板是否为自定义区域,然后进行特殊处理
  263. if (this.templateList[i].dimensionScale.length == 0) {
  264. this.isShowCustomRubikCube = true;//显示自定义
  265. }
  266. }
  267. }
  268. },
  269. //切换选中模板
  270. changeTemplateList: function (v) {
  271. this.isShowCustomRubikCube = false;
  272. for (var i = 0; i < this.templateList.length; i++) {
  273. if (i == v) {
  274. this.$parent.data.mode = this.templateList[i].className;
  275. //自定义区域特殊处理
  276. if (this.templateList[i].dimensionScale.length == 0) {
  277. this.isShowCustomRubikCube = true;
  278. //清空链接地址的数据
  279. this.currentList.length = 0;
  280. this.selectedRubikCubeArray.length = 0;
  281. } else {
  282. var count = this.templateList[i].dimensionScale.length;
  283. //重置当前编辑的图片集合
  284. //数量不够,进行添加
  285. if (count > this.currentList.length) {
  286. for (var j = 0; j < count; j++) {
  287. if ((j + 1) > this.currentList.length) this.currentList.push({
  288. imageUrl: "",
  289. imgWidth: 0,
  290. imgHeight: 0,
  291. previewWidth: 0,
  292. previewHeight: 0,
  293. link: {name: ""}
  294. });
  295. }
  296. } else {
  297. //数量不相同时,并且数量超出,减去
  298. if (count != this.currentList.length) {
  299. for (var j = 0; j < this.currentList.length; j++) {
  300. if ((j + 1) > count) {
  301. this.currentList.splice(j, 1);
  302. j = 0;
  303. }
  304. }
  305. //设置当前选中为最后一个
  306. this.currentIndex = this.currentList.length - 1;
  307. }
  308. }
  309. }
  310. }
  311. }
  312. this.templateList.push({});
  313. this.templateList.pop();
  314. this.calcRatio();
  315. },
  316. //选中当前编辑的布局
  317. changeCurrentIndex: function (index) {
  318. this.currentIndex = index;
  319. },
  320. calcRatio: function () {
  321. var singleRow = {
  322. 'row1-of2': {
  323. ratio: 2,
  324. width: '50%'
  325. },
  326. 'row1-of3': {
  327. ratio: 3,
  328. width: '33.33%'
  329. },
  330. 'row1-of4': {
  331. ratio: 4,
  332. width: '25%'
  333. }
  334. };
  335. if (singleRow[this.data.mode]) {
  336. this.calcSingleRow(singleRow[this.data.mode]);
  337. } else if (this.data.mode == 'row2-lt-of2-rt') {
  338. this.calcFourSquare();
  339. } else if (this.data.mode == 'row1-lt-of2-rt') {
  340. this.calcRowOneLeftOfTwoRight();
  341. } else if (this.data.mode == 'row1-tp-of2-bm') {
  342. this.calcRowOneTopOfTwoBottom();
  343. } else if (this.data.mode == 'row1-lt-of1-tp-of2-bm') {
  344. this.calcRowOneLeftOfOneTopOfTwoBottom();
  345. }
  346. },
  347. /**
  348. * 魔方:单行多个,平分宽度
  349. * 公式:
  350. * 宽度:屏幕宽度/2,示例:375/2=187.5
  351. * 比例:原图高/原图宽,示例:322/690=0.46
  352. * 高度:宽度*比例,示例:187.5*0.46=86.25
  353. */
  354. calcSingleRow: function (params) {
  355. let maxHeight = 0;
  356. this.currentList.forEach((item, index) => {
  357. let ratio = item.imgHeight / item.imgWidth; // 获取原图比例
  358. if (isNaN(ratio)) ratio = 0;
  359. let width = this.windowWidth - (this.data.margin.both * 2); // 减去左右间距
  360. if (this.data.imageGap > 0) {
  361. width -= params.ratio * this.data.imageGap ; // 减去间隙
  362. }
  363. item.previewWidth = width / params.ratio;
  364. item.previewHeight = item.previewWidth * ratio;
  365. // 获取最大高度
  366. if (maxHeight == 0 || maxHeight < item.previewHeight) maxHeight = item.previewHeight;
  367. });
  368. this.currentList.forEach((item, index) => {
  369. item.previewHeight = item.previewHeight.toFixed(2);
  370. item.previewHeight = maxHeight + 'px';
  371. });
  372. },
  373. /**
  374. * 魔方:四方型,各占50%
  375. */
  376. calcFourSquare: function () {
  377. let maxHeightFirst = 0;
  378. let maxHeightTwo = 0;
  379. this.currentList.forEach((item, index) => {
  380. var ratio = item.imgHeight / item.imgWidth; // 获取原图比例
  381. if (isNaN(ratio)) ratio = 0;
  382. item.previewWidth = this.windowWidth / 2;
  383. item.previewWidth -= this.data.margin.both * 2;
  384. item.previewHeight = item.previewWidth * ratio;
  385. // 获取每行最大高度
  386. if (index <= 1) {
  387. if (maxHeightFirst == 0 || maxHeightFirst < item.previewHeight) {
  388. maxHeightFirst = item.previewHeight;
  389. }
  390. } else if (index > 1) {
  391. if (maxHeightTwo == 0 || maxHeightTwo < item.previewHeight) {
  392. maxHeightTwo = item.previewHeight;
  393. }
  394. }
  395. });
  396. this.currentList.forEach((item, index) => {
  397. item.previewHeight = item.previewHeight.toFixed(2);
  398. if (index <= 1) {
  399. item.previewHeight = maxHeightFirst + 'px';
  400. } else if (index > 1) {
  401. item.previewHeight = maxHeightTwo + 'px';
  402. }
  403. });
  404. },
  405. /**
  406. * 魔方:1左2右
  407. * 如果右侧2图宽度一致,则
  408. */
  409. calcRowOneLeftOfTwoRight: function () {
  410. let rightHeight = 0; // 右侧两图平分高度
  411. let divide = 'left'; // 划分规则,left:左,right:右
  412. if (this.currentList[1].imgWidth === this.currentList[2].imgWidth) divide = 'right';
  413. this.currentList.forEach((item, index) => {
  414. if (index === 0) {
  415. var ratio = item.imgHeight / item.imgWidth; // 获取左图的尺寸比例
  416. if (isNaN(ratio)) ratio = 0;
  417. item.previewWidth = this.windowWidth / 2;
  418. item.previewWidth -= this.data.margin.both * 2;
  419. item.previewHeight = item.previewWidth * ratio;
  420. rightHeight = item.previewHeight / 2;
  421. } else {
  422. item.previewWidth = this.currentList[0].previewWidth;
  423. item.previewHeight = rightHeight;
  424. }
  425. });
  426. this.currentList.forEach((item, index) => {
  427. if (index == 0) {
  428. item.previewHeight += (this.data.imageGap);
  429. }
  430. item.previewHeight = item.previewHeight.toFixed(2);
  431. item.previewHeight += 'px';
  432. });
  433. },
  434. /**
  435. * 魔方:1上2下
  436. */
  437. calcRowOneTopOfTwoBottom: function () {
  438. var maxHeight = 0;
  439. this.currentList.forEach((item, index) => {
  440. var ratio = item.imgHeight / item.imgWidth; // 获取左图的尺寸比例
  441. if (isNaN(ratio)) ratio = 0;
  442. if (index == 0) item.previewWidth = this.windowWidth;
  443. else if (index > 0) item.previewWidth = this.windowWidth / 2;
  444. item.previewWidth -= this.data.margin.both * 2;
  445. item.previewHeight = item.previewWidth * ratio;
  446. // 获取最大高度
  447. if (index > 0 && (maxHeight == 0 || maxHeight < item.previewHeight)) maxHeight = item.previewHeight.toFixed(2);
  448. });
  449. this.currentList.forEach((item, index) => {
  450. item.previewWidth += 'px';
  451. if (index > 0) {
  452. item.previewHeight = maxHeight + 'px';
  453. } else {
  454. item.previewHeight = item.previewHeight.toFixed(2);
  455. item.previewHeight += 'px';
  456. }
  457. });
  458. },
  459. /**
  460. * 魔方:1左3右
  461. */
  462. calcRowOneLeftOfOneTopOfTwoBottom: function () {
  463. this.currentList.forEach((item, index) => {
  464. // 左图
  465. if (index == 0) {
  466. var ratio = item.imgHeight / item.imgWidth; // 获取原图比例
  467. if (isNaN(ratio)) ratio = 0;
  468. item.previewWidth = this.windowWidth / 2;
  469. item.previewWidth -= this.data.margin.both;
  470. item.previewHeight = item.previewWidth * ratio;
  471. } else if (index == 1) {
  472. item.previewWidth = this.windowWidth / 2;
  473. item.previewWidth -= this.data.margin.both;
  474. item.previewHeight = this.currentList[0].previewHeight / 2;
  475. } else if (index > 1) {
  476. item.previewWidth = this.currentList[0].previewWidth / 2;
  477. item.previewHeight = this.currentList[0].previewHeight / 2;
  478. }
  479. });
  480. this.currentList.forEach((item, index) => {
  481. if (index == 0) {
  482. item.previewHeight += (this.data.imageGap);
  483. }
  484. item.previewHeight = item.previewHeight.toFixed(2);
  485. item.previewHeight += 'px';
  486. });
  487. },
  488. //自定义魔方区域点击事件
  489. customRubikCubeClick: function (position) {
  490. if (this.customRubikCubeArray[position].start && !this.customRubikCubeArray[position].selected) {
  491. // console.log("当前操作还没有结束,不能继续操作哦");
  492. return;
  493. }
  494. //再次点击确定
  495. if (this.customRubikCubeArray[position].selected) {
  496. var ranksNumber = "";
  497. var selectedCoordinates = "";
  498. var positionXY = "";
  499. for (var i = 0; i < this.customRubikCubeArray.length; i++) {
  500. if (this.customRubikCubeArray[i].selected && this.customRubikCubeArray[i].start) {
  501. ranksNumber = this.customRubikCubeArray[i].ranksNumber;//行列数量
  502. selectedCoordinates = this.customRubikCubeArray[i].selectedCoordinates;//已选中的坐标集合
  503. }
  504. if (this.customRubikCubeArray[i].selected && !this.customRubikCubeArray[i].finish) {
  505. if (positionXY == "") positionXY = $(this.$refs.rubikCube[i]).position();
  506. }
  507. }
  508. var rowCount = ranksNumber.split(":")[0];//选中的总行数
  509. var columnCount = ranksNumber.split(":")[1];//选中的总列数
  510. //按照百分比计算宽高
  511. var width = (100 / this.customRubikCube) * columnCount;
  512. var height = (100 / this.customRubikCube) * rowCount;
  513. //left值采用百分比计算,公式:(同一行中当前魔方位置之前的宽度总和)
  514. //公式:(当前列-1) * (100/魔方密度)
  515. var left = (selectedCoordinates[0].split(":")[1] - 1) * (100 / this.customRubikCube);
  516. //1:4 2:4 第四列 left = (4-1)*25 = 75
  517. //3:3 4:3 第三列 left = (3-1)*25 = 50
  518. //3:2 3:3 4:2 4:3 第二列、第三列
  519. //2:3 2:4 3:3 3:4 第三列、第四列
  520. //1:3 1:4 2:3 2:4 3:3 3:4 4:3 4:4 第三列、第四列
  521. var selectedRubikCube = {
  522. proportion: rowCount + ":" + columnCount,
  523. selected: true,
  524. top: positionXY.top + "px",
  525. left: left + "%",
  526. width: (width + 0.0) + "%",
  527. height: (height + 0.0) + "%",
  528. lineHeight: 0 + "px",
  529. selectedCoordinates: selectedCoordinates
  530. };
  531. for (var i = 0; i < this.selectedRubikCubeArray.length; i++) {
  532. this.selectedRubikCubeArray[i].selected = false;
  533. }
  534. this.selectedRubikCubeArray.push(selectedRubikCube);
  535. for (var i = 0; i < this.customRubikCubeArray.length; i++) {
  536. //将当前选中的设置为已完成(表示不可操作了)
  537. if (this.customRubikCubeArray[i].selected) {
  538. this.customRubikCubeArray[i].finish = true;
  539. }
  540. //删除开始位置
  541. if (this.customRubikCubeArray[i].selected && this.customRubikCubeArray[i].start) {
  542. this.customRubikCubeArray[i].start = false;
  543. }
  544. }
  545. this.currentList.push({imageUrl: "", link: {name: ""}});
  546. //默认选择当前添加的下标
  547. this.changeCurrentIndex(this.currentList.length - 1);
  548. // console.log(JSON.stringify(this.currentList));
  549. // console.log(JSON.stringify(this.selectedRubikCubeArray));
  550. //计算当前添加的自定义魔方区域的行高,用于将图片进行垂直居中
  551. setTimeout(function () {
  552. selectedRubikCube.lineHeight = $(".draggable-element.selected .rubik-cube .layout div.selected-rubik-cube.selected").outerHeight() + "px";
  553. }, 100);
  554. } else {
  555. //设置当前自定义模块的开始位置,并且设定好它可以如何选中
  556. for (var i = 0; i < this.customRubikCubeArray.length; i++) {
  557. if (i == position) {
  558. this.customRubikCubeArray[i].start = true;
  559. this.customRubikCubeArray[i].selected = true;
  560. } else {
  561. this.customRubikCubeArray[i].start = false;
  562. }
  563. }
  564. }
  565. },
  566. //自定义魔方区域
  567. customRubikCubeMouseMove: function (position) {
  568. //当前坐标
  569. var currentMoveCoordinates = this.customRubikCubeArray[position].coordinates;
  570. var coordinates = "";
  571. for (var i = 0; i < this.customRubikCubeArray.length; i++) {
  572. //找到开始位置
  573. if (this.customRubikCubeArray[i].selected && this.customRubikCubeArray[i].start) {
  574. coordinates = this.customRubikCubeArray[i].coordinates;
  575. break;
  576. }
  577. }
  578. //清空
  579. for (var j = 0; j < this.customRubikCubeArray.length; j++) {
  580. if (this.customRubikCubeArray[j].coordinates != coordinates && !this.customRubikCubeArray[j].finish) {
  581. this.customRubikCubeArray[j].selected = false;
  582. }
  583. }
  584. if (coordinates != "") {
  585. //开始行列
  586. var rowStart = coordinates.split(":")[0];
  587. var columnStart = coordinates.split(":")[1];
  588. //结束行列
  589. var rowEnd = parseInt(currentMoveCoordinates.split(":")[0]);
  590. var columnEnd = parseInt(currentMoveCoordinates.split(":")[1]);
  591. var tempRow = rowStart;
  592. //如果开始行大于结束行,则开始行用结束行,结束行用开始行
  593. if (rowStart > rowEnd) {
  594. rowStart = rowEnd;
  595. rowEnd = tempRow;
  596. }
  597. var tempColumn = columnStart;
  598. //如果开始列大于结束列,则开始列用结束列,结束列用开始列
  599. if (columnStart > columnEnd) {
  600. columnStart = columnEnd;
  601. columnEnd = tempColumn;
  602. }
  603. var rowCount = 0; //总行数
  604. var columnCount = new Array(); //总列数
  605. var isAdd = true;
  606. var selectedCoordinates = new Array();
  607. //遍历行
  608. for (rowStart; rowStart <= rowEnd; rowStart++) {
  609. rowCount++;
  610. //遍历列
  611. for (var i = columnStart; i <= columnEnd; i++) {
  612. //当前行列坐标
  613. var currentCoordinates = rowStart + ":" + i;
  614. //检测当前的模块是否被占用,如果被占用,那么整个都不能选择
  615. for (var j = 0; j < this.customRubikCubeArray.length; j++) {
  616. if (this.customRubikCubeArray[j].coordinates == currentCoordinates && this.customRubikCubeArray[j].finish) {
  617. isAdd = false;
  618. break;
  619. }
  620. }
  621. if ($.inArray(i, columnCount) == -1) columnCount.push(i);
  622. selectedCoordinates.push(currentCoordinates);
  623. for (var j = 0; j < this.customRubikCubeArray.length; j++) {
  624. if (this.customRubikCubeArray[j].coordinates == currentCoordinates) {
  625. this.customRubikCubeArray[j].selected = true;
  626. }
  627. }
  628. }
  629. }
  630. if (!isAdd) {
  631. for (var j = 0; j < this.customRubikCubeArray.length; j++) {
  632. if (this.customRubikCubeArray[j].selected && !this.customRubikCubeArray[j].finish) {
  633. this.customRubikCubeArray[j].selected = false;
  634. }
  635. }
  636. for (var j = 0; j < this.customRubikCubeArray.length; j++) {
  637. if (this.customRubikCubeArray[j].start) {
  638. this.customRubikCubeArray[j].selected = true;
  639. }
  640. }
  641. }
  642. for (var j = 0; j < this.customRubikCubeArray.length; j++) {
  643. if (this.customRubikCubeArray[j].selected && this.customRubikCubeArray[j].start) {
  644. this.customRubikCubeArray[j].ranksNumber = rowCount + ":" + columnCount.length;
  645. this.customRubikCubeArray[j].selectedCoordinates = selectedCoordinates;
  646. }
  647. }
  648. this.customRubikCubeArray.push({});
  649. this.customRubikCubeArray.pop();
  650. }
  651. },
  652. //点击已设定好的自定义区域
  653. selectedRubikCubeClick: function (position) {
  654. for (var i = 0; i < this.selectedRubikCubeArray.length; i++) {
  655. if (i == position) {
  656. this.selectedRubikCubeArray[i].selected = true;
  657. } else {
  658. this.selectedRubikCubeArray[i].selected = false;
  659. }
  660. }
  661. this.changeCurrentIndex(position);
  662. },
  663. //删除已设定好的自定义区域
  664. deleteSelectedRubikCubeClick: function (position) {
  665. var selectedCoordinates = this.selectedRubikCubeArray[position].selectedCoordinates;
  666. for (var i = 0; i < selectedCoordinates.length; i++) {
  667. for (var j = 0; j < this.customRubikCubeArray.length; j++) {
  668. if (this.customRubikCubeArray[j].coordinates == selectedCoordinates[i]) {
  669. this.customRubikCubeArray[j].selected = false;
  670. this.customRubikCubeArray[j].finish = false;
  671. this.customRubikCubeArray[j].ranksNumber = "";
  672. }
  673. }
  674. }
  675. this.currentList.splice(position, 1);
  676. //删除后应该选择最后一个
  677. this.changeCurrentIndex(this.currentList.length - 1);
  678. for (var i = 0; i < this.selectedRubikCubeArray.length; i++) {
  679. if (this.currentIndex == i) {
  680. this.selectedRubikCubeArray[i].selected = true;
  681. break;
  682. }
  683. }
  684. this.customRubikCubeArray.push({});
  685. this.customRubikCubeArray.pop();
  686. this.selectedRubikCubeArray.splice(position, 1);
  687. },
  688. //刷新自定义区域Html代码
  689. refreshDiyHtml: function () {
  690. this.calcRatio();
  691. if (this.isShowCustomRubikCube) {
  692. var self = this;
  693. setTimeout(function () {
  694. var height = $(".draggable-element.selected .rubik-cube .layout div.selected-rubik-cube.have-image").parent().outerHeight() + "px";
  695. var diy = $(".draggable-element.selected .rubik-cube .layout div.selected-rubik-cube.have-image").clone();
  696. var diyHtml = '<div style="background:#ffffff;height:' + height + ';">';
  697. diy.each(function () {
  698. $(this).find(".del").remove();
  699. $(this).find("span").remove();
  700. diyHtml += $(this).prop("outerHTML");
  701. });
  702. diyHtml += "</div>";
  703. self.$parent.data.diyHtml = diyHtml.replace(/"/g, "&quot;").replace(/z-index: 1/g, "");
  704. }, 100);
  705. }
  706. },
  707. //监听链接地址回调,更新diyHtml
  708. linkCallBack: function (index) {
  709. this.refreshDiyHtml();
  710. },
  711. verify: function (index) {
  712. var res = {code: true, message: ""};
  713. if (vue.data[index].mode === "custom-rubik-cube") {
  714. //自定义魔方,不能有空缺
  715. var customRubikCubeArray = new Array();
  716. var selectedCount = 0;//选择数量
  717. for (var i = 0; i < this.customRubikCube; i++) {
  718. for (var j = 0; j < this.customRubikCube; j++) {
  719. customRubikCubeArray.push((i + 1) + ":" + (j + 1));
  720. }
  721. }
  722. for (var i = 0; i < this.customRubikCube; i++) {
  723. for (var j = 0; j < this.customRubikCube; j++) {
  724. customRubikCubeArray.push((i + 1) + ":" + (j + 1));
  725. }
  726. }
  727. for (var i = 0; i < customRubikCubeArray.length; i++) {
  728. for (var j = 0; j < this.selectedRubikCubeArray.length; j++) {
  729. var selectedCoordinates = this.selectedRubikCubeArray[j].selectedCoordinates;
  730. for (var k = 0; k < selectedCoordinates.length; k++) {
  731. if (customRubikCubeArray[i] == selectedCoordinates[k]) {
  732. selectedCount++;
  733. }
  734. }
  735. }
  736. }
  737. if (selectedCount != customRubikCubeArray.length) {
  738. res.code = false;
  739. res.message = "自定义魔方必须填满,不能有空缺哦";
  740. }
  741. }
  742. for (var i = 0; i < this.currentList.length; i++) {
  743. var item = this.currentList[i];
  744. if (!item.imageUrl) {
  745. res.code = false;
  746. res.message = "请上传图片";
  747. break;
  748. }
  749. }
  750. return res;
  751. },
  752. customRubikCubeFn(item,index){
  753. this.customRubikCube=item.value;
  754. this.isShowRubikCubeDensity=false;
  755. this.selectIndex=index;
  756. //自定义区域集合
  757. this.customRubikCubeArray.splice(0, this.customRubikCubeArray.length);
  758. this.selectedRubikCubeArray.splice(0, this.selectedRubikCubeArray.length);
  759. this.initCustomRubikCubeArray();
  760. }
  761. },
  762. watch: {
  763. /**
  764. * 监听集合,更新自定义区域Html代码
  765. */
  766. currentList: function () {
  767. this.refreshDiyHtml();
  768. }
  769. }
  770. });