x-chinesetopinyin-s 中文转拼音
中文转拼音,同时返回无声调和带声调两种结果。
兼容性
| Harmony | IOS | Android | WEB | 小程序 |
|---|---|---|---|---|
| 支持 | 支持 | 支持 | 支持 | 支持 |
调用
ts
import { toPinyin, XChineseToPinyinResult } from "@/uni_modules/x-chinesetopinyin-s"
toPinyin({
char: "你好",
success: (res : XChineseToPinyinResult) => {
console.log(res.detail) // ni hao
console.log(res.zhuyin) // nǐ hǎo
},
fail: (error) => {
console.log(error.errCode, error.errMsg)
}
})方法
| 名称 | 需要 | 说明 |
|---|---|---|
| toPinyin | char,可选 success / fail / complete | 转拼音,成功返回 detail(无声调)和 zhuyin(有声调) |
参数
XChineseToPinyinOptions
| 字段 | 说明 | 默认 |
|---|---|---|
| char | 待转换字符串,不能为空 | 必填 |
| success | 成功 | - |
| fail | 失败 | - |
| complete | 结束,失败时为 null | - |
XChineseToPinyinResult
| 字段 | 说明 |
|---|---|
| char | 原始输入 |
| detail | 无声调拼音,空格分音节,小写 |
| zhuyin | 带声调拼音,空格分音节,小写 |
错误码:1001 系统错误,1002 参数错误(char 为空)。
版本
版权归https://xui.tmui.design你不得修改及二次开发,仅供TMUI4会员商用使用。不得转给非VIP会员使用,一经查实数倍赔偿,并追究法律责任。
更新日志
1.1.0(2026-07-31)
- 统一对外 API 为规范命名
toPinyin - 删除非规范命名及旧类型定义
- 统一五端
success、fail、complete回调行为与结果结构 - 增加 DCloud 风格公共类型、
UniError错误对象和参数校验 - 修正 HarmonyOS 声调转换逻辑,统一输出格式
1.0.1(2025-10-09)
支持Android,iOS,Harmony,web/h5,小程序
1.0.0(2024-06-1)
安卓,ios支持。
