text-recover/src/App.vue

75 lines
1.7 KiB
Vue
Raw Normal View History

2024-03-14 15:44:56 +08:00
<script setup lang="ts">
2024-03-15 09:52:29 +08:00
import { ref, computed } from 'vue'
2024-03-14 15:44:56 +08:00
import { codecs } from '@/utils/codecs.ts'
import { EncodingConverter } from '@/utils/converter'
2024-03-14 21:55:01 +08:00
import { useOsTheme, darkTheme } from 'naive-ui'
const osThemeRef = useOsTheme()
const theme = computed(() => (osThemeRef.value === 'dark' ? darkTheme : undefined))
2024-03-14 15:44:56 +08:00
const Converter = new EncodingConverter()
const content = ref<string>('')
const result = ref<string[]>([])
const handleTextInput = (text: string) => {
codecs.forEach(codec => {
result.value = []
Converter.convert(codec, text).then(res => {
2024-03-14 21:55:01 +08:00
result.value?.push(res ?? '[转换失败]')
2024-03-14 15:44:56 +08:00
})
})
}
</script>
<template>
2024-03-14 21:55:01 +08:00
<n-config-provider :theme="theme">
<div class="container">
<n-input
v-model:value="content"
type="textarea"
2024-03-15 09:52:29 +08:00
placeholder="请输入待恢复的乱码文本"
2024-03-14 21:55:01 +08:00
clearable
class="input"
@input="handleTextInput"
/>
<n-table :single-line="false" striped class="table">
<thead>
<tr>
<th class="encode title">原来编码</th>
<th class="encode title">目标编码</th>
<th class="result title">结果</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in codecs" :key="index">
<td>{{ item.origin }}</td>
<td>{{ item.target }}</td>
<td>{{ result[index] }}</td>
</tr>
</tbody>
</n-table>
</div>
</n-config-provider>
2024-03-14 15:44:56 +08:00
</template>
<style scoped lang="less">
.container {
padding: 0.8rem;
.input {
margin-bottom: 0.8rem;
}
.table {
.encode {
2024-03-14 21:55:01 +08:00
width: 7rem;
}
.title {
font-weight: bold;
2024-03-14 15:44:56 +08:00
}
}
}
</style>