From 3329762d93d1183047095574a5d688974ed4335e Mon Sep 17 00:00:00 2001 From: songchenglin3 <353833373@qq.com> Date: Mon, 8 Jun 2026 16:00:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4jmfe=E6=A1=A5=E6=8E=A5?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/scale-f.ts | 67 ++++++-------------------------------------- 1 file changed, 8 insertions(+), 59 deletions(-) diff --git a/src/utils/scale-f.ts b/src/utils/scale-f.ts index c05cfc4ee6..cd5ded36df 100644 --- a/src/utils/scale-f.ts +++ b/src/utils/scale-f.ts @@ -1,36 +1,11 @@ /** - * 响应式缩放系数(--nut-scale-f):结合京东站内原生桥与站外视口规则, + * 响应式缩放系数(--nut-scale-f):按视口宽度计算, * 写入根节点 CSS 变量(--nut-scale-f / --nut-scale-font / --nut-scale-icon), * 供布局/字号/icon 等按比例换算(见 calcByProfile)。H5 与 Taro WebView 共用此实现。 */ import { canUseDom } from './can-use-dom' -/** 原生 DongScreenAdapterPlugin.getScale 的典型返回结构 */ -type NativeScaleResponse = { - status?: string - data?: { - scale?: number | string - } -} - -/** jmfe 通用 callNative 签名 */ -type NativeCaller = ( - plugin: string, - method: string, - params: string, - extra: string -) => Promise - -/** 站内容器的 jmfe 桥接方法(可选) */ -declare global { - interface Window { - jmfe?: { - callNative?: NativeCaller - } - } -} - -/** 当前基准缩放(来自原生或视口计算) */ +/** 当前基准缩放(来自视口计算) */ let scale = 1 /** 字体档位:标准、大字、老年 */ @@ -113,7 +88,7 @@ function roundByScaleRule( return Math.round(value) } -/** 无原生桥时按屏宽推算 scale(含平板与 375 基准窄屏区间) */ +/** 按屏宽推算 scale(含平板与 375 基准窄屏区间) */ function getScaleByViewport() { if (!canUseDom) return 1 const deviceWidth = window.innerWidth @@ -132,34 +107,8 @@ function getScaleByViewport() { return 1 } -/** 通过 jmfe.callNative 拉取 DongScreenAdapterPlugin;失败返回 null */ -async function getScaleByNative() { - if (!canUseDom || !window.jmfe?.callNative) return null - - try { - const res = await window.jmfe.callNative( - 'DongScreenAdapterPlugin', - 'getScale', - JSON.stringify({}), - '' - ) - if (res?.status === '0' && res.data?.scale !== undefined) { - const parsed = Number(res.data.scale) - if (Number.isFinite(parsed) && parsed > 0) { - return parsed - } - } - } catch { - /* 原生异常时由 getScaleF 回退到视口规则 */ - } - - return null -} - -/** 统一获取缩放:站内原生优先,失败则用视口规则 */ -async function getScaleF() { - const nativeScale = await getScaleByNative() - if (nativeScale) return nativeScale +/** 统一获取缩放:按视口规则计算 */ +function getScaleF() { return getScaleByViewport() } @@ -171,12 +120,12 @@ function setScaleF(nextScale: number) { return scale } -/** 重新拉取缩放;可选同时切换 profile,避免与当前值相同时重复写 DOM */ -async function refreshScaleF(nextProfile?: ScaleProfile) { +/** 重新计算缩放;可选同时切换 profile,避免与当前值相同时重复写 DOM */ +function refreshScaleF(nextProfile?: ScaleProfile) { if (nextProfile) { setScaleProfile(nextProfile) } - const nextScale = await getScaleF() + const nextScale = getScaleF() if (!scale || nextScale !== scale) { setScaleF(nextScale) }