Quellcode durchsuchen

资讯详情

gzb
wangzhonglu vor 1 Jahr
Ursprung
Commit
d1e806868c
6 geänderte Dateien mit 206 neuen und 15 gelöschten Zeilen
  1. 51
    2
      css/news.css
  2. 85
    12
      js/news.js
  3. 39
    0
      js/news_detail.js
  4. 1
    1
      sections/news.html
  5. 17
    0
      sections/news_detail.html
  6. 13
    0
      utils/index.js

+ 51
- 2
css/news.css Datei anzeigen

@@ -2,7 +2,8 @@
2 2
   position: relative;
3 3
   padding-top: 0.8rem;
4 4
   width: 100%;
5
-  height: 3.85rem;
5
+  height: 4.65rem;
6
+  box-sizing: border-box;
6 7
 }
7 8
 .news_banner img {
8 9
   width: 100%;
@@ -106,6 +107,7 @@
106 107
   background-color: #f8f8f8;
107 108
   box-shadow: 0 0 0.12rem 0 #0000001a;
108 109
   cursor: pointer;
110
+  overflow: hidden;
109 111
 }
110 112
 .news_list_item:nth-child(3n) {
111 113
   margin-right: 0;
@@ -114,6 +116,16 @@
114 116
   width: 100%;
115 117
   height: 2.7rem;
116 118
   object-fit: cover;
119
+  transition: all .3s ease-out;
120
+  -webkit-transition: all .3s ease-out;
121
+}
122
+.news_list_item:hover .news_item_img {
123
+  margin-left: -5%;
124
+  width: 110%;
125
+  height: 2.7rem;
126
+  object-fit: cover;
127
+  transition: all .3s ease-out;
128
+  -webkit-transition: all .3s ease-out;
117 129
 }
118 130
 .news_list_item .news_item_title {
119 131
   margin: 0.1rem 0.16rem;
@@ -139,7 +151,7 @@
139 151
   display: flex;
140 152
   justify-content: center;
141 153
   align-items: center;
142
-  padding: 0.5rem 0;
154
+  padding: 0.2rem 0 0.5rem;
143 155
   font-size: 0.16rem;
144 156
   color: #333;
145 157
   background-color: #fff;
@@ -158,6 +170,9 @@
158 170
   border: 1px solid #dddddd;
159 171
   cursor: pointer;
160 172
 }
173
+.news_page_box .news_page_prev.disabled {
174
+  cursor: not-allowed;
175
+}
161 176
 .news_page_box .news_page_num {
162 177
   margin-left: 0.1rem;
163 178
   margin-right: 0.1rem;
@@ -185,6 +200,9 @@
185 200
   border: 1px solid #dddddd;
186 201
   cursor: pointer;
187 202
 }
203
+.news_page_box .news_page_next.disabled {
204
+  cursor: not-allowed;
205
+}
188 206
 .news_page_box .news_page_prev img,
189 207
 .news_page_box .news_page_next img {
190 208
   display: inline-block;
@@ -196,4 +214,35 @@
196 214
   background-color: #1D70F2;
197 215
   border: 1px solid #1D70F2;
198 216
   color: #fff;
217
+}
218
+.news_detail_box {
219
+  padding: 0.73rem 0 0.84rem;
220
+  background-color: #fff;
221
+}
222
+.news_detail_main {
223
+  position: relative;
224
+  margin: 0 auto;
225
+  width: 13rem;
226
+}
227
+.news_detail_header {
228
+  font-size: 0.16rem;
229
+  border-bottom: 0.01rem dashed #ccc;
230
+  text-align: center;
231
+}
232
+.news_detail_header .detail_title {
233
+  font-size: 0.28rem;
234
+  line-height: 0.5rem;
235
+  color: #333;
236
+  font-weight: 700;
237
+}
238
+.news_detail_header .detail_stitle {
239
+  padding: 0.17rem 0 0.28rem;
240
+  font-size: 0.16rem;
241
+  color: #666;
242
+}
243
+.news_detail_content {
244
+  padding-top: 0.2rem;
245
+  font-size: 0.16rem;
246
+  line-height: 0.48rem;
247
+  color: #666;
199 248
 }

+ 85
- 12
js/news.js Datei anzeigen

