41 lines
962 B
Python
41 lines
962 B
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
侧边栏状态
|
|
"""
|
|
import reflex as rx
|
|
|
|
from application.states import AuthState
|
|
|
|
|
|
class SidebarState(rx.State):
|
|
"""
|
|
侧边栏状态
|
|
"""
|
|
|
|
@rx.var
|
|
async def generate_storage_key(self) -> str:
|
|
"""
|
|
生成 LocalStorage 键
|
|
"""
|
|
auth = await self.get_state(AuthState)
|
|
# 获取用户唯一标识
|
|
user_id = auth.user_id or "default"
|
|
return f"sidebar_{user_id}"
|
|
|
|
# 侧边栏中激活的图标导航按钮
|
|
activated_button = rx.LocalStorage(generate_storage_key, sync=True)
|
|
|
|
@rx.var
|
|
def get_activated_button(self) -> str:
|
|
"""
|
|
获取侧边栏中激活的图标导航按钮
|
|
"""
|
|
return self.activated_button
|
|
|
|
@rx.event
|
|
def switch_activated_button(self, button: str):
|
|
"""
|
|
将指定图标导航按钮设置为侧边栏中激活的图标导航按钮
|
|
"""
|
|
self.activated_button = button
|