refactor(modules): update existing module implementations across attendance, audit, auth, classes, course-plans, exams, files, homework, layout, proctoring, questions, scheduling, textbooks, users
- Update attendance components and data-access for record management - Update audit log views, filters, and data-access - Update auth login and register forms - Update classes actions, components, and data-access (admin, schedule, stats) - Update course-plans actions, form, list, progress, and schema - Update exams actions, AI pipeline, preview components, and hooks - Update files components (icon, list, preview, upload) and data-access - Update homework assignment form, review view, auto-save hook, and stats-service - Update layout sidebar, header, and navigation config - Update proctoring actions, anti-cheat monitor, and data-access - Update questions actions, components (dialog, actions, columns, filters), and data-access - Update scheduling actions, auto-scheduler, components, and schema - Update textbooks constants and text-selection hook - Update users class-registration, import-dialog, data-access, and user-service
This commit is contained in:
@@ -11,13 +11,6 @@ import {
|
||||
CollapsibleTrigger,
|
||||
} from "@/shared/components/ui/collapsible"
|
||||
import { ScrollArea } from "@/shared/components/ui/scroll-area"
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/shared/components/ui/select"
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
@@ -35,11 +28,13 @@ interface AppSidebarProps {
|
||||
}
|
||||
|
||||
export function AppSidebar({ mode }: AppSidebarProps) {
|
||||
const { expanded, toggleSidebar, isMobile, currentRole, setCurrentRole } = useSidebar()
|
||||
const { expanded, toggleSidebar, isMobile } = useSidebar()
|
||||
const pathname = usePathname()
|
||||
const { permissions, roles, hasRole } = usePermission()
|
||||
const { permissions, hasRole } = usePermission()
|
||||
|
||||
// 自动检测当前角色(优先级 admin > student > parent > teacher)
|
||||
// 注意:grade_head / teaching_head 统一归入 teacher,因为 teacher 导航已通过
|
||||
// 权限点(GRADE_MANAGE 等)动态显示班主任专属功能,无需切换角色。
|
||||
function detectAutoRole(): Role {
|
||||
if (hasRole("admin")) return "admin"
|
||||
if (hasRole("student")) return "student"
|
||||
@@ -47,14 +42,7 @@ export function AppSidebar({ mode }: AppSidebarProps) {
|
||||
return "teacher"
|
||||
}
|
||||
|
||||
// 用户在 NAV_CONFIG 中实际可用的角色(过滤掉未配置的角色)
|
||||
const availableRoles = roles.filter((r) => NAV_CONFIG[r] !== undefined)
|
||||
|
||||
// 如果 context 中有 currentRole 且用户拥有该角色,使用 currentRole;否则自动检测
|
||||
const effectiveRole: Role =
|
||||
currentRole !== null && availableRoles.includes(currentRole)
|
||||
? currentRole
|
||||
: detectAutoRole()
|
||||
const effectiveRole: Role = detectAutoRole()
|
||||
|
||||
const allNavItems = NAV_CONFIG[effectiveRole] ?? NAV_CONFIG.teacher ?? []
|
||||
|
||||
@@ -71,7 +59,7 @@ export function AppSidebar({ mode }: AppSidebarProps) {
|
||||
}))
|
||||
|
||||
// Ensure consistent state for hydration
|
||||
if (!expanded && mode === 'mobile') return null
|
||||
if (!expanded && mode === 'mobile') return null
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col gap-4">
|
||||
@@ -179,26 +167,12 @@ export function AppSidebar({ mode }: AppSidebarProps) {
|
||||
|
||||
{/* Sidebar Footer */}
|
||||
<div className="p-4">
|
||||
{availableRoles.length > 1 && (expanded || isMobile) && (
|
||||
<div className="px-2 pb-2">
|
||||
<Select value={effectiveRole} onValueChange={(v) => setCurrentRole(v as Role)}>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="切换角色" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{availableRoles.map((r) => (
|
||||
<SelectItem key={r} value={r}>{r}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
{!isMobile && (
|
||||
<button
|
||||
onClick={toggleSidebar}
|
||||
className="hover:bg-sidebar-accent text-sidebar-foreground flex w-full items-center justify-center rounded-md border p-2 text-sm transition-colors"
|
||||
>
|
||||
{expanded ? "收起" : <ChevronRight className="size-4" />}
|
||||
{expanded ? "收起" : <ChevronRight className="size-4" />}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user