fix: isPreview 2 isFilePreview & getFileNameFormat
This commit is contained in:
parent
3e570b71aa
commit
bc0212b0f1
7 changed files with 40 additions and 43 deletions
|
|
@ -12,7 +12,7 @@ export interface TypeSetting {
|
|||
|
||||
export const useFileInfoStore = defineStore('info', () => {
|
||||
const fileInfo = ref<EhrFile>()
|
||||
const isPreview = ref<Boolean>(false)
|
||||
const isFilePreview = ref<Boolean>(false)
|
||||
const file: TypeSetting = {
|
||||
word: { icon: 'mdi-file-word-outline', color: 'blue-11' },
|
||||
excel: { icon: 'mdi-file-excel-outline', color: 'green-4' },
|
||||
|
|
@ -126,13 +126,14 @@ export const useFileInfoStore = defineStore('info', () => {
|
|||
},
|
||||
}
|
||||
|
||||
function getType(mimeType: any): string {
|
||||
return mimeType && mimeFileMapping.hasOwnProperty(mimeType)
|
||||
? mimeFileMapping[mimeType].type
|
||||
: 'unknown type'
|
||||
function getType(mimeType: string | undefined): string {
|
||||
if (mimeType === undefined) {
|
||||
return 'unknown type'
|
||||
}
|
||||
return mimeFileMapping[mimeType].type
|
||||
}
|
||||
|
||||
function getFormatDate(dateTime: any): string {
|
||||
function getFormatDate(dateTime: string | undefined): string {
|
||||
if (dateTime === undefined) {
|
||||
return 'unknown date'
|
||||
}
|
||||
|
|
@ -144,30 +145,43 @@ export const useFileInfoStore = defineStore('info', () => {
|
|||
})
|
||||
}
|
||||
|
||||
function getSize(size: any): string {
|
||||
function getFileNameFormat(fileName: string | undefined): string {
|
||||
if (fileName === undefined) {
|
||||
return 'unknow name'
|
||||
}
|
||||
const dotIndex = fileName.lastIndexOf('.')
|
||||
const fileNameOnly = fileName.substring(0, dotIndex)
|
||||
|
||||
return fileNameOnly
|
||||
}
|
||||
|
||||
function getSize(size: string | undefined): string {
|
||||
if (size === undefined) {
|
||||
return 'unknow size'
|
||||
}
|
||||
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||
let i = 0
|
||||
while (size >= 1024 && i < units.length - 1) {
|
||||
size /= 1024
|
||||
let sizeNumber = parseFloat(size)
|
||||
while (sizeNumber >= 1024 && i < units.length - 1) {
|
||||
sizeNumber /= 1024
|
||||
i++
|
||||
}
|
||||
return size.toFixed(2) + ' ' + units[i]
|
||||
return sizeNumber.toFixed(2) + ' ' + units[i]
|
||||
}
|
||||
|
||||
async function getFileInfo(data: EhrFile) {
|
||||
isFilePreview.value = true
|
||||
fileInfo.value = data
|
||||
}
|
||||
|
||||
return {
|
||||
mimeFileMapping,
|
||||
isPreview,
|
||||
isFilePreview,
|
||||
fileInfo,
|
||||
getSize,
|
||||
getType,
|
||||
getFormatDate,
|
||||
getFileNameFormat,
|
||||
getSize,
|
||||
getFileInfo,
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue