chatlog.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  6. <title>聊天记录</title>
  7. <link rel="stylesheet" href="http://local.res.layui.com/layui/src/css/layui.css">
  8. <style>
  9. body .layim-chat-main{height: auto;}
  10. </style>
  11. </head>
  12. <body>
  13. <div class="layim-chat-main">
  14. <ul id="LAY_view"></ul>
  15. </div>
  16. <div id="LAY_page" style="margin: 0 10px;"></div>
  17. <textarea title="消息模版" id="LAY_tpl" style="display:none;">
  18. {{# layui.each(d.data, function(index, item){
  19. if(item.id == parent.layui.layim.cache().mine.id){ }}
  20. <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>
  21. {{# } else { }}
  22. <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>
  23. {{# }
  24. }); }}
  25. </textarea>
  26. <!--
  27. 上述模版采用了 laytpl 语法,不了解的同学可以去看下文档:http://www.layui.com/doc/modules/laytpl.html
  28. -->
  29. <script src="http://local.res.layui.com/layui/src/layui.js"></script>
  30. <script>
  31. layui.use(['layim', 'laypage'], function(){
  32. var layim = layui.layim
  33. ,layer = layui.layer
  34. ,laytpl = layui.laytpl
  35. ,$ = layui.jquery
  36. ,laypage = layui.laypage;
  37. //聊天记录的分页此处不做演示,你可以采用laypage,不了解的同学见文档:http://www.layui.com/doc/modules/laypage.html
  38. //开始请求聊天记录
  39. var param = location.search //获得URL参数。该窗口url会携带会话id和type,他们是你请求聊天记录的重要凭据
  40. //实际使用时,下述的res一般是通过Ajax获得,而此处仅仅只是演示数据格式
  41. ,res = {
  42. code: 0
  43. ,msg: ''
  44. ,data: [{
  45. username: '纸飞机'
  46. ,id: 100000
  47. ,avatar: 'http://tva3.sinaimg.cn/crop.0.0.512.512.180/8693225ajw8f2rt20ptykj20e80e8weu.jpg'
  48. ,timestamp: 1480897882000
  49. ,content: 'face[抱抱] face[心] 你好啊小美女'
  50. }, {
  51. username: 'Z_子晴'
  52. ,id: 108101
  53. ,avatar: 'http://tva3.sinaimg.cn/crop.0.0.512.512.180/8693225ajw8f2rt20ptykj20e80e8weu.jpg'
  54. ,timestamp: 1480897892000
  55. ,content: '你没发错吧?face[微笑]'
  56. },{
  57. username: 'Z_子晴'
  58. ,id: 108101
  59. ,avatar: 'http://tva3.sinaimg.cn/crop.0.0.512.512.180/8693225ajw8f2rt20ptykj20e80e8weu.jpg'
  60. ,timestamp: 1480897898000
  61. ,content: '你是谁呀亲。。我爱的是贤心!我爱的是贤心!我爱的是贤心!重要的事情要说三遍~'
  62. },{
  63. username: 'Z_子晴'
  64. ,id: 108101
  65. ,avatar: 'http://tva3.sinaimg.cn/crop.0.0.512.512.180/8693225ajw8f2rt20ptykj20e80e8weu.jpg'
  66. ,timestamp: 1480897908000
  67. ,content: '注意:这些都是模拟数据,实际使用时,需将其中的模拟接口改为你的项目真实接口。\n该模版文件所在目录(相对于layui.js):\n/css/modules/layim/html/chatlog.html'
  68. }]
  69. }
  70. //console.log(param)
  71. var html = laytpl(LAY_tpl.value).render({
  72. data: res.data
  73. });
  74. $('#LAY_view').html(html);
  75. });
  76. </script>
  77. </body>
  78. </html>