原创作品,允许转载,转载时请务必以超链接形式标明文章
原始出处 、作者信息和本声明。否则将追究法律责任。
http://qingkechina.blog.51cto.com/5552198/1544928
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
/**
* 按时间降序排列后标识页面最后一条记录的索引值
*/
var
CURRENT_ITEM_INDEX = 0;
$(document).ready(
function
()
{
// 获取首页内容
getPageContent(CURRENT_ITEM_INDEX);
});
function
getPageContent(currentIndex)
{
var
data = {
"currentIndex"
: currentIndex};
asyncRequest(
"mainContent.data"
, data,
function
(result)
{
// 由第3步实现
});
}
|
1
2
3
4
5
6
7
|
$(document).ready(
function
()
{
// 略
getBreifUserInfo();
// 监听滚动条拖拽事件
bindScrollEvent();
});
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
/**
* 绑定滚动条拖拽事件
*/
function
bindScrollEvent()
{
var
scrollBarDistance = 0;
// 滚动条的当前位置
var
documentHeight = 0;
// 文档高度
var
windowHeight = $(window).height();
// 当前窗口高度
$(window).scroll(
function
(){
scrollBarDistance = $(document).scrollTop();
documentHeight = $(document).height();
if
(scrollBarDistance + windowHeight >= documentHeight)
{
if
(isQueryFlag ===
true
)
{
return
;
}
// 获取页面内容
getPageContent(CURRENT_ITEM_INDEX);
}
});
}
|
1
2
|
<!--获取系统首页内容信息-->
<
business
name
=
"mainContent"
business-class
=
"com.medical.server.data.MainDataAction"
/>
|
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
|
@Override
public
String execute()
throws
FrameException
{
// 获取当前记录索引值
String currentIndex = getParameter(
"currentIndex"
);
if
(FrameUtil.isEmpty(currentIndex))
{
TopicResultBean result =
new
TopicResultBean();
result.setErrorCode(FrameErrorCode.REQUEST_PARAM_ERROR);
return
gson.toJson(result);
}
// 从数据库中读取数据
int
index = Integer.valueOf(currentIndex);
List<TopicDAO> topicList = TopicUtil.getTopicList(index);
if
(FrameUtil.isEmpty(topicList))
{
TopicResultBean result =
new
TopicResultBean();
result.setErrorCode(FrameErrorCode.REQUEST_CONTENT_EMPTY);
return
gson.toJson(result);
}
// 组装界面所需要内容
List<TopicBean> topicBeanList =
new
ArrayList<TopicBean>();
for
(TopicDAO element : topicList)
{
UserDAO author = UserUtil.getUserByName(element.getUserId());
TopicBean bean =
new
TopicBean();
bean.setUserName(author.getUserId());
bean.setUserIcon(author.getIconPath());
bean.setNickName(author.getUserSign());
bean.setTopicId(element.getTopicId());
bean.setTopicTitle(element.getTopicTitle());
bean.setCommentNum(CommentUtil.getCommentNum(element.getTopicId()));
bean.setTopicSummary(getTopicSummary(element.getPrescript()));
bean.setTopicTime(element.getTopicTime());
topicBeanList.add(bean);
}
// 返回JSON结果
TopicResultBean result =
new
TopicResultBean();
result.setErrorCode(
0
);
result.setTopicList(topicBeanList);
return
gson.toJson(result);
}
|
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
|
// 设置查询标识
isQueryFlag =
true
;
asyncRequest(
"mainContent.data"
, data,
function
(result)
{
// 若读取数据未成功直接返回
var
resultJson = eval(result);
if
(resultJson.errorCode != 0)
{
return
;
}
var
topicList = resultJson.topicList;
if
(!topicList){
return
;
}
// 重置数据当前索引值
CURRENT_ITEM_INDEX = CURRENT_ITEM_INDEX + topicList.length;
// 操纵DOM把数据绘制到页面上
$.each(topicList,
function
(i, item){
appendData(i, item);
});
// 重置查询标识
isQueryFlag =
false
;
});
|
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
|
/**
* 操纵DOM把数据绘制到页面上
*/
function
appendData(i, item)
{
var
topicItem = $(
"<div />"
).attr(
"class"
,
"main_item"
);
topicItem.appendTo($(
"#main_content_dynamic_id"
));
// 添加用户头像
var
userIcon = $(
"<i />"
).attr(
"class"
,
"main_item_icon"
);
userIcon.appendTo(topicItem);
// 添加挑战内容
var
content = $(
"<div />"
).attr(
"class"
,
"main_item_content"
);
content.appendTo(topicItem);
// >>>>>>设置挑战话题标题
var
topWrapper = $(
"<div />"
).attr(
"class"
,
"main_item_wrapper"
);
var
topicTitle = $(
"<div />"
).attr(
"class"
,
"main_item_title"
);
var
titleLink = $(
"<a />"
).attr(
"href"
,
"#"
).text(item.topicTitle);
titleLink.appendTo(topicTitle);
topicTitle.appendTo(topWrapper);
topWrapper.appendTo(content);
// >>>>>>设置挑战话题标题
var
topicTime = $(
"<div />"
).attr(
"class"
,
"main_item_time"
).text(item.topicTime);
topicTime.appendTo(topWrapper);
// >>>>>>设置用户名称和昵称
var
centerWrapper = $(
"<div />"
).attr(
"class"
,
"main_item_wrapper"
);
var
userName = $(
"<label />"
).attr(
"class"
,
"main_item_author"
).text(item.userName +
","
);
var
userNick = $(
"<label />"
).attr(
"class"
,
"main_item_nickname"
).text(item.nickName);
userName.appendTo(centerWrapper);
userNick.appendTo(centerWrapper);
centerWrapper.appendTo(content);
// >>>>>>设置话题摘要信息
var
middleWrapper = $(
"<div />"
).attr(
"class"
,
"main_item_wrapper"
);
var
topicSummary = $(
"<div />"
).attr(
"class"
,
"main_item_substance"
).html(item.topicSummary);
topicSummary.appendTo(middleWrapper);
middleWrapper.appendTo(content);
// >>>>>>设置话题附属信息
var
bottomWrapper = $(
"<div />"
).attr(
"class"
,
"main_item_wrapper"
);
var
topicAttach = $(
"<div />"
).attr(
"class"
,
"main_item_attach"
);
topicAttach.appendTo(bottomWrapper);
bottomWrapper.appendTo(content);
// >>>>>>>>>>>>设置话题关注信息
var
followLink = $(
"<a />"
).attr(
"href"
,
"#"
);
var
followIcon = $(
"<i />"
).attr(
"class"
,
"main_item_attention"
);
followIcon.appendTo(followLink);
followLink.appendTo(topicAttach);
followLink.text(
"关注"
);
// >>>>>>>>>>>>设置话题关注信息
var
commentLink = $(
"<a />"
).attr(
"href"
,
"#"
);
var
commentIcon = $(
"<i />"
).attr(
"class"
,
"main_item_discuss"
);
commentIcon.appendTo(commentLink);
commentLink.appendTo(topicAttach);
commentLink.text(item.commentNum +
"人评论"
);
// >>>>>>>>>>>>设置话题分享信息
var
shareLink = $(
"<a />"
).attr(
"href"
,
"#"
);
var
shareIcon = $(
"<i />"
).attr(
"class"
,
"main_item_share"
);
shareIcon.appendTo(shareLink);
shareLink.appendTo(topicAttach);
shareLink.text(
"分享"
);
// >>>>>>>>>>>>设置话题收藏信息
var
favoriteLink = $(
"<a />"
).attr(
"href"
,
"#"
);
var
favoriteIcon = $(
"<i />"
).attr(
"class"
,
"main_item_collection"
);
favoriteIcon.appendTo(favoriteLink);
favoriteLink.appendTo(topicAttach);
favoriteLink.text(
"收藏"
);
}
|