Skip to content

Commit 83f853e

Browse files
committed
fix: 精简编码格式
1 parent 1b68d85 commit 83f853e

File tree

7 files changed

+1503
-23
lines changed

7 files changed

+1503
-23
lines changed

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"dependencies": {
99
"@koa/cors": "^5.0.0",
10-
"iconv-lite": "^0.7.0",
10+
"iconv-lite": "^0.7.1",
1111
"koa": "^3.1.1",
1212
"koa-bodyparser": "^4.4.1"
1313
},

backend/pnpm-lock.yaml

Lines changed: 1482 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/hooks/useCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function useCode(option: OptionModel) {
3434
org: '',
3535
value: '',
3636
lang: '',
37-
encode: 'utf8',
37+
encode: 'utf-8',
3838
})
3939

4040
const load = async (path: string) => {

frontend/src/layout/ViewLeft/ViewFolder.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const addFile = async (node: RenderContentContext['node']) => {
9090
9191
const path = `${node.data.value}/${value}`
9292
93-
await axios.post(HOST, { encode: 'utf8', path, value: '', force: 1 }, { params: { _api: 'save' } })
93+
await axios.post(HOST, { encode: 'utf-8', path, value: '', force: 1 }, { params: { _api: 'save' } })
9494
9595
editor.add(path, { keep: false })
9696

frontend/src/store/user.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface LikeModel {
2121
fileBigWait: number // 多大文件暂停加载,0为不启用
2222
fileCameraUseConfirm: boolean // 切换快照时询问
2323
fileCameraUseDoSave: boolean // 切换快照立即保存
24+
fileEncodeFrom: 'org' | 'value' // 切换编码从何处选择
2425
editorOption: {
2526
// 编辑器配置
2627
fontSize: number // 字体大小
@@ -51,6 +52,7 @@ const getDef = (): LikeModel => ({
5152
fileBigWait: 50 * 1024 * 1024, // 多大文件暂停加载,0为不启用,默认50M
5253
fileCameraUseConfirm: true, // 切换快照时询问
5354
fileCameraUseDoSave: false, // 切换快照立即保存
55+
fileEncodeFrom: 'org', // 切换编码从何处选择
5456
editorOption: {
5557
// 编辑器配置
5658
fontSize: 14, // 字体大小
@@ -96,7 +98,7 @@ export const useUserStore = defineStore('user', () => {
9698
await axios.post(
9799
HOST,
98100
{
99-
encode: 'utf8',
101+
encode: 'utf-8',
100102
path: USER_CONFIG_PATH,
101103
value: JSON.stringify({ ...cfg.value, folderDefOpen: cfg.value.folderDefOpen || '' }),
102104
force: 1,

frontend/src/utils/file.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ export const getEncodeValue = async (blob: Blob) => {
5656
continue
5757
}
5858

59+
if (item.match) {
60+
if (!item.match(text)) {
61+
continue
62+
}
63+
}
64+
5965
encode.push(item.value)
6066
} catch {
6167
continue

frontend/src/utils/option.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ export const THEME_OPTIONS: { label: string; value: string; dark: boolean }[] =
8484
{ label: 'High Contrast Black(深色模式)', value: 'hc-black', dark: true },
8585
]
8686

87+
const codeMatch = (v: string) => {
88+
const sum = v.length
89+
const err = v.split('').filter((i) => i.charCodeAt(0) > 191).length
90+
return err / sum < 0.1
91+
}
92+
8793
export const ENCODING_OPTIONS = [
8894
// 推荐优先显示(常用编码)
8995
{ value: 'utf-8', label: 'UTF-8' },
@@ -96,29 +102,13 @@ export const ENCODING_OPTIONS = [
96102
{ value: 'utf-16le', label: 'UTF-16 LE' },
97103
{ value: 'utf-16be', label: 'UTF-16 BE' },
98104
{ value: 'utf-16', label: 'UTF-16' },
99-
{ value: 'ascii', label: 'ASCII' },
100-
{ value: 'latin1', label: 'ISO-8859-1' },
101-
{ value: 'windows-1252', label: 'Windows-1252' },
105+
{ value: 'ascii', label: 'ASCII', match: codeMatch },
106+
{ value: 'latin1', label: 'ISO-8859-1', match: codeMatch },
107+
{ value: 'windows-1252', label: 'Windows-1252', match: codeMatch },
102108

103109
// 日韩编码
104110
{ value: 'shift_jis', label: 'Shift_JIS' },
105111
{ value: 'euc-jp', label: 'EUC-JP' },
106112
{ value: 'euc-kr', label: 'EUC-KR' },
107113
{ value: 'windows-949', label: 'Windows-949' },
108-
109-
// 东欧/斯拉夫编码
110-
{ value: 'windows-1251', label: 'Windows-1251' },
111-
{ value: 'koi8-r', label: 'KOI8-R' },
112-
{ value: 'iso-8859-5', label: 'ISO-8859-5' },
113-
114-
// 西欧/南欧编码
115-
{ value: 'iso-8859-2', label: 'ISO-8859-2' },
116-
{ value: 'windows-1250', label: 'Windows-1250' },
117-
{ value: 'iso-8859-3', label: 'ISO-8859-3' },
118-
119-
// 中东编码
120-
{ value: 'windows-1256', label: 'Windows-1256' },
121-
{ value: 'iso-8859-6', label: 'ISO-8859-6' },
122-
{ value: 'windows-1255', label: 'Windows-1255' },
123-
{ value: 'iso-8859-8', label: 'ISO-8859-8' },
124114
]

0 commit comments

Comments
 (0)