11import { reactive } from 'vue'
2- import { ElMessage , ElMessageBox } from 'element-plus'
2+ import { dayjs , ElMessage , ElMessageBox } from 'element-plus'
33import axios from 'axios'
44
55import { HOST } from '@/utils/env'
@@ -21,6 +21,8 @@ interface CodeModel {
2121 value : string
2222 lang : string
2323 encode : string
24+ byte ?: number
25+ date ?: dayjs . Dayjs
2426}
2527
2628export default function useCode ( option : OptionModel ) {
@@ -42,7 +44,7 @@ export default function useCode(option: OptionModel) {
4244 return ''
4345 }
4446
45- const { data } = await axios . get ( HOST , {
47+ const { data, headers } = await axios . get ( HOST , {
4648 params : { _api : 'read' , path } ,
4749 responseType : 'blob' ,
4850 } )
@@ -53,10 +55,11 @@ export default function useCode(option: OptionModel) {
5355 return
5456 }
5557
56- code . blob = data
58+ code . byte = headers [ 'content-length' ] ? Number ( headers [ 'content-length' ] ) : undefined
59+ code . date = headers [ 'last-modified' ] ? dayjs ( headers [ 'last-modified' ] ) : undefined
5760
61+ code . blob = data
5862 code . path = path
59-
6063 code . org = code . value = await data . text ( )
6164
6265 const filename = path . split ( '/' ) . pop ( ) || ''
@@ -91,7 +94,11 @@ export default function useCode(option: OptionModel) {
9194
9295 const upload = async ( force ?: 1 ) => {
9396 try {
94- const { data : value } : any = await axios . post (
97+ const { data : value } = await axios . post < {
98+ code : number
99+ msg : string
100+ data : { size : number ; time : string }
101+ } > (
95102 HOST ,
96103 {
97104 encode : code . encode ,
@@ -105,6 +112,9 @@ export default function useCode(option: OptionModel) {
105112 if ( value . code === 200 ) {
106113 ElMessage ( { type : 'success' , message : '操作成功' } )
107114
115+ code . byte = value . data . size
116+ code . date = dayjs ( value . data . time )
117+
108118 code . org = code . value
109119
110120 option . onSave ( )
0 commit comments