From 660c5a7efb215b0c9f395b4749481a874497aa11 Mon Sep 17 00:00:00 2001 From: loveuer Date: Sun, 13 Oct 2024 22:19:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E4=BA=86=20file=20li?= =?UTF-8?q?st=20=E5=8F=B3=E9=94=AE=E7=AE=80=E5=8D=95=E8=8F=9C=E5=8D=95=20f?= =?UTF-8?q?eat:=20=E5=AE=8C=E6=88=90=E4=BA=86=20file=20=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=20todo:=20=E6=A1=B6=E5=8F=B3=E9=94=AE=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E5=92=8C=E5=88=A0=E9=99=A4=E6=A1=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/component/connection/list.tsx | 69 ++++---- frontend/src/component/file/list_file.tsx | 175 ++++++++++++++++----- frontend/src/component/file/path.tsx | 2 +- frontend/src/component/preview/preview.tsx | 3 + frontend/src/store/bucket.tsx | 2 +- frontend/src/store/connection.tsx | 2 +- frontend/src/store/file.tsx | 12 +- frontend/src/store/preview.tsx | 18 +++ go.mod | 2 +- internal/api/api.go | 4 + internal/handler/dialog.go | 57 +++++++ internal/handler/file.go | 97 ++++++++++++ internal/s3/get.go | 121 ++++++++++++++ xtest/path.js | 10 -- 14 files changed, 489 insertions(+), 85 deletions(-) create mode 100644 frontend/src/component/preview/preview.tsx create mode 100644 frontend/src/store/preview.tsx create mode 100644 internal/s3/get.go delete mode 100644 xtest/path.js diff --git a/frontend/src/component/connection/list.tsx b/frontend/src/component/connection/list.tsx index ac147da..b7b6d76 100644 --- a/frontend/src/component/connection/list.tsx +++ b/frontend/src/component/connection/list.tsx @@ -9,9 +9,15 @@ import { tokens, Tooltip } from "@fluentui/react-components" -import {DatabaseLinkRegular, DismissRegular} from "@fluentui/react-icons"; -import React, { useEffect, useState} from "react"; -import { Connection} from "../../interfaces/connection"; +import { + DatabaseLinkRegular, + DeleteRegular, + DismissRegular, + PlugConnectedRegular, PlugDisconnectedRegular, + SettingsRegular +} from "@fluentui/react-icons"; +import React, {useEffect, useState} from "react"; +import {Connection} from "../../interfaces/connection"; import {useToast} from "../../message"; import {Dial} from "../../api"; import {useStoreConnection} from "../../store/connection"; @@ -92,13 +98,15 @@ export function ConnectionList() { y: number, display: 'none' | 'block' }>({x: 0, y: 0, display: 'none'}); + const [menu_conn, set_menu_conn] = useState(null); useEffect(() => { document.addEventListener("click", (e) => { set_ctx_menu({x: 0, y: 0, display: 'none'}); }) return () => { - document.removeEventListener("click", (e) => {}) + document.removeEventListener("click", (e) => { + }) } }, []) @@ -112,7 +120,8 @@ export function ConnectionList() { }) } - async function handleConnect(item: Connection) { + async function handleConnect(item: Connection | null) { + if (!item) return; let res = await Dial('/api/connection/connect', {id: item.id}); if (res.status !== 200) { dispatchMessage(res.msg, "error") @@ -124,7 +133,8 @@ export function ConnectionList() { bucket_set(null) } - async function handleDisconnect(item: Connection) { + async function handleDisconnect(item: Connection | null) { + if (!item) return; let res = await Dial('/api/connection/disconnect', {id: item.id}) if (res.status !== 200) { dispatchMessage(res.msg, "error") @@ -135,11 +145,17 @@ export function ConnectionList() { async function handleRightClick(e: React.MouseEvent, item: Connection) { e.preventDefault() - console.log('[DEBUG] right click connection =', item, 'event =', e) - console.log(`[DEBUG] click position: [${e.pageX}, ${e.pageY}]`) + set_menu_conn(item) + + const ele = document.querySelector('#list-connection-container') + const eleX = ele ? ele.clientWidth : 0 + const eleY = ele ? ele.clientHeight : 0 + const positionX = (e.pageX + eleX > window.innerWidth) ? e.pageX - eleX : e.pageX + const positionY = (e.pageY + eleY > window.innerHeight) ? e.pageY - eleY : e.pageY + set_ctx_menu({ - x: e.pageX, - y: e.pageY, + x: positionX, + y: positionY, display: 'block', }) } @@ -160,13 +176,24 @@ export function ConnectionList() { onChange={(e) => set_conn_filter(e.target.value)} /> -
- 连接 - 设置 - 删除 + { + await handleConnect(menu_conn) + }} + icon={}>连接 + { + await handleDisconnect(menu_conn) + }} + icon={}>断开 + }>设置 + }>删除
@@ -186,18 +213,6 @@ export function ConnectionList() { icon={} key={item.id}> {item.name} - -