Pārlūkot izejas kodu

Merge commit 'd1e806868cdc2903bb0813eff8618e67d2ea40e8' into gzb

gzb
guozhongbo pirms 1 gada
vecāks
revīzija
62c5233c26
6 mainītis faili ar 306 papildinājumiem un 25 dzēšanām
  1. 116
    4
      css/news.css
  2. 112
    15
      js/news.js
  3. 39
    0
      js/news_detail.js
  4. 8
    5
      sections/news.html
  5. 17
    0
      sections/news_detail.html
  6. 14
    1
      utils/index.js

+ 116
- 4
css/news.css Parādīt failu

@@ -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%;
@@ -42,12 +43,12 @@
42 43
   font-size: 0.14rem;
43 44
   text-align: right;
44 45
 }
45
-.header_content_right{
46
+.header_content_right {
46 47
   position: relative;
47 48
   display: inline-block;
48 49
   width: 2.5rem;
49 50
   height: 0.3rem;
50
-  border: 0.01rem solid #DCDEE2;
51
+  border: 0.01rem solid #dcdee2;
51 52
   background-color: #fff;
52 53
   border-radius: 0.04rem;
53 54
   overflow: hidden;
@@ -103,8 +104,10 @@
103 104
   margin-bottom: 0.3rem;
104 105
   display: inline-block;
105 106
   width: 4.1rem;
106
-  background-color: #F8F8F8;
107
+  background-color: #f8f8f8;
107 108
   box-shadow: 0 0 0.12rem 0 #0000001a;
109
+  cursor: pointer;
110
+  overflow: hidden;
108 111
 }
109 112
 .news_list_item:nth-child(3n) {
110 113
   margin-right: 0;
@@ -113,6 +116,16 @@
113 116
   width: 100%;
114 117
   height: 2.7rem;
115 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;
116 129
 }
117 130
 .news_list_item .news_item_title {
118 131
   margin: 0.1rem 0.16rem;
@@ -133,4 +146,103 @@
133 146
   font-size: 0.16rem;
134 147
   line-height: 0.32rem;
135 148
   color: #666;
149
+}
150
+.news_page_box {
151
+  display: flex;
152
+  justify-content: center;
153
+  align-items: center;
154
+  padding: 0.2rem 0 0.5rem;
155
+  font-size: 0.16rem;
156
+  color: #333;
157
+  background-color: #fff;
158
+}
159
+.news_page_box .news_page_prev {
160
+  margin-left: 0.1rem;
161
+  margin-right: 0.1rem;
162
+  width: 0.4rem;
163
+  height: 0.4rem;
164
+  line-height: 0.4rem;
165
+  text-align: center;
166
+  transition: all 0.6s cubic-bezier(0.215, 0.61, 0.355, 1) 0s;
167
+  -webkit-transition: all 0.6s cubic-bezier(0.215, 0.61, 0.355, 1) 0s;
168
+  transform: rotateY(0.5turn);
169
+  background: #ffffff;
170
+  border: 1px solid #dddddd;
171
+  cursor: pointer;
172
+}
173
+.news_page_box .news_page_prev.disabled {
174
+  cursor: not-allowed;
175
+}
176
+.news_page_box .news_page_num {
177
+  margin-left: 0.1rem;
178
+  margin-right: 0.1rem;
179
+  width: 0.4rem;
180
+  height: 0.4rem;
181
+  color: #333;
182
+  line-height: 0.4rem;
183
+  text-align: center;
184
+  transition: all 0.6s cubic-bezier(0.215, 0.61, 0.355, 1) 0s;
185
+  -webkit-transition: all 0.6s cubic-bezier(0.215, 0.61, 0.355, 1) 0s;
186
+  background: #ffffff;
187
+  border: 1px solid #dddddd;
188
+  cursor: pointer;
189
+}
190
+.news_page_box .news_page_next {
191
+  margin-left: 0.1rem;
192
+  margin-right: 0.1rem;
193
+  width: 0.4rem;
194
+  height: 0.4rem;
195
+  line-height: 0.4rem;
196
+  text-align: center;
197
+  transition: all 0.6s cubic-bezier(0.215, 0.61, 0.355, 1) 0s;
198
+  -webkit-transition: all 0.6s cubic-bezier(0.215, 0.61, 0.355, 1) 0s;
199
+  background: #ffffff;
200
+  border: 1px solid #dddddd;
201
+  cursor: pointer;
202
+}
203
+.news_page_box .news_page_next.disabled {
204
+  cursor: not-allowed;
205
+}
206
+.news_page_box .news_page_prev img,
207
+.news_page_box .news_page_next img {
208
+  display: inline-block;
209
+  width: 0.2rem;
210
+  vertical-align: middle;
211
+}
212
+.news_page_box > div:hover,
213
+.news_page_box .news_page_num.selected {
214
+  background-color: #1D70F2;
215
+  border: 1px solid #1D70F2;
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;
136 248
 }

+ 112
- 15
js/news.js Parādīt failu

@@ -5,39 +5,131 @@ $(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: "",
11
-    total: 0
10
+    newstitle: $.getQueryVariable("newstitle") || "",
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
-    $.each(params.list, function(newsIndex, newsItem) {
17
-      newsItemHtml = '<div class="news_list_item"><img class="news_item_img" src="' + $.showImageUrl + newsItem.newspic + '" /><div class="news_item_title">' + newsItem.newstitle + '</div><div class="news_item_stitle">' + $.msToDateString(newsItem.createtime) + '</div></div>';
17
+    $.each(params.list, function (newsIndex, newsItem) {
18
+      newsItemHtml =
19
+        '<div class="news_list_item" data-newsid="' +
20
+        newsItem.newsid +
21
+        '"><img class="news_item_img" src="' +
22
+        $.showImageUrl +
23
+        newsItem.newspic +
24
+        '" /><div class="news_item_title">' +
25
+        newsItem.newstitle +
26
+        '</div><div class="news_item_stitle">' +
27
+        $.msToDateString(newsItem.createtime * 1000) +
28
+        "</div></div>";
29
+    });
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
+    });
35
+  }
36
+  // 加载新闻资讯页码
37
+  function loadNewsPages(params) {
38
+    newsInfo.total = params.total || 0;
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++) {
46
+      newsPageHtml +=
47
+        '<div data-page="' +
48
+        (_page + 1) +
49
+        '" class="news_page_num ' +
50
+        (_page + 1 === newsInfo.page ? "selected" : "") +
51
+        '">' +
52
+        (_page + 1) +
53
+        "</div>";
54
+    }
55
+    newsPageHtml +=
56
+      '<div class="news_page_next"><img src="../img/home/scheme/jiantou_right.png" /></div>';
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
+      }
18 105
     });
19
-    $(".news_list_box").html(newsItem);
20 106
   }
21 107
   // 搜索新闻列表
22 108
   function searchList() {
23 109
     let _url = $.baseUrl + "n/listc";
24 110
     $.ajax({
25
-      type: 'POST',
111
+      type: "POST",
26 112
       url: _url,
27 113
       dataType: "json",
28 114
       contentType: "application/json; charset=utf-8",
29 115
       data: JSON.stringify({
30 116
         page: newsInfo.page,
31 117
         size: newsInfo.size,
32
-        newstitle: newsInfo.newstitle
118
+        newstitle: newsInfo.newstitle,
33 119
       }),
34 120
       success: function (data) {
35 121
         if (data.code === 0) {
36
-          loadNewsList(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
+          }
37 129
         } else {
38 130
           alert(data.msg);
39 131
         }
40
-      }
132
+      },
41 133
     });
42 134
   }
43 135
   // 回车搜索
@@ -46,17 +138,22 @@ $(function () {
46 138
     let theEvent = event || window.event;
47 139
     let code = theEvent.keyCode || theEvent.which || theEvent.charCode;
48 140
     let content = theEvent.target.value;
49
-    search_helpcomm = content;
141
+    newsInfo.newstitle = content;
50 142
     if (code == 13) {
51
-      searchList();
143
+      // searchList();
144
+      window.location.href = "/sections/news.html?page=" + newsInfo.page + "&newstitle=" + newsInfo.newstitle;
52 145
     }
53 146
   }
54 147
   // 输入内容改变
55 148
   function searchInputChange(event) {
56 149
     let theEvent = event || window.event;
57
-    search_helpcomm = theEvent.target.value;
150
+    newsInfo.newstitle = theEvent.target.value;
58 151
   }
59 152
   $(".news_info #search_help").on("change", searchInputChange);
60 153
   $(".news_info #search_help").on("keydown", enterSearch);
61
-  $(".news_info .search_box").click(searchList);
62
-});
154
+  $(".news_info .search_box").click(function () {
155
+    // searchList();
156
+    window.location.href = "/sections/news.html?page=" + newsInfo.page + "&newstitle=" + newsInfo.newstitle;
157
+  });
158
+  searchList();
159
+});

+ 39
- 0
js/news_detail.js Parādīt failu

@@ -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
+});

+ 8
- 5
sections/news.html Parādīt failu

@@ -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>
@@ -46,10 +46,13 @@
46 46
       </div>
47 47
     </div>
48 48
     <div class="news_page_box">
49
-      <div></div>
50
-      <div></div>
51
-      <div></div>
52
-      <div></div>
49
+      <!-- <div class="news_page_prev">
50
+        <img src="../img/home/scheme/jiantou_right.png" />
51
+      </div>
52
+      <div class="news_page_num selected">1</div>
53
+      <div class="news_page_next">
54
+        <img src="../img/home/scheme/jiantou_right.png" />
55
+      </div> -->
53 56
     </div>
54 57
     <div class="footer_root"></div>
55 58
     <script src="../librarys/jquery@1.12.4/jquery.min.js"></script>

+ 17
- 0
sections/news_detail.html Parādīt failu

@@ -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>

+ 14
- 1
utils/index.js Parādīt failu

@@ -1,6 +1,6 @@
1 1
 jQuery.extend({
2 2
   baseUrl: "//xhwebapitest.xhkjedu.com/",
3
-  showImageUrl: "//schoolstatic.xhkjedu.com/static/",
3
+  showImageUrl: "//schoolstatictest.xhkjedu.com/static/",
4 4
   //毫秒时间转换为yyyy-MM-dd
5 5
   msToDateString: function (ms) {
6 6
     let date = new Date(ms);
@@ -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
 });

Notiek ielāde…
Atcelt
Saglabāt