feat(sidebar): surface unlock entry

This commit is contained in:
aits2026
2026-03-06 12:55:08 +08:00
parent 80a193a394
commit c108070696
2 changed files with 25 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
import { useState, useEffect, useRef } from 'react' import { useState, useEffect, useRef } from 'react'
import { NavLink, useLocation } from 'react-router-dom' import { NavLink, useLocation, useNavigate } from 'react-router-dom'
import { Home, MessageSquare, BarChart3, Users, FileText, Settings, ChevronLeft, ChevronRight, Download, Aperture, UserCircle, Lock, ChevronUp, Trash2 } from 'lucide-react' import { Home, MessageSquare, BarChart3, Users, FileText, Settings, ChevronLeft, ChevronRight, Download, Aperture, UserCircle, Lock, LockOpen, ChevronUp, Trash2 } from 'lucide-react'
import { useAppStore } from '../stores/appStore' import { useAppStore } from '../stores/appStore'
import * as configService from '../services/config' import * as configService from '../services/config'
import { onExportSessionStatus, requestExportSessionStatus } from '../services/exportBridge' import { onExportSessionStatus, requestExportSessionStatus } from '../services/exportBridge'
@@ -64,6 +64,7 @@ const normalizeAccountId = (value?: string | null): string => {
function Sidebar() { function Sidebar() {
const location = useLocation() const location = useLocation()
const navigate = useNavigate()
const [collapsed, setCollapsed] = useState(false) const [collapsed, setCollapsed] = useState(false)
const [authEnabled, setAuthEnabled] = useState(false) const [authEnabled, setAuthEnabled] = useState(false)
const [activeExportTaskCount, setActiveExportTaskCount] = useState(0) const [activeExportTaskCount, setActiveExportTaskCount] = useState(0)
@@ -465,16 +466,20 @@ function Sidebar() {
</div> </div>
</div> </div>
{authEnabled && ( <button
<button className="nav-item"
className="nav-item" onClick={() => {
onClick={() => setLocked(true)} if (authEnabled) {
title={collapsed ? '锁定' : undefined} setLocked(true)
> return
<span className="nav-icon"><Lock size={20} /></span> }
<span className="nav-label"></span> navigate('/settings', { state: { initialTab: 'security' } })
</button> }}
)} title={collapsed ? (authEnabled ? '锁定' : '未锁定') : undefined}
>
<span className="nav-icon">{authEnabled ? <Lock size={20} /> : <LockOpen size={20} />}</span>
<span className="nav-label">{authEnabled ? '锁定' : '未锁定'}</span>
</button>
<NavLink <NavLink
to="/settings" to="/settings"

View File

@@ -1,4 +1,5 @@
import { useState, useEffect, useRef } from 'react' import { useState, useEffect, useRef } from 'react'
import { useLocation } from 'react-router-dom'
import { useAppStore } from '../stores/appStore' import { useAppStore } from '../stores/appStore'
import { useChatStore } from '../stores/chatStore' import { useChatStore } from '../stores/chatStore'
import { useThemeStore, themes } from '../stores/themeStore' import { useThemeStore, themes } from '../stores/themeStore'
@@ -45,6 +46,7 @@ interface WxidOption {
} }
function SettingsPage() { function SettingsPage() {
const location = useLocation()
const { const {
isDbConnected, isDbConnected,
setDbConnected, setDbConnected,
@@ -209,6 +211,12 @@ function SettingsPage() {
} }
}, []) }, [])
useEffect(() => {
const initialTab = (location.state as { initialTab?: SettingsTab } | null)?.initialTab
if (!initialTab) return
setActiveTab(initialTab)
}, [location.state])
// 点击外部关闭下拉框 // 点击外部关闭下拉框
useEffect(() => { useEffect(() => {
const handleClickOutside = (e: MouseEvent) => { const handleClickOutside = (e: MouseEvent) => {