wo
This commit is contained in:
@@ -6,8 +6,9 @@ import { Badge } from "../ui/badge";
|
|||||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "../ui/dialog";
|
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "../ui/dialog";
|
||||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../ui/table";
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../ui/table";
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select";
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select";
|
||||||
import { Search, Eye, Download, FileText, CheckCircle, User, Building, ChevronLeft, ChevronRight } from "lucide-react";
|
import { Search, Eye, Download, FileText, CheckCircle, User, Building, ChevronLeft, ChevronRight, FileDown } from "lucide-react";
|
||||||
import { apiGet } from "../../lib/services/api";
|
import { apiGet, API_BASE_URL } from "../../lib/services/api";
|
||||||
|
import { getUserToken } from "../../lib/utils/storage";
|
||||||
|
|
||||||
interface ArchivedWorkOrder {
|
interface ArchivedWorkOrder {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -74,6 +75,41 @@ export default function WorkOrderArchivePage() {
|
|||||||
fetchArchivedOrders();
|
fetchArchivedOrders();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// 下载报告
|
||||||
|
const handleDownloadReport = (workOrderNumber: string) => {
|
||||||
|
try {
|
||||||
|
const token = getUserToken();
|
||||||
|
let url = `${API_BASE_URL}/back/record/downloadReport/${workOrderNumber}`;
|
||||||
|
|
||||||
|
// 如果有 token,作为查询参数传递(如果后端支持的话)
|
||||||
|
// 或者直接打开 URL 让浏览器处理下载
|
||||||
|
console.log('开始下载报告:', url);
|
||||||
|
|
||||||
|
// 创建一个临时的 a 标签来触发下载
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = `${workOrderNumber}_报告.xlsx`;
|
||||||
|
a.style.display = 'none';
|
||||||
|
|
||||||
|
// 添加 token 到 URL(如果后端接口支持通过查询参数传递 token)
|
||||||
|
// 如果不支持,可能需要后端修改接口允许 CORS
|
||||||
|
if (token) {
|
||||||
|
// 尝试作为查询参数
|
||||||
|
url = `${url}?token=${encodeURIComponent(token)}`;
|
||||||
|
a.href = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
document.body.removeChild(a);
|
||||||
|
|
||||||
|
console.log('下载请求已发送');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('下载报告失败详情:', error);
|
||||||
|
alert(`下载报告失败: ${error instanceof Error ? error.message : '未知错误'}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const filteredOrders = archivedOrders.filter((order) => {
|
const filteredOrders = archivedOrders.filter((order) => {
|
||||||
const matchesSearch =
|
const matchesSearch =
|
||||||
order.workOrderType.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
order.workOrderType.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||||
@@ -250,10 +286,16 @@ export default function WorkOrderArchivePage() {
|
|||||||
<TableCell>{order.updatedAt}</TableCell>
|
<TableCell>{order.updatedAt}</TableCell>
|
||||||
<TableCell>{order.updatedAt}</TableCell>
|
<TableCell>{order.updatedAt}</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Button variant="outline" size="sm" onClick={() => openDetailDialog(order)}>
|
<div className="flex items-center space-x-2">
|
||||||
<Eye className="h-4 w-4 mr-1" />
|
<Button variant="outline" size="sm" onClick={() => openDetailDialog(order)}>
|
||||||
查看详情
|
<Eye className="h-4 w-4 mr-1" />
|
||||||
</Button>
|
查看详情
|
||||||
|
</Button>
|
||||||
|
<Button variant="outline" size="sm" onClick={() => handleDownloadReport(order.workOrderNumber)}>
|
||||||
|
<FileDown className="h-4 w-4 mr-1" />
|
||||||
|
下载报告
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))
|
))
|
||||||
|
Reference in New Issue
Block a user