0.8.0.0
This commit is contained in:
@@ -50,7 +50,8 @@ export function DialogProvider({ children }: { children: ReactNode }) {
|
||||
confirmText: "确定",
|
||||
onConfirm: () => {
|
||||
setOpen(false)
|
||||
resolve()
|
||||
// 等待模态框动画完成后再 resolve
|
||||
setTimeout(() => resolve(), 150)
|
||||
},
|
||||
})
|
||||
setOpen(true)
|
||||
@@ -72,11 +73,13 @@ export function DialogProvider({ children }: { children: ReactNode }) {
|
||||
variant,
|
||||
onConfirm: () => {
|
||||
setOpen(false)
|
||||
resolve(true)
|
||||
// 等待模态框动画完成后再 resolve
|
||||
setTimeout(() => resolve(true), 150)
|
||||
},
|
||||
onCancel: () => {
|
||||
setOpen(false)
|
||||
resolve(false)
|
||||
// 等待模态框动画完成后再 resolve
|
||||
setTimeout(() => resolve(false), 150)
|
||||
},
|
||||
})
|
||||
setOpen(true)
|
||||
@@ -99,11 +102,13 @@ export function DialogProvider({ children }: { children: ReactNode }) {
|
||||
cancelText: "取消",
|
||||
onConfirm: (value) => {
|
||||
setOpen(false)
|
||||
resolve(value || null)
|
||||
// 等待模态框动画完成后再 resolve
|
||||
setTimeout(() => resolve(value || null), 150)
|
||||
},
|
||||
onCancel: () => {
|
||||
setOpen(false)
|
||||
resolve(null)
|
||||
// 等待模态框动画完成后再 resolve
|
||||
setTimeout(() => resolve(null), 150)
|
||||
},
|
||||
})
|
||||
setOpen(true)
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Upload, X, Loader2, Crop } from "lucide-react"
|
||||
import ReactCrop, { type Crop as CropType } from "react-image-crop"
|
||||
import "react-image-crop/dist/ReactCrop.css"
|
||||
import imageCompression from "browser-image-compression"
|
||||
import { useDialog } from "@/components/ui/alert-dialog-custom"
|
||||
|
||||
interface ImageUploadProps {
|
||||
value?: string // The image URL
|
||||
@@ -24,6 +25,7 @@ export function ImageUpload({ value, onChange, className }: ImageUploadProps) {
|
||||
const [completedCrop, setCompletedCrop] = useState<CropType>()
|
||||
const imgRef = useRef<HTMLImageElement>(null)
|
||||
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||
const { showAlert } = useDialog()
|
||||
|
||||
// Load preview if value (URL) exists
|
||||
useEffect(() => {
|
||||
@@ -41,7 +43,7 @@ export function ImageUpload({ value, onChange, className }: ImageUploadProps) {
|
||||
try {
|
||||
// Basic validation
|
||||
if (!file.type.startsWith("image/")) {
|
||||
alert("请选择图片文件")
|
||||
await showAlert("请选择图片文件", "提示")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -63,7 +65,7 @@ export function ImageUpload({ value, onChange, className }: ImageUploadProps) {
|
||||
reader.readAsDataURL(compressedFile)
|
||||
} catch (error) {
|
||||
console.error("Failed to process image:", error)
|
||||
alert("图片处理失败")
|
||||
await showAlert("图片处理失败", "错误")
|
||||
} finally {
|
||||
// Reset input
|
||||
if (fileInputRef.current) fileInputRef.current.value = ""
|
||||
@@ -108,7 +110,7 @@ export function ImageUpload({ value, onChange, className }: ImageUploadProps) {
|
||||
}, 'image/jpeg', 0.9)
|
||||
} catch (error) {
|
||||
console.error("Failed to crop image:", error)
|
||||
alert("图片裁剪失败")
|
||||
await showAlert("图片裁剪失败", "错误")
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
setShowCropDialog(false)
|
||||
@@ -146,7 +148,7 @@ export function ImageUpload({ value, onChange, className }: ImageUploadProps) {
|
||||
setImageToCrop(null)
|
||||
} catch (error) {
|
||||
console.error("Failed to save image:", error)
|
||||
alert("图片保存失败: " + (error instanceof Error ? error.message : '未知错误'))
|
||||
await showAlert("图片保存失败: " + (error instanceof Error ? error.message : '未知错误'), "错误")
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user