diff --git a/example/src/components/LayerManage/index.module.scss b/example/src/components/LayerManage/index.module.scss index f759b93..4fd2525 100644 --- a/example/src/components/LayerManage/index.module.scss +++ b/example/src/components/LayerManage/index.module.scss @@ -1,6 +1,38 @@ .layerMangeContainer { overflow: auto; height: 100%; + position: relative; + + &.dragging { + background-color: var(--semi-color-fill-0); + } + + .dragOverlay { + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: rgba(var(--semi-blue-0), 0.8); + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 16px; + z-index: 100; + border: 2px dashed var(--semi-color-primary); + pointer-events: none; + + span { + color: var(--semi-color-text-0); + font-size: 16px; + } + + :global(.semi-icon) { + color: var(--semi-color-primary); + } + } + .addLayer { display: flex; margin-bottom: 10px; @@ -8,6 +40,12 @@ margin: 0 10px; } } + &:global { + &.drag-over { + border: 2px dashed var(--semi-color-primary); + background-color: var(--semi-color-fill-0); + } + } } .layerItemControl { width: 100%; @@ -158,4 +196,61 @@ margin-bottom: 10px; } } +} + +.uploadBox { + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; + padding: 12px 16px; + background-color: transparent; + border: 1px dashed var(--semi-color-border); + border-radius: 4px; + transition: all 0.2s; + cursor: pointer; + gap: 8px; + + &:hover { + border-color: var(--semi-color-primary); + } + + :global(.semi-icon) { + color: var(--semi-color-text-2); + margin: 0; + } +} + +.uploadText { + margin: 0; + text-align: left; + + .mainText { + display: block; + color: var(--semi-color-text-0); + font-size: 14px; + margin-bottom: 2px; + } + + .subText { + display: block; + color: var(--semi-color-text-2); + font-size: 12px; + } +} + +.uploadArea { + margin: 0 0 12px 0; + width: 100%; + + :global { + .semi-upload-drag { + width: 100%; + } + + // 移除 Semi UI 上传组件的默认背景色 + .semi-upload-drag-area-legal { + background-color: transparent !important; + } + } } \ No newline at end of file diff --git a/example/src/components/LayerManage/index.tsx b/example/src/components/LayerManage/index.tsx index dd15cbd..fc3c046 100644 --- a/example/src/components/LayerManage/index.tsx +++ b/example/src/components/LayerManage/index.tsx @@ -4,12 +4,14 @@ import { useCallback, useState } from 'react'; import DragableLayerItems from './DragableLayerItems'; import styles from './index.module.scss' import { FileItem } from '@douyinfe/semi-ui/lib/es/upload'; +import { IconUpload } from '@douyinfe/semi-icons'; const LayerManage = () => { const { allLayers, addLayer, moveLayer } = LayerHook.useHook(); const [url, setUrl] = useState('') const [loading, setLoading] = useState(false); const [uploading, setUploading] = useState(false); + const [isDragging, setIsDragging] = useState(false); const addCogLayer = useCallback( async () => { @@ -47,20 +49,72 @@ const LayerManage = () => { return false } + const handleDragOver = (e: React.DragEvent) => { + e.preventDefault(); + e.stopPropagation(); + setIsDragging(true); + }; + + const handleDragLeave = (e: React.DragEvent) => { + e.preventDefault(); + e.stopPropagation(); + setIsDragging(false); + }; + + const handleDrop = (e: React.DragEvent) => { + e.preventDefault(); + e.stopPropagation(); + setIsDragging(false); + + const files = Array.from(e.dataTransfer.files); + const tiffFiles = files.filter(file => + file.name.endsWith('.tif') || file.name.endsWith('.tiff') + ); + + tiffFiles.forEach(file => { + uploadFile({ + name: file.name, + fileInstance: file, + status: 'success', + uid: file.name, + size: String(file.size), + }); + }); + }; + return ( -
+ 点击或拖拽文件到此处 + 支持 .tif, .tiff 格式 +
+