forked from wangziqi/gongxue-base
feat: add platform audit export
This commit is contained in:
@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
|
||||
import Taro from '@tarojs/taro';
|
||||
import { Button, Text, View } from '@tarojs/components';
|
||||
import {
|
||||
exportPlatformAuditLogs,
|
||||
loadPlatformAuditLogs,
|
||||
loadPlatformInvoices,
|
||||
loadPlatformOverview,
|
||||
@@ -21,6 +22,17 @@ function money(cents: unknown) {
|
||||
return `¥${(Number(cents || 0) / 100).toFixed(2)}`;
|
||||
}
|
||||
|
||||
function downloadBase64File(filename: string, contentBase64: string, mimeType: string) {
|
||||
if (typeof document === 'undefined') return false;
|
||||
const link = document.createElement('a');
|
||||
link.href = `data:${mimeType};base64,${contentBase64}`;
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
return true;
|
||||
}
|
||||
|
||||
export default function PlatformWorkbenchPage() {
|
||||
const [overview, setOverview] = useState<PlatformOverview | null>(null);
|
||||
const [tenants, setTenants] = useState<PlatformTenantItem[]>([]);
|
||||
@@ -29,6 +41,7 @@ export default function PlatformWorkbenchPage() {
|
||||
const [banks, setBanks] = useState<PlatformQuestionBankItem[]>([]);
|
||||
const [grants, setGrants] = useState<PlatformQuestionBankGrant[]>([]);
|
||||
const [error, setError] = useState('');
|
||||
const [busy, setBusy] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
Promise.all([
|
||||
@@ -54,6 +67,23 @@ export default function PlatformWorkbenchPage() {
|
||||
{ name: '公共题库', path: '/pages/platform-admin/question-banks/index', meta: '地区题库、授权、披露范围' },
|
||||
];
|
||||
|
||||
async function exportAuditLogs() {
|
||||
setBusy('audit-export');
|
||||
setError('');
|
||||
try {
|
||||
const payload = await exportPlatformAuditLogs({ format: 'csv', limit: 1000 });
|
||||
const item = payload.item;
|
||||
if (item?.contentBase64 && item.filename) {
|
||||
const ok = downloadBase64File(item.filename, item.contentBase64, item.mimeType || 'text/csv');
|
||||
Taro.showToast({ title: ok ? '已导出' : '已生成', icon: 'success' });
|
||||
}
|
||||
} catch (nextError) {
|
||||
setError(nextError instanceof Error ? nextError.message : '审计导出失败');
|
||||
} finally {
|
||||
setBusy('');
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<View className='platform-page'>
|
||||
<View className='platform-shell'>
|
||||
@@ -112,6 +142,9 @@ export default function PlatformWorkbenchPage() {
|
||||
</View>
|
||||
<View className='platform-section'>
|
||||
<Text className='platform-section-title'>最近平台审计</Text>
|
||||
<View className='platform-actions'>
|
||||
<Button className='platform-button' loading={busy === 'audit-export'} onClick={exportAuditLogs}>导出审计 CSV</Button>
|
||||
</View>
|
||||
<View className='platform-list'>
|
||||
{auditLogs.map(item => (
|
||||
<View className='platform-row' key={item.id}>
|
||||
|
||||
Reference in New Issue
Block a user