feat: 汉字转拼音 — pinyin-pro词典, 三种声调风格, 词组级多音字智能转换(三百六十行→háng), 多音字全读音标注, 原文可选显示, 受控授权
This commit is contained in:
1 parent
506c452d57
commit
eb5c5c7f5c
10 files changed
+342
-1
No files matched your search
Vendored
+1
@@ -198,6 +198,7 @@ declare module '@vue/runtime-core' {
|
||||
PdfTools: typeof import('./src/tools/pdf-tools/pdf-tools.vue')['default']
|
||||
PercentageCalculator: typeof import('./src/tools/percentage-calculator/percentage-calculator.vue')['default']
|
||||
PhoneParserAndFormatter: typeof import('./src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue')['default']
|
||||
PinyinConverter: typeof import('./src/tools/pinyin-converter/pinyin-converter.vue')['default']
|
||||
'Pricing.page': typeof import('./src/pages/Pricing.page.vue')['default']
|
||||
QrCodeGenerator: typeof import('./src/tools/qr-code-generator/qr-code-generator.vue')['default']
|
||||
RandomPortGenerator: typeof import('./src/tools/random-port-generator/random-port-generator.vue')['default']
|
||||
|
||||
@@ -44,7 +44,7 @@ AUTH_PASS = os.environ.get("AUTH_PASS", "")
|
||||
PROJECT_NAME = os.environ.get("PROJECT_NAME", "IT-Tools")
|
||||
TRIAL_FILE = os.environ.get("TRIAL_FILE", "/app/data/trials.json")
|
||||
TRIAL_MS = int(os.environ.get("TRIAL_MS_MIN", "30")) * 60 * 1000
|
||||
PROTECTED_TOOLS = {"translator", "image-ocr", "pdf-ocr", "ai-retouch", "label-designer", "doc-convert", "image-tools", "pdf-tools", "video-tools", "audio-tools", "seal-maker", "signature-pad", "text-to-image", "zh-convert"}
|
||||
PROTECTED_TOOLS = {"translator", "image-ocr", "pdf-ocr", "ai-retouch", "label-designer", "doc-convert", "image-tools", "pdf-tools", "video-tools", "audio-tools", "seal-maker", "signature-pad", "text-to-image", "zh-convert", "pinyin-converter"}
|
||||
MACHINE_RE = re.compile(r"^\d{10,16}$")
|
||||
|
||||
# verify() messages that unconditionally block activation
|
||||
|
||||
@@ -275,6 +275,9 @@ tools:
|
||||
title: Image OCR
|
||||
description: Extract text from images with OCR - click, drag & drop or paste a screenshot, get recognized lines with confidence scores, copy or download as TXT.
|
||||
|
||||
pinyin-converter:
|
||||
title: 'Pinyin converter'
|
||||
description: 'Convert Chinese characters to pinyin with tones, intelligent polyphonic character handling'
|
||||
zh-convert:
|
||||
title: 'Chinese converter'
|
||||
description: 'Convert between Simplified and Traditional Chinese (OpenCC dictionaries), load TXT, copy or download'
|
||||
|
||||
@@ -272,6 +272,9 @@ tools:
|
||||
title: 图片OCR文字识别
|
||||
description: 上传、拖拽或粘贴截图识别图片中的文字,逐行输出识别结果和置信度,支持复制全部和下载TXT。
|
||||
|
||||
pinyin-converter:
|
||||
title: '汉字转拼音'
|
||||
description: '汉字转拼音(pinyin-pro 词典),带声调/数字/无声调三种风格,多音字智能转换与全读音标注,原文可选显示'
|
||||
zh-convert:
|
||||
title: '简繁体转换'
|
||||
description: '简体与繁体中文互转(台湾/香港标准,OpenCC 字典),支持打开 TXT、复制与下载结果'
|
||||
|
||||
@@ -93,6 +93,7 @@
|
||||
"pdf-signature-reader": "^1.4.2",
|
||||
"pdfjs-dist": "3.11.174",
|
||||
"pinia": "^2.0.34",
|
||||
"pinyin-pro": "^3.29.5",
|
||||
"plausible-tracker": "^0.3.8",
|
||||
"qrcode": "^1.5.1",
|
||||
"randexp": "^0.5.3",
|
||||
|
||||
Generated
+8
@@ -179,6 +179,9 @@ importers:
|
||||
pinia:
|
||||
specifier: ^2.0.34
|
||||
version: 2.0.34(typescript@5.2.2)(vue@3.3.4)
|
||||
pinyin-pro:
|
||||
specifier: ^3.29.5
|
||||
version: 3.29.5
|
||||
plausible-tracker:
|
||||
specifier: ^0.3.8
|
||||
version: 0.3.8
|
||||
@@ -4783,6 +4786,9 @@ packages:
|
||||
typescript:
|
||||
optional: true
|
||||
|
||||
pinyin-pro@3.29.5:
|
||||
resolution: {integrity: sha512-Fk5YoRmtdHqJWqAuzYVG/NzvzeCbaG+ZEwbY6Nbps3QAIrvQQEtcm49frcyCM8i2b5najnzPDtYqrHRYTTiuwQ==}
|
||||
|
||||
pkg-types@1.0.3:
|
||||
resolution: {integrity: sha512-nN7pYi0AQqJnoLPC9eHFQ8AcyaixBUOwvqc5TDnIKCMEE6I0y8P7OKA7fPexsXGCGxQDl/cmrLAp26LhcwxZ4A==}
|
||||
|
||||
@@ -11358,6 +11364,8 @@ snapshots:
|
||||
optionalDependencies:
|
||||
typescript: 5.2.2
|
||||
|
||||
pinyin-pro@3.29.5: {}
|
||||
|
||||
pkg-types@1.0.3:
|
||||
dependencies:
|
||||
jsonc-parser: 3.2.0
|
||||
|
||||
@@ -87,6 +87,7 @@ import { tool as sealMaker } from './seal-maker';
|
||||
import { tool as signaturePad } from './signature-pad';
|
||||
import { tool as textToImage } from './text-to-image';
|
||||
import { tool as zhConvert } from './zh-convert';
|
||||
import { tool as pinyinConverter } from './pinyin-converter';
|
||||
import { tool as docConvert } from './doc-convert';
|
||||
import { tool as aiRetouch } from './ai-retouch';
|
||||
import { tool as wifiQrCodeGenerator } from './wifi-qr-code-generator';
|
||||
@@ -203,6 +204,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
asciiTextDrawer,
|
||||
translator,
|
||||
zhConvert,
|
||||
pinyinConverter,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@ export const PROTECTED_TOOLS: Record<string, string> = {
|
||||
'/signature-pad': '手写签名',
|
||||
'/text-to-image': '文字生成图片',
|
||||
'/zh-convert': '简繁转换',
|
||||
'/pinyin-converter': '拼音转换',
|
||||
};
|
||||
|
||||
export const TRIAL_MS = 30 * 60 * 1000; // 每个功能免费 30 分钟
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { LetterCase } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.pinyin-converter.title'),
|
||||
path: '/pinyin-converter',
|
||||
description: translate('tools.pinyin-converter.description'),
|
||||
keywords: ['pinyin', '拼音', '汉字', '声调', '多音字', '注音'],
|
||||
component: () => import('./pinyin-converter.vue'),
|
||||
icon: LetterCase,
|
||||
});
|
||||
@@ -0,0 +1,310 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import { useHead } from '@vueuse/head';
|
||||
import GenHistory from '@/tools/gen-history/GenHistory.vue';
|
||||
import { useGenHistory } from '@/tools/gen-history/gen-history';
|
||||
|
||||
useHead({ title: '汉字转拼音 - IT-TOOLS-PRO' });
|
||||
|
||||
const genHist = useGenHistory('pinyin-converter');
|
||||
|
||||
const text = ref('中文汉字转拼音工具\n将汉字转换为中文拼音,支持显示声调,常见多音字智能转换\n多音字示例:\n三百六十行,我最行');
|
||||
const toneStyle = ref<'symbol' | 'none' | 'num'>('symbol');
|
||||
const showOriginal = ref(false);
|
||||
const showPoly = ref(false);
|
||||
|
||||
const busy = ref(false);
|
||||
const error = ref('');
|
||||
const result = ref('');
|
||||
const copied = ref(false);
|
||||
|
||||
const TONE_OPTS = [
|
||||
{ value: 'symbol', label: '带声调(hàn)' },
|
||||
{ value: 'none', label: '不带声调(han)' },
|
||||
{ value: 'num', label: '数字声调(han4)' },
|
||||
];
|
||||
|
||||
async function convert() {
|
||||
error.value = '';
|
||||
if (!text.value.trim()) {
|
||||
error.value = '请输入文本内容';
|
||||
return;
|
||||
}
|
||||
busy.value = true;
|
||||
try {
|
||||
const { pinyin } = await import('pinyin-pro');
|
||||
const toneType = toneStyle.value;
|
||||
const lines = text.value.split('\n');
|
||||
const out: string[] = [];
|
||||
for (const line of lines) {
|
||||
if (!line.trim()) {
|
||||
out.push('');
|
||||
continue;
|
||||
}
|
||||
const pyArr = pinyin(line, { toneType, type: 'array' });
|
||||
const chars = [...line];
|
||||
let pyLine: string;
|
||||
if (showPoly.value) {
|
||||
pyLine = chars.map((ch, i) => {
|
||||
if (/[\u4e00-\u9fff]/.test(ch)) {
|
||||
const all = pinyin(ch, { toneType, multiple: true, type: 'array' });
|
||||
const uniq = [...new Set(all)];
|
||||
if (uniq.length > 1) {
|
||||
return `${pyArr[i]}(${uniq.join('/')})`;
|
||||
}
|
||||
}
|
||||
return pyArr[i];
|
||||
}).join(' ');
|
||||
}
|
||||
else {
|
||||
pyLine = pyArr.join(' ');
|
||||
}
|
||||
if (showOriginal.value) {
|
||||
out.push(line, pyLine);
|
||||
}
|
||||
else {
|
||||
out.push(pyLine);
|
||||
}
|
||||
}
|
||||
result.value = out.join('\n');
|
||||
genHist.add({ title: `拼音转换: ${text.value.slice(0, 18)}`, detail: `${TONE_OPTS.find(t => t.value === toneStyle.value)?.label}${showPoly.value ? ' · 多音字标注' : ''}` });
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = String(e?.message || e);
|
||||
}
|
||||
finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function copyResult() {
|
||||
if (!result.value) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await navigator.clipboard.writeText(result.value);
|
||||
copied.value = true;
|
||||
setTimeout(() => (copied.value = false), 1500);
|
||||
}
|
||||
catch { /* ignore */ }
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
text.value = '';
|
||||
result.value = '';
|
||||
error.value = '';
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="py-root">
|
||||
<div class="py-panel">
|
||||
<div class="py-panel-title">📝 文本内容</div>
|
||||
<textarea v-model="text" class="py-textarea" rows="8" placeholder="输入要转拼音的汉字…" />
|
||||
</div>
|
||||
|
||||
<div class="py-row">
|
||||
<div class="py-field">
|
||||
<label class="py-label">拼音风格</label>
|
||||
<select v-model="toneStyle" class="py-select">
|
||||
<option v-for="t in TONE_OPTS" :key="t.value" :value="t.value">{{ t.label }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="py-field">
|
||||
<label class="py-label">原文</label>
|
||||
<select v-model="showOriginal" class="py-select">
|
||||
<option :value="false">不显示</option>
|
||||
<option :value="true">显示(原文+拼音交替)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="py-field">
|
||||
<label class="py-label">显示多音字</label>
|
||||
<div class="py-switch-wrap">
|
||||
<input v-model="showPoly" type="checkbox" class="py-switch">
|
||||
<span class="py-switch-text">{{ showPoly ? '开(多音字标注全部读音)' : '关' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="py-btns">
|
||||
<button class="py-btn" :disabled="busy" @click="convert">
|
||||
{{ busy ? '⏳ 转换中…' : '🔄 转换' }}
|
||||
</button>
|
||||
<button class="py-btn py-btn-ghost" :disabled="!result" @click="copyResult">
|
||||
{{ copied ? '已复制 ✓' : '📋 复制' }}
|
||||
</button>
|
||||
<button class="py-btn py-btn-ghost" @click="clearAll">
|
||||
🗑 清空
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="error" class="py-error">
|
||||
{{ error }}
|
||||
</div>
|
||||
|
||||
<div v-if="result" class="py-panel py-result">
|
||||
<div class="py-panel-title">✅ 转换结果</div>
|
||||
<pre class="py-output">{{ result }}</pre>
|
||||
</div>
|
||||
|
||||
<GenHistory tool="pinyin-converter" label="转换记录" class="mt-10px" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.py-root {
|
||||
padding-bottom: 40px;
|
||||
}
|
||||
|
||||
.py-panel {
|
||||
border: 1px solid rgba(128, 128, 128, 0.22);
|
||||
border-radius: 12px;
|
||||
padding: 12px 14px;
|
||||
background: #fff;
|
||||
margin-bottom: 12px;
|
||||
|
||||
.py-panel-title {
|
||||
font-size: 14px;
|
||||
font-weight: 800;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.py-textarea {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
border: 1px solid rgba(128, 128, 128, 0.3);
|
||||
border-radius: 8px;
|
||||
padding: 10px 12px;
|
||||
font-size: 14px;
|
||||
font-family: inherit;
|
||||
resize: vertical;
|
||||
outline: none;
|
||||
|
||||
&:focus {
|
||||
border-color: #18a058;
|
||||
}
|
||||
}
|
||||
|
||||
.py-row {
|
||||
display: flex;
|
||||
gap: 18px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.py-field {
|
||||
.py-label {
|
||||
display: block;
|
||||
font-size: 11.5px;
|
||||
opacity: 0.65;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.py-select {
|
||||
border: 1px solid rgba(128, 128, 128, 0.35);
|
||||
border-radius: 7px;
|
||||
padding: 6px 10px;
|
||||
font-size: 12.5px;
|
||||
background: #fff;
|
||||
outline: none;
|
||||
min-width: 170px;
|
||||
}
|
||||
}
|
||||
|
||||
.py-switch-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
height: 31px;
|
||||
|
||||
.py-switch {
|
||||
appearance: none;
|
||||
width: 40px;
|
||||
height: 22px;
|
||||
border-radius: 11px;
|
||||
background: rgba(128, 128, 128, 0.3);
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
outline: none;
|
||||
flex-shrink: 0;
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
left: 2px;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border-radius: 50%;
|
||||
background: #fff;
|
||||
transition: left 0.2s;
|
||||
}
|
||||
|
||||
&:checked {
|
||||
background: #18a058;
|
||||
|
||||
&::after {
|
||||
left: 20px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.py-switch-text {
|
||||
font-size: 12px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
.py-btns {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.py-btn {
|
||||
background: #18a058;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
padding: 8px 18px;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
&.py-btn-ghost {
|
||||
background: #fff;
|
||||
color: inherit;
|
||||
border: 1px solid rgba(128, 128, 128, 0.35);
|
||||
font-weight: 400;
|
||||
}
|
||||
}
|
||||
|
||||
.py-error {
|
||||
color: #d03050;
|
||||
font-size: 12.5px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.py-output {
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
font-family: inherit;
|
||||
font-size: 14px;
|
||||
line-height: 1.9;
|
||||
background: rgba(24, 160, 88, 0.04);
|
||||
border-radius: 8px;
|
||||
padding: 12px 14px;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user