فهرست منبع

数据库备份与还原

lrf 7 ماه پیش
والد
کامیت
3b7412473e
2فایلهای تغییر یافته به همراه53 افزوده شده و 3 حذف شده
  1. 16 1
      src/store/api/systemFunc.js
  2. 37 2
      src/views/system/parts/system-func.vue

+ 16 - 1
src/store/api/systemFunc.js

@@ -1,5 +1,6 @@
 import { defineStore } from 'pinia'
 import { AxiosWrapper } from '@/utils/axios-wrapper'
+import { indexOf } from 'lodash-es'
 const url = '/system/func'
 const axios = new AxiosWrapper()
 
@@ -29,12 +30,26 @@ export const SystemFuncStore = defineStore('systemFunc', () => {
     return res
   }
 
+  const dbRestore = async (payload) => {
+    const body = {}
+    if (payload) body.path = payload
+    const res = await axios.$post(`${url}/dbRestore`, body)
+    return res
+  }
+
+  const dbBackUp = async () => {
+    const res = await axios.$get(`${url}/dbBackUp`)
+    return res
+  }
+
   return {
     initES,
     correctImportData,
     initSystemMenus,
     initUserMenus,
     initRoleData,
-    initRoleMenus
+    initRoleMenus,
+    dbRestore,
+    dbBackUp
   }
 })

+ 37 - 2
src/views/system/parts/system-func.vue

@@ -18,10 +18,17 @@
     <el-col :span="4">
       <el-button type="primary" @click="toMethod('irm')">{{ $t('pages.systemFunc.irm') }}</el-button>
     </el-col>
+    <el-col :span="4">
+      <el-button type="primary" @click="toMethod('dbBackUp')">数据库备份</el-button>
+    </el-col>
+    <el-col :span="4">
+      <el-button type="primary" @click="toMethod('dbRestore')">数据库还原</el-button>
+    </el-col>
   </el-row>
 </template>
 
 <script setup>
+import { ElMessage, ElMessageBox } from 'element-plus'
 import { SystemFuncStore } from '@/store/api/systemFunc'
 const $checkRes = inject('$checkRes')
 const store = SystemFuncStore()
@@ -30,26 +37,54 @@ const toMethod = async (method) => {
   switch (method) {
     case 'initES':
       res = await store.initES()
+      $checkRes(res, true, res.errmsg)
       break
     case 'cid':
       res = await store.correctImportData()
+      $checkRes(res, true, res.errmsg)
       break
     case 'ism':
       res = await store.initSystemMenus()
+      $checkRes(res, true, res.errmsg)
       break
     case 'ium':
       res = await store.initUserMenus()
+      $checkRes(res, true, res.errmsg)
       break
     case 'ir':
       res = await store.initRoleData()
+      $checkRes(res, true, res.errmsg)
       break
     case 'irm':
       res = await store.initRoleMenus()
+      $checkRes(res, true, res.errmsg)
+      break
+    case 'dbBackUp':
+      res = await store.dbBackUp()
+      $checkRes(res, true, res.errmsg)
+      break
+    case 'dbRestore':
+      // 需要输入还原文件夹
+      ElMessageBox.prompt('请输入json文件所在目录地址,默认地址为备份地址', '数据库还原', {
+        confirmButtonText: '确认',
+        cancelButtonText: '取消'
+      })
+        .then(async ({ value }) => {
+          res = await store.dbRestore(value)
+          console.log(res)
+          $checkRes(res, true, res.errmsg)
+        })
+        .catch(() => {})
+      //
       break
     default:
       break
   }
-  $checkRes(res, true, res.errmsg)
+  
 }
 </script>
-<style scoped></style>
+<style scoped>
+.el-col {
+  margin-top: 10px;
+}
+</style>