Browse Source

资讯详情

gzb
wangzhonglu 1 year ago
parent
commit
d1e806868c
6 changed files with 206 additions and 15 deletions
  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 View File

2
   position: relative;
2
   position: relative;
3
   padding-top: 0.8rem;
3
   padding-top: 0.8rem;
4
   width: 100%;
4
   width: 100%;
5
-  height: 3.85rem;
5
+  height: 4.65rem;
6
+  box-sizing: border-box;
6
 }
7
 }
7
 .news_banner img {
8
 .news_banner img {
8
   width: 100%;
9
   width: 100%;
106
   background-color: #f8f8f8;
107
   background-color: #f8f8f8;
107
   box-shadow: 0 0 0.12rem 0 #0000001a;
108
   box-shadow: 0 0 0.12rem 0 #0000001a;
108
   cursor: pointer;
109
   cursor: pointer;
110
+  overflow: hidden;
109
 }
111
 }
110
 .news_list_item:nth-child(3n) {
112
 .news_list_item:nth-child(3n) {
111
   margin-right: 0;
113
   margin-right: 0;
114
   width: 100%;
116
   width: 100%;
115
   height: 2.7rem;
117
   height: 2.7rem;
116
   object-fit: cover;
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
 .news_list_item .news_item_title {
130
 .news_list_item .news_item_title {
119
   margin: 0.1rem 0.16rem;
131
   margin: 0.1rem 0.16rem;
139
   display: flex;
151
   display: flex;
140
   justify-content: center;
152
   justify-content: center;
141
   align-items: center;
153
   align-items: center;
142
-  padding: 0.5rem 0;
154
+  padding: 0.2rem 0 0.5rem;
143
   font-size: 0.16rem;
155
   font-size: 0.16rem;
144
   color: #333;
156
   color: #333;
145
   background-color: #fff;
157
   background-color: #fff;
158
   border: 1px solid #dddddd;
170
   border: 1px solid #dddddd;
159
   cursor: pointer;
171
   cursor: pointer;
160
 }
172
 }
173
+.news_page_box .news_page_prev.disabled {
174
+  cursor: not-allowed;
175
+}
161
 .news_page_box .news_page_num {
176
 .news_page_box .news_page_num {
162
   margin-left: 0.1rem;
177
   margin-left: 0.1rem;
163
   margin-right: 0.1rem;
178
   margin-right: 0.1rem;
185
   border: 1px solid #dddddd;
200
   border: 1px solid #dddddd;
186
   cursor: pointer;
201
   cursor: pointer;
187
 }
202
 }
203
+.news_page_box .news_page_next.disabled {
204
+  cursor: not-allowed;
205
+}
188
 .news_page_box .news_page_prev img,
206
 .news_page_box .news_page_prev img,
189
 .news_page_box .news_page_next img {
207
 .news_page_box .news_page_next img {
190
   display: inline-block;
208
   display: inline-block;
196
   background-color: #1D70F2;
214
   background-color: #1D70F2;
197
   border: 1px solid #1D70F2;
215
   border: 1px solid #1D70F2;
198
   color: #fff;
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 View File

5
   $(".header_root").data("nav_info", 5);
5
   $(".header_root").data("nav_info", 5);
6
   // 新闻资讯搜索信息
6
   // 新闻资讯搜索信息
7
   let newsInfo = {
7
   let newsInfo = {
8
-    page: 1,
8
+    page: Number($.getQueryVariable("page") || 1),
9
     size: 9,
9
     size: 9,
10
-    newstitle: "",
10
+    newstitle: $.getQueryVariable("newstitle") || "",
11
     total: 0,
11
     total: 0,
12
   };
12
   };
13
+  $(".news_info #search_help").val(newsInfo.newstitle);
13
   // 加载新闻资讯列表
14
   // 加载新闻资讯列表
14
   function loadNewsList(params) {
15
   function loadNewsList(params) {
15
     let newsItemHtml = "";
16
     let newsItemHtml = "";
16
     $.each(params.list, function (newsIndex, newsItem) {
17
     $.each(params.list, function (newsIndex, newsItem) {
17
       newsItemHtml =
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
         $.showImageUrl +
22
         $.showImageUrl +
20
         newsItem.newspic +
23
         newsItem.newspic +
21
         '" /><div class="news_item_title">' +
24
         '" /><div class="news_item_title">' +
25
         "</div></div>";
28
         "</div></div>";
26
     });
29
     });
27
     $(".news_list_box").html(newsItemHtml);
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
   function loadNewsPages(params) {
37
   function loadNewsPages(params) {
31
     newsInfo.total = params.total || 0;
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
       newsPageHtml +=
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
         (_page + 1) +
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
     $(".news_page_box").html(newsPageHtml);
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
   function searchList() {
108
   function searchList() {
55
       }),
119
       }),
56
       success: function (data) {
120
       success: function (data) {
57
         if (data.code === 0) {
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
         } else {
129
         } else {
61
           alert(data.msg);
130
           alert(data.msg);
62
         }
131
         }
71
     let content = theEvent.target.value;
140
     let content = theEvent.target.value;
72
     newsInfo.newstitle = content;
141
     newsInfo.newstitle = content;
73
     if (code == 13) {
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
   }
151
   }
82
   $(".news_info #search_help").on("change", searchInputChange);
152
   $(".news_info #search_help").on("change", searchInputChange);
83
   $(".news_info #search_help").on("keydown", enterSearch);
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
   searchList();
158
   searchList();
86
 });
159
 });

+ 39
- 0
js/news_detail.js View File

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 View File

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

+ 17
- 0
sections/news_detail.html View File

13
   </head>
13
   </head>
14
   <body>
14
   <body>
15
     <div class="header_root bg_white"></div>
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
     <div class="footer_root"></div>
32
     <div class="footer_root"></div>
17
     <script src="../librarys/jquery@1.12.4/jquery.min.js"></script>
33
     <script src="../librarys/jquery@1.12.4/jquery.min.js"></script>
18
     <script src="../librarys/swiper@3.4.2/swiper.jquery.min.js"></script>
34
     <script src="../librarys/swiper@3.4.2/swiper.jquery.min.js"></script>
35
+    <script src="../utils/index.js"></script>
19
     <script src="../js/news_detail.js"></script>
36
     <script src="../js/news_detail.js"></script>
20
   </body>
37
   </body>
21
 </html>
38
 </html>

+ 13
- 0
utils/index.js View File

15
     }
15
     }
16
     return year + "-" + month + "-" + day;
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
 });

Loading…
Cancel
Save