backups.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <com-list-page :crumbs="crumbs" id="application">
  2. <com-list-table
  3. ref="table"
  4. :api="'admin/expire-notice/backups'"
  5. :search-list="searchList"
  6. @selection-change="handleSelectionChange"
  7. @get-api-data="handleGetApiData"
  8. >
  9. <el-table-column type="selection" width="55px" :selectable="selectables" align="center"></el-table-column>
  10. <el-table-column prop="id" label="ID" align="center"> </el-table-column>
  11. <el-table-column prop="name" label="备份文件名称" align="center"></el-table-column>
  12. <el-table-column prop="size" label="文件大小" align="center"></el-table-column>
  13. <el-table-column prop="created_at" label="备份时间" align="center">
  14. <template slot-scope="scope">
  15. {{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}
  16. </template>
  17. </el-table-column>
  18. <el-table-column prop="status" label="备份状态" align="center">
  19. <template slot-scope="scope">
  20. <div v-if="scope.row.status == 2">
  21. <el-tooltip class="item" effect="dark" :content="scope.row.desc" placement="top">
  22. <span>{{status_list[scope.row.status]}}</span>
  23. </el-tooltip>
  24. </div>
  25. <div v-else>
  26. {{status_list[scope.row.status]}}
  27. </div>
  28. </template>
  29. </el-table-column>
  30. <el-table-column label="操作" align="center" >
  31. <template slot-scope="scope">
  32. <el-button v-if="scope.row.status==1" type="text" :loading="btnLoad" size="mini" @click="download(scope.row.id)">
  33. 下载
  34. </el-button>
  35. <el-button type="text" :loading="btnLoad" size="mini" @click="handle('delete', scope.row.id)">
  36. 删除
  37. </el-button>
  38. </template>
  39. </el-table-column>
  40. <template slot="header-left">
  41. <el-button @click="dialogVisible = true" type="primary" size="small">备份当前</el-button>
  42. </template>
  43. <template slot="header-left">
  44. <el-button @click="multipleDownload" type="danger" size="small">批量删除</el-button>
  45. </template>
  46. </com-list-table>
  47. <el-dialog
  48. title="备份当前"
  49. :visible.sync="dialogVisible"
  50. width="30%"
  51. :before-close="handleClose">
  52. <div style="margin-left:20px;margin-bottom:10px;">
  53. <div class="el-icon-warning" style="font-size:24px;color:#e6a23c;"></div>
  54. <span style="font-size:18px;">确认备份当前时间下的服务器备份</span>
  55. </div>
  56. <span style="color:red;margin-left:45px;">注意:该操作需要一定时间才能完成</span>
  57. <span slot="footer" class="dialog-footer">
  58. <el-button @click="dialogVisible = false" size="small">取 消</el-button>
  59. <el-button type="primary" size="small" @click="StartBackups">确 定</el-button>
  60. </span>
  61. </el-dialog>
  62. </com-list-page>
  63. <script>
  64. const application = new Vue({
  65. el: '#application',
  66. data: {
  67. crumbs: [{
  68. title: '备份管理',
  69. router: '',
  70. },
  71. ],
  72. searchList: [
  73. {
  74. key: 'datetime',
  75. title: '备份时间',
  76. type: 'date-picker',
  77. valueFormat: 'yyyy-MM-dd',
  78. },
  79. ],
  80. type_list: {},
  81. status_list: {
  82. 0: "备份中",
  83. 1: "备份完成",
  84. 2: "备份失败"
  85. },
  86. multipleSelect: [],
  87. btnLoad: false,
  88. dialogVisible: false,
  89. },
  90. methods: {
  91. handleGetApiData(data) {
  92. this.type_list = data.type_list
  93. // this.status_list = data.status_list
  94. },
  95. download(id) {
  96. this.btnLoad = true;
  97. window.location.href = '/index.php?r=admin/expire-notice/down&download_id=' + id;
  98. this.btnLoad = false;
  99. },
  100. multipleDownload() {
  101. if (this.multipleSelect.length) {
  102. let val = this.multipleSelect;
  103. let download_ids = [];
  104. let for_num = val.length;
  105. for (let i = 0; i < for_num; i++) {
  106. // if (val[i].status != 2) {
  107. // // 选择了不可下载的文件
  108. // this.$message.error('选择了不可导出的文件[' + val[i].name + '(ID:' + val[i].id + ')],请重新选择');
  109. // return false;
  110. // }
  111. download_ids.push(val[i].id);
  112. }
  113. this.$confirm('确认批量删除这些数据, 注意操作不可恢复!?', '提示', {
  114. confirmButtonText: '确定',
  115. cancelButtonText: '取消',
  116. type: 'warning'
  117. }).then(() => {
  118. this.handleDelete(download_ids);
  119. }).catch(() => {
  120. });
  121. // window.location.href = '/index.php?r=mall/download/multiple-download&download_id=' + download_ids;
  122. // this.handleDelete(download_ids);
  123. } else {
  124. this.$confirm('确认清空当前所有备份, 注意操作不可恢复!?', '提示', {
  125. confirmButtonText: '确定',
  126. cancelButtonText: '取消',
  127. type: 'warning'
  128. }).then(() => {
  129. this.handleDelete('');
  130. }).catch(() => {
  131. });
  132. }
  133. },
  134. handle(type, id) {
  135. switch (type) {
  136. case 'delete':
  137. this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
  138. confirmButtonText: '确定',
  139. cancelButtonText: '取消',
  140. type: 'warning'
  141. }).then(() => {
  142. this.handleDelete(id);
  143. }).catch(() => {
  144. });
  145. break;
  146. }
  147. },
  148. handleDelete(id) {
  149. this.$request({
  150. params: {
  151. r: 'admin/expire-notice/delete',
  152. },
  153. data: {
  154. id:id
  155. },
  156. method: 'post',
  157. }).then(e => {
  158. if (e.data.code == 0) {
  159. this.$message({
  160. message: e.data.msg,
  161. type: 'success'
  162. });
  163. this.btnLoad = false
  164. this.$refs.table.handleSearch()
  165. }
  166. }).catch(e => {});
  167. },
  168. selectables(row, index) {
  169. if (row.status == 1 || row.status == 0 || row.status == 2) {
  170. return true
  171. } else {
  172. return false;
  173. }
  174. },
  175. handleSelectionChange(val) {
  176. this.multipleSelect = []
  177. this.multipleSelect = val
  178. },
  179. StartBackups() {
  180. // this.btnLoad = true;
  181. this.dialogVisible = false;
  182. request({
  183. params: {
  184. r: 'admin/expire-notice/start-backups',
  185. },
  186. method: 'post',
  187. }).then(e => {
  188. if (e.data.code == 0) {
  189. this.$message({
  190. message: e.data.msg,
  191. type: 'success'
  192. });
  193. this.btnLoad = false
  194. this.$refs.table.handleSearch()
  195. } else {
  196. this.$message({
  197. message: e.data.msg,
  198. type: 'error'
  199. });
  200. }
  201. }).catch(e => {});
  202. },
  203. handleClose(done) {
  204. done();
  205. }
  206. },
  207. })
  208. </script>