feat: finished 1.0.0
After Width: | Height: | Size: 33 KiB |
|
@ -7,7 +7,7 @@ export {}
|
||||||
|
|
||||||
declare module 'vue' {
|
declare module 'vue' {
|
||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
Greet: typeof import('./src/components/Greet.vue')['default']
|
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||||
NInput: typeof import('naive-ui')['NInput']
|
NInput: typeof import('naive-ui')['NInput']
|
||||||
NTable: typeof import('naive-ui')['NTable']
|
NTable: typeof import('naive-ui')['NTable']
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,10 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vue-tsc --noEmit && vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"tauri": "tauri"
|
"tauri": "tauri",
|
||||||
|
"icon": "tauri icon"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tauri-apps/api": "^1",
|
"@tauri-apps/api": "^1",
|
||||||
|
|
|
@ -2816,7 +2816,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "text-recover"
|
name = "text-recover"
|
||||||
version = "0.0.0"
|
version = "1.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
[package]
|
[package]
|
||||||
name = "text-recover"
|
name = "text-recover"
|
||||||
version = "0.0.0"
|
version = "1.0.0"
|
||||||
description = "A Tauri App"
|
description = "TextRecover App"
|
||||||
authors = ["you"]
|
authors = ["TaurusXin"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 8.7 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 974 B After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 7.0 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 9.8 KiB |
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 903 B After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 85 KiB After Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 31 KiB |
|
@ -6,8 +6,8 @@
|
||||||
"distDir": "../dist"
|
"distDir": "../dist"
|
||||||
},
|
},
|
||||||
"package": {
|
"package": {
|
||||||
"productName": "text-recover",
|
"productName": "TextRecover",
|
||||||
"version": "0.0.0"
|
"version": "1.0.0"
|
||||||
},
|
},
|
||||||
"tauri": {
|
"tauri": {
|
||||||
"allowlist": {
|
"allowlist": {
|
||||||
|
@ -19,9 +19,9 @@
|
||||||
},
|
},
|
||||||
"windows": [
|
"windows": [
|
||||||
{
|
{
|
||||||
"title": "text-recover",
|
"title": "Text Recover",
|
||||||
"width": 800,
|
"width": 800,
|
||||||
"height": 600
|
"height": 800
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"security": {
|
"security": {
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
"bundle": {
|
"bundle": {
|
||||||
"active": true,
|
"active": true,
|
||||||
"targets": "all",
|
"targets": "all",
|
||||||
"identifier": "com.tauri.dev",
|
"identifier": "com.taurusxin.text-recover",
|
||||||
"icon": [
|
"icon": [
|
||||||
"icons/32x32.png",
|
"icons/32x32.png",
|
||||||
"icons/128x128.png",
|
"icons/128x128.png",
|
||||||
|
|
68
src/App.vue
|
@ -2,6 +2,10 @@
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { codecs } from '@/utils/codecs.ts'
|
import { codecs } from '@/utils/codecs.ts'
|
||||||
import { EncodingConverter } from '@/utils/converter'
|
import { EncodingConverter } from '@/utils/converter'
|
||||||
|
import { useOsTheme, darkTheme } from 'naive-ui'
|
||||||
|
|
||||||
|
const osThemeRef = useOsTheme()
|
||||||
|
const theme = computed(() => (osThemeRef.value === 'dark' ? darkTheme : undefined))
|
||||||
|
|
||||||
const Converter = new EncodingConverter()
|
const Converter = new EncodingConverter()
|
||||||
|
|
||||||
|
@ -12,43 +16,47 @@ const handleTextInput = (text: string) => {
|
||||||
codecs.forEach(codec => {
|
codecs.forEach(codec => {
|
||||||
result.value = []
|
result.value = []
|
||||||
Converter.convert(codec, text).then(res => {
|
Converter.convert(codec, text).then(res => {
|
||||||
result.value?.push(res ?? '')
|
result.value?.push(res ?? '[转换失败]')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="container">
|
<n-config-provider :theme="theme">
|
||||||
<n-input
|
<div class="container">
|
||||||
v-model:value="content"
|
<n-input
|
||||||
type="textarea"
|
v-model:value="content"
|
||||||
placeholder="请输入待转换的乱码文本"
|
type="textarea"
|
||||||
clearable
|
placeholder="请输入待转换的乱码文本"
|
||||||
class="input"
|
clearable
|
||||||
@input="handleTextInput"
|
class="input"
|
||||||
/>
|
@input="handleTextInput"
|
||||||
<n-table :single-line="false" striped class="table">
|
/>
|
||||||
<thead>
|
<n-table :single-line="false" striped class="table">
|
||||||
<tr>
|
<thead>
|
||||||
<th class="encode">原来编码</th>
|
<tr>
|
||||||
<th class="encode">目标编码</th>
|
<th class="encode title">原来编码</th>
|
||||||
<th class="result">结果</th>
|
<th class="encode title">目标编码</th>
|
||||||
</tr>
|
<th class="result title">结果</th>
|
||||||
</thead>
|
</tr>
|
||||||
<tbody>
|
</thead>
|
||||||
<tr v-for="(item, index) in codecs" :key="index">
|
<tbody>
|
||||||
<td>{{ item.origin }}</td>
|
<tr v-for="(item, index) in codecs" :key="index">
|
||||||
<td>{{ item.target }}</td>
|
<td>{{ item.origin }}</td>
|
||||||
<td>{{ result[index] }}</td>
|
<td>{{ item.target }}</td>
|
||||||
</tr>
|
<td>{{ result[index] }}</td>
|
||||||
</tbody>
|
</tr>
|
||||||
</n-table>
|
</tbody>
|
||||||
</div>
|
</n-table>
|
||||||
|
</div>
|
||||||
|
</n-config-provider>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped lang="less">
|
<style scoped lang="less">
|
||||||
.container {
|
.container {
|
||||||
|
// disable selection
|
||||||
|
user-select: none;
|
||||||
padding: 0.8rem;
|
padding: 0.8rem;
|
||||||
|
|
||||||
.input {
|
.input {
|
||||||
|
@ -57,7 +65,11 @@ const handleTextInput = (text: string) => {
|
||||||
|
|
||||||
.table {
|
.table {
|
||||||
.encode {
|
.encode {
|
||||||
width: 8rem;
|
width: 7rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,47 @@
|
||||||
export interface Codec {
|
export interface Codec {
|
||||||
origin: string;
|
origin: string
|
||||||
target: string;
|
target: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const codecs: Codec[] = [
|
export const codecs: Codec[] = [
|
||||||
{
|
{
|
||||||
origin: 'gbk',
|
origin: 'GBK',
|
||||||
target: 'utf8',
|
target: 'UTF-8',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
origin: 'utf8',
|
origin: 'UTF-8',
|
||||||
target: 'gbk',
|
target: 'GBK',
|
||||||
}
|
},
|
||||||
]
|
{
|
||||||
|
origin: 'GBK',
|
||||||
|
target: 'ISO-8859-1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
origin: 'GBK',
|
||||||
|
target: 'BIG5',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
origin: 'GBK',
|
||||||
|
target: 'UTF-16',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
origin: 'GBK',
|
||||||
|
target: 'WINDOWS-1252',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
origin: 'UTF-8',
|
||||||
|
target: 'ISO-8859-1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
origin: 'UTF-8',
|
||||||
|
target: 'BIG5',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
origin: 'UTF-8',
|
||||||
|
target: 'UTF-16',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
origin: 'UTF-8',
|
||||||
|
target: 'WINDOWS-1252',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
|
@ -1,18 +1,15 @@
|
||||||
import { Codec } from '@/utils/codecs'
|
import { Codec } from '@/utils/codecs'
|
||||||
|
import '@/utils/iconv'
|
||||||
|
|
||||||
export class EncodingConverter {
|
export class EncodingConverter {
|
||||||
async convert(codec: Codec, text: string): Promise<string | null> {
|
async convert(codec: Codec, text: string): Promise<string | null> {
|
||||||
let convertedText: string | null = null
|
let convertedText: string | null = null
|
||||||
try {
|
try {
|
||||||
const byteArray = new TextEncoder().encode(text)
|
const byteArray = iconv.encode(text, codec.origin)
|
||||||
const decodedText = new TextDecoder(codec.origin).decode(byteArray)
|
convertedText = iconv.decode(byteArray, codec.target)
|
||||||
const byteArray2 = new TextEncoder().encode(decodedText)
|
|
||||||
convertedText = new TextDecoder(codec.target).decode(byteArray2)
|
|
||||||
text = convertedText
|
text = convertedText
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
console.error(`Failed to convert from ${codec.origin} to ${codec.target}: ${error}`)
|
||||||
`Failed to convert from ${codec.origin} to ${codec.target}: ${error}`
|
|
||||||
)
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return convertedText
|
return convertedText
|
||||||
|
|