0.0.1.2
This commit is contained in:
@@ -3,8 +3,10 @@
|
||||
import { useState, useEffect } from "react"
|
||||
import { db } from "@/lib/db"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"
|
||||
import { X, Plus, ZoomIn } from "lucide-react"
|
||||
import { Card } from "@/components/ui/card"
|
||||
import { X, Upload, Image as ImageIcon } from "lucide-react"
|
||||
import { uploadImage } from "@/lib/image-upload"
|
||||
import { useDialog } from "@/components/ui/alert-dialog-custom"
|
||||
import { v4 as uuidv4 } from "uuid"
|
||||
import imageCompression from "browser-image-compression"
|
||||
|
||||
@@ -15,6 +17,7 @@ interface PhotoGalleryProps {
|
||||
}
|
||||
|
||||
export function PhotoGallery({ photoIds = [], onChange, readonly = false }: PhotoGalleryProps) {
|
||||
const { showAlert, showConfirm } = useDialog()
|
||||
const [photos, setPhotos] = useState<{ id: string; url: string }[]>([])
|
||||
const [selectedPhoto, setSelectedPhoto] = useState<string | null>(null)
|
||||
const [isUploading, setIsUploading] = useState(false)
|
||||
@@ -85,15 +88,16 @@ export function PhotoGallery({ photoIds = [], onChange, readonly = false }: Phot
|
||||
onChange([...photoIds, ...newPhotoIds])
|
||||
} catch (error) {
|
||||
console.error('上传照片失败:', error)
|
||||
alert('上传照片失败')
|
||||
await showAlert('上传照片失败', '错误')
|
||||
} finally {
|
||||
setIsUploading(false)
|
||||
e.target.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = (photoId: string) => {
|
||||
if (confirm('确定要删除这张照片吗?')) {
|
||||
const handleDelete = async (photoId: string) => {
|
||||
const confirmed = await showConfirm('确定要删除这张照片吗?', '删除照片')
|
||||
if (confirmed) {
|
||||
onChange(photoIds.filter(id => id !== photoId))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user