"use client" import { useEffect, useState } from "react" import { Globe, Shield, ShieldAlert } from "lucide-react" interface IpDisplayProps { mobileSimplified?: boolean } interface IpInfo { ip: string isAllowed: boolean enableIpWhitelist: boolean allowedIps: string[] timestamp: string } export default function IpDisplay({ mobileSimplified = false }: IpDisplayProps) { const [ipInfo, setIpInfo] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) useEffect(() => { const fetchIpInfo = async () => { try { const response = await fetch('/api/ip') if (!response.ok) { throw new Error('無法獲取IP信息') } const data = await response.json() setIpInfo(data) } catch (error) { console.error("無法獲取IP信息:", error) setError("無法獲取IP信息") } finally { setLoading(false) } } fetchIpInfo() }, []) if (loading) { return (
載入中...
) } if (error || !ipInfo) { return (
錯誤
) } // 手機版簡化顯示 if (mobileSimplified) { return (
{ipInfo.enableIpWhitelist && !ipInfo.isAllowed ? ( ) : ( )} {ipInfo.ip.split('.').slice(0, 2).join('.')}...
) } return (
{ipInfo.enableIpWhitelist && !ipInfo.isAllowed ? ( ) : ( )} {ipInfo.ip} {ipInfo.enableIpWhitelist && ( {ipInfo.isAllowed ? '允許' : '拒絕'} )}
) }