tatak
tatak
  • 发布:2025-04-09 13:56
  • 更新:2025-04-09 13:56
  • 阅读:68

【报Bug】鸿蒙5.0 - uni.upx2px 在入参是750的情况下,返回值有误

分类:鸿蒙Next

产品分类: uniapp/App

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: macOS 15

手机系统: HarmonyOS NEXT

手机系统版本号: HarmonyOS NEXT Developer Beta2

手机厂商: 华为

手机机型: pure 70 / mate 60

页面类型: vue

vue版本: vue3

打包方式: 离线

项目创建方式: CLI

CLI版本号: 3.0.0-4030620241128001

示例代码:
  for(let i = 0; i <= 750; i += 50) {  
    console.log(`uni.upx2px(${i}) = ${uni.upx2px(i)}`);  
  }

操作步骤:

在 uni-app 中执行上述测试代码

预期结果:

uni.upx2px(0) = 0
uni.upx2px(50) = 25
uni.upx2px(100) = 50
uni.upx2px(150) = 75
uni.upx2px(200) = 100
uni.upx2px(250) = 125
uni.upx2px(300) = 150
uni.upx2px(350) = 175
uni.upx2px(400) = 200
uni.upx2px(450) = 225
uni.upx2px(500) = 250
uni.upx2px(550) = 275
uni.upx2px(600) = 300
uni.upx2px(650) = 325
uni.upx2px(700) = 350
uni.upx2px(750) = 375

实际结果:

uni.upx2px(0) = 0
uni.upx2px(50) = 25
uni.upx2px(100) = 50
uni.upx2px(150) = 75
uni.upx2px(200) = 100
uni.upx2px(250) = 125
uni.upx2px(300) = 150
uni.upx2px(350) = 175
uni.upx2px(400) = 200
uni.upx2px(450) = 225
uni.upx2px(500) = 250
uni.upx2px(550) = 275
uni.upx2px(600) = 300
uni.upx2px(650) = 325
uni.upx2px(700) = 350
uni.upx2px(750) = 1205

bug描述:

鸿蒙 5.0 app 集成 uni-app 小程序sdk(2.3.23)版本,uni.upx2px(number) 在入参 number 为 750 的情况下,返回的值有误。

根据我的定位排查,最终 uni.upx2px 是在 uni-app-harmony-framework.js / uni-app-harmony-framework-dev.js 中实现:

  var upx2px = defineSyncApi(API_UPX2PX, (number, newDeviceWidth) => {  
    if (deviceWidth === 0) {  
      checkDeviceWidth();  
      {  
        checkMaxWidth();  
      }  
    }  
    number = Number(number);  
    if (number === 0) {  
      return 0;  
    }  
    let width = newDeviceWidth || deviceWidth;  
    {  
      width = number === includeWidth || width <= maxWidth ? width : baseWidth;  
    }  
    let result = number / BASE_DEVICE_WIDTH * width;  
    if (result < 0) {  
      result = -result;  
    }  
    result = Math.floor(result + EPS);  
    if (result === 0) {  
      if (deviceDPR === 1 || !isIOS2) {  
        result = 1;  
      } else {  
        result = 0.5;  
      }  
    }  
    return number < 0 ? -result : result;  
  }, Upx2pxProtocol);

上述代码在入参为 750 的情况下,会出现前面提到的问题

2025-04-09 13:56 负责人:DCloud_UNI_OttoJi 分享
已邀请:

要回复问题请先登录注册