Merge branch 'phatt' into dev/front

This commit is contained in:
puri-ph4tt 2023-11-28 16:47:50 +07:00 committed by Methapon2001
commit 6e77d30236
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 }>()
function getIcon(mimeType: string) {
if (mimeFileMapping.hasOwnProperty(mimeType)) {
return mimeFileMapping[mimeType].icon
} else {
return 'mdi-file-question-outline'
}
return mimeType && mimeFileMapping.hasOwnProperty(mimeType)
? mimeFileMapping[mimeType].icon
: 'mdi-file-question-outline'
}
function getColor(mimeType: string) {
if (mimeFileMapping.hasOwnProperty(mimeType)) {
return mimeFileMapping[mimeType].color
} else {
return 'blue-11'
}
return mimeType && mimeFileMapping.hasOwnProperty(mimeType)
? mimeFileMapping[mimeType].color
: 'blue-11'
}
function getSize(s: string) {
if (s === 'preview') {
return '6em'
function getIconSize(s: string) {
type SizeMapping = {
[key: string]: string
}
if (s === 'list') {
return '2em'
const sizeMapping: SizeMapping = {
preview: '6em',
list: '2em',
}
return sizeMapping[s]
}
</script>
@ -33,6 +31,6 @@ function getSize(s: string) {
<q-icon
:name="fileMimeType && getIcon(fileMimeType)"
:color="fileMimeType && getColor(fileMimeType)"
:size="getSize(size)"
:size="getIconSize(size)"
/>
</template>

View file

@ -127,43 +127,34 @@ export const useFileInfoStore = defineStore('info', () => {
}
function getType(mimeType: any): string {
if (mimeType === undefined) {
return 'unknow type'
} else {
if (mimeFileMapping.hasOwnProperty(mimeType)) {
return mimeFileMapping[mimeType].type
} else {
return 'unknow type'
}
}
return mimeType && mimeFileMapping.hasOwnProperty(mimeType)
? mimeFileMapping[mimeType].type
: 'unknown type'
}
function getFormatDate(dateTime: any): string {
if (dateTime === undefined) {
return 'unknow date'
} else {
const date = new Date(dateTime)
const result = date.toLocaleDateString('th-TH', {
year: 'numeric',
month: 'long',
day: 'numeric',
})
return result
return 'unknown date'
}
const date = new Date(dateTime)
return date.toLocaleDateString('th-TH', {
year: 'numeric',
month: 'long',
day: 'numeric',
})
}
function getSize(size: any): string {
if (size === undefined) {
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) {