refactor: file info preview mime type, icon, type
This commit is contained in:
parent
0666a60741
commit
b10679b53c
4 changed files with 85 additions and 69 deletions
|
|
@ -6,147 +6,158 @@ import type { EhrFile } from '@/stores/tree-data'
|
|||
export interface MimeMap {
|
||||
[key: string]: { icon: string; color: string; type: string }
|
||||
}
|
||||
export interface TypeSetting {
|
||||
[key: string]: { icon: string; color: string }
|
||||
}
|
||||
|
||||
export const useFileInfoStore = defineStore('info', () => {
|
||||
const fileInfo = ref<EhrFile>()
|
||||
const isPreview = ref<Boolean>(false)
|
||||
const file: TypeSetting = {
|
||||
word: { icon: 'mdi-file-word-outline', color: 'blue-11' },
|
||||
excel: { icon: 'mdi-file-excel-outline', color: 'green-4' },
|
||||
powerpoint: { icon: 'mdi-file-powerpoint-outline', color: 'orange-4' },
|
||||
pdf: { icon: 'mdi-file-document-outline', color: 'red-11' },
|
||||
txt: { icon: 'mdi-file-document-outline', color: 'blue-11' },
|
||||
image: { icon: 'mdi-file-image-outline', color: 'blue-11' },
|
||||
}
|
||||
const mimeFileMapping: MimeMap = {
|
||||
'application/msword': {
|
||||
icon: 'mdi-file-word-outline',
|
||||
color: 'blue-11',
|
||||
...file.word,
|
||||
type: '.doc',
|
||||
},
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': {
|
||||
icon: 'mdi-file-word-outline',
|
||||
color: 'blue-11',
|
||||
...file.word,
|
||||
type: '.docx',
|
||||
},
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.template': {
|
||||
icon: 'mdi-file-word-outline',
|
||||
color: 'blue-11',
|
||||
...file.word,
|
||||
type: '.dotx',
|
||||
},
|
||||
'application/vnd.ms-word.document.macroEnabled.12': {
|
||||
icon: 'mdi-file-word-outline',
|
||||
color: 'blue-11',
|
||||
...file.word,
|
||||
type: '.docm',
|
||||
},
|
||||
'application/vnd.ms-word.template.macroEnabled.12': {
|
||||
icon: 'mdi-file-word-outline',
|
||||
color: 'blue-11',
|
||||
...file.word,
|
||||
type: '.dotm',
|
||||
},
|
||||
|
||||
'application/vnd.ms-excel': {
|
||||
icon: 'mdi-file-excel-outline',
|
||||
color: 'green-12',
|
||||
...file.excel,
|
||||
type: '.xls',
|
||||
},
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': {
|
||||
icon: 'mdi-file-excel-outline',
|
||||
color: 'green-12',
|
||||
...file.excel,
|
||||
type: '.xlsx',
|
||||
},
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.template': {
|
||||
icon: 'mdi-file-excel-outline',
|
||||
color: 'green-12',
|
||||
...file.excel,
|
||||
type: '.xltx',
|
||||
},
|
||||
'application/vnd.ms-excel.sheet.macroEnabled.12': {
|
||||
icon: 'mdi-file-excel-outline',
|
||||
color: 'green-12',
|
||||
...file.excel,
|
||||
type: '.xlsm',
|
||||
},
|
||||
'application/vnd.ms-excel.template.macroEnabled.12': {
|
||||
icon: 'mdi-file-excel-outline',
|
||||
color: 'green-12',
|
||||
...file.excel,
|
||||
type: '.xltm',
|
||||
},
|
||||
'application/vnd.ms-excel.addin.macroEnabled.12': {
|
||||
icon: 'mdi-file-excel-outline',
|
||||
color: 'green-12',
|
||||
...file.excel,
|
||||
type: '.xlam',
|
||||
},
|
||||
'application/vnd.ms-excel.sheet.binary.macroEnabled.12': {
|
||||
icon: 'mdi-file-excel-outline',
|
||||
color: 'green-12',
|
||||
...file.excel,
|
||||
type: '.xlsb',
|
||||
},
|
||||
|
||||
'application/vnd.ms-powerpoint': {
|
||||
icon: 'mdi-file-powerpoint-outline',
|
||||
color: 'orange-12',
|
||||
...file.powerpoint,
|
||||
type: '.ppt',
|
||||
},
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation':
|
||||
{
|
||||
icon: 'mdi-file-powerpoint-outline',
|
||||
color: 'orange-12',
|
||||
...file.powerpoint,
|
||||
type: '.pptx',
|
||||
},
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.template': {
|
||||
icon: 'mdi-file-powerpoint-outline',
|
||||
color: 'orange-12',
|
||||
...file.powerpoint,
|
||||
type: '.potx',
|
||||
},
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.slideshow': {
|
||||
icon: 'mdi-file-powerpoint-outline',
|
||||
color: 'orange-12',
|
||||
...file.powerpoint,
|
||||
type: '.ppsx',
|
||||
},
|
||||
'application/vnd.ms-powerpoint.addin.macroEnabled.12': {
|
||||
icon: 'mdi-file-powerpoint-outline',
|
||||
color: 'orange-12',
|
||||
...file.powerpoint,
|
||||
type: '.ppam',
|
||||
},
|
||||
'application/vnd.ms-powerpoint.presentation.macroEnabled.12': {
|
||||
icon: 'mdi-file-powerpoint-outline',
|
||||
color: 'orange-12',
|
||||
...file.powerpoint,
|
||||
type: '.pptm',
|
||||
},
|
||||
'application/vnd.ms-powerpoint.template.macroEnabled.12': {
|
||||
icon: 'mdi-file-powerpoint-outline',
|
||||
color: 'orange-12',
|
||||
...file.powerpoint,
|
||||
type: '.potm',
|
||||
},
|
||||
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12': {
|
||||
icon: 'mdi-file-powerpoint-outline',
|
||||
color: 'orange-12',
|
||||
...file.powerpoint,
|
||||
type: '.ppsm',
|
||||
},
|
||||
|
||||
'application/pdf': {
|
||||
icon: 'mdi-file-document-outline',
|
||||
color: 'red-12',
|
||||
...file.pdf,
|
||||
type: '.pdf',
|
||||
},
|
||||
|
||||
'text/plain': {
|
||||
icon: 'mdi-file-document-outline',
|
||||
color: 'blue-11',
|
||||
...file.txt,
|
||||
type: '.txt',
|
||||
},
|
||||
|
||||
'image/x-png': {
|
||||
icon: 'mdi-file-image-outline',
|
||||
color: 'blue-11',
|
||||
...file.image,
|
||||
type: '.png',
|
||||
},
|
||||
'image/x-citrix-jpeg': {
|
||||
icon: 'mdi-file-image-outline',
|
||||
color: 'blue-11',
|
||||
...file.image,
|
||||
type: '.jpg, jpeg',
|
||||
},
|
||||
}
|
||||
|
||||
function getType(mimeType: any) {
|
||||
if (mimeFileMapping.hasOwnProperty(mimeType)) {
|
||||
return mimeFileMapping[mimeType].type
|
||||
} else {
|
||||
function getType(mimeType: any): string {
|
||||
if (mimeType === undefined) {
|
||||
return 'unknow type'
|
||||
} else {
|
||||
if (mimeFileMapping.hasOwnProperty(mimeType)) {
|
||||
return mimeFileMapping[mimeType].type
|
||||
} else {
|
||||
return 'unknow type'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getFormatDate(dateTime: any): string {
|
||||
const date = new Date(dateTime)
|
||||
const result = date.toLocaleDateString('th-TH', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
function getSize(size: any): string {
|
||||
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) {
|
||||
fileInfo.value = data
|
||||
}
|
||||
|
|
@ -155,7 +166,9 @@ export const useFileInfoStore = defineStore('info', () => {
|
|||
mimeFileMapping,
|
||||
isPreview,
|
||||
fileInfo,
|
||||
getFileInfo,
|
||||
getSize,
|
||||
getType,
|
||||
getFormatDate,
|
||||
getFileInfo,
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue