添加公示数据加载
Showing
3 changed files
with
71 additions
and
15 deletions
... | @@ -143,7 +143,7 @@ | ... | @@ -143,7 +143,7 @@ |
143 | <i>查看全部 ></i> | 143 | <i>查看全部 ></i> |
144 | </a> | 144 | </a> |
145 | </h2> | 145 | </h2> |
146 | <ul class="notice_list"> | 146 | <ul class="notice_list" id="ulNotice"> |
147 | <li> | 147 | <li> |
148 | <a href="" title="1地信中心开展外业安全生产监控系统培训工作"> | 148 | <a href="" title="1地信中心开展外业安全生产监控系统培训工作"> |
149 | 1地信中心开展外业安全生产监控系统培训工作 | 149 | 1地信中心开展外业安全生产监控系统培训工作 | ... | ... |
1 | //设置当前页面导航栏背景色 | 1 | //设置当前页面导航栏背景色 |
2 | function addTabs(id){ | 2 | function addTabs(id) { |
3 | $('.layui-nav-item').removeClass('layui-this') | 3 | $('.layui-nav-item').removeClass('layui-this') |
4 | $(id).addClass('layui-this') | 4 | $(id).addClass('layui-this') |
5 | } | 5 | } |
6 | 6 | ||
7 | //设置ajax调取服务接口 | 7 | //设置ajax调取服务接口 |
8 | 8 | ||
9 | function SetServicesPath(){ | 9 | function SetServicesPath() { |
10 | return "http://192.168.2.108" | 10 | return "http://192.168.2.108" |
11 | } | 11 | } |
12 | 12 | ||
13 | //设置全局參數 | 13 | //设置全局參數 |
... | @@ -17,10 +17,10 @@ var portal = | ... | @@ -17,10 +17,10 @@ var portal = |
17 | 'name': 'myName' | 17 | 'name': 'myName' |
18 | }; | 18 | }; |
19 | 19 | ||
20 | 20 | //截取日期 | |
21 | function CutDate(times){ | 21 | function CutDate(times) { |
22 | var timearr = times.replace(" ", ":").replace(/\:/g, "-").split("-"); | 22 | var timearr = times.replace(" ", ":").replace(/\:/g, "-").split("-"); |
23 | var timestr = ""+timearr[0]+"/" + timearr[1] + "/" + timearr[2] | 23 | var timestr = "" + timearr[0] + "/" + timearr[1] + "/" + timearr[2] |
24 | //var timestr = "" + timearr[1].split("")[1] + "月" + timearr[2] + "日\t" + timearr[3] + ":" + timearr[4] + "" | 24 | //var timestr = "" + timearr[1].split("")[1] + "月" + timearr[2] + "日\t" + timearr[3] + ":" + timearr[4] + "" |
25 | return timestr | 25 | return timestr |
26 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
26 | } | ... | ... |
... | @@ -29,17 +29,39 @@ layui.use('util', function () { | ... | @@ -29,17 +29,39 @@ layui.use('util', function () { |
29 | }); | 29 | }); |
30 | }); | 30 | }); |
31 | 31 | ||
32 | var recentlyDay; | ||
33 | |||
34 | function getDate() { | ||
35 | var date = new Date(); | ||
36 | var base = new Date(date).getTime(); | ||
37 | var oneDay = 24 * 3600 * 1000; | ||
38 | var date = []; | ||
39 | var data = [Math.random() * 300]; | ||
40 | var time = new Date(base); | ||
41 | date.push([time.getFullYear(), time.getMonth() + 1, time.getDate()].join('/')); | ||
42 | for (var i = 1; i < 7; i++) {//控制需要的天数 | ||
43 | var now = new Date(base -= oneDay); //这里控制往前一周还是往后一周 | ||
44 | date.push([now.getFullYear(), now.getMonth() + 1, now.getDate()].join('/')); | ||
45 | data.push(Math.round((Math.random() - 0.5) * 20 + data[i - 1])); | ||
46 | } | ||
47 | return date.reverse(); | ||
48 | // var newdate = date.reverse(); //往后一周的话需要将数组倒叙 | ||
49 | //console.log(date); | ||
50 | } | ||
51 | |||
32 | //初始化方法 | 52 | //初始化方法 |
33 | $(function () { | 53 | $(function () { |
34 | // NewsData(); | 54 | addTabs('#index'); |
35 | addTabs('#index') | 55 | recentlyDay = getDate(); |
56 | NewsData(); | ||
57 | NoticeData(); | ||
36 | }); | 58 | }); |
37 | 59 | ||
38 | //加载新闻首页数据 | 60 | //加载新闻数据 |
39 | function NewsData() { | 61 | function NewsData() { |
40 | var ulNews = $("#ulNews"); | 62 | var ulNews = $("#ulNews"); |
41 | ulNews.empty(); | 63 | ulNews.empty(); |
42 | var str = ''; | 64 | var li, publishTime; |
43 | $.ajax({ | 65 | $.ajax({ |
44 | type: "get", //提交方式 | 66 | type: "get", //提交方式 |
45 | url: portal.api_url + "/hlwj/Mh/getNewsHotArticleList",//路径 | 67 | url: portal.api_url + "/hlwj/Mh/getNewsHotArticleList",//路径 |
... | @@ -49,13 +71,47 @@ function NewsData() { | ... | @@ -49,13 +71,47 @@ function NewsData() { |
49 | if (result.code == 200 && result.data != null) { | 71 | if (result.code == 200 && result.data != null) { |
50 | for (var i = 0; i < result.data.length; i++) { | 72 | for (var i = 0; i < result.data.length; i++) { |
51 | if (i == 6) return; | 73 | if (i == 6) return; |
52 | str = '<li><a href="#" title="' + result.data[i].headline + '">' + result.data[i].headline + '</a>'; | 74 | publishTime = CutDate(result.data[i].publishTime); |
53 | str+='<span>' + CutDate(result.data[i].publishTime) + '</span></li>'; | 75 | li = '<li><a href="#" title="' + result.data[i].headline + '">'; |
54 | ulNews.append(str); | 76 | li += '<div class="news_item">'; |
77 | if (recentlyDay.indexOf(publishTime) > -1) { | ||
78 | li += '<svg class="icon svg-icon" aria-hidden="true"> <use xlink:href="#iconzuixin"></use> </svg>'; | ||
79 | } | ||
80 | li += result.data[i].headline + '</div>'; | ||
81 | li += '<span>' + publishTime + '</span></a></li>'; | ||
82 | ulNews.append(li); | ||
55 | } | 83 | } |
56 | 84 | ||
57 | } | 85 | } |
58 | } | 86 | } |
59 | }); | 87 | }); |
88 | } | ||
60 | 89 | ||
90 | //加载公告数据 | ||
91 | function NoticeData() { | ||
92 | var ulTag = $("#ulNotice"); | ||
93 | ulTag.empty(); | ||
94 | var li; | ||
95 | $.ajax({ | ||
96 | type: "get", //提交方式 | ||
97 | url: portal.api_url + "/hlwj/Mh/getMHNotice",//路径 | ||
98 | dataType: "json", | ||
99 | //数据,这里使用的是Json格式进行传输 | ||
100 | success: function (result) {//返回数据根据结果进行相应的处理 | ||
101 | if (result.code == 200 && result.data != null) { | ||
102 | for (var i = 0; i < result.data.length; i++) { | ||
103 | if (i == 6) return; | ||
104 | li = '<li><a href="#" title="' + result.data[i].title + '">' + result.data[i].title; | ||
105 | if (result.data[i].noticeType == 1) { | ||
106 | li += '<svg class="icon svg-icon" aria-hidden="true"> <use xlink:href="#icongonggao1"></use> </svg>'; | ||
107 | } | ||
108 | else { | ||
109 | li += '<svg class="icon svg-icon" aria-hidden="true"> <use xlink:href="#icongongshi"></use> </svg>'; | ||
110 | } | ||
111 | li += '</a></li>'; | ||
112 | ulTag.append(li); | ||
113 | } | ||
114 | } | ||
115 | } | ||
116 | }); | ||
61 | } | 117 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment