星火官网,前端页面(前台)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

news.js 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. $(function () {
  2. $(".header_root").load("./comm/header.html");
  3. $(".footer_root").load("./comm/footer.html");
  4. // nav传值显示下划线
  5. $(".header_root").data("nav_info", 5);
  6. // 新闻资讯搜索信息
  7. let newsInfo = {
  8. page: 1,
  9. size: 9,
  10. newstitle: "",
  11. total: 0,
  12. };
  13. // 加载新闻资讯列表
  14. function loadNewsList(params) {
  15. let newsItemHtml = "";
  16. $.each(params.list, function (newsIndex, newsItem) {
  17. newsItemHtml =
  18. '<div class="news_list_item"><img class="news_item_img" src="' +
  19. $.showImageUrl +
  20. newsItem.newspic +
  21. '" /><div class="news_item_title">' +
  22. newsItem.newstitle +
  23. '</div><div class="news_item_stitle">' +
  24. $.msToDateString(newsItem.createtime * 1000) +
  25. "</div></div>";
  26. });
  27. $(".news_list_box").html(newsItemHtml);
  28. }
  29. // 加载新闻资讯页码
  30. function loadNewsPages(params) {
  31. newsInfo.total = params.total || 0;
  32. let newsPageHtml = "";
  33. for (let _page = 0; _page < Math.ceil(params.total / 9); _page++) {
  34. newsPageHtml +=
  35. '<div class="news_page_prev"><img src="../img/home/scheme/jiantou_right.png" /></div><div class="news_page_num ' +
  36. (_page === 0 ? "selected" : "") +
  37. '">' +
  38. (_page + 1) +
  39. '</div><div class="news_page_next"><img src="../img/home/scheme/jiantou_right.png" /></div>';
  40. }
  41. $(".news_page_box").html(newsPageHtml);
  42. }
  43. // 搜索新闻列表
  44. function searchList() {
  45. let _url = $.baseUrl + "n/listc";
  46. $.ajax({
  47. type: "POST",
  48. url: _url,
  49. dataType: "json",
  50. contentType: "application/json; charset=utf-8",
  51. data: JSON.stringify({
  52. page: newsInfo.page,
  53. size: newsInfo.size,
  54. newstitle: newsInfo.newstitle,
  55. }),
  56. success: function (data) {
  57. if (data.code === 0) {
  58. loadNewsList(data.obj);
  59. loadNewsPages(data.obj);
  60. } else {
  61. alert(data.msg);
  62. }
  63. },
  64. });
  65. }
  66. // 回车搜索
  67. function enterSearch(event) {
  68. // 兼容FF和IE和Opera
  69. let theEvent = event || window.event;
  70. let code = theEvent.keyCode || theEvent.which || theEvent.charCode;
  71. let content = theEvent.target.value;
  72. newsInfo.newstitle = content;
  73. if (code == 13) {
  74. searchList();
  75. }
  76. }
  77. // 输入内容改变
  78. function searchInputChange(event) {
  79. let theEvent = event || window.event;
  80. newsInfo.newstitle = theEvent.target.value;
  81. }
  82. $(".news_info #search_help").on("change", searchInputChange);
  83. $(".news_info #search_help").on("keydown", enterSearch);
  84. $(".news_info .search_box").click(searchList);
  85. searchList();
  86. });