---
title: 工具类
summary: "提供 RN 工具类（颜色转换、适配、温度、JSON 等）迁移到 @ray-js/panel-sdk 的对照指南。"
tags: [RN迁移工具类, 颜色转换迁移, 设备尺寸适配迁移]
questions:
  - RN 中的 convertX 适配方法在面板小程序中如何替代？
  - 面板小程序为什么不再需要 RatioUtils 做屏幕适配？
  - RN 的 ColorUtils 颜色转换工具迁移到小程序后如何使用？
  - 面板小程序中温度工具方法从哪个包引入？
  - RN 的 JsonUtils 在面板小程序中对应什么？
  - 面板小程序中字符串工具和数值工具如何使用？
  - RN 的 CoreUtils 和 TimeUtils 在小程序中如何替换？
  - "@ray-js/panel-sdk 中的 utils 提供了哪些工具方法？"
---

# 工具类

## 适配类工具

**之前：**

```js
import { Utils } from "tuya-panel-kit";
const { convertX } = Utils.RatioUtils;

// 某组件设计稿上宽13
width = convertX(13); // 最后该组件在当前设备的宽度
```

**现在：**

```css
.content {
  width: 26rpx;
}
```

由于小程序天然支持 CSS 环境，可通过 rpx 单位进行适配，无需再使用 `convertX` 进行转换，详见 [TYSS 语法参考-rpx 单位](/cn/miniapp/develop/miniapp/framework/tyss#rpx-%E5%8D%95%E4%BD%8D)

## 颜色转换工具

**之前：**

```js
import { Utils } from "tuya-panel-kit";
const { hsvToRgb } = Utils.ColorUtils;

hsvToRgb( h, s, v ); 
// Example:
hsvToRgb(0, 1, 1);
```

**现在：**

```js
import { utils } from '@ray-js/panel-sdk';
const { hsv2rgb } = utils;
 
hsv2rgb(h, s, v);
// Example:
hsv2rgb(0, 100, 100);
```

详见 [工具方法-颜色](/cn/miniapp/solution-panel/ability/common/utils/color)

## 温度工具

**之前：**

```js
import { Utils } from "tuya-panel-kit";
const { f2c } = Utils.TemperatureUtils;

f2c(fah);
// Example:
f2c(100);
```

**现在：**

```js
import { utils } from '@ray-js/panel-sdk';
const { f2c } = utils;
 
f2c(fah);
// Example:
f2c(100);
```

详见 [工具方法-温度](/cn/miniapp/solution-panel/ability/common/utils/temperature)

## JSON 解析工具

**之前：**

```js
import { Utils } from "tuya-panel-kit";
const { parseJSON } = Utils.JsonUtils;

parseJSON(str);
//Example：
parseJSON("{a:1, b:2}");  
```

**现在：**

```js
import { utils } from '@ray-js/panel-sdk';
const { parseJSON } = utils;
 
parseJSON(str);
//Example：
parseJSON('{a:1, b:2}');
```

详见 [工具方法-JSON](/cn/miniapp/solution-panel/ability/common/utils/json)

## 核心工具

**之前：**

```js
import { Utils } from "tuya-panel-kit";
const { toFixed } = Utils.CoreUtils;

toFixed(str, num);
// Example:
toFixed("111", 5); 
toFixed("3456111", 5);
```

**现在：**

```js
import { utils } from '@ray-js/panel-sdk';
const { toFixed } = utils;
 
toFixed(str, num);
// Example:
toFixed('111', 5);
toFixed('3456111', 5);
```

详见 [工具方法-通用](/cn/miniapp/solution-panel/ability/common/utils/core)

## 字符串工具

**之前：**

```js
import { Utils } from "tuya-panel-kit";
const { hexStringToNumber } = Utils.StringUtils;

hexStringToNumber(bits);
// Example:
hexStringToNumber("AD03");
```

**现在：**

```js
import { utils } from '@ray-js/panel-sdk';
const { hexStringToNumber } = utils;
 
hexStringToNumber(bits);
// Example:
hexStringToNumber("AD03");
```

详见 [工具方法-字符串](/cn/miniapp/solution-panel/ability/common/utils/string)

## 时间工具

**之前：**

```js
import { Utils } from "tuya-panel-kit";
const { parseSecond } = Utils.TimeUtils;

parseSecond(second, num);
// Example
parseSecond(111); 
parseSecond(3333333);
```

**现在：**

```js
import { utils } from '@ray-js/panel-sdk';
const { parseSecond } = utils;
 
parseSecond(second, num);
// Example
parseSecond(111);
parseSecond(3333333);
```

详见 [工具方法-时间](/cn/miniapp/solution-panel/ability/common/utils/time)

## 数值工具

**之前：**

```js
import { Utils } from "tuya-panel-kit";
const { toFixedString } = Utils.NumberUtils;

toFixedString(value, length);
// Example:
toFixedString(111, 5); 
toFixedString(3456111, 5);
```

**现在：**

```js
import { utils } from '@ray-js/panel-sdk';
const { toFixedString } = utils;
 
toFixedString(value, length);
// Example:
toFixedString(111, 5);
toFixedString(3456111, 5);
```

详见 [工具方法-数值](/cn/miniapp/solution-panel/ability/common/utils/number)
