25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

303 lines
13 KiB

  1. $(function () {
  2. "use strict";
  3. $.fn.SiteCarousel = function (options) {
  4. //默认配置
  5. var defaults = {
  6. speed: 4000, //滚动速度,值越大速度越慢
  7. rowHeight: 47 //每行的高度
  8. };
  9. var opts = $.extend({}, defaults, options), intId;
  10. function marquee(obj, step, callback) {
  11. obj.find("ul").animate({
  12. marginTop: '-=' + step
  13. }, 300, function () {
  14. $(this).find("li").slice(0, 1).appendTo($(this));
  15. $(this).css("margin-top", 0);
  16. callback();
  17. });
  18. }
  19. this.each(function (i) {
  20. var sh = opts["rowHeight"], speed = opts["speed"], _this = $(this);
  21. var _fn = function (flag) {
  22. if (flag) {
  23. clearInterval(intId);
  24. intId = setTimeout(_fn, speed);
  25. }
  26. else {
  27. if (_this.find("ul").height() > _this.height()) {
  28. marquee(_this, sh, function () {
  29. clearInterval(intId);
  30. intId = setTimeout(_fn, speed);
  31. });
  32. }
  33. }
  34. };
  35. _fn(true);
  36. _this.hover(function () {
  37. if (intId) {
  38. clearInterval(intId);
  39. }
  40. }, function () {
  41. _fn(true);
  42. });
  43. });
  44. };
  45. var formatDate = function (v, format) {
  46. if (!v) return "";
  47. var d = v;
  48. if (typeof v === 'string') {
  49. if (v.indexOf("/Date(") > -1)
  50. d = new Date(parseInt(v.replace("/Date(", "").replace(")/", ""), 10));
  51. else
  52. d = new Date(Date.parse(v.replace(/-/g, "/").replace("T", " ").split(".")[0]));//.split(".")[0] 用来处理出现毫秒的情况,截取掉.xxx,否则会出错
  53. }
  54. var o = {
  55. "M+": d.getMonth() + 1, //month
  56. "d+": d.getDate(), //day
  57. "h+": d.getHours(), //hour
  58. "m+": d.getMinutes(), //minute
  59. "s+": d.getSeconds(), //second
  60. "q+": Math.floor((d.getMonth() + 3) / 3), //quarter
  61. "S": d.getMilliseconds() //millisecond
  62. };
  63. if (/(y+)/.test(format)) {
  64. format = format.replace(RegExp.$1, (d.getFullYear() + "").substr(4 - RegExp.$1.length));
  65. }
  66. for (var k in o) {
  67. if (new RegExp("(" + k + ")").test(format)) {
  68. format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
  69. }
  70. }
  71. return format;
  72. };
  73. /*模块3标签页切换*/
  74. $('.lr-site-modules').on('click', '.lr-site-tab', function () {
  75. var $this = $(this);
  76. if (!$this.hasClass('active')) {
  77. var $parent = $this.parent();
  78. $parent.find('.active').removeClass('active');
  79. $this.addClass('active');
  80. var value = $this.attr('data-value');
  81. $parent.next().find('.active').removeClass('active');
  82. $parent.next().find('[data-value="' + value + '"]').addClass('active');
  83. }
  84. });
  85. $('.lr-site-modules').on('click', '.lr-site-more', function () {
  86. var $this = $(this);
  87. var data = $this.parents('.lr-site-module')[0].data;
  88. if (data.F_Url) {
  89. window.location.href = $.rootUrl + '/Home/ChildIndex?id=' + data.F_Url + '&module=' + escape(data.F_Name);
  90. }
  91. });
  92. $('.lr-site-modules').on('click', '.lr-site-article-list-item', function () {
  93. var data = $(this)[0].data;
  94. window.open($.rootUrl + '/Home/DetailIndex?id=' + data.F_Id);
  95. return false;
  96. });
  97. var renderModule = function (data) {
  98. var schemeObj = JSON.parse(data.F_Scheme);
  99. var $item;
  100. var $list = $('.lr-site-modules');
  101. switch (schemeObj.type) {
  102. case '1':// 风格一
  103. $item = $('<div class="lr-site-module module1">\
  104. <div class="lr-site-box">\
  105. <div class="title">\
  106. <i class="fa fa-volume-down"></i>\
  107. <span class="name" >' + data.F_Name + '</span>\
  108. <span class="arrow"></span>\
  109. </div>\
  110. <div class="content">\
  111. <ul>\
  112. </ul>\
  113. </div>\
  114. <div class="lr-site-more">' + (data.F_Url ? '更多' : '') + '</div>\
  115. </div>\
  116. </div>');
  117. $item.find('.content').SiteCarousel();
  118. var $ul = $item.find('ul');
  119. $ul.html('');
  120. $.each(schemeObj.list, function (_index, _item) {
  121. var _$li = $('<li><a href="javascript:void(0);" class="lr-text-item lr-site-article-list-item">' + _item.F_Title + '</a></li>');
  122. _$li[0].data = _item;
  123. $ul.append(_$li);
  124. });
  125. $list.append($item);
  126. break;
  127. case '2':
  128. $item = $('<div class="lr-site-module module2" data-value="' + data.F_Id + '" >\
  129. <div class="lr-site-box">\
  130. <div class="lr-site-title"><span class="name" >' + data.F_Name + '</span><div class="lr-site-more">' + (data.F_Url ? '更多' : '') + '</div></div>\
  131. <div class="lr-site-body">\
  132. <div class="lr-site-module-pic">\
  133. <div class="lr-site-module-swiper-container swiper-container">\
  134. <div class="swiper-wrapper">\
  135. </div>\
  136. <div class="swiper-pagination"></div>\
  137. </div>\
  138. </div>\
  139. <div class="lr-site-module-list">\
  140. </div>\
  141. </div>\
  142. </div>\
  143. </div>');
  144. $list.append($item);
  145. $item[0].swiper = new Swiper('[data-value="' + data.F_Id + '"] .lr-site-module-swiper-container', {
  146. direction: 'horizontal',
  147. autoplay: true,
  148. loop: true,
  149. speed: 600,
  150. // 分页器
  151. pagination: {
  152. el: '.swiper-pagination',
  153. clickable: true
  154. },
  155. });
  156. $item.css({ width: parseFloat(schemeObj.prop) * 100 + '%' });
  157. // 加载图片
  158. if (schemeObj.list1.length == 0) {
  159. $item.addClass('noimg');
  160. }
  161. else {
  162. $item.removeClass('noimg');
  163. var $swrapper = $item.find('.swiper-wrapper');
  164. $swrapper.html('');
  165. $.each(schemeObj.list1, function (_index, _item) {
  166. var $li = $('<div class="swiper-slide lr-site-article-list-item">\
  167. <img class="img" src="' + top.$.rootUrl + '/Home/GetArticleImg?keyValue=' + _item.F_Id + '" />\
  168. </div>');
  169. $li[0].data = _item;
  170. $swrapper.append($li);
  171. });
  172. $item[0].swiper.update();
  173. }
  174. // 加载文字列表
  175. var $textList = $item.find('.lr-site-module-list');
  176. $textList.html('');
  177. $.each(schemeObj.list2, function (_index, _item) {
  178. var $li = $('<div class="lr-site-module-item lr-site-article-list-item">\
  179. <div class="text">'+ _item.F_Title + '</div>\
  180. <div class="date">' + formatDate(_item.F_PushDate, 'yyyy-MM-dd') + '</div>\
  181. </div>');
  182. $li[0].data = _item;
  183. $textList.append($li);
  184. });
  185. break;
  186. case '3':
  187. $item = $('<div class="lr-site-module module3" data-value="' + data.F_Id + '" >\
  188. <div class="lr-site-box">\
  189. <div class="lr-site-tabs"></div>\
  190. <div class="lr-site-body">\
  191. </div>\
  192. </div>\
  193. </div>');
  194. $list.append($item);
  195. $item.css({ width: parseFloat(schemeObj.prop) * 100 + '%' });
  196. var tabList = $item.find('.lr-site-tabs');
  197. var tabBody = $item.find('.lr-site-body');
  198. tabList.html('');
  199. tabBody.html('');
  200. $.each(schemeObj.list, function (_index, _item) {
  201. var $li = $('<div class="lr-site-tab" data-value="' + _index + '">' + _item.name + '</div>');
  202. tabList.append($li);
  203. var $tabContent = $('<div class="lr-site-tab-content" data-value="' + _index + '"></div>')
  204. $.each(_item.list, function (_jindex, _jitem) {
  205. var _$jli = $('<div class="lr-site-tab-content-item lr-site-article-list-item">' + _jitem.F_Title + '</div>');
  206. _$jli[0].data = _jitem;
  207. $tabContent.append(_$jli);
  208. });
  209. tabBody.append($tabContent);
  210. if (_index == 0) {
  211. $li.trigger('click');
  212. }
  213. });
  214. break;
  215. case '4':
  216. $item = $('<div class="lr-site-module module4" data-value="' + data.F_Id + '" >\
  217. <div class="lr-site-box">\
  218. <div class="lr-site-title"><span class="name" >' + data.F_Name + '</span><div class="lr-site-more">' + (data.F_Url ? '更多' : '') + '</div></div>\
  219. <div class="lr-site-body">\
  220. </div>\
  221. </div>\
  222. </div>');
  223. $list.append($item);
  224. var $body = $item.find('.lr-site-body');
  225. $body.html('');
  226. $.each(schemeObj.list, function (_index, _item) {
  227. var _$li = $('<div class="lr-site-img-item lr-site-article-list-item">\
  228. <div class="lr-site-img-item-content">\
  229. <img class="img" src="' + $.rootUrl + '/Home/GetArticleImg?keyValue=' + _item.F_Id + '" />\
  230. <div class="text">' + _item.F_Title + '</div>\
  231. </div>\
  232. </div>');
  233. _$li[0].data = _item;
  234. $body.append(_$li);
  235. });
  236. break;
  237. case '5':
  238. $item = $('<div class="lr-site-module module5" data-value="' + data.F_Id + '" >\
  239. <div class="lr-site-box lr-site-article-list-item">\
  240. <div class="lr-site-title"><span class="name" >' + data.F_Name + '</span></div>\
  241. <div class="lr-site-body">\
  242. <div class="lr-site-article-pic">\
  243. <img class="img" src="' + $.rootUrl + '/Home/GetArticleImg?keyValue=' + schemeObj.article + '" />\
  244. </div>\
  245. <div class="text-content">\
  246. <div class="text" data-text="' + schemeObj.article + '" ></div>\
  247. </div>\
  248. </div>\
  249. </div>\
  250. </div>');
  251. $list.append($item);
  252. $item.find('.lr-site-box')[0].data = { F_Id: schemeObj.article };
  253. $item.css({ width: parseFloat(schemeObj.prop) * 100 + '%' });
  254. httpGet($.rootUrl + '/Home/GetArticle?keyValue=' + schemeObj.article, function (res) {
  255. if (res && res.code == 200) {
  256. var data = res.data;
  257. var text = $('<div></div>').html(data.F_Content).text().substring(0, 106) || '';
  258. if (text.length == 106) {
  259. text = text.substring(0, 105) + '...';
  260. }
  261. $('.module5 [data-text="' + data.F_Id + '"]').text(text);
  262. }
  263. });
  264. break;
  265. }
  266. $item[0].data = data;
  267. }
  268. httpGet($.rootUrl + '/Home/GetList?type=9', function (res) {
  269. if (res && res.code == 200) {
  270. $.each(res.data, function (_index, _item) {
  271. renderModule(_item);
  272. });
  273. }
  274. });
  275. });