This commit is contained in:
2018-03-27 13:52:36 +08:00
parent e699ead679
commit 8c3c7b4db9
7 changed files with 320 additions and 2 deletions
+273 -2
View File
@@ -25,13 +25,54 @@
</button>
<h1 class="title"></h1>
</header>
<div class="content contentText">
<div class="content contentText infinite-scroll infinite-scroll-bottom" data-distance="40">
<div class="content-padded">
<h1 id="title"></h1>
<p><small id="source"></small><small style="float:right;" id="visit_count"><i class="icon icon-eye"></i></small><br><small id="create_time"></small></p>
<div id="content">
</div>
</div>
<div class="newCss">
<ul>
<li><span>房贷</span></li>
<li><span>广州</span></li>
<li><span>首套房</span></li>
</ul>
</div>
<div class="adBoxApp">
<img src="../../images/wx_app.png">
<p><label>有房&nbsp;&nbsp;有家&nbsp;&nbsp;有爱</label><br><small>更多房产资讯上有房APP</small></p>
</div>
<div class="list-block media-list commentList">
<ul>
</ul>
</div>
<!-- 加载提示符 -->
<div class="infinite-scroll-preloader" style="position: relative;top: -70px;">
<div class="preloader"></div>
</div>
</div>
<div class="bar commentInput">
<div class="searchbar row">
<div class="search-input col-66">
<label class="icon icon-comments" for="search"></label>
<input type="text" placeholder="我也说两句">
</div>
<span class="col-33">
<a class="praise"><i class="icon icon-praise-grey02"></i><label id="newsPraise"></label></a>
<a class="collection collection01"><i class="icon icon-collection01"></i></a>
<a class="collection collection02 dn"><i class="icon icon-collection02"></i></a>
</span>
</div>
</div>
</div>
</div>
</div>
@@ -45,16 +86,20 @@ Zepto = $
$.config = {router: false}
</script>
<script type="text/javascript" src="../../js/beacon_release.js"></script>
<script type="text/javascript" src="../../js/light7.js" charset="utf-8"></script>
<script type="text/javascript" src="../../js/cn.js" charset="utf-8"></script>
<script src="../../config.js"></script>
<script type="text/javascript" src="../../js/common.js" ></script>
<script type="text/javascript" src="../../js/axios.min.js"></script>
<script>
document.addEventListener('plusready', onPlusReady, false);
var id = "183627425584775168";
function onPlusReady() {
var self = plus.webview.currentWebview();
var id = self.newsId;
id = self.newsId;
$.ajax({
type : 'get',
url : BASE_PATH + "/rest/news/detail",
@@ -72,13 +117,239 @@ function onPlusReady() {
var dateStr = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
$("#create_time").text(dateStr)
$("#content").html(data.content)
$("#newsPraise").text(data.thumbsUpCount);
//预先加载20条
}
},
error:function(){
}
})
}
//新闻评论列表
$.init()
//加载flag
var loading = false;
//最多可加载的条目
var maxItems = 100;
//上次加载的序号
var lastIndex = 0;
//每次加载添加多少条目
var itemsPerLoad = 10;
var url = BASE_PATH + "/rest/news/comment"
var curpage = 1;
var totalCount = 0;
var curPageSize = 0;
function addItems(number, lastIndex) {
if(!id){
return;
}
curpage = lastIndex/itemsPerLoad + 1;
axios.get(url, {
params: {
newsId: id,
page:curpage,
pageSize:itemsPerLoad
}
})
.then(function (response) {
var results = response.data.data
if(results==null || results.length==0) {
// 加载完毕,则注销无限加载事件,以防不必要的加载
$.detachInfiniteScroll($('.infinite-scroll'));
// 删除加载提示符
$('.infinite-scroll-preloader').remove();
$('.infinite-scroll-bottom').html("");
return;
}
curPageSize = results.length;
// 生成新条目的HTML
var html = '';
for(var i in results){
var vo = results[i];
html = html+"<li>"+
"<a class='item-content'>";
if(vo.headImg!=null){
html = html + "<div class='item-media'><img src='"+vo.headImg+"'></div>";
}else{
html = html + "<div class='item-media'><img src='../../images/headPortrait.png'></div>";
}
html = html + "<div class='item-inner'>";
var name = "游客"
if(vo.wxName){
name = vo.wxName
}else if(vo.name){
name = vo.name
}
html = html + "<div class='item-title-row'>"+
"<div class='item-title'>"+name+"</div>"+
"<div class='item-after'><span><i class='icon icon-praise-grey01'></i>"+vo.praiseCount+"</span></div>"+
"</div>"+
"<div class='item-title-row'>";
var address = "";
if(vo.commentUserProvince && vo.commentUserCity && vo.commentUserProvince == vo.commentUserCity){
html = html + "<div class='item-title'><span>"+vo.commentUserCity+" </span></div>";
}else{
html = html + "<div class='item-title'><span>"+vo.commentUserProvince+vo.commentUserCity+" </span></div>";
}
var curTime = new Date().getTime()
var publishTime = vo.addTime;
var timeString = getDateDiff(curTime, publishTime)
html = html + "<div class='item-after'><span>"+timeString+"</span></div>"+
"</div>"+
"<div class='item-text'>"+vo.content+"</div>"+
"</div>"+
"</a>"+
"</li>";
}
// 添加新条目
$('.commentList ul').append(html);
if($('.commentList li').length== totalCount+1){
// 加载完毕,则注销无限加载事件,以防不必要的加载
$.detachInfiniteScroll($('.infinite-scroll'));
// 删除加载提示符
$('.infinite-scroll-preloader').hide();
}
})
.catch(function (error) {
console.log(error);
});
}
addItems(itemsPerLoad, 0);
//注册'infinite'事件处理函数
$(document).on('infinite', '.infinite-scroll-bottom',function() {
// 如果正在加载,则退出
if (loading) return;
// 设置flag
loading = true;
// 模拟1s的加载过程
setTimeout(function() {
// 重置加载flag
loading = false;
// 更新最后加载的序号
lastIndex = $('.commentList li').length;
if (curPageSize < itemsPerLoad) {
// 加载完毕,则注销无限加载事件,以防不必要的加载
$.detachInfiniteScroll($('.infinite-scroll'));
// 删除加载提示符
$('.infinite-scroll-preloader').hide();
return;
}
// 添加新条目
addItems(itemsPerLoad, $('.commentList li').length);
//容器发生改变,如果是js滚动,需要刷新滚动
// $.refreshScroller();
}, 1000);
});
var MINU_SEC = 60;
var HOUR_SEC = 3600;
var DAY_SEC = HOUR_SEC * 24;
var MONTH_SEC = DAY_SEC * 30;
var YEAR_SEC = MONTH_SEC * 12;
function getDateDiff(curTime, publishTime){
if (publishTime <= curTime) {
var diffSec = (curTime - publishTime) / 1000;
if (diffSec < DAY_SEC) {
if (diffSec >= HOUR_SEC) {
var t = diffSec / HOUR_SEC;
return parseInt(t) + "小时前";
} else if (diffSec >= MINU_SEC) {
var t = diffSec / MINU_SEC;
return parseInt(t) + "分钟前";
} else {
return "刚刚";
}
} else if (DAY_SEC > diffSec && diffSec < DAY_SEC*2) {
return "昨天";
} else {
var date = new Date(publishTime)
var dateStr = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
return dateStr;
}
} else {
return "刚刚";// 输入时间大于 系统时间 返回 "刚刚"
}
}
//添加评论
//点赞
$(".icon-praise-grey02").click(function(){
axios.get(BASE_PATH+"/rest/news/thumbsUp", {
params: {
newsId : id
}
})
.then(function (response) {
var msg = response.data.data
$.toast(msg);
})
.catch(function (error) {
console.log(error);
});
});
//收藏
$(".collection01").on("click", function () {
$(".collection01").hide();
$(".collection02").show();
collect();
});
$(".collection02").on("click", function () {
$(".collection02").hide();
$(".collection01").show();
collect();
});
function collect(){
//var params = new URLSearchParams();
//params.append('newsId', id);
axios.post(BASE_PATH+"/rest/news/collect", {
params: {
newsId : id
}
})
.then(function (response) {
var msg = response.data.data
$.toast(msg);
})
.catch(function (error) {
console.log(error);
});
}
</script>
</body>