import { useState } from "react"; import { Image, Text, View } from "@tarojs/components"; import { Button } from "@nutui/nutui-react-taro"; import Taro from "@tarojs/taro"; import { Icon } from "@/components"; interface Step3SuccessProps { pdfUrl: string; picUrl?: string; } export default function Step3Success(props: Step3SuccessProps) { const { pdfUrl, picUrl } = props; const [tempFilePath, setTempFilePath] = useState(); // 保存图片 const handleSaveImage = async () => { if (!picUrl) { Taro.showToast({ title: "没有可保存的预览图片", icon: "none", duration: 2000, }); return; } try { // 下载文件 const downloadRes = await Taro.downloadFile({ url: picUrl!, }); // 保存图片到相册 await Taro.saveImageToPhotosAlbum({ filePath: downloadRes.tempFilePath, }); Taro.showToast({ title: "图片已保存到相册", icon: "success", duration: 2000, }); } catch (error) { console.error("保存图片失败:", error); Taro.showToast({ title: "保存图片失败,请检查相册权限", icon: "none", duration: 2000, }); } }; // 下载PDF const handleDownloadPDF = async () => { Taro.showToast({ title: "正在下载PDF文件", icon: "loading", duration: 2000, }); try { // 下载文件 const downloadRes = await Taro.downloadFile({ url: pdfUrl!, }); if (downloadRes.tempFilePath) { setTempFilePath(downloadRes.tempFilePath); // 保存PDF到手机 if (Taro.saveFile) { await Taro.saveFile({ tempFilePath: downloadRes.tempFilePath, }); Taro.showToast({ title: "PDF下载成功", icon: "success", duration: 2000, }); } else { // 如果不支持saveFile,直接提示下载完成 Taro.openDocument({ filePath: downloadRes.tempFilePath, showMenu: true, }); } } } catch (error) { console.error("下载PDF失败:", error); Taro.showToast({ title: "下载PDF失败", icon: "none", duration: 2000, }); } }; // 查看PDF文档 const handleViewPDF = async () => { if (!tempFilePath) { await handleDownloadPDF(); } if (tempFilePath) { Taro.openDocument({ filePath: tempFilePath, showMenu: true, }); } }; return ( {/* 预览区域 */} {picUrl ? ( { Taro.previewImage({ urls: [picUrl], current: picUrl, }); }} /> ) : ( 暂无预览图片 )} {/* 底部按钮区域 */} {/* 保存图片按钮 */} {picUrl && ( )} {/* PDF操作按钮 */} {tempFilePath && ( )} {/* 提示信息 */} 点击预览图片可放大查看 ); }