index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <div class="table-box">
  3. <ProTable
  4. ref="proTable"
  5. :init-param="initParam"
  6. :columns="columns"
  7. row-key="id"
  8. :request-api="listBackupRestoreLogApi"
  9. :data-callback="dataCallback"
  10. >
  11. <!-- 表格 header 按钮 -->
  12. <template #tableHeader>
  13. <el-button type="primary" v-auth="['manage:backupRestore:sync']" @click="backupAll()"> 全量备份 </el-button>
  14. <el-button type="primary" v-auth="['manage:backupRestore:sync']" @click="backup()"> 增量备份 </el-button>
  15. </template>
  16. <!-- 表格操作 -->
  17. <template #operation="scope">
  18. <el-button type="primary" link icon="View" v-auth="['manage:backupRestore:query']" @click="openDialog(3, '备份恢复日志查看', scope.row)">
  19. 查看
  20. </el-button>
  21. <el-button
  22. type="primary"
  23. v-if="scope.row.operateType === '备份' && scope.row.restoreStatus !== '成功'"
  24. link
  25. icon="View"
  26. @click="restore(scope.row)"
  27. >
  28. 恢复
  29. </el-button>
  30. </template>
  31. </ProTable>
  32. <FormDialog ref="formDialogRef" />
  33. <TableDialog ref="tableDialogRef" @submit-form="submitForm" />
  34. </div>
  35. </template>
  36. <script setup lang="tsx" name="BackupRestore">
  37. import { ref, reactive } from 'vue'
  38. import { ElMessage } from 'element-plus'
  39. import ProTable from '@/components/ProTable/index.vue'
  40. import FormDialog from '@/components/FormDialog/index.vue'
  41. import TableDialog from '@/components/TableDialog/index.vue'
  42. import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
  43. import { listBackupRestoreLogApi, dbBackupAllApi, dbRestoreApi, dbBackupApi } from '@/api/modules/manage/backupRestore'
  44. import { listDbTableApi } from '@/api/modules/tool/gen'
  45. // ProTable 实例
  46. const proTable = ref<ProTableInstance>()
  47. const dataCallback = (data: any) => {
  48. const page = proTable.value!.pageable
  49. return {
  50. list: data.data,
  51. total: data.total,
  52. pageNum: page.pageNum,
  53. pageSize: page.pageSize
  54. }
  55. }
  56. const dataType = [
  57. { label: '文件', value: 1 },
  58. { label: '数据库', value: 2 }
  59. ]
  60. const initParam = reactive({ type: 2 })
  61. const backupAll = () => {
  62. dbBackupAllApi({}).then(res => {
  63. if (res.code === 200) {
  64. proTable.value?.getTableList()
  65. ElMessage.success('备份成功')
  66. } else {
  67. ElMessage.error(res.msg)
  68. }
  69. })
  70. }
  71. const restore = (val: any) => {
  72. dbRestoreApi(val.id).then(res => {
  73. if (res.code === 200) {
  74. proTable.value?.getTableList()
  75. ElMessage.success('恢复成功')
  76. } else {
  77. ElMessage.error(res.msg)
  78. }
  79. })
  80. }
  81. // const syncFileData = () => {
  82. // syncFileDataApi({}).then(res => {
  83. // if (res.code === 200) {
  84. // ElMessage.success('同步成功')
  85. // proTable.value?.getTableList()
  86. // } else {
  87. // ElMessage.error(res.msg)
  88. // }
  89. // })
  90. // }
  91. // 表格弹框提交
  92. const submitForm = () => {
  93. proTable.value?.getTableList()
  94. }
  95. // 批量添加表信息
  96. const tableDialogRef = ref<InstanceType<typeof TableDialog> | null>(null)
  97. const backup = () => {
  98. const params = {
  99. title: '备份表',
  100. width: 880,
  101. toolButton: false,
  102. rowKey: 'tableName',
  103. columns: subColumns,
  104. api: dbBackupApi,
  105. getTableList: listDbTableApi
  106. }
  107. tableDialogRef.value?.openDialog(params)
  108. }
  109. const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
  110. // 打开弹框的功能
  111. const openDialog = async (type: number, title: string, row?: any) => {
  112. // 重置表单
  113. setItemsOptions()
  114. const params = {
  115. title,
  116. width: 580,
  117. isEdit: false,
  118. itemsOptions: itemsOptions,
  119. model: row,
  120. getTableList: proTable.value?.getTableList
  121. }
  122. formDialogRef.value?.openDialog(params)
  123. }
  124. // 表格配置项
  125. const columns = reactive<ColumnProps<any>[]>([
  126. {
  127. prop: 'type',
  128. label: '数据类型',
  129. enum: dataType,
  130. tag: true,
  131. search: {
  132. el: 'select'
  133. }
  134. },
  135. {
  136. prop: 'operateType',
  137. label: '操作方式',
  138. search: {
  139. el: 'input'
  140. }
  141. },
  142. {
  143. prop: 'target',
  144. label: '目标'
  145. },
  146. {
  147. prop: 'status',
  148. label: '备份状态'
  149. },
  150. {
  151. prop: 'updateTime',
  152. label: '更新时间'
  153. },
  154. { prop: 'operation', label: '操作', width: 230, fixed: 'right' }
  155. ])
  156. // 表单配置项
  157. let itemsOptions: ProForm.ItemsOptions[] = []
  158. const setItemsOptions = () => {
  159. itemsOptions = [
  160. {
  161. label: '数据类型',
  162. prop: 'type',
  163. compOptions: {
  164. elTagName: 'select',
  165. enum: dataType,
  166. placeholder: '请输入数据类型'
  167. }
  168. },
  169. {
  170. label: '目标',
  171. prop: 'target',
  172. compOptions: {
  173. placeholder: '请输入操作方式'
  174. }
  175. },
  176. {
  177. label: '操作方式',
  178. prop: 'operateType',
  179. compOptions: {
  180. placeholder: '请输入操作方式'
  181. }
  182. },
  183. {
  184. label: '备份状态',
  185. prop: 'status',
  186. compOptions: {
  187. placeholder: '请输入备份状态'
  188. }
  189. }
  190. ]
  191. }
  192. // 表格配置项
  193. const subColumns: ColumnProps[] = [
  194. { type: 'selection', fixed: 'left', width: 60 },
  195. {
  196. prop: 'tableName',
  197. label: '表名称',
  198. search: {
  199. el: 'input'
  200. }
  201. },
  202. {
  203. prop: 'tableComment',
  204. label: '表描述',
  205. search: {
  206. el: 'input'
  207. }
  208. },
  209. {
  210. prop: 'createTime',
  211. label: '创建时间'
  212. }
  213. ]
  214. </script>