style.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. // 幻灯片·组件
  2. var sliderPreviewHtml = '<div v-bind:id="id" class="carousel" :class="{fillet: data.sliderRadius==\'fillet\'}" @mouseover="stopAuto" @mouseout="autoPlay">';
  3. sliderPreviewHtml += ' <div class="carousel-box" :style="{width:allCount,\'-webkit-transition\':transitionConfig,\'-webkit-transform\':slateX}" ref="carousel">';
  4. sliderPreviewHtml += ' <div class="carousel-item" :style="{\'-webkit-transform\':imgLateX}" v-if="loop">';
  5. sliderPreviewHtml += ' <img :src="list[list.length-1].imageUrl?list[list.length-1].imageUrl:\'/static/images/diy/crack_figure.png\'" />';
  6. sliderPreviewHtml += ' </div>';
  7. sliderPreviewHtml += ' <div class="carousel-item" v-for="(item,index) in list" :style="{\'-webkit-transform\':getImgLateX(index)}">';
  8. sliderPreviewHtml += ' <img :src="item.imageUrl?item.imageUrl:\'/static/images/diy/crack_figure.png\'" />';
  9. sliderPreviewHtml += ' </div>';
  10. sliderPreviewHtml += ' <div class="carousel-item" :style="{\'-webkit-transform\':endImgLateX}" v-if="loop">';
  11. sliderPreviewHtml += ' <img :src="list[0].imageUrl?list[0].imageUrl:\'/static/images/diy/crack_figure.png\'" />';
  12. sliderPreviewHtml += ' </div>';
  13. sliderPreviewHtml += ' </div>';
  14. sliderPreviewHtml += ' <div class="carousel-dots" v-if="dots">';
  15. sliderPreviewHtml += ' <button v-for="(item,index) in list.length" :key="index" @click="toDots(index)" v-bind:style="{ background: index==dotsIndex?data.textColor:\'#E7E9E7\'}"></button>';
  16. sliderPreviewHtml += ' </div>';
  17. sliderPreviewHtml += '</div>';
  18. Vue.component("slider", {
  19. data: function () {
  20. return {
  21. id: "slider_" + get_math_rant(10),
  22. data: this.$parent.data,
  23. list: this.$parent.data.list,
  24. selectedTemplate: this.$parent.data.selectedTemplate,
  25. // 图片宽
  26. imgWidth: 343,
  27. // 指示器
  28. dots: true,
  29. arrow: true,
  30. // 初始播放位置
  31. initIndex: 0,
  32. // 是否循环
  33. loop: true,
  34. // 持续时间
  35. duration: 0.3,
  36. // 自动播放
  37. auto: true,
  38. // 自动播放时间间隔
  39. autoTime: 2000,
  40. imgIndex: 0,
  41. durationTime: 0.2,
  42. dotsIndex: 0,
  43. autoer: null,
  44. }
  45. },
  46. computed: {
  47. allCount() {
  48. return (this.list.length * this.imgWidth) + 'px';
  49. },
  50. slateX() {
  51. return 'translate3d(' + (-this.imgIndex * this.imgWidth) + 'px,0,0)'
  52. },
  53. transitionConfig() {
  54. return 'all ' + this.durationTime + 's';
  55. },
  56. imgLateX() {
  57. let width = -this.imgWidth
  58. return 'translate3d(' + (width) + 'px,0,0)'
  59. },
  60. endImgLateX() {
  61. let width = this.list.length
  62. return 'translate3d(' + (width) + 'px,0,0)'
  63. }
  64. },
  65. created: function () {
  66. if (!this.$parent.data.verify) this.$parent.data.verify = [];
  67. this.$parent.data.verify.push(this.verify); //加载验证方法
  68. this.imgIndex = this.dotsIndex = this.initIndex;
  69. this.durationTime = this.duration;
  70. if (this.auto) this.autoPlay();
  71. },
  72. watch: {
  73. list : function(val, oldval){
  74. console.log(val)
  75. console.log(oldval)
  76. },
  77. },
  78. methods: {
  79. verify: function () {
  80. var res = {
  81. code: true,
  82. message: ""
  83. };
  84. return res;
  85. },
  86. getImgLateX(i) {
  87. let width = this.imgWidth * (i + 1)
  88. return 'translate3d(' + (width) + 'px,0,0)'
  89. },
  90. toLeft() {
  91. if (this.loop) {
  92. this.imgIndex--;
  93. this.dotsIndex--;
  94. if (this.dotsIndex <= -1) this.dotsIndex = this.list.length - 1;
  95. if (this.imgIndex <= -2) this.loopFn('left');
  96. } else {
  97. if (this.imgIndex == 0) return this.dotsIndex = this.imgIndex = this.list.length - 1;
  98. this.imgIndex--;
  99. this.dotsIndex--;
  100. }
  101. },
  102. toRight() {
  103. if (this.loop) {
  104. this.imgIndex++;
  105. this.dotsIndex++;
  106. if (this.dotsIndex == this.list.length) this.dotsIndex = 0;
  107. if (this.imgIndex == this.list.length + 1) this.loopFn('right');
  108. } else {
  109. this.imgIndex++;
  110. this.dotsIndex++;
  111. if (this.imgIndex > this.list.length - 1) return this.dotsIndex = this.imgIndex = 0;
  112. }
  113. },
  114. loopFn(type) {
  115. const dur = this.durationTime;
  116. this.durationTime = 0;
  117. this.imgIndex = type == 'right' ? 0 : this.list.length - 1;
  118. setTimeout(() => {
  119. this.$nextTick(function () {
  120. this.durationTime = dur;
  121. if (type == 'right') this.imgIndex++;
  122. else this.imgIndex--;
  123. })
  124. }, 30)
  125. },
  126. toDots(index) {
  127. this.dotsIndex = this.imgIndex = index;
  128. },
  129. autoPlay() {
  130. if (this.auto) {
  131. clearInterval(this.autoer);
  132. this.autoer = setInterval(() => {
  133. this.toRight();
  134. }, this.autoTime)
  135. }
  136. },
  137. stopAuto() {
  138. if (this.auto) return clearInterval(this.autoer);
  139. }
  140. },
  141. template: sliderPreviewHtml
  142. });
  143. /**
  144. * [图片导航的图片]·组件
  145. */
  146. var sliderListHtml = '<div class="slider-list">';
  147. sliderListHtml += '<div class="template-edit-wrap">';
  148. sliderListHtml += '<ul>';
  149. sliderListHtml += '<p class="hint">建议上传尺寸相同的图片(710px * 320px)</p>';
  150. sliderListHtml += '<li v-for="(item,index) in list" v-bind:key="index">';
  151. sliderListHtml += '<img-sec-upload v-bind:data="{ data: item }" v-bind:condition="$parent.data.selectedTemplate == \'imageNavigation\'"></img-sec-upload>';
  152. sliderListHtml += '<div class="content-block" v-bind:class="$parent.data.selectedTemplate">';
  153. sliderListHtml += '<sel-link v-bind:data="{ field : $parent.data.list[index].link }"></sel-link>';
  154. sliderListHtml += '</div>';
  155. sliderListHtml += '<i class="del" v-on:click="list.splice(index,1)" data-disabled="1">x</i>';
  156. sliderListHtml += '<div class="error-msg"></div>';
  157. sliderListHtml += '</li>';
  158. sliderListHtml += '<div v-if="showAddItem" class="add-item ns-text-color" v-on:click="list.push({ imageUrl : \'\', title : \'\', link : {} })">';
  159. sliderListHtml += '<i>+</i>';
  160. sliderListHtml += '<span>添加一张图片</span>';
  161. sliderListHtml += '</div>';
  162. sliderListHtml += '</ul>';
  163. sliderListHtml += '</div>';
  164. sliderListHtml += '<div class="template-edit-wrap">';
  165. sliderListHtml += '<color v-bind:data="{ defaultcolor: \'#666666\', label : \'选中颜色\' }"></color>';
  166. sliderListHtml += '<slider-radius></slider-radius>';
  167. sliderListHtml += '</div>';
  168. sliderListHtml += '<div class="template-edit-title">';
  169. sliderListHtml += '<h3>其他设置</h3>';
  170. sliderListHtml += '<i class="layui-icon layui-icon-down" onclick="closeBox(this)"></i>';
  171. sliderListHtml += '</div>';
  172. sliderListHtml += '<div class="template-edit-wrap">';
  173. sliderListHtml += '<color v-bind:data="{ field : \'backgroundColor\', label : \'背景颜色\' }"></color>';
  174. sliderListHtml += '<div class="text-slide">';
  175. sliderListHtml += '<slide v-bind:data="{ field : \'marginTop\', label : \'页面间距\' }"></slide>';
  176. sliderListHtml += '</div>';
  177. sliderListHtml += '</div>';
  178. sliderListHtml += '</div>';
  179. Vue.component("slider-list", {
  180. data: function () {
  181. return {
  182. data: this.$parent.data,
  183. showAddItem: true,
  184. list: this.$parent.data.list,
  185. imageScale: this.$parent.data.imageScale,
  186. padding: this.$parent.data.padding,
  187. maxTip: 5, //最大上传数量提示
  188. selectedTemplate: this.$parent.data.selectedTemplate,
  189. scrollSettingList: [{
  190. name: "固定",
  191. value: "fixed",
  192. max: 5
  193. }],
  194. };
  195. },
  196. created: function () {
  197. this.changeShowAddItem();
  198. if (!this.$parent.data.verify) this.$parent.data.verify = [];
  199. this.$parent.data.verify.push(this.verify); //加载验证方法
  200. },
  201. watch: {
  202. list: function () {
  203. this.changeShowAddItem();
  204. }
  205. },
  206. methods: {
  207. //改变图文导航按钮的显示隐藏
  208. changeShowAddItem: function () {
  209. if (this.list.length >= this.scrollSettingList[0].max) this.showAddItem = false;
  210. else this.showAddItem = true;
  211. this.maxTip = this.scrollSettingList[0].max;
  212. },
  213. //改变上下边距
  214. changePadding: function (event) {
  215. var v = event.target.value;
  216. if (v != "") {
  217. if (v >= 0 && v <= 100) {
  218. this.padding = v;
  219. this.$parent.data.padding = this.padding; //更新父级对象
  220. } else {
  221. layer.msg("请输入合法数字0~100");
  222. }
  223. } else {
  224. layer.msg("请输入合法数字0~100");
  225. }
  226. },
  227. verify: function () {
  228. var res = {
  229. code: true,
  230. message: ""
  231. };
  232. var _self = this;
  233. $(".draggable-element[data-index='" + this.data.index + "'] .slider .slider-list .template-edit-wrap>ul>li").each(function (index) {
  234. if (_self.selectedTemplate == "imageNavigation") {
  235. $(this).find("input[name='title']").removeAttr("style"); //清空输入框的样式
  236. //检测是否有未上传的图片
  237. if (_self.list[index].imageUrl == "") {
  238. res.code = false;
  239. res.message = "请选择一张图片";
  240. $(this).find(".error-msg").text("请选择一张图片").show();
  241. return res;
  242. } else {
  243. $(this).find(".error-msg").text("").hide();
  244. }
  245. } else {
  246. if (_self.list[index].title == "") {
  247. res.code = false;
  248. res.message = "请输入标题";
  249. $(this).find("input[name='title']").attr("style", "border-color:red !important;").focus();
  250. $(this).find(".error-msg").text("请输入标题").show();
  251. return res;
  252. } else {
  253. $(this).find("input[name='title']").removeAttr("style");
  254. $(this).find(".error-msg").text("").hide();
  255. }
  256. }
  257. });
  258. return res;
  259. }
  260. },
  261. template: sliderListHtml
  262. });
  263. var sliderRadiusHtml = '<div class="layui-form-item ns-icon-radio">';
  264. sliderRadiusHtml += '<label class="layui-form-label sm">圆角展示</label>';
  265. sliderRadiusHtml += '<div class="layui-input-block">';
  266. sliderRadiusHtml += '<template v-for="(item, index) in sliderRadius" v-bind:k="index">';
  267. sliderRadiusHtml += '<span :class="[item.value == data.sliderRadius ? \'\' : \'layui-hide\']">{{item.text}}</span>';
  268. sliderRadiusHtml += '</template>';
  269. sliderRadiusHtml += '<ul class="ns-icon">';
  270. sliderRadiusHtml += '<li v-for="(item, index) in sliderRadius" v-bind:k="index" :class="[item.value == data.sliderRadius ? \'ns-text-color ns-border-color ns-bg-color-diaphaneity\' : \'\']" @click="data.sliderRadius=item.value">';
  271. sliderRadiusHtml += '<img v-if="item.value == data.sliderRadius" :src="item.selectedSrc" />'
  272. sliderRadiusHtml += '<img v-else :src="item.src" />'
  273. sliderRadiusHtml += '</li>';
  274. sliderRadiusHtml += '</ul>';
  275. sliderRadiusHtml += '</div>';
  276. sliderRadiusHtml += '</div>';
  277. Vue.component("slider-radius", {
  278. template: sliderRadiusHtml,
  279. data: function () {
  280. return {
  281. data: this.$parent.data,
  282. sliderRadius: [{
  283. text: "直角",
  284. value: "right-angle",
  285. src: sliderResourcePath + "/graphic_nav/img/right-angle.png",
  286. selectedSrc: sliderResourcePath + "/graphic_nav/img/right-angle_1.png"
  287. },
  288. {
  289. text: "圆角",
  290. value: "fillet",
  291. src: sliderResourcePath + "/graphic_nav/img/fillet.png",
  292. selectedSrc: sliderResourcePath + "/graphic_nav/img/fillet_1.png"
  293. }
  294. ],
  295. }
  296. },
  297. created: function () {
  298. if (!this.$parent.data.verify) this.$parent.data.verify = [];
  299. this.$parent.data.verify.push(this.verify); //加载验证方法
  300. },
  301. methods: {
  302. verify: function () {
  303. var res = {
  304. code: true,
  305. message: ""
  306. };
  307. return res;
  308. },
  309. },
  310. });