汉字转拼音/五笔
相关方法
说明
usePinyinAndWubi 提供了汉字转拼音(全拼、简拼)和五笔码的工具函数。
适用于需要根据汉字生成助记码、搜索关键字等场景。内部集成了 js-pinyin 库和五笔字库。
类型定义
typescript
function usePinyinAndWubi(): {
getFullPinyin: (str: string) => string;
getSimplePinyin: (str: string) => string;
getWBCode: (str: string) => string;
};1
2
3
4
5
2
3
4
5
方法说明
| 方法名 | 参数 | 返回值 | 说明 |
|---|---|---|---|
getFullPinyin | str: string | string | 获取字符串的拼音全拼(大写) |
getSimplePinyin | str: string | string | 获取字符串的拼音首字母简拼(大写) |
getWBCode | str: string | string | 获取字符串的五笔码 |
代码示例
typescript
import { usePinyinAndWubi } from '@vue3-simple-bui/platform';
const { getFullPinyin, getSimplePinyin, getWBCode } = usePinyinAndWubi();
const text = '你好世界';
// 获取全拼
const full = getFullPinyin(text);
console.log(full); // 输出: NIHAOSHIJIE
// 获取简拼
const simple = getSimplePinyin(text);
console.log(simple); // 输出: NHSJ
// 获取五笔码
const wb = getWBCode(text);
console.log(wb);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17