From e9bf76d5065036556e57df57593e91f44789dc61 Mon Sep 17 00:00:00 2001 From: SuchJack <2640808535@qq.com> Date: Sun, 1 Jun 2025 18:39:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix=EF=BC=9A=E4=BC=98=E5=8C=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7avatar=E6=98=BE=E7=A4=BA=E9=80=BB=E8=BE=91=EF=BC=88?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=9C=AA=E8=AE=BE=E7=BD=AEavatar=E5=88=99?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=B3=BB=E7=BB=9Fdefault=5Favatar=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/activity/groupon/detail.vue | 4 ++-- pages/user/info.vue | 2 +- sheep/components/s-user-card/s-user-card.vue | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pages/activity/groupon/detail.vue b/pages/activity/groupon/detail.vue index 5312b879..f9ef7816 100644 --- a/pages/activity/groupon/detail.vue +++ b/pages/activity/groupon/detail.vue @@ -98,7 +98,7 @@ - + 团长 @@ -107,7 +107,7 @@ v-for="item in state.data.memberRecords" :key="item.id" > - + From 6c6f8c84aa9e92c269ed4d94b58ece00931c35b4 Mon Sep 17 00:00:00 2001 From: binny1024 <596928539@qq.com> Date: Sun, 15 Jun 2025 07:45:51 +0000 Subject: [PATCH 2/2] =?UTF-8?q?!153=20feat(utils):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E5=AE=BD=E5=BA=A6=E6=B5=8B=E9=87=8F=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E5=87=BD=E6=95=B0=20*=20feat(utils):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=96=87=E6=9C=AC=E5=AE=BD=E5=BA=A6=E6=B5=8B=E9=87=8F?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../canvas-poster/poster/user.js | 5 +-- utils/textUtils.js | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 utils/textUtils.js diff --git a/sheep/components/s-share-modal/canvas-poster/poster/user.js b/sheep/components/s-share-modal/canvas-poster/poster/user.js index 5c4d3b96..aa73922e 100644 --- a/sheep/components/s-share-modal/canvas-poster/poster/user.js +++ b/sheep/components/s-share-modal/canvas-poster/poster/user.js @@ -1,10 +1,11 @@ import sheep from '@/sheep'; import { formatImageUrlProtocol, getWxaQrcode } from './index'; - +import { measureTextWidth } from '@/utils/textUtils'; // 引入新封装的方法 const user = async (poster) => { const width = poster.width; const userInfo = sheep.$store('user').userInfo; const wxa_qrcode = await getWxaQrcode(poster.shareInfo.path, poster.shareInfo.query); + const widthNickName = measureTextWidth(userInfo.nickname, 14); // 使用新方法 return [ { type: 'image', @@ -28,7 +29,7 @@ const user = async (poster) => { fontFamily: 'sans-serif', position: 'fixed', top: width * 0.4, - left: width / 2, + left: (width-widthNickName) / 2, }, }, { diff --git a/utils/textUtils.js b/utils/textUtils.js new file mode 100644 index 00000000..f6231a0d --- /dev/null +++ b/utils/textUtils.js @@ -0,0 +1,34 @@ +// sheep/utils/textUtils.js +export function measureTextWidth(text, fontSize = 14, fontFamily = 'sans-serif') { + // 钉钉小程序没有 uni.createCanvasContext 方法 + if (typeof uni === 'undefined' || typeof uni.createCanvasContext !== 'function') { + return estimateTextWidth(text, fontSize); + } + + try { + const ctx = uni.createCanvasContext('tempCanvasForText'); + ctx.setFontSize(fontSize); + ctx.font = `${fontSize}px ${fontFamily}`; + const metrics = ctx.measureText(text); + return metrics.width; + } catch (e) { + // 某些平台可能不支持 measureText,降级使用估算 + return estimateTextWidth(text, fontSize); + } +} + +// 简单估算中文和英文字符宽度 +function estimateTextWidth(text, fontSize = 14) { + let width = 0; + for (let i = 0; i < text.length; i++) { + const charCode = text.charCodeAt(i); + if (charCode >= 0x4e00 && charCode <= 0x9fff) { + // 中文字符 + width += fontSize; + } else { + // 英文字符 + width += fontSize * 0.5; + } + } + return width; +}