We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6d50982 commit 1c7a79fCopy full SHA for 1c7a79f
5 files changed
frontend/package.json
@@ -14,7 +14,6 @@
14
"axios": "^1.13.2",
15
"buffer": "^6.0.3",
16
"element-plus": "^2.11.9",
17
- "iconv-lite": "^0.7.0",
18
"lodash": "^4.17.21",
19
"marked": "^17.0.1",
20
"monaco-editor": "^0.54.0",
frontend/pnpm-lock.yaml
frontend/src/components/MonacoEditor.vue
@@ -57,7 +57,6 @@
57
import { computed, onMounted, ref, watch } from 'vue'
58
import MonacoEditor from 'monaco-editor-vue3'
59
import { Camera } from '@element-plus/icons-vue'
60
-import * as iconv from 'iconv-lite'
61
62
import MdView from '@/components/MdView.vue'
63
@@ -94,7 +93,7 @@ const { editorDidMount, changeLang, changeTheme, changeOption } = useEditor({ on
94
93
95
const changeEncode = async (v: string) => {
96
const buffer = await code.blob.arrayBuffer()
97
- code.org = code.value = iconv.decode(new Uint8Array(buffer), v)
+ code.org = code.value = new TextDecoder(v).decode(buffer)
98
}
99
100
watch(
frontend/src/utils/file.ts
@@ -1,5 +1,3 @@
1
2
-
3
import { HOST } from '@/utils/env'
4
import { ENCODING_OPTIONS } from '@/utils/option'
5
@@ -46,44 +44,25 @@ export const getKey = (path: string) =>
46
44
.replace(/\./g, '_')
47
45
48
export const getEncodeValue = async (blob: Blob) => {
49
- const result = { encode: '', value: '' }
50
51
- const buffer = new Uint8Array(await blob.arrayBuffer())
+ const encode: string[] = []
+ const buffer = await blob.arrayBuffer()
52
53
- if (buffer.length >= 3 && buffer[0] === 0xef && buffer[1] === 0xbb && buffer[2] === 0xbf) {
54
- result.encode = 'utf8'
55
- } else if (buffer[0] === 0xfe && buffer[1] === 0xff) {
56
- result.encode = 'utf16be'
- } else if (buffer[0] === 0xff && buffer[1] === 0xfe) {
- result.encode = 'utf16le'
- }
+ for (const item of ENCODING_OPTIONS) {
+ try {
+ const decoder = new TextDecoder(item.value)
+ const text = decoder.decode(buffer)
- if (!result.encode) {
- for (const item of ENCODING_OPTIONS) {
- try {
64
- const text = iconv.decode(buffer, item.value)
65
- const sum = text.length
66
- const err = text.split('').filter((i) => i === '�').length
67
68
- if (err / sum > 0.3) {
69
- result.encode = item.value
70
- result.value = text
71
72
- } catch {
+ if (text.includes('�')) {
73
continue
74
75
76
77
78
79
80
81
82
- if (!result.value) {
83
- result.value = iconv.decode(buffer, result.encode)
+ encode.push(item.value)
+ } catch {
+ continue
+ }
84
85
86
- return result
+ return { encode: encode[0] || 'utf8', value: new TextDecoder(encode[0] || 'utf8').decode(buffer) }
87
88
89
export const isBinaryContent = async (blob: Blob) => {
frontend/src/utils/option.ts
@@ -86,16 +86,16 @@ export const THEME_OPTIONS: { label: string; value: string; dark: boolean }[] =
export const ENCODING_OPTIONS = [
// 推荐优先显示(常用编码)
- { value: 'utf8', label: 'UTF-8' },
+ { value: 'utf-8', label: 'UTF-8' },
90
{ value: 'gbk', label: 'GBK' },
91
{ value: 'gb2312', label: 'GB2312' },
92
{ value: 'gb18030', label: 'GB18030' },
{ value: 'big5', label: 'Big5' },
// 国际通用编码
- { value: 'utf16le', label: 'UTF-16 LE' },
- { value: 'utf16be', label: 'UTF-16 BE' },
- { value: 'utf16', label: 'UTF-16' },
+ { value: 'utf-16le', label: 'UTF-16 LE' },
+ { value: 'utf-16be', label: 'UTF-16 BE' },
+ { value: 'utf-16', label: 'UTF-16' },
{ value: 'ascii', label: 'ASCII' },
{ value: 'latin1', label: 'ISO-8859-1' },
101
{ value: 'windows-1252', label: 'Windows-1252' },
0 commit comments