From 899c5881acfe5bd7ff2a45e054dafc39158e4a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=88=90?= Date: Sat, 6 Dec 2025 23:11:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/HomeNavbar/index.scss | 5 ++-- src/components/HomeNavbar/index.tsx | 1 + src/components/Radar/indexV2.tsx | 39 +++++++++++++++++++++++-- src/other_pages/ntrp-evaluate/index.tsx | 2 +- src/static/logo.svg | 33 +++++---------------- 5 files changed, 48 insertions(+), 32 deletions(-) diff --git a/src/components/HomeNavbar/index.scss b/src/components/HomeNavbar/index.scss index 2d1ef39..fa21036 100644 --- a/src/components/HomeNavbar/index.scss +++ b/src/components/HomeNavbar/index.scss @@ -63,7 +63,6 @@ gap: 8px; .logo { - width: 28px; height: 16px; } @@ -147,8 +146,8 @@ padding-left: 10px; .logo { - width: 32px; - height: 32px; + width: 29px; + height: 29px; } } diff --git a/src/components/HomeNavbar/index.tsx b/src/components/HomeNavbar/index.tsx index c1ae8fb..aef82a7 100644 --- a/src/components/HomeNavbar/index.tsx +++ b/src/components/HomeNavbar/index.tsx @@ -319,6 +319,7 @@ const HomeNavbar = (props: IProps) => { {/* 搜索框 */} diff --git a/src/components/Radar/indexV2.tsx b/src/components/Radar/indexV2.tsx index 3a5e4ee..b3aed22 100644 --- a/src/components/Radar/indexV2.tsx +++ b/src/components/Radar/indexV2.tsx @@ -158,6 +158,17 @@ const RadarChartV2 = forwardRef((props, ref) }); } + // 获取图片信息(宽高) + function getImageInfo(src: string): Promise<{ width: number; height: number }> { + return new Promise((resolve, reject) => { + (Taro as any).getImageInfo({ + src, + success: (res: any) => resolve({ width: res.width, height: res.height }), + fail: reject, + }); + }); + } + // 绘制圆角矩形 function roundRect(ctx: any, x: number, y: number, width: number, height: number, radius: number) { @@ -177,8 +188,12 @@ const RadarChartV2 = forwardRef((props, ref) // 格式化 NTRP 显示 function formatNtrpDisplay(level: string): string { if (!level) return ""; + // 检查是否包含 + 号 + const hasPlus = level.includes("+"); const num = parseFloat(level); - return num % 1 === 0 ? num.toFixed(0) : num.toFixed(1); + if (isNaN(num)) return level; + const formatted = num % 1 === 0 ? num.toFixed(0) : num.toFixed(1); + return hasPlus ? `${formatted}+` : formatted; } useImperativeHandle(ref, () => ({ @@ -250,6 +265,7 @@ const RadarChartV2 = forwardRef((props, ref) try { const avatarSize = 43.46 * scale; // 设计稿头像尺寸 const avatarImg = await loadImage(canvas, options.avatarUrl); + const avatarInfo = await getImageInfo(options.avatarUrl); // 头像区域总宽度(头像 + 装饰图片重叠部分) const avatarWrapWidth = 84.7 * scale; // 设计稿 Frame 1912055063 宽度 @@ -266,11 +282,30 @@ const RadarChartV2 = forwardRef((props, ref) ctx.lineWidth = 1 * scale; ctx.stroke(); + // 计算头像绘制尺寸,保持宽高比 + const innerSize = avatarSize - 1.94 * scale; // 内部可用尺寸 + const avatarAspectRatio = avatarInfo.width / avatarInfo.height; + let drawWidth = innerSize; + let drawHeight = innerSize; + let drawX = avatarX + 0.97 * scale; + let drawY = avatarY + 0.97 * scale; + + // 根据宽高比调整尺寸,保持比例不变形 + if (avatarAspectRatio > 1) { + // 图片更宽,以高度为准 + drawWidth = innerSize * avatarAspectRatio; + drawX = avatarX + avatarSize / 2 - drawWidth / 2; + } else { + // 图片更高或正方形,以宽度为准 + drawHeight = innerSize / avatarAspectRatio; + drawY = avatarY + avatarSize / 2 - drawHeight / 2; + } + // 绘制头像(圆形裁剪) ctx.beginPath(); ctx.arc(avatarX + avatarSize / 2, avatarY + avatarSize / 2, avatarSize / 2 - 0.97 * scale, 0, Math.PI * 2); ctx.clip(); - ctx.drawImage(avatarImg, avatarX + 0.97 * scale, avatarY + 0.97 * scale, avatarSize - 1.94 * scale, avatarSize - 1.94 * scale); + ctx.drawImage(avatarImg, drawX, drawY, drawWidth, drawHeight); ctx.restore(); // 绘制装饰图片(DocCopy)- 在头像右侧 diff --git a/src/other_pages/ntrp-evaluate/index.tsx b/src/other_pages/ntrp-evaluate/index.tsx index ed05cab..7a3f111 100644 --- a/src/other_pages/ntrp-evaluate/index.tsx +++ b/src/other_pages/ntrp-evaluate/index.tsx @@ -667,7 +667,7 @@ function Result() { } useShareAppMessage(async (res) => { - console.log(res, "res"); + console.log( "res",result); return { title: "来测一测你的NTRP等级吧", imageUrl: result?.level_img || undefined, diff --git a/src/static/logo.svg b/src/static/logo.svg index f6fc4a2..40369b2 100644 --- a/src/static/logo.svg +++ b/src/static/logo.svg @@ -1,30 +1,11 @@ - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - + + +