index.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. use yii\grid\GridView;
  3. use yii\helpers\Html;
  4. /* @var $this yii\web\View */
  5. /* @var $dataProvider yii\data\ActiveDataProvider */
  6. $this->title = '数据还原';
  7. $this->params['breadcrumbs'][] = $this->title;
  8. ?>
  9. <div class="config-index">
  10. <div class="box box-success">
  11. <div class="box-body">
  12. <?= GridView::widget([
  13. 'dataProvider' => $dataProvider,
  14. 'columns' => [
  15. [
  16. 'attribute' => 'time',
  17. 'label' => '备份名称',
  18. 'value' => function($model) {
  19. return date('Ymd-His', $model['time']);
  20. }
  21. ],
  22. 'part:text:卷数',
  23. 'compress:text:压缩',
  24. [
  25. 'attribute' => 'size',
  26. 'label' => '数据大小',
  27. 'value' => function($model) {
  28. return Yii::$app->formatter->asShortSize($model['size']);
  29. }
  30. ],
  31. // 'create_time:text:备份时间',
  32. [
  33. 'class' => 'yii\grid\ActionColumn',
  34. 'template' => '{a} {b}',
  35. 'buttons' => [
  36. 'a' => function ($url, $model, $key) {
  37. return Html::a('还原',
  38. ['init', 'time' => $model['time']],
  39. ['class' => 'btn btn-default btn-xs db-import']
  40. );
  41. },
  42. 'b' => function ($url, $model, $key) {
  43. return Html::a('删除',
  44. ['del'],
  45. [
  46. 'data-method' => 'post',
  47. 'data-ajax' => 1,
  48. 'data-params' => ['time' => $model['time']],
  49. 'data-confirm' => '删除后不能恢复,确定要删除吗?',
  50. 'data-refresh' => '1',
  51. 'class' => 'btn btn-default btn-xs'
  52. ]
  53. );
  54. }
  55. ]
  56. ],
  57. ],
  58. ]); ?>
  59. </div>
  60. </div>
  61. </div>
  62. <?php $this->beginBlock('js') ?>
  63. <script type="text/javascript">
  64. $(".db-import").click(function(){
  65. var self = this, status = ".";
  66. $.post(self.href, success, "json");
  67. window.onbeforeunload = function(){ return "正在还原数据库,请不要关闭!" }
  68. return false;
  69. function success(data){
  70. if(data.status){
  71. if(data.gz){
  72. data.info += status;
  73. if(status.length === 5){
  74. status = ".";
  75. } else {
  76. status += ".";
  77. }
  78. }
  79. $(self).parent().prev().text(data.info);
  80. if(data.part){
  81. $.post('<?= \yii\helpers\Url::to(['start'])?>',
  82. {"part" : data.part, "start" : data.start},
  83. success,
  84. "json"
  85. );
  86. } else {
  87. window.onbeforeunload = function(){ return null; }
  88. }
  89. } else {
  90. $.modal.error(data.info);
  91. }
  92. }
  93. });
  94. </script>
  95. <?php $this->endBlock('js') ?>