Skip to content

x-chinesetopinyin-s 中文转拼音

中文转拼音,同时返回无声调和带声调两种结果。

兼容性

HarmonyIOSAndroidWEB小程序
支持支持支持支持支持

调用

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)
  }
})

方法

名称需要说明
toPinyinchar,可选 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
  • 删除非规范命名及旧类型定义
  • 统一五端 successfailcomplete 回调行为与结果结构
  • 增加 DCloud 风格公共类型、UniError 错误对象和参数校验
  • 修正 HarmonyOS 声调转换逻辑,统一输出格式

1.0.1(2025-10-09)

支持Android,iOS,Harmony,web/h5,小程序

1.0.0(2024-06-1)

安卓,ios支持。

最近更新