index.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. {extend name="app/shop/view/base.html"/}
  2. {block name="resources"}
  3. <style>
  4. .progress-layer {width:400px;background:#fff;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);box-shadow:1px 1px 50px rgba(0,0,0,.3);padding:20px 20px;z-index:100;display:none;}
  5. .progress-layer h3 {line-height:1;margin-bottom:15px;text-align:center;font-size:14px;}
  6. .progress-layer .layui-progress-big,.progress-layer .layui-progress-big .layui-progress-bar {height:14px;line-height:14px;}
  7. .progress-layer .layui-progress-text {line-height:14px;}
  8. .room-info {padding: 5px 0;align-items: center;flex-wrap:unset!important;}
  9. .room-info .room-img{width:50px;height: 50px;background: #f5f5f5;}
  10. .room-info img {width:50px;height: 50px;}
  11. .room-info .room-name {padding-left: 5px;line-height: 1;flex: 1}
  12. .single-filter-box{justify-content: end}
  13. .push-layer{text-align: center;padding: 30px 0;}
  14. .push-layer .qrcode{width:100px;height:100px;margin:10px auto;display:block}
  15. .layui-layout-admin.admin-style-2 .layui-body .layui-tab + .body-content {
  16. padding-top: 65px !important;
  17. }
  18. </style>
  19. {/block}
  20. {block name="main"}
  21. <div class="single-filter-box">
  22. <button class="layui-btn" onclick="sync()">同步直播间</button>
  23. <a href="{:addon_url('live://shop/room/add')}" class="layui-btn layui-btn-primary">添加直播间</a>
  24. </div>
  25. <table id="room_list" lay-filter="room_list"></table>
  26. <!-- 直播间信息 -->
  27. <script type="text/html" id="roominfo">
  28. <div class="table-btn room-info">
  29. <div class="room-img">
  30. <img src="{{ ns.img(d.share_img) }}">
  31. </div>
  32. <div class="room-name" title="{{ d.name }}">{{ d.name }}</div>
  33. </div>
  34. </script>
  35. <!-- 操作 -->
  36. <script type="text/html" id="operation">
  37. <div class="table-btn">
  38. <a class="layui-btn" lay-event="operate">运营</a>
  39. {{# if( d.live_status == '102' ){ }}
  40. <a class="layui-btn" lay-event="push">推流入口</a>
  41. {{# } }}
  42. <a class="layui-btn" lay-event="delete">删除</a>
  43. </div>
  44. </script>
  45. <div class="progress-layer">
  46. <h3>正在同步中...</h3>
  47. <div class="layui-progress layui-progress-big" lay-showPercent="true" lay-filter="progress">
  48. <div class="layui-progress-bar layui-bg-blue" lay-percent="0%"></div>
  49. </div>
  50. </div>
  51. <script type="text/html" id="push">
  52. <div class="push-layer">
  53. <img src="LIVE_IMG/weapp_push.png" class="qrcode">
  54. <p>主播可通过微信扫该小程序码或搜一搜“小程序直播”进入主播小程序进行推流</p>
  55. </div>
  56. </script>
  57. <!-- 批量操作 -->
  58. <script type="text/html" id="batchOperation">
  59. <button class="layui-btn layui-btn-primary" lay-event="delete">批量删除</button>
  60. </script>
  61. {/block}
  62. {block name="script"}
  63. <script>
  64. var form,table,element,syncClick = false,repeat_flag = false;
  65. layui.use(['form', 'element'], function() {
  66. form = layui.form;
  67. element = layui.element;
  68. table = new Table({
  69. elem: '#room_list',
  70. url: ns.url("live://shop/room/index"),
  71. bottomToolbar: "#batchOperation",
  72. cols: [
  73. [{
  74. type: 'checkbox',
  75. unresize: 'false',
  76. width: '3%'
  77. },{
  78. title: '直播间信息',
  79. unresize: 'false',
  80. width: '17%',
  81. templet: "#roominfo"
  82. }, {
  83. field: 'roomid',
  84. title: '直播间ID',
  85. unresize: 'false',
  86. width: '10%'
  87. }, {
  88. field: 'anchor_name',
  89. title: '主播昵称',
  90. unresize: 'false',
  91. width: '10%'
  92. }, {
  93. field: 'start_time',
  94. title: '开播时间',
  95. unresize: 'false',
  96. width: '15%',
  97. templet: function(data) {
  98. return ns.time_to_date(data.start_time);
  99. }
  100. }, {
  101. field: 'end_time',
  102. title: '结束时间',
  103. unresize: 'false',
  104. width: '15%',
  105. templet: function(data) {
  106. return ns.time_to_date(data.end_time);
  107. }
  108. }, {
  109. title: '商品数量',
  110. unresize: 'false',
  111. width: '10%',
  112. templet: function(data) {
  113. return data.goods.length;
  114. }
  115. }, {
  116. field: 'status_name',
  117. title: '状态',
  118. unresize: 'false',
  119. width: '10%',
  120. }, {
  121. title: '操作',
  122. toolbar: '#operation',
  123. unresize: 'false',
  124. align:'right'
  125. }]
  126. ]
  127. });
  128. table.tool(function(obj) {
  129. var data = obj.data;
  130. switch (obj.event) {
  131. case 'operate': // 运营
  132. location.href = ns.url("live://shop/room/operate", {"id": data.id});
  133. break;
  134. case 'push':
  135. layer.open({
  136. type: 1,
  137. title: false,
  138. skin: 'weapp-preview',
  139. closeBtn: 1, //不显示关闭按钮
  140. anim: 0,
  141. shadeClose: false,
  142. content: $('#push').html()
  143. });
  144. break;
  145. case 'delete':
  146. deleteRoom(data.id);
  147. break;
  148. }
  149. })
  150. // 批量操作
  151. table.bottomToolbar(function (obj) {
  152. if (obj.data.length < 1) {
  153. layer.msg('请选择要操作的数据');
  154. return;
  155. }
  156. var id_array = new Array();
  157. for (i in obj.data) id_array.push(obj.data[i].id);
  158. switch (obj.event) {
  159. case "delete":
  160. deleteRoom(id_array.toString());
  161. break;
  162. }
  163. });
  164. });
  165. // 同步直播间
  166. function sync(start){
  167. if (syncClick) return;
  168. syncClick = true;
  169. start = start == undefined ? 0 : start;
  170. $.ajax({
  171. url: ns.url("live://shop/room/sync"),
  172. data: {
  173. start: 0,
  174. },
  175. dataType: 'JSON',
  176. type: 'POST',
  177. success: function(res) {
  178. syncClick = false;
  179. if (res.code == 0) {
  180. var data = res.data,
  181. next = parseInt(start) + 1;
  182. if (next < data.total_page) {
  183. if (start == 0) {
  184. $(".progress-layer").fadeOut();
  185. }
  186. var progress = (next / data.total_page * 100).toFixed(2);
  187. element.progress('progress', progress + '%');
  188. // 拉取下一页
  189. sync(next);
  190. } else {
  191. if (!$(".progress-layer").is(':hidden')) $(".progress-layer").fadeOut();
  192. layer.closeAll();
  193. layer.msg('同步成功');
  194. table.reload();
  195. }
  196. } else {
  197. layer.msg(res.message);
  198. }
  199. }
  200. });
  201. }
  202. function
  203. deleteRoom(room_ids){
  204. layer.confirm('是否确定要删除所选直播间?', {title: '提示'}, function () {
  205. if (repeat_flag) return;
  206. repeat_flag = true;
  207. $.ajax({
  208. url: ns.url("live://shop/room/delete"),
  209. data: {room_ids: room_ids},
  210. dataType: 'JSON',
  211. type: 'POST',
  212. success: function (res) {
  213. layer.msg(res.message);
  214. repeat_flag = false;
  215. if (res.code == 0) {
  216. table.reload();
  217. }
  218. }
  219. });
  220. });
  221. }
  222. </script>
  223. {/block}