index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <div class="table-box">
  3. <ProTable ref="proTable" :columns="columns" row-key="id" :request-api="listBackupRestoreLogApi" :data-callback="dataCallback">
  4. <!-- 表格 header 按钮 -->
  5. <template #tableHeader>
  6. <el-button type="primary" v-auth="['manage:backupRestore:sync']" @click="backup()"> 备份文件 </el-button>
  7. <el-button type="primary" v-auth="['manage:faultCase:sync']" icon="Refresh" @click="syncFileData()"> 同步文件至服务器 </el-button>
  8. </template>
  9. <!-- 表格操作 -->
  10. <template #operation="scope">
  11. <el-button type="primary" link icon="View" v-auth="['manage:backupRestore:query']" @click="openDialog(3, '备份恢复日志查看', scope.row)">
  12. 查看
  13. </el-button>
  14. <el-button type="primary" v-if="scope.row.operateType === '备份'" link icon="View" @click="restore()"> 恢复 </el-button>
  15. </template>
  16. </ProTable>
  17. <FormDialog ref="formDialogRef" />
  18. </div>
  19. </template>
  20. <script setup lang="tsx" name="BackupRestore">
  21. import { ref, reactive } from 'vue'
  22. import { ElMessage } from 'element-plus'
  23. import ProTable from '@/components/ProTable/index.vue'
  24. import FormDialog from '@/components/FormDialog/index.vue'
  25. import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
  26. import { listBackupRestoreLogApi, backupApi, restoreApi, syncFileDataApi } from '@/api/modules/manage/backupRestore'
  27. // ProTable 实例
  28. const proTable = ref<ProTableInstance>()
  29. const dataCallback = (data: any) => {
  30. const page = proTable.value!.pageable
  31. return {
  32. list: data.data,
  33. total: data.total,
  34. pageNum: page.pageNum,
  35. pageSize: page.pageSize
  36. }
  37. }
  38. const backup = () => {
  39. backupApi().then(res => {
  40. if (res.code === 200) {
  41. proTable.value?.getTableList()
  42. ElMessage.success('备份成功')
  43. } else {
  44. ElMessage.error(res.msg)
  45. }
  46. })
  47. }
  48. const restore = () => {
  49. restoreApi().then(res => {
  50. if (res.code === 200) {
  51. proTable.value?.getTableList()
  52. ElMessage.success('恢复成功')
  53. } else {
  54. ElMessage.error(res.msg)
  55. }
  56. })
  57. }
  58. const syncFileData = () => {
  59. syncFileDataApi({}).then(res => {
  60. if (res.code === 200) {
  61. ElMessage.success('同步成功')
  62. proTable.value?.getTableList()
  63. } else {
  64. ElMessage.error(res.msg)
  65. }
  66. })
  67. }
  68. const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
  69. // 打开弹框的功能
  70. const openDialog = async (type: number, title: string, row?: any) => {
  71. // 重置表单
  72. setItemsOptions()
  73. const params = {
  74. title,
  75. width: 580,
  76. isEdit: false,
  77. itemsOptions: itemsOptions,
  78. model: row,
  79. getTableList: proTable.value?.getTableList
  80. }
  81. formDialogRef.value?.openDialog(params)
  82. }
  83. // 表格配置项
  84. const columns = reactive<ColumnProps<any>[]>([
  85. {
  86. prop: 'type',
  87. label: '数据类型'
  88. },
  89. {
  90. prop: 'operateType',
  91. label: '操作方式',
  92. search: {
  93. el: 'input'
  94. }
  95. },
  96. {
  97. prop: 'status',
  98. label: '备份状态'
  99. },
  100. {
  101. prop: 'updateTime',
  102. label: '更新时间'
  103. },
  104. { prop: 'operation', label: '操作', width: 230, fixed: 'right' }
  105. ])
  106. // 表单配置项
  107. let itemsOptions: ProForm.ItemsOptions[] = []
  108. const setItemsOptions = () => {
  109. itemsOptions = [
  110. {
  111. label: '数据类型',
  112. prop: 'type',
  113. compOptions: {
  114. placeholder: '请输入数据类型'
  115. }
  116. },
  117. {
  118. label: '操作方式',
  119. prop: 'operateType',
  120. compOptions: {
  121. placeholder: '请输入操作方式'
  122. }
  123. },
  124. {
  125. label: '备份状态',
  126. prop: 'status',
  127. compOptions: {
  128. placeholder: '请输入备份状态'
  129. }
  130. }
  131. ]
  132. }
  133. </script>
  134. @/api/modules/manage/backupRestore