"use client" import { useEffect, useState } from "react" import { Globe } from "lucide-react" interface IpDisplayProps { mobileSimplified?: boolean } export default function IpDisplay({ mobileSimplified = false }: IpDisplayProps) { const [ip, setIp] = useState("") const [loading, setLoading] = useState(true) useEffect(() => { const fetchIp = async () => { try { // 使用 ipify API 來獲取客戶端IP const response = await fetch("https://api.ipify.org?format=json") const data = await response.json() setIp(data.ip) } catch (error) { console.error("無法獲取IP地址:", error) setIp("未知") } finally { setLoading(false) } } fetchIp() }, []) if (loading) { return (
載入中...
) } // 手機版簡化顯示 if (mobileSimplified) { return (
{ip.split('.').slice(0, 2).join('.')}...
) } return (
{ip}
) }