new.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. function newPage() {
  2. var obj_2 = {
  3. obj_box: ".page_1",
  4. total_item: +window.sessionStorage.getItem("total"), //总共数据
  5. type: +window.sessionStorage.getItem("newType"),
  6. per_num: 10, //每页显示数据
  7. current_page: 1, //当前页
  8. change_content: function(per_num, current_page) {
  9. per_num = per_num ? per_num : 10;
  10. current_page = current_page ? current_page : 1;
  11. var type = window.sessionStorage.getItem("newType");
  12. if (type == "undefined") {
  13. var data = {
  14. pageNo: current_page
  15. };
  16. } else {
  17. var data = {
  18. type,
  19. pageNo: current_page
  20. };
  21. }
  22. $.ajax({
  23. url: api + "/open/listNews",
  24. data,
  25. type: "GET",
  26. dataType: "json",
  27. success: function(data) {
  28. if (data.error && data.error.length) {
  29. alert("数据加载失败,请刷新页面");
  30. } else {
  31. var html = "";
  32. if (data.data.list.length) {
  33. for (var i = 0; i < data.data.list.length; i++) {
  34. var newList = data.data.list[i];
  35. var content = newList.content.replace(/<.*?>/gi, "");
  36. html +=
  37. "<li><a target='_blank' href=" +
  38. newUrl +
  39. "?id=" +
  40. newList.id +
  41. "><div class=news-item><div><img src=" +
  42. avatarUploadHost +
  43. newList.pictureUrl +
  44. " / ></div><div><h6>" +
  45. newList.title +
  46. "</h6><span>" +
  47. newList.releaseTimeConvert +
  48. "</span><div>" +
  49. content +
  50. "</div></div></div></a></li>";
  51. }
  52. window.sessionStorage.setItem("total", data.data.totalCount);
  53. } else {
  54. html =
  55. "<h4 style='text-align:center;margin-top:90px;color:#666' >暂无新闻动态</h4>";
  56. $(".page_ctrl").css({
  57. display: "none"
  58. });
  59. }
  60. $(".newslist").html(html);
  61. }
  62. }
  63. });
  64. }
  65. };
  66. //调用分页
  67. page_ctrl(obj_2);
  68. }
  69. function newFn() {
  70. // var api = window.globalConfig.apiUrl ? window.globalConfig.apiUrl : "http://kede.jishutao.com"
  71. $(".secondary-menu").on("click", "a", function() {
  72. $(".secondary-menu ul li").removeClass("active");
  73. $(this)
  74. .parent()
  75. .addClass("active");
  76. if ($(this).html() == "全部") {
  77. window.sessionStorage.setItem("newType", undefined);
  78. } else if ($(this).html() == "科德新闻") {
  79. window.sessionStorage.setItem("newType", 0);
  80. } else if ($(this).html() == "行业资讯") {
  81. window.sessionStorage.setItem("newType", 1);
  82. }
  83. var type = window.sessionStorage.getItem("newType");
  84. if(type != "undefined") {
  85. var data = {
  86. type,
  87. releaseStatus: 1
  88. }
  89. }else {
  90. var data = {
  91. releaseStatus: 1
  92. }
  93. }
  94. $.ajax({
  95. method: "get",
  96. url: api + "/open/listNews",
  97. data,
  98. success: function(data) {
  99. if (data.error && data.error.length) {
  100. alert("数据加载失败,请刷新页面");
  101. } else {
  102. var html = "";
  103. if(data.data.list.length) {
  104. for (var i = 0; i < data.data.list.length; i++) {
  105. var newList = data.data.list[i];
  106. var content = newList.content.replace(/<.*?>/gi, "");
  107. html +=
  108. "<li><a target='_blank' href=" +
  109. newUrl +
  110. "?id=" +
  111. newList.id +
  112. "><div class=news-item><div><img src=" +
  113. avatarUploadHost +
  114. newList.pictureUrl +
  115. " / ></div><div><h6>" +
  116. newList.title +
  117. "</h6><span>" +
  118. newList.releaseTimeConvert +
  119. "</span><div>" +
  120. content +
  121. "</div></div></div></a></li>";
  122. }
  123. window.sessionStorage.setItem("total", data.data.totalCount);
  124. newPage()
  125. }else {
  126. html =
  127. "<h4 style='text-align:center;margin-top:90px;color:#666' >暂无新闻动态</h4>";
  128. $(".page_ctrl").css({
  129. display: "none"
  130. });
  131. }
  132. $(".newslist").html(html);
  133. }
  134. }
  135. });
  136. });
  137. $(".secondary-menu > div > ul > li > a")
  138. .eq(0)
  139. .click();
  140. }
  141. newFn()