feat: 简繁体转换 — OpenCC字典(台湾/香港标准), 简繁互转词组级准确, 打开TXT/复制/下载, 受控授权
This commit is contained in:
1 parent
9c849e78ba
commit
506c452d57
10 files changed
+302
-9
No files matched your search
@@ -86,6 +86,7 @@ import { tool as audioTools } from './audio-tools';
|
||||
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 docConvert } from './doc-convert';
|
||||
import { tool as aiRetouch } from './ai-retouch';
|
||||
import { tool as wifiQrCodeGenerator } from './wifi-qr-code-generator';
|
||||
@@ -201,6 +202,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
numeronymGenerator,
|
||||
asciiTextDrawer,
|
||||
translator,
|
||||
zhConvert,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@ export const PROTECTED_TOOLS: Record<string, string> = {
|
||||
'/seal-maker': '印章生成',
|
||||
'/signature-pad': '手写签名',
|
||||
'/text-to-image': '文字生成图片',
|
||||
'/zh-convert': '简繁转换',
|
||||
};
|
||||
|
||||
export const TRIAL_MS = 30 * 60 * 1000; // 每个功能免费 30 分钟
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Language } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.zh-convert.title'),
|
||||
path: '/zh-convert',
|
||||
description: translate('tools.zh-convert.description'),
|
||||
keywords: ['chinese', 'convert', '简繁', '繁简', '简体', '繁体', '转换', '中文'],
|
||||
component: () => import('./zh-convert.vue'),
|
||||
icon: Language,
|
||||
});
|
||||
@@ -0,0 +1,269 @@
|
||||
<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('zh-convert');
|
||||
|
||||
const text = ref('');
|
||||
const from = ref('cn');
|
||||
const to = ref('tw');
|
||||
const busy = ref(false);
|
||||
const error = ref('');
|
||||
const converted = ref('');
|
||||
const copied = ref(false);
|
||||
|
||||
const LANGS = [
|
||||
{ value: 'cn', label: '简体中文' },
|
||||
{ value: 'tw', label: '繁體中文(台湾)' },
|
||||
{ value: 'hk', label: '繁體中文(香港)' },
|
||||
];
|
||||
|
||||
async function convert() {
|
||||
error.value = '';
|
||||
if (!text.value.trim()) {
|
||||
error.value = '请输入文本内容';
|
||||
return;
|
||||
}
|
||||
busy.value = true;
|
||||
try {
|
||||
const { Converter } = await import('opencc-js');
|
||||
const conv = Converter({ from: from.value as any, to: to.value as any });
|
||||
converted.value = conv(text.value);
|
||||
genHist.add({ title: `简繁转换 ${text.value.slice(0, 20)}`, detail: `${LANGS.find(l => l.value === from.value)?.label} → ${LANGS.find(l => l.value === to.value)?.label}` });
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = String(e?.message || e);
|
||||
}
|
||||
finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const fileInput = ref<HTMLInputElement>();
|
||||
|
||||
function pickFile() {
|
||||
fileInput.value?.click();
|
||||
}
|
||||
|
||||
function onFile(e: Event) {
|
||||
const input = e.target as HTMLInputElement;
|
||||
const f = input.files?.[0];
|
||||
input.value = '';
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
text.value = String(reader.result ?? '');
|
||||
converted.value = '';
|
||||
};
|
||||
reader.readAsText(f, 'utf-8');
|
||||
}
|
||||
|
||||
async function copyResult() {
|
||||
if (!converted.value) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await navigator.clipboard.writeText(converted.value);
|
||||
copied.value = true;
|
||||
setTimeout(() => (copied.value = false), 1500);
|
||||
}
|
||||
catch { /* ignore */ }
|
||||
}
|
||||
|
||||
function downloadResult() {
|
||||
if (!converted.value) {
|
||||
return;
|
||||
}
|
||||
const blob = new Blob([converted.value], { type: 'text/plain;charset=utf-8' });
|
||||
const a = document.createElement('a');
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.download = `转换结果-${from.value}-to-${to.value}.txt`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(a.href);
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
text.value = '';
|
||||
converted.value = '';
|
||||
error.value = '';
|
||||
}
|
||||
|
||||
function swap() {
|
||||
const f = from.value;
|
||||
from.value = to.value;
|
||||
to.value = f;
|
||||
if (converted.value) {
|
||||
text.value = converted.value;
|
||||
converted.value = '';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="zc-root">
|
||||
<div class="zc-panel">
|
||||
<div class="zc-panel-title">📝 文本内容</div>
|
||||
<textarea v-model="text" class="zc-textarea" rows="10" placeholder="粘贴或输入要转换的中文文本…" />
|
||||
</div>
|
||||
|
||||
<div class="zc-row">
|
||||
<select v-model="from" class="zc-select">
|
||||
<option v-for="l in LANGS" :key="l.value" :value="l.value">{{ l.label }}</option>
|
||||
</select>
|
||||
<a href="javascript:;" class="zc-swap" title="交换方向" @click="swap">⇄</a>
|
||||
<select v-model="to" class="zc-select">
|
||||
<option v-for="l in LANGS" :key="l.value" :value="l.value">{{ l.label }}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="zc-btns">
|
||||
<button class="zc-btn zc-btn-ghost" @click="pickFile">
|
||||
📂 打开 TXT
|
||||
</button>
|
||||
<input ref="fileInput" type="file" hidden accept=".txt,.md,.csv,text/plain" @change="onFile">
|
||||
<button class="zc-btn" :disabled="busy" @click="convert">
|
||||
{{ busy ? '⏳ 转换中…' : '🔄 转换' }}
|
||||
</button>
|
||||
<button class="zc-btn zc-btn-ghost" :disabled="!converted" @click="copyResult">
|
||||
{{ copied ? '已复制 ✓' : '📋 复制' }}
|
||||
</button>
|
||||
<button class="zc-btn zc-btn-ghost" :disabled="!converted" @click="downloadResult">
|
||||
⬇ 下载 TXT
|
||||
</button>
|
||||
<button class="zc-btn zc-btn-ghost" @click="clearAll">
|
||||
🗑 清空
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="error" class="zc-error">
|
||||
{{ error }}
|
||||
</div>
|
||||
|
||||
<div v-if="converted" class="zc-panel zc-result">
|
||||
<div class="zc-panel-title">✅ 转换结果 <span class="zc-sub">{{ converted.length }} 字</span></div>
|
||||
<textarea v-model="converted" class="zc-textarea zc-textarea-result" rows="10" readonly />
|
||||
</div>
|
||||
|
||||
<GenHistory tool="zh-convert" label="转换记录" class="mt-10px" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.zc-root {
|
||||
padding-bottom: 40px;
|
||||
}
|
||||
|
||||
.zc-panel {
|
||||
border: 1px solid rgba(128, 128, 128, 0.22);
|
||||
border-radius: 12px;
|
||||
padding: 12px 14px;
|
||||
background: #fff;
|
||||
margin-bottom: 12px;
|
||||
|
||||
.zc-panel-title {
|
||||
font-size: 14px;
|
||||
font-weight: 800;
|
||||
margin-bottom: 10px;
|
||||
|
||||
.zc-sub {
|
||||
font-size: 11.5px;
|
||||
font-weight: 400;
|
||||
opacity: 0.5;
|
||||
margin-left: 6px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.zc-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;
|
||||
}
|
||||
}
|
||||
|
||||
.zc-textarea-result {
|
||||
background: rgba(24, 160, 88, 0.04);
|
||||
}
|
||||
|
||||
.zc-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-bottom: 12px;
|
||||
|
||||
.zc-select {
|
||||
border: 1px solid rgba(128, 128, 128, 0.35);
|
||||
border-radius: 7px;
|
||||
padding: 6px 10px;
|
||||
font-size: 13px;
|
||||
background: #fff;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.zc-swap {
|
||||
font-size: 18px;
|
||||
color: #18a058;
|
||||
text-decoration: none;
|
||||
font-weight: 700;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.zc-btns {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.zc-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;
|
||||
}
|
||||
|
||||
&.zc-btn-ghost {
|
||||
background: #fff;
|
||||
color: inherit;
|
||||
border: 1px solid rgba(128, 128, 128, 0.35);
|
||||
font-weight: 400;
|
||||
}
|
||||
}
|
||||
|
||||
.zc-error {
|
||||
color: #d03050;
|
||||
font-size: 12.5px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user