database.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. {extend name="base"/}
  2. {block name="resources"}
  3. <link rel="stylesheet" type="text/css" href="__STATIC__/loading/msgbox.css">
  4. <style>
  5. .data-table{border-width: 0 !important;}
  6. .data-table[lay-size=lg] th,.data-table[lay-size=lg] td{padding: 15px 15px;}
  7. .data-table[lay-size=lg] th{border: 0;}
  8. .data-table[lay-size=lg] .check-box{padding-left: 0;padding-right: 0;}
  9. .check-box .layui-form{text-align: center;}
  10. .layui-form-checkbox[lay-skin=primary]{padding-left: 0;}
  11. .layui-table tr .toolbar a{display: inline-block;height: 23px;line-height: 23px;border-radius: 50px;background-color: #F3F3F3;font-size: 13px;color: #5A5A5A;text-align: center;padding: 2px 8px;margin: 5px;}
  12. .layui-table tr .toolbar a:hover{color: #fff !important;background-color: #4685FD;}
  13. .layui-layout-admin.admin-style-2 .layui-body .layui-tab + .body-content {padding-top: 63px !important;}
  14. </style>
  15. {/block}
  16. {block name="main"}
  17. <!-- 搜索框 -->
  18. <div class="single-filter-box top">
  19. <button type="button" class="layui-btn" lay-filter="backups" lay-submit>备份</button>
  20. <!-- <button type="button" class="layui-btn" lay-filter="datarepair" lay-submit>恢复</button>-->
  21. </div>
  22. <table class="layui-table data-table" lay-skin="line" lay-size="lg">
  23. <colgroup>
  24. <col width="3%">
  25. <col width="30%">
  26. <col width="21%">
  27. <col width="21%">
  28. <col width="25%">
  29. <!-- <col width="10%"> -->
  30. </colgroup>
  31. <thead>
  32. <tr>
  33. <th class="check-box">
  34. <div class="layui-form">
  35. <input type="checkbox" class="selectAll" name="" lay-filter="selectAll" lay-skin="primary">
  36. </div>
  37. </th>
  38. <th>表名</th>
  39. <th>数据量</th>
  40. <th>数据大小</th>
  41. <th>创建时间</th>
  42. <!-- <th class="toolbar">操作</th> -->
  43. </tr>
  44. </thead>
  45. <tbody>
  46. {foreach name=$list as $list_k => $list_v}
  47. <tr>
  48. <td class="check-box">
  49. <div class="layui-form">
  50. <input type="checkbox" name="" lay-filter="select{$list_k}" lay-skin="primary">
  51. </div>
  52. </td>
  53. <td class="data-table-name">{$list_v.Name}</td>
  54. <td class="data-table-num">{$list_v.Rows}</td>
  55. <td class="data-length">
  56. <input type="hidden" value="{$list_v.Data_length / 1024}" />
  57. </td>
  58. <td>{$list_v.Create_time}</td>
  59. <!-- <td class="toolbar">
  60. <a class="default" lay-filter="tablerepair" lay-submit>恢复</a>
  61. </td> -->
  62. </tr>
  63. {/foreach}
  64. </tbody>
  65. </table>
  66. {/block}
  67. {block name="script"}
  68. <script type="text/javascript" src="__STATIC__/loading/msgbox.js"></script>
  69. <script>
  70. layui.use('form', function() {
  71. var form = layui.form,
  72. repeat_flag = false;
  73. form.render();
  74. $(".data-length").each(function(i) {
  75. var data = $(this).find("input").val();
  76. var dataNew = Math.round(data * 100) / 100;
  77. $(this).text(dataNew + "KB");
  78. });
  79. /**
  80. * 监听全选按钮
  81. */
  82. form.on('checkbox(selectAll)', function(data) {
  83. if (data.elem.checked) {
  84. $("tr .check-box input:checkbox").each(function() {
  85. $(this).prop("checked", true);
  86. });
  87. } else {
  88. $("tr .check-box input:checkbox").each(function() {
  89. $(this).prop("checked", false);
  90. });
  91. }
  92. form.render();
  93. });
  94. /**
  95. * 监听每一行的多选按钮
  96. */
  97. var len = $("tbody tr").length;
  98. for (var i = 0; i < len; i++) {
  99. form.on('checkbox(select' + i + ')', function(data) {
  100. if ($("tbody tr input:checked").length == len) {
  101. $("input[lay-filter='selectAll']").prop("checked", true);
  102. } else {
  103. $("input[lay-filter='selectAll']").prop("checked", false);
  104. }
  105. form.render();
  106. });
  107. }
  108. /**
  109. * 监听备份
  110. */
  111. form.on('submit(backups)', function() {
  112. var _selected = [];
  113. $("tbody tr input:checked").each(function() {
  114. _selected.push($(this).parents("td").siblings(".data-table-name").text());
  115. });
  116. if (_selected.length == 0) {
  117. layer.msg('请选择需要备份的数据表!');
  118. return;
  119. }
  120. layer.confirm('是否备份?', function(index){
  121. $.ajax({
  122. url: ns.url("shop/system/backup"),
  123. data: {
  124. "tables": _selected
  125. },
  126. dataType: 'JSON',
  127. type: 'POST',
  128. success: function(res) {
  129. layer.close(index);
  130. if (res.status == 1 && res.message == "初始化成功") {
  131. backup(res.tab);
  132. ZENG.msgbox.show(res.message, 4, 3000);
  133. return;
  134. } else {
  135. ZENG.msgbox.show(res.message, 5);
  136. }
  137. }
  138. });
  139. });
  140. });
  141. //备份数据库
  142. function backup(tab, status) {
  143. $.ajax({
  144. url: ns.url("shop/system/backup"),
  145. data: {
  146. "id": tab.id,
  147. "start": tab.start
  148. },
  149. dataType: 'JSON',
  150. type: 'POST',
  151. success: function(res) {
  152. ZENG.msgbox.show("正在备份数据库,请不要关闭窗口", 6);
  153. if (res.status == 1) {
  154. if (!$.isPlainObject(res.tab)) {
  155. ZENG.msgbox.show(res.message, 5);
  156. return;
  157. }else{
  158. ZENG.msgbox.show("正在处理"+ res.tab.table +' ...', 6);
  159. }
  160. backup(res.tab, res.id != res.tab.id);
  161. } else {
  162. if(res.status == -1){
  163. ZENG.msgbox.show(res.message, 5);
  164. }else{
  165. ZENG.msgbox.show("备份完成", 4, 3000);
  166. }
  167. }
  168. }
  169. });
  170. }
  171. /**
  172. * 监听数据表恢复
  173. */
  174. form.on('submit(tablerepair)', function() {
  175. var table_name = $(this).parents("tr").find(".data-table-name").text();
  176. repair(table_name);
  177. });
  178. /**
  179. * 批量操作
  180. */
  181. form.on('submit(datarepair)', function() {
  182. var tables = [];
  183. $("tbody tr input:checked").each(function() {
  184. tables.push($(this).parents("td").siblings(".data-table-name").text());
  185. });
  186. if (tables.length == 0) {
  187. layer.msg('请选择需要恢复的数据表!');
  188. return;
  189. }
  190. repair(tables.toString());
  191. });
  192. function repair(tables) {
  193. if (repeat_flag) return false;
  194. repeat_flag = true;
  195. layer.confirm('确定要恢复改数据表吗?', function() {
  196. $.ajax({
  197. type: 'POST',
  198. dataType: 'JSON',
  199. url: ns.url("shop/system/tablerepair"),
  200. data: {
  201. "tables": tables
  202. },
  203. success: function(res) {
  204. layer.msg(res.message);
  205. repeat_flag = false;
  206. }
  207. });
  208. }, function () {
  209. layer.close();
  210. repeat_flag = false;
  211. });
  212. }
  213. })
  214. </script>
  215. {/block}