take shorturl data
This commit is contained in:
@@ -11,6 +11,8 @@ import { EventsSummary, TimeSeriesData, GeoData, DeviceAnalytics as DeviceAnalyt
|
||||
import { TeamSelector } from '@/app/components/ui/TeamSelector';
|
||||
import { ProjectSelector } from '@/app/components/ui/ProjectSelector';
|
||||
import { TagSelector } from '@/app/components/ui/TagSelector';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { useShortUrlStore } from '@/app/utils/store';
|
||||
|
||||
// 事件类型定义
|
||||
interface Event {
|
||||
@@ -114,6 +116,29 @@ const extractEventInfo = (event: Event) => {
|
||||
};
|
||||
|
||||
export default function AnalyticsPage() {
|
||||
// 从 URL 获取查询参数
|
||||
const searchParams = useSearchParams();
|
||||
const shorturlParam = searchParams.get('shorturl');
|
||||
|
||||
// 使用 Zustand store
|
||||
const { selectedShortUrl } = useShortUrlStore();
|
||||
|
||||
// 存储 shorturl 参数
|
||||
const [selectedShortUrlString, setSelectedShortUrlString] = useState<string | null>(null);
|
||||
|
||||
// 当 URL 参数变化时更新状态
|
||||
useEffect(() => {
|
||||
if (shorturlParam) {
|
||||
setSelectedShortUrlString(shorturlParam);
|
||||
console.log('Selected shorturl from URL:', shorturlParam);
|
||||
|
||||
// 已经通过 Zustand store 传递了完整数据
|
||||
if (selectedShortUrl) {
|
||||
console.log('Complete shortUrl data from store:', selectedShortUrl);
|
||||
}
|
||||
}
|
||||
}, [shorturlParam, selectedShortUrl]);
|
||||
|
||||
// 默认日期范围为最近7天
|
||||
const today = new Date();
|
||||
const [dateRange, setDateRange] = useState({
|
||||
@@ -247,6 +272,33 @@ export default function AnalyticsPage() {
|
||||
<div className="flex justify-between items-center mb-8">
|
||||
<h1 className="text-2xl font-bold text-gray-900">Analytics Dashboard</h1>
|
||||
<div className="flex flex-col gap-4 md:flex-row md:items-center">
|
||||
{/* 如果有选定的 shorturl,可以显示一个提示,显示更多详细信息 */}
|
||||
{selectedShortUrl && (
|
||||
<div className="bg-blue-100 text-blue-800 px-3 py-2 rounded-md text-sm flex flex-col">
|
||||
<div className="flex items-center">
|
||||
<span className="font-medium">{selectedShortUrl.title || 'Untitled'}</span>
|
||||
<span className="mx-2">-</span>
|
||||
<span>{selectedShortUrl.shortUrl}</span>
|
||||
</div>
|
||||
{selectedShortUrl.tags && selectedShortUrl.tags.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1 mt-1">
|
||||
{selectedShortUrl.tags.map((tag, index) => (
|
||||
<span key={index} className="bg-blue-50 text-blue-700 text-xs px-1.5 py-0.5 rounded">
|
||||
{tag}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 如果只有 URL 参数但没有完整数据,则显示简单提示 */}
|
||||
{selectedShortUrlString && !selectedShortUrl && (
|
||||
<div className="bg-blue-100 text-blue-800 px-3 py-1 rounded-md text-sm flex items-center">
|
||||
<span>Filtered by Short URL:</span>
|
||||
<span className="ml-2 font-medium">{selectedShortUrlString}</span>
|
||||
</div>
|
||||
)}
|
||||
<TeamSelector
|
||||
value={selectedTeamIds}
|
||||
onChange={(value) => {
|
||||
|
||||
Reference in New Issue
Block a user