fix: file-icon

This commit is contained in:
puri-ph4tt 2023-11-28 16:47:38 +07:00 committed by Methapon2001
parent 9e889ccaa1
commit c69d1f6702
No known key found for this signature in database
GPG key ID: 849924FEF46BD132
2 changed files with 31 additions and 42 deletions

View file

@ -6,26 +6,24 @@ const { mimeFileMapping } = useFileInfoStore()
defineProps<{ fileMimeType: string | undefined; size: string }>() defineProps<{ fileMimeType: string | undefined; size: string }>()
function getIcon(mimeType: string) { function getIcon(mimeType: string) {
if (mimeFileMapping.hasOwnProperty(mimeType)) { return mimeType && mimeFileMapping.hasOwnProperty(mimeType)
return mimeFileMapping[mimeType].icon ? mimeFileMapping[mimeType].icon
} else { : 'mdi-file-question-outline'
return 'mdi-file-question-outline'
}
} }
function getColor(mimeType: string) { function getColor(mimeType: string) {
if (mimeFileMapping.hasOwnProperty(mimeType)) { return mimeType && mimeFileMapping.hasOwnProperty(mimeType)
return mimeFileMapping[mimeType].color ? mimeFileMapping[mimeType].color
} else { : 'blue-11'
return 'blue-11'
}
} }
function getSize(s: string) { function getIconSize(s: string) {
if (s === 'preview') { type SizeMapping = {
return '6em' [key: string]: string
} }
if (s === 'list') { const sizeMapping: SizeMapping = {
return '2em' preview: '6em',
list: '2em',
} }
return sizeMapping[s]
} }
</script> </script>
@ -33,6 +31,6 @@ function getSize(s: string) {
<q-icon <q-icon
:name="fileMimeType && getIcon(fileMimeType)" :name="fileMimeType && getIcon(fileMimeType)"
:color="fileMimeType && getColor(fileMimeType)" :color="fileMimeType && getColor(fileMimeType)"
:size="getSize(size)" :size="getIconSize(size)"
/> />
</template> </template>

View file

@ -127,43 +127,34 @@ export const useFileInfoStore = defineStore('info', () => {
} }
function getType(mimeType: any): string { function getType(mimeType: any): string {
if (mimeType === undefined) { return mimeType && mimeFileMapping.hasOwnProperty(mimeType)
return 'unknow type' ? mimeFileMapping[mimeType].type
} else { : 'unknown type'
if (mimeFileMapping.hasOwnProperty(mimeType)) {
return mimeFileMapping[mimeType].type
} else {
return 'unknow type'
}
}
} }
function getFormatDate(dateTime: any): string { function getFormatDate(dateTime: any): string {
if (dateTime === undefined) { if (dateTime === undefined) {
return 'unknow date' return 'unknown date'
} else {
const date = new Date(dateTime)
const result = date.toLocaleDateString('th-TH', {
year: 'numeric',
month: 'long',
day: 'numeric',
})
return result
} }
const date = new Date(dateTime)
return date.toLocaleDateString('th-TH', {
year: 'numeric',
month: 'long',
day: 'numeric',
})
} }
function getSize(size: any): string { function getSize(size: any): string {
if (size === undefined) { if (size === undefined) {
return 'unknow size' return 'unknow size'
} else {
const units = ['B', 'KB', 'MB', 'GB', 'TB']
let i = 0
while (size >= 1024 && i < units.length - 1) {
size /= 1024
i++
}
return size.toFixed(2) + ' ' + units[i]
} }
const units = ['B', 'KB', 'MB', 'GB', 'TB']
let i = 0
while (size >= 1024 && i < units.length - 1) {
size /= 1024
i++
}
return size.toFixed(2) + ' ' + units[i]
} }
async function getFileInfo(data: EhrFile) { async function getFileInfo(data: EhrFile) {