From 6890f13aa9bc660f5e80e170da3c4c8a071ffff4 Mon Sep 17 00:00:00 2001 From: shenlei Date: Fri, 23 Oct 2026 10:44:35 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=92=89=E9=92=89=E6=A1=8C=E9=9D=A2?= =?UTF-8?q?=E7=AB=AF=E9=80=9A=E7=9F=A5=E4=BA=8C=E7=BB=B4=E7=A0=81=E8=A2=AB?= =?UTF-8?q?=E8=A3=81=E5=89=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 桌面端钉钉会把 Markdown 图片裁成横向区域,正方形二维码上下被裁掉。 二维码居中放到 3:2 白底画布上;网页中的二维码图片改用 object-fit 避免拉伸。 Co-Authored-By: Claude Opus 5.5 --- backend/services/distribution.py | 18 +++++++++++++++++- frontend/src/views/BuildView.vue | 2 +- frontend/src/views/HistoryView.vue | 4 ++-- tests/test_distribution.py | 5 +++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/backend/services/distribution.py b/backend/services/distribution.py index 3c1a537..01d9169 100644 --- a/backend/services/distribution.py +++ b/backend/services/distribution.py @@ -454,6 +454,22 @@ def _upload_oss(config: dict, files: list[tuple[Path, str]]) -> dict[str, str]: return urls +# 桌面端钉钉会把 Markdown 图片裁成约 1.4:1 的横向区域,正方形二维码上下被裁掉 +# (手机端完整显示)。居中放到 3:2 的白底画布上:桌面端裁掉的只是空白, +# 手机端二维码仍占图片宽度的 2/3,不至于太小。 +_QR_CANVAS_RATIO = 1.5 + + +def _pad_to_wide(image): + from PIL import Image + + image = image.convert("RGB") + width, height = image.size + canvas = Image.new("RGB", (round(height * _QR_CANVAS_RATIO), height), "white") + canvas.paste(image, ((canvas.width - width) // 2, 0)) + return canvas + + def publish_ipa(config: dict, ipa_path: Path, build_dir: Path) -> tuple[str, str]: """发布 IPA,返回下载 URL 与二维码公开 URL。""" upload = config.get("_upload_config", {}) @@ -487,7 +503,7 @@ def publish_ipa(config: dict, ipa_path: Path, build_dir: Path) -> tuple[str, str qr = qrcode.QRCode(box_size=5, border=4) qr.add_data(urls[".html"]) qr.make(fit=True) - qr.make_image(fill_color="black", back_color="white").save(qr_path) + _pad_to_wide(qr.make_image(fill_color="black", back_color="white").get_image()).save(qr_path) urls.update(uploader(upload, [(qr_path, qr_remote)])) return urls[".html"], urls[".png"] diff --git a/frontend/src/views/BuildView.vue b/frontend/src/views/BuildView.vue index 18a9150..4ecf56c 100644 --- a/frontend/src/views/BuildView.vue +++ b/frontend/src/views/BuildView.vue @@ -513,7 +513,7 @@ const errorCategoryHint = (cat) => { .download-link { color: #1890ff; text-decoration: none; } .download-link:hover { text-decoration: underline; } .qr-section { text-align: center; padding: 16px; background: #fafafa; border-radius: 8px; } -.qr-image { width: 180px; height: 180px; border: 1px solid #f0f0f0; border-radius: 8px; } +.qr-image { width: 180px; height: 180px; object-fit: contain; border: 1px solid #f0f0f0; border-radius: 8px; } .qr-hint { margin-top: 8px; font-size: 13px; color: #999; } .error-msg { color: #ff4d4f; font-size: 13px; word-break: break-all; } diff --git a/frontend/src/views/HistoryView.vue b/frontend/src/views/HistoryView.vue index 9075d83..8000dec 100644 --- a/frontend/src/views/HistoryView.vue +++ b/frontend/src/views/HistoryView.vue @@ -570,7 +570,7 @@ const errorCategoryLabel = (cat) => { .download-link:disabled { color: #999; cursor: default; } .download-link:disabled:hover { text-decoration: none; } .text-muted { color: #999; font-size: 13px; } -.qr-thumb { width: 40px; height: 40px; cursor: pointer; border-radius: 4px; border: 1px solid #e8e8e8; } +.qr-thumb { width: 40px; height: 40px; object-fit: cover; cursor: pointer; border-radius: 4px; border: 1px solid #e8e8e8; } .qr-thumb:hover { border-color: #1890ff; } .btn-danger { color: #ff4d4f; border-color: #ff4d4f; } .btn-danger:hover { background: #ff4d4f; color: white; } @@ -580,7 +580,7 @@ const errorCategoryLabel = (cat) => { .qr-preview-modal .modal-header { display: flex; justify-content: center; align-items: center; position: relative; margin-bottom: 16px; } .qr-preview-modal .modal-close { position: absolute; right: 0; top: 50%; transform: translateY(-50%); background: none; border: none; font-size: 20px; cursor: pointer; color: #999; } .qr-preview-modal .modal-close:hover { color: #333; } -.qr-preview-img { width: 260px; height: 260px; border: 1px solid #f0f0f0; border-radius: 8px; margin: 16px 0; } +.qr-preview-img { width: 260px; height: 260px; object-fit: contain; border: 1px solid #f0f0f0; border-radius: 8px; margin: 16px 0; } .qr-preview-info { text-align: left; padding: 12px 16px; background: #fafafa; border-radius: 8px; } .qr-preview-info p { margin: 6px 0; font-size: 13px; color: #555; } diff --git a/tests/test_distribution.py b/tests/test_distribution.py index bd5dcbb..c530001 100644 --- a/tests/test_distribution.py +++ b/tests/test_distribution.py @@ -87,6 +87,11 @@ def test_adhoc_distribution_uploads_qrcode(tmp_path): ".ipa", ".plist", ".html", ".png", ] + # 桌面端钉钉会把图片裁成横向比例,二维码需放在 3:2 的横向画布上 + from PIL import Image + with Image.open(tmp_path / "build" / "distribution" / "100_2_0_0_dev_adhoc.png") as image: + assert image.width == round(image.height * 1.5) + def test_delete_adhoc_artifacts_deletes_all_remote_files(): config = {"APPID": "100", "VERSION": "2.0.0.0", "SOURCE_BRANCH": "main", "BUILD_TYPE": "Ad_Hoc", "OSS_FLODER": "readoor"}