Python/agent/application/states/sidebar.py

35 lines
765 B
Python

# -*- coding: utf-8 -*-
"""
侧边栏状态
"""
import reflex as rx
from application.states.auth import AuthState
class SidebarState(rx.State):
"""
侧边栏状态
"""
@rx.var
async def storage_key(self) -> str:
"""
LocalStorage 键
"""
# 获取认证状态
auth = await self.get_state(AuthState)
# 获取用户唯一标识
user_id = auth.user_id or "default"
return f"sidebar_{user_id}"
# 激活的导航按钮
activated_nav_button: str = rx.LocalStorage(storage_key, sync=True)
@rx.event
def switch_nav_button(self, button: str):
"""
将指定导航按钮设置为激活的导航按钮
"""
self.activated_nav_button = button