course_use_log.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. {extend name="public/layout"}
  2. {block name="body"}
  3. <style>
  4. html,body {
  5. background-color: #fff;
  6. }
  7. .layui-table thead tr,
  8. .layui-table-header {
  9. background-color: #D8E6F1 !important;
  10. }
  11. </style>
  12. <body>
  13. <div class="layui-fluid">
  14. <div class="layui-row layui-col-space15">
  15. <div class="layui-col-md12">
  16. <div class="layui-card">
  17. <div class="layui-card-body">
  18. <form class="layui-form" enctype="multipart/form-data" lay-filter="records">
  19. <div class="layui-form">
  20. <div class="layui-inline" style="width: 100%;">
  21. <!-- <span style="float:left"><a class="layui-btn layui-btn-xs" id="hotseting" >人气管理</a></span>-->
  22. <p style="text-align: right; float:right">当前在线:<span id="onlinenumber" style="color:green"></span>
  23. 人<span>
  24. <!-- <a class="layui-btn layui-btn-xs" id="refreshbutton">刷新</a></span> -->
  25. </p>
  26. </div>
  27. </div>
  28. </form>
  29. <table class="layui-hide" id="records" lay-filter="records"></table>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. {/block}
  36. {block name="js"}
  37. <script src="__STATIC__/js/jquery.min.js"></script>
  38. <script type="text/html" id="onlineTpl">
  39. {{# if(d.online) { }}
  40. <div style="text-align: center; color:green">在线</div>
  41. {{# }else{}}
  42. <div style="text-align: center; color:#c0c4cc;">离线</div>
  43. {{# } }}
  44. </script>
  45. <script type="text/html" id="switchTpl">
  46. <input type="checkbox" name="state" value="{{d.id}}" lay-skin="switch" lay-text="开|关" lay-filter="state" {{
  47. d.state== 1 ? 'checked disabled' : '' }}>
  48. </script>
  49. <script type="text/html" id="sex">
  50. {{# if(d.sex == 1){ }}
  51. {{# }else if(d.sex==2){ }}
  52. {{# }else { }}
  53. 未知
  54. {{# } }}
  55. </script>
  56. <script type="text/html" id="time">
  57. var time = math.floor({{d.time}});
  58. </script>
  59. <script>
  60. var courseid = '{$cid}';
  61. var useLog = '{:url("broad/course_use_log")}';
  62. var hotsetting = '{:url("course/hotsetting")}';
  63. var ta;
  64. layui.use(['table', 'form'], function () {
  65. var date = new Date();
  66. var form = layui.form
  67. , table = layui.table
  68. , $ = layui.jquery
  69. , active = {
  70. };
  71. //展示已知数据
  72. ta = table.render({
  73. elem: '#records'
  74. , initSort: {
  75. field: 'online'
  76. , type: 'desc'
  77. }
  78. , height: 'full-110'
  79. , url: useLog + '?cid=' + courseid
  80. , parseData: function (res) { //res 即为原始返回的数据
  81. $('#onlinenumber').text(res.onlinenum);
  82. return {
  83. "code": res.code, //解析接口状态
  84. "count": res.count, //解析数据长度
  85. "data": res.data, //解析数据列表
  86. };
  87. }
  88. , page: true
  89. , autoSort: true
  90. , cols: [[ //标题栏
  91. { type: 'numbers', title: '序号', fixed: 'left', width: 50 }
  92. , { field: 'nickname', title: '微信昵称', width: 120 }
  93. , { field: 'sex', title: '性别', width: 80, templet: '#sex' }
  94. , { field: 'first_login_time', title: '第一次访问时间', sort: true }
  95. , {
  96. field: 'total_duration', title: '累计访问时间', templet: function (d) {
  97. total_i = parseInt(d.total_duration / 60); //总分钟
  98. i = total_i % 60;
  99. h = parseInt(total_i / 60);
  100. s = d.total_duration % 60; //秒
  101. time = '';
  102. if (h !== 0) {
  103. time += h + '时';
  104. }
  105. if (i !== 0) {
  106. time += i + '分';
  107. }
  108. if (s !== 0) {
  109. time += s + '秒';
  110. }
  111. return time;
  112. }
  113. }
  114. , { field: 'online', title: '状态', toolbar: '#onlineTpl', width: 100, sort: true }
  115. ]]
  116. , id: 'recordTable'
  117. });
  118. $('.layui-form>.layui-btn').on('click', function () {
  119. var type = $(this).data('type');
  120. active[type] ? active[type].call(this) : '';
  121. });
  122. table.on('sort(records)', function (obj) {
  123. if (obj.type == null) obj.field = 'last_login_time';
  124. table.reload('recordTable', {
  125. initSort: obj
  126. , where: obj
  127. });
  128. });
  129. table.on('toolbar(records)', function (obj) {
  130. var type = obj.event;
  131. active[type] ? active[type].call(this) : '';
  132. });
  133. table.on('tool(records)', function (obj) {
  134. var type = obj.event;
  135. active[type] ? active[type].call(obj) : '';
  136. })
  137. form.on('switch(state)', function (obj) {
  138. var id = this.value;
  139. var cid = '{$cid}';
  140. $.post('{:url("course/vodstate")}', { id: id, cid: cid }, function (res) {
  141. if (res.code == 0) {
  142. layer.msg(res.msg, { anim: 0 }, function () {
  143. });
  144. } else {
  145. layer.msg(res.msg, { anim: 6 });
  146. }
  147. table.reload('recordTable', {
  148. page: {
  149. curr: 1 //重新从第 1 页开始
  150. }
  151. });
  152. });
  153. });
  154. $('#refreshbutton').on('click', function () {
  155. table.reload('recordTable', {
  156. page: {
  157. curr: 1 //重新从第 1 页开始
  158. }
  159. });
  160. });
  161. $('#hotseting').on('click', function () {
  162. layer.open({
  163. title: ['人气设置', 'color:#333333;background-color:#D8E6F1;'],
  164. type: 2,
  165. content: hotsetting + '?cid=' + courseid,
  166. resize: false,
  167. area: ['80%', '80%']
  168. });
  169. });
  170. });
  171. </script>
  172. {/block}