11import { reactive } from 'vue'
22import { dayjs , ElMessage , ElMessageBox } from 'element-plus'
33import axios from 'axios'
4+ import iconv from 'iconv-lite'
45
56import { HOST } from '@/utils/env'
67import { LANG_MAP } from '@/utils/option'
@@ -15,8 +16,8 @@ interface OptionModel {
1516}
1617
1718interface CodeModel {
19+ buffer : ArrayBuffer
1820 path : string
19- blob : Blob
2021 org : string
2122 value : string
2223 lang : string
@@ -29,8 +30,8 @@ export default function useCode(option: OptionModel) {
2930 // const open = useOpenStore()
3031
3132 const code = reactive < CodeModel > ( {
33+ buffer : new ArrayBuffer ( ) ,
3234 path : '' ,
33- blob : new Blob ( ) ,
3435 org : '' ,
3536 value : '' ,
3637 lang : '' ,
@@ -49,15 +50,15 @@ export default function useCode(option: OptionModel) {
4950 responseType : 'blob' ,
5051 } )
5152
52- const info = await getEncodeValue ( data )
53-
54- code . blob = data
53+ code . buffer = await data . arrayBuffer ( )
5554 code . path = path
56- code . encode = info . encode
57- code . org = code . value = info . value
5855 code . byte = headers [ 'x-size' ] ? Number ( headers [ 'x-size' ] ) : undefined
5956 code . date = headers [ 'x-update-date' ] ? dayjs ( headers [ 'x-update-date' ] ) : undefined
6057
58+ const info = getEncodeValue ( code . buffer )
59+ code . encode = info . encode
60+ code . org = code . value = info . value
61+
6162 // if (await isBinaryContent(data)) {
6263 // option.onError('不支持二进制文件的编辑')
6364 // open.removeHistory(path)
@@ -118,6 +119,7 @@ export default function useCode(option: OptionModel) {
118119 code . date = dayjs ( value . data . time )
119120
120121 code . org = code . value
122+ code . buffer = iconv . encode ( code . value , code . encode )
121123
122124 option . onSave ( )
123125 } else {
0 commit comments