feat: finished 1.0.0

This commit is contained in:
TaurusXin 2024-03-14 21:55:01 +08:00
parent d1005bcd13
commit d88cc8a01b
Signed by: taurusxin
GPG Key ID: C334DCA04AC2D2CC
26 changed files with 6962 additions and 55 deletions

BIN
app-icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

2
components.d.ts vendored
View File

@ -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']
} }

View File

@ -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",

2
src-tauri/Cargo.lock generated
View File

@ -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",

View File

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 974 B

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 903 B

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

@ -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",

View File

@ -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,13 +16,14 @@ 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>
<n-config-provider :theme="theme">
<div class="container"> <div class="container">
<n-input <n-input
v-model:value="content" v-model:value="content"
@ -31,9 +36,9 @@ const handleTextInput = (text: string) => {
<n-table :single-line="false" striped class="table"> <n-table :single-line="false" striped class="table">
<thead> <thead>
<tr> <tr>
<th class="encode">原来编码</th> <th class="encode title">原来编码</th>
<th class="encode">目标编码</th> <th class="encode title">目标编码</th>
<th class="result">结果</th> <th class="result title">结果</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -45,10 +50,13 @@ const handleTextInput = (text: string) => {
</tbody> </tbody>
</n-table> </n-table>
</div> </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;
} }
} }
} }

View File

@ -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',
},
] ]

View File

@ -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

6865
src/utils/iconv.js Normal file

File diff suppressed because it is too large Load Diff