From 9f707e879e930c0fb9924c0d3ae7a011e3d3e93c Mon Sep 17 00:00:00 2001 From: "mula.liu" Date: Wed, 3 Jun 2026 17:08:06 +0800 Subject: [PATCH] fix project share --- .memsearch/memory/2026-06-03.md | 3 + .../ModernSidebar/ModernSidebar.css | 6 + frontend/src/pages/Document/DocumentPage.jsx | 27 +---- .../src/pages/ProjectList/ProjectList.jsx | 114 ++++++++---------- 4 files changed, 60 insertions(+), 90 deletions(-) diff --git a/.memsearch/memory/2026-06-03.md b/.memsearch/memory/2026-06-03.md index 307b486..c806275 100644 --- a/.memsearch/memory/2026-06-03.md +++ b/.memsearch/memory/2026-06-03.md @@ -4,3 +4,6 @@ ## Session 14:59 + +## Session 16:54 + diff --git a/frontend/src/components/ModernSidebar/ModernSidebar.css b/frontend/src/components/ModernSidebar/ModernSidebar.css index 9b16b0d..c6aa53d 100644 --- a/frontend/src/components/ModernSidebar/ModernSidebar.css +++ b/frontend/src/components/ModernSidebar/ModernSidebar.css @@ -180,6 +180,12 @@ transition: all 0.2s; } +/* 折叠状态下给头像留足空间 */ +.ant-layout-sider-collapsed .user-card { + padding: 12px 4px; + justify-content: center; +} + .user-info { display: flex; align-items: center; diff --git a/frontend/src/pages/Document/DocumentPage.jsx b/frontend/src/pages/Document/DocumentPage.jsx index 2e37434..891b1ab 100644 --- a/frontend/src/pages/Document/DocumentPage.jsx +++ b/frontend/src/pages/Document/DocumentPage.jsx @@ -1156,43 +1156,24 @@ function DocumentPage() { {hasPassword && ( -
+ setPassword(e.target.value)} /> - -
+ )} ) : ( <>
- 当前文件尚未创建独立分享。文件分享不受项目是否公开影响,分享页只包含该文件本身。 + 当前文件尚未创建独立分享。
-
- - 访问密码保护 - - -
- - {hasPassword && ( - setPassword(e.target.value)} - /> - )} - diff --git a/frontend/src/pages/ProjectList/ProjectList.jsx b/frontend/src/pages/ProjectList/ProjectList.jsx index 0cfba40..9647641 100644 --- a/frontend/src/pages/ProjectList/ProjectList.jsx +++ b/frontend/src/pages/ProjectList/ProjectList.jsx @@ -146,42 +146,58 @@ function ProjectList({ type = 'my' }) { editForm.setFieldsValue({ name: project.name, description: project.description, - is_public: project.is_public === 1, }) - setShareInfo(project.is_public === 1 ? null : { enabled: false, share_url: null, has_password: false, access_pass: null }) + setShareInfo(null) setHasPassword(false) setPassword('') setEditModalVisible(true) } - // 更新项目 - const handleUpdateProject = async (values) => { + // 切换公开/私有(立即生效) + const handlePublicToggle = async (checked) => { + if (!currentProject) return try { - const shouldKeepOpenForShare = currentProject?.is_public !== 1 && values.is_public const res = await updateProject(currentProject.id, { - ...values, - is_public: values.is_public ? 1 : 0, + is_public: checked ? 1 : 0, }) const updatedProject = res.data || { ...currentProject, - ...values, - is_public: values.is_public ? 1 : 0, + is_public: checked ? 1 : 0, } setCurrentProject(updatedProject) - message.success('项目更新成功') + message.success(checked ? '项目已设为公开' : '项目已设为私有') await fetchProjects() - if (shouldKeepOpenForShare) { + if (checked) { const shareRes = await getProjectShareInfo(currentProject.id) setShareInfo(shareRes.data) setHasPassword(shareRes.data.has_password) setPassword(shareRes.data.access_pass || '') - return + } else { + setShareInfo({ enabled: false, share_url: null, has_password: false, access_pass: null }) + setHasPassword(false) + setPassword('') } + } catch (error) { + console.error('Toggle public error:', error) + message.error('操作失败') + } + } - setShareInfo({ enabled: false, share_url: null, has_password: false, access_pass: null }) - setHasPassword(false) - setPassword('') + // 更新项目(仅名称和描述) + const handleUpdateProject = async (values) => { + try { + const res = await updateProject(currentProject.id, { + name: values.name, + description: values.description, + }) + const updatedProject = res.data || { + ...currentProject, + ...values, + } + setCurrentProject(updatedProject) + message.success('项目更新成功') + await fetchProjects() setEditModalVisible(false) editForm.resetFields() } catch (error) { @@ -193,9 +209,10 @@ function ProjectList({ type = 'my' }) { useEffect(() => { if (!editModalVisible || !currentProject) return - const isPublic = editForm.getFieldValue('is_public') - if (!isPublic) { + if (currentProject.is_public !== 1) { setShareInfo({ enabled: false, share_url: null, has_password: false, access_pass: null }) + setHasPassword(false) + setPassword('') return } @@ -209,39 +226,7 @@ function ProjectList({ type = 'my' }) { console.error('Get project share info error:', error) } })() - }, [editModalVisible, currentProject, editForm]) - - const currentEditPublic = Form.useWatch('is_public', editForm) - const isPublicEnablePending = editModalVisible && currentEditPublic && currentProject?.is_public !== 1 - - useEffect(() => { - if (!editModalVisible || !currentProject) return - - if (!currentEditPublic) { - setShareInfo({ enabled: false, share_url: null, has_password: false, access_pass: null }) - setHasPassword(false) - setPassword('') - return - } - - if (currentProject.is_public !== 1) { - setShareInfo(null) - setHasPassword(false) - setPassword('') - return - } - - ;(async () => { - try { - const res = await getProjectShareInfo(currentProject.id) - setShareInfo(res.data) - setHasPassword(res.data.has_password) - setPassword(res.data.access_pass || '') - } catch (error) { - console.error('Refresh project share info error:', error) - } - })() - }, [currentEditPublic, editModalVisible, currentProject, editForm]) + }, [editModalVisible, currentProject]) const [gitRepos, setGitRepos] = useState([]) const [loadingRepos, setLoadingRepos] = useState(false) @@ -765,25 +750,20 @@ function ProjectList({ type = 'my' }) { /> - - + + - {!editForm.getFieldValue('is_public') ? ( + {currentProject?.is_public !== 1 ? (
- 开启“公开项目”后,才可以生成项目分享链接和配置访问密码。 + 开启“公开项目”后,可以生成项目分享链接和访问密码。
- ) : isPublicEnablePending ? ( -
- 保存项目后将自动生成项目分享链接。 -
- ) : ( + ) : shareInfo ? ( <>
{hasPassword && ( -
+ setPassword(e.target.value)} /> - -
+ )} - )} + ) : null}