design.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /**
  2. * 图片广告的图片上传
  3. */
  4. var imageAdsCarouselHtml = '<div style="display:none;"></div>';
  5. Vue.component("image-ads-carouse", {
  6. data: function () {
  7. return {
  8. data: this.$parent.data
  9. }
  10. },
  11. created: function () {
  12. this.$parent.data.ignore = ['textColor', 'elementBgColor', 'elementAngle'];//加载忽略内容 -- 其他设置中的属性设置
  13. this.$parent.data.ignoreLoad = true; // 等待忽略数组赋值后加载
  14. // 组件所需的临时数据
  15. this.$parent.data.tempData = {
  16. swiperHeight: 0,
  17. carouselIndex: 0
  18. };
  19. var imgArr = [];
  20. for (let i = 0; i < this.data.list.length; i++) {
  21. let item = this.data.list[i];
  22. imgArr[i] = (item.imgWidth / item.imgHeight);
  23. }
  24. imgArr.sort(function (a, b) {
  25. return b - a
  26. });
  27. var swiperHeight = (370 / imgArr[0]).toFixed(2);
  28. this.$parent.data.tempData.swiperHeight = swiperHeight;
  29. },
  30. template: imageAdsCarouselHtml,
  31. watch: {
  32. data: {
  33. handler: function (val, oldVal) {
  34. // 计算图片高度
  35. var imgArr = [];
  36. for (let i = 0; i < this.data.list.length; i++) {
  37. let item = this.data.list[i];
  38. imgArr[i] = (item.imgWidth / item.imgHeight) || 2;
  39. }
  40. imgArr.sort(function (a, b) {
  41. return b - a
  42. });
  43. // 屏幕宽度
  44. var rootWidth = 370 - this.data.margin.both * 2;
  45. var swiperHeight = (rootWidth / imgArr[0]).toFixed(2);
  46. this.$parent.data.tempData.swiperHeight = swiperHeight;
  47. },
  48. deep: true
  49. }
  50. },
  51. methods: {}
  52. });
  53. var imageAdsListHtml = '<div style="display:none;"></div>';
  54. Vue.component("image-ads-list", {
  55. template: imageAdsListHtml,
  56. data: function () {
  57. return {
  58. data: this.$parent.data,
  59. list: this.$parent.data.list,
  60. imgAdsCarousel: [
  61. {
  62. text: "圆点",
  63. value: "circle",
  64. src: "iconyuandian",
  65. },
  66. {
  67. text: "直线",
  68. value: "line",
  69. src: "iconzhishiqi-yuanjiao",
  70. }
  71. ]
  72. }
  73. },
  74. created: function () {
  75. if (!this.$parent.data.verify) this.$parent.data.verify = [];
  76. this.$parent.data.verify.push(this.verify);//加载验证方法
  77. this.list.forEach(function (e, i) {
  78. if (!e.id) e.id = ns.gen_non_duplicate(6);
  79. });
  80. this.$parent.data.list = this.list;
  81. // 组件所需的临时数据
  82. this.$parent.data.tempData = {
  83. ...this.$parent.data.tempData,
  84. imgAdsCarousel: this.imgAdsCarousel,
  85. methods: {
  86. deleteItem: this.deleteItem,
  87. addItem: this.addItem,
  88. }
  89. };
  90. var moveBeforeIndex = 0;
  91. var _this = this;
  92. setTimeout(function () {
  93. var componentIndex = _this.data.index;
  94. $('[data-index="' + componentIndex + '"] .navigation-set-list').DDSort({
  95. target: 'li',
  96. floatStyle: {
  97. 'border': '1px solid #ccc',
  98. 'background-color': '#fff'
  99. },
  100. //设置可拖拽区域
  101. draggableArea: "icontuodong",
  102. down: function (index) {
  103. moveBeforeIndex = index;
  104. },
  105. up: function () {
  106. var index = $(this).index();
  107. var temp = _this.list[moveBeforeIndex];
  108. _this.list.splice(moveBeforeIndex, 1);
  109. _this.list.splice(index, 0, temp);
  110. _this.$parent.data.list = _this.list;
  111. }
  112. });
  113. });
  114. },
  115. methods: {
  116. verify: function (index) {
  117. var res = {code: true, message: ""};
  118. $(".draggable-element[data-index='" + index + "'] .image-ads .image-ad-list>ul>li").each(function (i) {
  119. if (vue.data[index].list[i].imageUrl === "") {
  120. res.code = false;
  121. res.message = "请添加图片";
  122. $(this).find(".error-msg").text("请添加图片").show();
  123. return res;
  124. } else {
  125. $(this).find(".error-msg").text("").hide();
  126. }
  127. });
  128. return res;
  129. },
  130. addItem: function () {
  131. this.list.push({
  132. imageUrl: "",
  133. imgWidth: 0,
  134. imgHeight: 0,
  135. link: {name: ""}
  136. });
  137. },
  138. deleteItem: function (index) {
  139. this.list.splice(index, 1);
  140. }
  141. }
  142. });