fix
This commit is contained in:
parent
705032657d
commit
50ca8c1e3a
|
|
@ -1,6 +1,7 @@
|
|||
import React, { useState, useEffect } from 'react'
|
||||
import { Plus, Edit, Trash2, Search, Save, X, FolderOpen, Package } from 'lucide-react'
|
||||
import { open } from '@tauri-apps/plugin-dialog'
|
||||
import { convertFileSrc } from '@tauri-apps/api/core'
|
||||
import { ProjectService, Project } from '../services/projectService'
|
||||
|
||||
const ProjectManagePage: React.FC = () => {
|
||||
|
|
@ -16,6 +17,18 @@ const ProjectManagePage: React.FC = () => {
|
|||
product_image: ''
|
||||
})
|
||||
|
||||
// 辅助函数:转换图片路径为Tauri可访问的URL
|
||||
const getImageSrc = (imagePath: string): string => {
|
||||
if (!imagePath) return ''
|
||||
if (imagePath.startsWith('http')) return imagePath
|
||||
try {
|
||||
return convertFileSrc(imagePath)
|
||||
} catch (error) {
|
||||
console.error('Failed to convert file src:', error)
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
loadProjects()
|
||||
}, [])
|
||||
|
|
@ -209,7 +222,7 @@ const ProjectManagePage: React.FC = () => {
|
|||
{project.product_image ? (
|
||||
<>
|
||||
<img
|
||||
src={project.product_image.startsWith('http') ? project.product_image : `file:///${project.product_image.split('\\').join('/')}`}
|
||||
src={getImageSrc(project.product_image)}
|
||||
alt={project.product_name || project.name}
|
||||
className="w-full h-full object-cover"
|
||||
onError={(e) => {
|
||||
|
|
@ -400,7 +413,7 @@ const ProjectManagePage: React.FC = () => {
|
|||
<p className="text-xs text-gray-500 mb-1">预览:</p>
|
||||
<div className="w-20 h-20 border border-gray-200 rounded-lg overflow-hidden bg-gray-50 flex items-center justify-center">
|
||||
<img
|
||||
src={formData.product_image.startsWith('http') ? formData.product_image : `file:///${formData.product_image.split('\\').join('/')}`}
|
||||
src={getImageSrc(formData.product_image)}
|
||||
alt="商品图片预览"
|
||||
className="w-full h-full object-cover"
|
||||
onError={(e) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue