xwdt.js
3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
$(function () {
layui.use('element', function () {
let element = layui.element; //导航的hover效果、二级菜单等功能,需要依赖element模块
});
LoadNewsData();
HotArticle();
PolicyHotArticle();
addTabs('#news');
});
//加载新闻列表数据
function LoadNewsData(currentPage) {
var currentPage = currentPage || 1;
$.ajax({
type: "get", //提交方式
url: portal.api_url + "/portal/MhNews/getNewsArticleList",//路径
data: {
"currentPage": currentPage,
"pageSize": 5
},
async: false,
dataType: "json",
//数据,这里使用的是Json格式进行传输
success: function (result) {
data.total = result.data.total;
if (result.code == 200 && result.data != null) {
data.list = result.data.records;
}
layui.use('laytpl', function () {
laytpl = layui.laytpl;
var getTpl = document.getElementById('demo').innerHTML
, view = document.getElementById('ulNews');
laytpl(getTpl).render(data, function (html) {
view.innerHTML = html;
})
})
}
})
}
// 获取新闻动态的推荐数据
function HotArticle() {
var recommend = $("#news_recommendation");
recommend.empty();
var li = '';
$.ajax({
type: "get", //提交方式
url: portal.api_url + "/portal/MhNews/getNewsHotArticleList",//路径
dataType: "json",
//数据,这里使用的是Json格式进行传输
success: function (result) {//返回数据根据结果进行相应的处理
if (result.code == 200 && result.data != null) {
for (var i = 0; i < result.data.length; i++) {
li = '<li class="tj"><a href="./xwxq.html?id='+result.data[i].id+'" target="_blank">';
if ( result.data[i].cover ) {
li += '<img src="' + result.data[i].cover + '">';
}
li += '<span class="tj-title">' + result.data[i].headline + '</span>';
li += '<span class="tj-date">' + result.data[i].deadtime + '</span>';
li += '</a></li>';
recommend.append(li);
}
}
}
})
}
// 政策法规推荐
function PolicyHotArticle() {
var regulation = $("#regulation");
regulation.empty();
var li = '';
$.ajax({
type: "get", //提交方式
url: portal.api_url + "/portal/MhPolicy/getPolicyHotArticleList",//路径
dataType: "json",
//数据,这里使用的是Json格式进行传输
success: function (result) {//返回数据根据结果进行相应的处理
if (result.code == 200 && result.data != null) {
for (var i = 0; i < result.data.length; i++) {
li = '<li class="zcfg">'
li += '<div class="zcfg-top">' + result.data[i].headline + '</div>'
li += '<p class="zcfg-body">' + result.data[i].summary + '</p>'
li += '<div class="zcfg-bottom">' + result.data[i].deadtime + '</div>'
li += '</li>'
regulation.append(li);
}
}
}
})
}
layui.use('laypage', function () {
let laypage = layui.laypage;
laypage.render({
elem: 'page' //注意,这里的 test1 是 ID,不用加 # 号
, count: data.total //数据总数,从服务端得到
, limit: 5
, prev: '<'
, next: '>'
, theme: '#0091FF'
, jump: function (obj, first) {
if (!first) {
LoadNewsData(obj.curr);
}
}
});
})
var data = { //数据
"list": [],
total: undefined
};