index.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. {extend name="public/container"}
  2. {block name="content"}
  3. <div class="row">
  4. <div class="col-sm-12">
  5. <div class="ibox float-e-margins">
  6. <div class="ibox-title">
  7. <h5>数据库备份记录</h5>
  8. </div>
  9. <div class="ibox-content" style="display: block;">
  10. <div class="table-responsive">
  11. <table class="layui-hide" id="fileList" lay-filter="fileList"></table>
  12. <script type="text/html" id="fileListtool">
  13. <button type="button" class="layui-btn layui-btn-xs" lay-event="import"><i class="layui-icon layui-icon-edit"></i>导入</button>
  14. <button type="button" class="layui-btn layui-btn-xs" lay-event="delFile"><i class="layui-icon layui-icon-edit"></i>删除</button>
  15. <button type="button" class="layui-btn layui-btn-xs" lay-event="downloadFile"><i class="layui-icon layui-icon-edit"></i>下载</button>
  16. </script>
  17. </div>
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22. <div class="row">
  23. <div class="col-sm-12">
  24. <div class="ibox">
  25. <div class="ibox-title">
  26. <h5>数据库表列表</h5>
  27. </div>
  28. <div class="ibox-content">
  29. <div class="table-responsive">
  30. <script type="text/html" id="toolbarDemo">
  31. <div class="layui-btn-container">
  32. <button class="layui-btn layui-btn-sm" lay-event="backup">备份</button>
  33. <button class="layui-btn layui-btn-sm" lay-event="optimize">优化表</button>
  34. <button class="layui-btn layui-btn-sm" lay-event="repair">修复表</button>
  35. </div>
  36. </script>
  37. <table class="layui-hide" id="tableListID" lay-filter="tableListID"></table>
  38. <script type="text/html" id="barDemo">
  39. <button type="button" class="layui-btn layui-btn-xs" lay-event="see"><i class="layui-icon layui-icon-edit"></i>详情</button>
  40. </script>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. <script src="{__ADMIN_PATH}js/layuiList.js"></script>
  47. <script>
  48. function ipmosrting(time,part = null,start = null) {
  49. var datas = {
  50. time:time,
  51. part:part,
  52. start:start
  53. };
  54. $.ajax({
  55. url: layList.Url({a: 'import'}),
  56. data: datas,
  57. type: 'post',
  58. dataType: 'json',
  59. success: function (res) {
  60. console.log(res);
  61. if(res.data){
  62. if(res.code){
  63. setTimeout(ipmosrting(time,res.data.part,res.data.start),2000);
  64. }
  65. }else{
  66. layList.msg(res.msg);
  67. return false;
  68. }
  69. },
  70. error: function (err) {
  71. console.log(err)
  72. }
  73. });
  74. }
  75. layui.use(['table', 'layer'], function(){
  76. var layer = layui.layer;
  77. var fileList = layui.table;
  78. var tableList = layui.table;
  79. //加载sql备份列表
  80. var buckdata = fileList.render({
  81. elem: '#fileList'
  82. ,url:"{:Url('fileList')}"
  83. ,cols: [[
  84. {field: 'filename', title: '备份名称', sort: true,width:'25%'},
  85. {field: 'part', title: 'part',width:'10%'},
  86. {field: 'size', title: '大小',width:'10%'},
  87. {field: 'compress', title: 'compress',width:'10%'},
  88. {field: 'backtime', title: '时间',width:'20%'},
  89. {fixed: 'right', title: '操作', width: '25%', align: 'center', toolbar: '#fileListtool'}
  90. ]]
  91. ,page: false
  92. });
  93. //监听工具条
  94. fileList.on('tool(fileList)', function(obj){
  95. var data = obj.data;
  96. var layEvent = obj.event;
  97. switch (layEvent){
  98. case 'import':
  99. layer.confirm('真的倒入该备份吗?', function(index){
  100. ipmosrting(data.time,null,null);
  101. layer.close(index);
  102. });
  103. break;
  104. case 'delFile':
  105. layer.confirm('真的删除该备份吗?', function(index){
  106. layList.basePost(layList.Url({a:'delFile'}),{feilname:data.time},function (res) {
  107. layer.msg(res.msg);
  108. buckdata.reload();
  109. });
  110. obj.del();
  111. layer.close(index);
  112. });
  113. break;
  114. case 'downloadFile':
  115. location.href = layList.Url({a:'downloadFile',p:{feilname:data.time}});
  116. break;
  117. }
  118. });
  119. //加载table
  120. tableList.render({
  121. elem: '#tableListID'
  122. ,url:"{:Url('tablelist')}"
  123. ,toolbar: '#toolbarDemo'
  124. ,cols: [[
  125. {type:'checkbox'},
  126. {field: 'name', title: '表名称', sort: true,width:'20%'},
  127. {field: 'comment', title: '备注',width:'20%'},
  128. {field: 'engine', title: '类型', sort: true,width:'10%'},
  129. {field: 'data_length', title: '大小',width:'10%', sort: true,totalRow: true},
  130. {field: 'update_time', title: '更新时间',width:'20%', sort: true},
  131. {field: 'rows', title: '行数'},
  132. {fixed: 'right', title: '操作', width: '10%', align: 'center', toolbar: '#barDemo'}
  133. ]]
  134. ,page: false
  135. });
  136. //头工具栏事件
  137. tableList.on('toolbar(tableListID)', function(obj){
  138. var checkStatus = tableList.checkStatus(obj.config.id);
  139. var data = checkStatus.data;
  140. var tables = [];
  141. $.each(data, function (name, value) {
  142. if (value['name'] != undefined) tables.push(value['name']);
  143. });
  144. if(tables.length < 1 ){
  145. return layer.msg('请选择表');
  146. }
  147. switch(obj.event){
  148. case 'backup':
  149. layList.basePost(layList.Url({a:'backup'}),{tables:tables},function (res) {
  150. layer.msg(res.msg,{icon:1,time:1000,end:function(){
  151. buckdata.reload();
  152. }});
  153. },function (res) {
  154. layer.msg(res.msg);
  155. });
  156. break;
  157. case 'optimize':
  158. layList.basePost(layList.Url({a:'optimize'}),{tables:tables},function (res) {
  159. layer.msg(res.msg);
  160. },function (res) {
  161. layer.msg(res.msg);
  162. });
  163. break;
  164. case 'repair':
  165. layList.basePost(layList.Url({a:'repair'}),{tables:tables},function (res) {
  166. layer.msg(res.msg);
  167. },function (res) {
  168. layer.msg(res.msg);
  169. });
  170. break;
  171. };
  172. });
  173. //监听并执行操作
  174. tableList.on('tool(tableListID)', function(obj){
  175. var data = obj.data;
  176. if(obj.event === 'see'){
  177. $eb.createModalFrame('表名:['+data.name+'] '+data.comment,layList.Url({a:'seetable',p:{tablename:data.name}}),{w:1000,h:600});
  178. }
  179. });
  180. });
  181. </script>
  182. {/block}