import { VStack, HStack, Button, Box, Table, Thead, Tr, Th, Tbody, Td, } from "@hope-ui/solid" import { useT, useRouter } from "~/hooks" import { For, createSignal, onMount } from "solid-js" import { DeletePopover } from "~/pages/manage/common/DeletePopover" import { getSessionList, evictSession, cleanSessions } from "~/utils/api" import { handleResp, notify } from "~/utils" import { clearUserData } from "~/utils/auth" import { getSystemDisplayName } from "~/utils/ua-parser" const Manage = () => { const t = useT() const { to } = useRouter() const [sessions, setSessions] = createSignal([]) const [loading, setLoading] = createSignal(false) const [error, setError] = createSignal(null) const [kickingSession, setKickingSession] = createSignal(null) const [cleaning, setCleaning] = createSignal(false) const handleKickOut = async (sessionId: string) => { setKickingSession(sessionId) try { const resp = await evictSession(sessionId) handleResp( resp, () => { notify.success(t("session.kick_out_success")) fetchSessions() }, (message) => { notify.error(message || t("session.kick_out_failed")) }, ) } catch (err) { notify.error(t("session.kick_out_failed")) } finally { setKickingSession(null) } } // 检查是否是当前设备的会话 const isCurrentDeviceSession = (session: any) => { const currentDeviceKey = localStorage.getItem("device_key") return currentDeviceKey && session.session_id === currentDeviceKey } // 处理踢出会话,如果是当前设备则走登出逻辑 const handleKickOutWithDeviceCheck = async (session: any) => { const isCurrent = isCurrentDeviceSession(session) if (isCurrent) { // 如果是当前设备,走登出逻辑 notify.error(t("session.kick_out_current_session")) clearUserData() to(`/@login?redirect=${encodeURIComponent(window.location.pathname)}`) } else { // 如果不是当前设备,正常踢出 await handleKickOut(session.session_id) } } const fetchSessions = async () => { setLoading(true) setError(null) try { const resp = await getSessionList() handleResp( resp, (data) => { setSessions(data || []) }, (message) => { setError(message) }, ) } catch (err) { setError(err instanceof Error ? err.message : "Unknown error") } finally { setLoading(false) } } onMount(() => { fetchSessions() }) const handleClean = async () => { setCleaning(true) try { const resp = await cleanSessions() handleResp( resp, () => { notify.success(t("session.clean_success")) fetchSessions() }, (message) => { notify.error(message || t("session.clean_failed")) }, ) } catch (err) { notify.error(t("session.clean_failed")) } finally { setCleaning(false) } } return ( {error() && ( {error()} )} {(col) => ( )} {(session) => ( handleKickOutWithDeviceCheck(session) } buttonText={t("session.kick_out")} /> ), }, ]} > {(col) => ( )} )}
{col.key === "operations" ? t("global.operations") : t(`session.${col.key}`)}
{col.content}
) } export default Manage