@using Dpz.Core.Infrastructure
@using Newtonsoft.Json
@model IPagedList<VmChatRecord>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>聊天记录</title>
<link rel="stylesheet" href="@(Program.CdnBaseAddress)/lib/layui/css/layui.css">
<style>
body .layim-chat-main { height: auto; }
</style>
</head>
<body>
<div class="layim-chat-main">
<ul id="LAY_view"></ul>
</div>
<div id="LAY_page" style="margin: 0 10px;text-align: center;"></div>
<textarea title="消息模版" id="LAY_tpl" style="display:none;">
{{# layui.each(d.data, function(index, item){
if(item.id == parent.layui.layim.cache().mine.id){ }}
<li class="layim-chat-mine"><div class="layim-chat-user"><img src="{{ item.avatar }}"><cite><i>{{ layui.data.date(item.timestamp) }}</i>{{ item.username }}</cite></div><div class="layim-chat-text">{{ layui.layim.content(item.content) }}</div></li>
{{# } else { }}
<li><div class="layim-chat-user"><img src="{{ item.avatar }}"><cite>{{ item.username }}<i>{{ layui.data.date(item.timestamp) }}</i></cite></div><div class="layim-chat-text">{{ layui.layim.content(item.content) }}</div></li>
{{# }
}); }}
</textarea>
<script src="@(Program.CdnBaseAddress)/lib/layui/layui.js"></script>
<script>
layui.config({
layimPath: "@(Program.CdnBaseAddress)/lib/layim/",
layimAssetsPath: "@(Program.CdnBaseAddress)/lib/layim/layim-assets/",
}).extend({
layim: layui.cache.layimPath + 'layim'
}).use(['layim', 'laypage'],
function() {
let layim = layui.layim,
layer = layui.layer,
laytpl = layui.laytpl,
$ = layui.jquery,
laypage = layui.laypage;
//开始请求聊天记录
let param = location.search,
res = {
code: 0,
msg: '',
data:
@Html.Raw(JsonConvert.SerializeObject(Model.Select(x => new{username = x.Sender.Name,id = x.Sender.Id,avatar = x.Sender.Avatar,timestamp = (x.SendTime.ToTimeStamp() * 1000),content = x.Message})))
};
laypage.render({
elem: 'LAY_page',
count: @Model.TotalItemCount,
limit: 100,
hash: true,
jump: function(obj, first) {
console.log(obj.curr);
console.log(obj.limit);
console.log(location.search);
//首次不执行
if (!first) {
$.ajax({
url: param + "&pageIndex=" + obj.curr
}).done(function(result) {
var html = laytpl(LAY_tpl.value).render({
data: result
});
$('#LAY_view').html(html);
});
}
}
});
var html = laytpl(LAY_tpl.value).render({
data: res.data
});
$('#LAY_view').html(html);
});
</script>
</body>
</html>