新增支付配置备份导出功能

This commit is contained in:
yml2213
2026-06-07 14:11:16 +08:00
parent 53eb4acad8
commit 9740ff8799
11 changed files with 161 additions and 14 deletions
+2 -2
View File
@@ -4,8 +4,8 @@
"private": true,
"type": "module",
"scripts": {
"dev": "vue-tsc -b --watch & vite --host 0.0.0.0",
"build": "vue-tsc -b && vite build",
"dev": "vue-tsc -b --noEmit --watch & vite --host 0.0.0.0",
"build": "vue-tsc -b --noEmit && vite build",
"preview": "vite preview --host 0.0.0.0",
"typecheck": "vue-tsc -b --noEmit"
},
@@ -92,6 +92,16 @@ export async function fetchPaymentConfig(id: number, includeSecret = false) {
return data.data
}
export async function exportPaymentConfigBackup() {
const response = await apiClient.get<Blob>('/admin/payment-configs/export', {
responseType: 'blob',
})
return {
blob: response.data,
filename: readDownloadFilename(response.headers['content-disposition']) || fallbackBackupFilename(),
}
}
export async function createPaymentConfig(payload: CreatePaymentConfigRequest) {
const { data } = await apiClient.post<ApiResponse<PaymentConfig>>('/admin/payment-configs', payload)
return data.data
@@ -106,3 +116,15 @@ export async function deletePaymentConfig(id: number) {
const { data } = await apiClient.delete<ApiResponse<{ message: string }>>(`/admin/payment-configs/${id}`)
return data.data
}
function readDownloadFilename(contentDisposition: unknown) {
if (typeof contentDisposition !== 'string') return ''
const encoded = contentDisposition.match(/filename\*=UTF-8''([^;]+)/i)?.[1]
if (encoded) return decodeURIComponent(encoded)
return contentDisposition.match(/filename="?([^";]+)"?/i)?.[1] || ''
}
function fallbackBackupFilename() {
const stamp = new Date().toISOString().replace(/[-:]/g, '').replace(/\.\d{3}Z$/, '')
return `payment-config-backup-${stamp}.json`
}
@@ -1,11 +1,12 @@
<script setup lang="ts">
import { ElMessage, ElMessageBox } from 'element-plus'
import { computed, onMounted, ref } from 'vue'
import { Plus, Refresh, View, Edit, Delete } from '@element-plus/icons-vue'
import { Plus, Refresh, View, Edit, Delete, Download } from '@element-plus/icons-vue'
import {
fetchPaymentConfigs,
deletePaymentConfig,
exportPaymentConfigBackup,
type PaymentConfig,
} from '@/features/admin/api/paymentConfig'
import { formatDateTime } from '@/utils/time'
@@ -17,6 +18,7 @@ const configs = ref<PaymentConfig[]>([])
const total = ref(0)
const currentPage = ref(1)
const pageSize = ref(20)
const exporting = ref(false)
const dialogVisible = ref(false)
const dialogMode = ref<'create' | 'edit' | 'view'>('create')
@@ -110,6 +112,38 @@ async function handleDelete(row: PaymentConfig) {
}
}
async function handleExportBackup() {
try {
await ElMessageBox.confirm('备份文件会包含支付密钥明文,请妥善保管。确定导出吗?', '导出支付配置备份', {
type: 'warning',
confirmButtonText: '导出',
cancelButtonText: '取消',
})
exporting.value = true
const { blob, filename } = await exportPaymentConfigBackup()
downloadBlob(blob, filename)
ElMessage.success('导出成功')
} catch (error: any) {
if (error !== 'cancel') {
ElMessage.error(readError(error, '导出备份失败'))
}
} finally {
exporting.value = false
}
}
function downloadBlob(blob: Blob, filename: string) {
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = filename
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
URL.revokeObjectURL(url)
}
function handleDialogClose() {
dialogVisible.value = false
currentConfig.value = null
@@ -187,6 +221,7 @@ function deleteDisabledReason(row: PaymentConfig) {
<el-option v-for="opt in environmentOptions" :key="opt.value" :label="opt.label" :value="opt.value" />
</el-select>
<el-button :icon="Refresh" @click="loadConfigs">刷新</el-button>
<el-button :icon="Download" :loading="exporting" @click="handleExportBackup">导出备份</el-button>
<el-button type="primary" :icon="Plus" @click="handleCreate">新增配置</el-button>
</div>
@@ -315,6 +350,8 @@ function deleteDisabledReason(row: PaymentConfig) {
.filter-bar {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
-1
View File
@@ -549,7 +549,6 @@ h1 {
align-items: center;
gap: 8px;
flex-shrink: 0;
}
padding-bottom: 1px;
white-space: nowrap;
}
+8
View File
@@ -37,6 +37,14 @@ export default defineConfig({
},
build: {
rollupOptions: {
onwarn(warning, warn) {
const isVueusePureWarning =
warning.message.includes("#__PURE__") &&
typeof warning.id === "string" &&
warning.id.includes("node_modules/@vueuse/core/");
if (isVueusePureWarning) return;
warn(warning);
},
output: {
manualChunks(id) {
if (!id.includes("node_modules")) return;