time chart int

This commit is contained in:
2025-04-08 07:46:20 +08:00
parent 4e7266240d
commit 6940d60510
8 changed files with 541 additions and 39 deletions

View File

@@ -115,30 +115,77 @@ export default function LinksPage() {
// 使用 Zustand store
const { setSelectedShortUrl } = useShortUrlStore();
// 处理链接记录点击
const handleLinkClick = (shortUrl: string, link: ShortLink, metadata: any) => {
// 编码 shortUrl 以确保 URL 安全
const encodedShortUrl = encodeURIComponent(shortUrl);
// 处理点击链接行
const handleRowClick = (link: any) => {
// 解析 attributes 字符串为对象
let attributes: Record<string, any> = {};
try {
if (link.attributes && typeof link.attributes === 'string') {
attributes = JSON.parse(link.attributes || '{}');
}
} catch (e) {
console.error('Error parsing link attributes:', e);
}
// 创建完整的 ShortUrlData 对象
const shortUrlData: ShortUrlData = {
// 解析 teams 字符串为数组
let teams: any[] = [];
try {
if (link.teams && typeof link.teams === 'string') {
teams = JSON.parse(link.teams || '[]');
}
} catch (e) {
console.error('Error parsing teams:', e);
}
// 解析 projects 字符串为数组
let projects: any[] = [];
try {
if (link.projects && typeof link.projects === 'string') {
projects = JSON.parse(link.projects || '[]');
}
} catch (e) {
console.error('Error parsing projects:', e);
}
// 解析 tags 字符串为数组
let tags: string[] = [];
try {
if (link.tags && typeof link.tags === 'string') {
const parsedTags = JSON.parse(link.tags);
if (Array.isArray(parsedTags)) {
tags = parsedTags.map((tag: { tag_name?: string }) => tag.tag_name || '');
}
}
} catch (e) {
console.error('Error parsing tags:', e);
}
// 确保 shortUrl 存在
const shortUrlValue = attributes.shortUrl || '';
// 提取用于显示的字段
const shortUrlData = {
id: link.id,
slug: metadata.slug,
originalUrl: metadata.originalUrl,
title: metadata.title,
shortUrl: shortUrl,
teams: metadata.teamNames,
tags: metadata.tagNames,
projects: metadata.projectNames,
createdAt: metadata.createdAt,
domain: metadata.domain
externalId: link.external_id, // 明确添加 externalId 字段
slug: link.slug,
originalUrl: link.original_url,
title: link.title,
shortUrl: shortUrlValue,
teams: teams,
projects: projects,
tags: tags,
createdAt: link.created_at,
domain: shortUrlValue ? new URL(shortUrlValue).hostname : 'shorturl.example.com'
};
// 使用 Zustand store 保存数据
// 打印完整数据,确保 externalId 被包含
console.log('Setting shortURL data in store with externalId:', link.external_id);
// 将数据保存到 Zustand store
setSelectedShortUrl(shortUrlData);
// 导航到 analytics 页面并带上参数
router.push(`/analytics?shorturl=${encodedShortUrl}`);
// 导航到分析页面,并在 URL 中包含 shortUrl 参数
router.push(`/analytics?shorturl=${encodeURIComponent(shortUrlValue)}`);
};
// Extract link metadata from attributes
@@ -423,7 +470,7 @@ export default function LinksPage() {
const shortUrl = `https://${metadata.domain}/${metadata.slug}`;
return (
<tr key={link.id} className="hover:bg-gray-50 cursor-pointer" onClick={() => handleLinkClick(shortUrl, link, metadata)}>
<tr key={link.id} className="hover:bg-gray-50 cursor-pointer" onClick={() => handleRowClick(link)}>
<td className="px-6 py-4">
<div className="flex flex-col space-y-1">
<span className="font-medium text-gray-900">{metadata.title}</span>