@@ -5,17 +5,20 @@ $(function () {
5 5
   $(".header_root").data("nav_info", 5);
6 6
   // 新闻资讯搜索信息
7 7
   let newsInfo = {
8
-    page: 1,
8
+    page: Number($.getQueryVariable("page") || 1),
9 9
     size: 9,
10
-    newstitle: "",
10
+    newstitle: $.getQueryVariable("newstitle") || "",
11 11
     total: 0,
12 12
   };
13
+  $(".news_info #search_help").val(newsInfo.newstitle);
13 14
   // 加载新闻资讯列表
14 15
   function loadNewsList(params) {
15 16
     let newsItemHtml = "";
16 17
     $.each(params.list, function (newsIndex, newsItem) {
17 18
       newsItemHtml =
18
-        '<div class="news_list_item"><img class="news_item_img" src="' +
19
+        '<div class="news_list_item" data-newsid="' +
20
+        newsItem.newsid +
21
+        '"><img class="news_item_img" src="' +
19 22
         $.showImageUrl +
20 23
         newsItem.newspic +
21 24
         '" /><div class="news_item_title">' +
@@ -25,20 +28,81 @@ $(function () {
25 28
         "</div></div>";
26 29
     });
27 30
     $(".news_list_box").html(newsItemHtml);
31
+    $(".news_list_box").on("click", ".news_list_item", function () {
32
+      window.location.href =
33
+        "/sections/news_detail.html?newsid=" + $(this).data("newsid");
34
+    });
28 35
   }
29 36
   // 加载新闻资讯页码
30 37
   function loadNewsPages(params) {
31 38
     newsInfo.total = params.total || 0;
32
-    let newsPageHtml = "";
33
-    for (let _page = 0; _page < Math.ceil(params.total / 9); _page++) {
39
+    if (newsInfo.total === 0) {
40
+      $(".news_page_box").html("");
41
+      return;
42
+    }
43
+    let newsPageHtml =
44
+      '<div class="news_page_prev"><img src="../img/home/scheme/jiantou_right.png" /></div>';
45
+    for (let _page = 0; _page < Math.ceil(newsInfo.total / 9); _page++) {
34 46
       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" : "") +
47
+        '<div data-page="' +
48
+        (_page + 1) +
49
+        '" class="news_page_num ' +
50
+        (_page + 1 === newsInfo.page ? "selected" : "") +
37 51
         '">' +
38 52
         (_page + 1) +
39
-        '</div><div class="news_page_next"><img src="../img/home/scheme/jiantou_right.png" /></div>';
53
+        "</div>";
40 54
     }
55
+    newsPageHtml +=
56
+      '<div class="news_page_next"><img src="../img/home/scheme/jiantou_right.png" /></div>';
41 57
     $(".news_page_box").html(newsPageHtml);
58
+    // 上下页禁止点击
59
+    function setNotAllowed() {
60
+      if (newsInfo.page === 1) {
61
+        $(".news_page_box .news_page_prev").addClass("disabled");
62
+      } else {
63
+        $(".news_page_box .news_page_prev.disabled").removeClass("disabled");
64
+      }
65
+      if (newsInfo.page === Math.ceil(newsInfo.total / 9)) {
66
+        $(".news_page_box .news_page_next").addClass("disabled");
67
+      } else {
68
+        $(".news_page_box .news_page_next.disabled").removeClass("disabled");
69
+      }
70
+    }
71
+    setNotAllowed();
72
+    $(".news_page_box").on("click", ".news_page_prev", function () {
73
+      if (newsInfo.page > 1) {
74
+        newsInfo.page--;
75
+        $(".news_page_box .news_page_num.selected").removeClass("selected");
76
+        $(
77
+          ".news_page_box .news_page_num[data-page='" + newsInfo.page + "']"
78
+        ).addClass("selected");
79
+        setNotAllowed();
80
+        // searchList();
81
+        window.location.href = "/sections/news.html?page=" + newsInfo.page + "&newstitle=" + newsInfo.newstitle;
82
+      }
83
+    });
84
+    $(".news_page_box").on("click", ".news_page_num", function () {
85
+      newsInfo.page = $(this).data("page");
86
+      $(".news_page_box .news_page_num.selected").removeClass("selected");
87
+      $(
88
+        ".news_page_box .news_page_num[data-page='" + newsInfo.page + "']"
89
+      ).addClass("selected");
90
+      setNotAllowed();
91
+      // searchList();
92
+      window.location.href = "/sections/news.html?page=" + newsInfo.page + "&newstitle=" + newsInfo.newstitle;
93
+    });
94
+    $(".news_page_box").on("click", ".news_page_next", function () {
95
+      if (newsInfo.page < Math.ceil(newsInfo.total / 9)) {
96
+        newsInfo.page++;
97
+        $(".news_page_box .news_page_num.selected").removeClass("selected");
98
+        $(
99
+          ".news_page_box .news_page_num[data-page='" + newsInfo.page + "']"
100
+        ).addClass("selected");
101
+        setNotAllowed();
102
+        // searchList();
103
+        window.location.href = "/sections/news.html?page=" + newsInfo.page + "&newstitle=" + newsInfo.newstitle;
104
+      }
105
+    });
42 106
   }
43 107
   // 搜索新闻列表
44 108
   function searchList() {
@@ -55,8 +119,13 @@ $(function () {
55 119
       }),
56 120
       success: function (data) {
57 121
         if (data.code === 0) {
58
-          loadNewsList(data.obj);
59
-          loadNewsPages(data.obj);
122
+          if (data.obj.list.length === 0 && newsInfo.page > 1) {
123
+            newsInfo.page--;
124
+            searchList();
125
+          } else {
126
+            loadNewsList(data.obj);
127
+            loadNewsPages(data.obj);
128
+          }
60 129
         } else {
61 130
           alert(data.msg);
62 131
         }
@@ -71,7 +140,8 @@ $(function () {
71 140
     let content = theEvent.target.value;
72 141
     newsInfo.newstitle = content;
73 142
     if (code == 13) {
74
-      searchList();
143
+      // searchList();
144
+      window.location.href = "/sections/news.html?page=" + newsInfo.page + "&newstitle=" + newsInfo.newstitle;
75 145
     }
76 146
   }
77 147
   // 输入内容改变
@@ -81,6 +151,9 @@ $(function () {
81 151
   }
82 152
   $(".news_info #search_help").on("change", searchInputChange);
83 153
   $(".news_info #search_help").on("keydown", enterSearch);
84
-  $(".news_info .search_box").click(searchList);
154
+  $(".news_info .search_box").click(function () {
155
+    // searchList();
156
+    window.location.href = "/sections/news.html?page=" + newsInfo.page + "&newstitle=" + newsInfo.newstitle;
157
+  });
85 158
   searchList();
86 159
 });

+ 39
- 0
js/news_detail.js Datei anzeigen

@@ -0,0 +1,39 @@
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
+  function getNewsDetail() {
8
+    let _url = $.baseUrl + "n/detail";
9
+    $.ajax({
10
+      type: "POST",
11
+      url: _url,
12
+      dataType: "json",
13
+      contentType: "application/json; charset=utf-8",
14
+      data: JSON.stringify({
15
+        newsid: $.getQueryVariable("newsid")
16
+      }),
17
+      success: function (data) {
18
+        if (data.code === 0) {
19
+          loadNewsDetail(data.obj);
20
+        } else {
21
+          alert(data.msg);
22
+        }
23
+      },
24
+    });
25
+  }
26
+  // 加载详情页面
27
+  function loadNewsDetail(params) {
28
+    if (!params) {
29
+      $(".news_detail_header .detail_title").html("");
30
+      $(".news_detail_header .detail_stitle").html("发布时间:");
31
+      $(".news_detail_content").html("");
32
+      return;
33
+    }
34
+    $(".news_detail_header .detail_title").html(params.newstitle);
35
+    $(".news_detail_header .detail_stitle").html("发布时间:" + $.msToDateString(params.createtime * 1000));
36
+    $(".news_detail_content").html(params.newscontent);
37
+  }
38
+  getNewsDetail();
39
+});

+ 1
- 1
sections/news.html Datei anzeigen

@@ -38,7 +38,7 @@
38 38
     </div>
39 39
     <div class="news_list">
40 40
       <div class="news_list_box">
41
-        <!-- <div class="news_list_item">
41
+        <!-- <div class="news_list_item" data-newsid="1">
42 42
           <img class="news_item_img" src="" />
43 43
           <div class="news_item_title"></div>
44 44
           <div class="news_item_stitle"></div>

+ 17
- 0
sections/news_detail.html Datei anzeigen

@@ -13,9 +13,26 @@
13 13
   </head>
14 14
   <body>
15 15
     <div class="header_root bg_white"></div>
16
+    <div class="news_banner">
17
+      <img src="../img/news/news_banner.png" />
18
+      <div class="news_header_info">
19
+        <div class="news_header_title">新闻资讯</div>
20
+        <div class="news_header_stitle">星火最新资讯,让一切皆有可能</div>
21
+      </div>
22
+    </div>
23
+    <div class="news_detail_box">
24
+      <div class="news_detail_main">
25
+        <div class="news_detail_header">
26
+          <div class="detail_title"></div>
27
+          <div class="detail_stitle">发布时间:</div>
28
+        </div>
29
+        <div class="news_detail_content"></div>
30
+      </div>
31
+    </div>
16 32
     <div class="footer_root"></div>
17 33
     <script src="../librarys/jquery@1.12.4/jquery.min.js"></script>
18 34
     <script src="../librarys/swiper@3.4.2/swiper.jquery.min.js"></script>
35
+    <script src="../utils/index.js"></script>
19 36
     <script src="../js/news_detail.js"></script>
20 37
   </body>
21 38
 </html>

+ 13
- 0
utils/index.js Datei anzeigen

@@ -15,4 +15,17 @@ jQuery.extend({
15 15
     }
16 16
     return year + "-" + month + "-" + day;
17 17
   },
18
+  // 读取url参数
19
+  getQueryVariable: function(variable) {
20
+    let query = window.location.search.substring(1);
21
+    query = decodeURI(query);
22
+    let vars = query.split("&");
23
+    for (let i = 0; i < vars.length; i++) {
24
+      let pair = vars[i].split("=");
25
+      if (pair[0] === variable) {
26
+        return pair[1];
27
+      }
28
+    }
29
+    return false;
30
+  }
18 31
 });

Laden…
Abbrechen
Speichern