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
|
|
@ -3,7 +3,7 @@ import { useFileInfoStore } from '@/stores/file-info-data'
|
||||||
|
|
||||||
const { mimeFileMapping } = useFileInfoStore()
|
const { mimeFileMapping } = useFileInfoStore()
|
||||||
|
|
||||||
defineProps<{ fileMimeType: any; size: string }>()
|
defineProps<{ fileMimeType: string | undefined; size: string }>()
|
||||||
|
|
||||||
function getIcon(mimeType: string) {
|
function getIcon(mimeType: string) {
|
||||||
if (mimeFileMapping.hasOwnProperty(mimeType)) {
|
if (mimeFileMapping.hasOwnProperty(mimeType)) {
|
||||||
|
|
@ -23,13 +23,16 @@ function getSize(s: string) {
|
||||||
if (s === 'preview') {
|
if (s === 'preview') {
|
||||||
return '6em'
|
return '6em'
|
||||||
}
|
}
|
||||||
|
if (s === 'list') {
|
||||||
|
return '2em'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<q-icon
|
<q-icon
|
||||||
:name="getIcon(fileMimeType)"
|
:name="fileMimeType && getIcon(fileMimeType)"
|
||||||
:color="getColor(fileMimeType)"
|
:color="fileMimeType && getColor(fileMimeType)"
|
||||||
:size="getSize(size)"
|
:size="getSize(size)"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { useSearchDataStore } from '@/stores/searched-data'
|
import { useSearchDataStore } from '@/stores/searched-data'
|
||||||
import { useFileInfoStore } from '@/stores/file-info-data'
|
import { useFileInfoStore } from '@/stores/file-info-data'
|
||||||
|
import FileIcon from '@/components/FileIcon.vue'
|
||||||
|
|
||||||
const { foundFile } = storeToRefs(useSearchDataStore())
|
const { foundFile } = storeToRefs(useSearchDataStore())
|
||||||
const { isPreview } = storeToRefs(useFileInfoStore())
|
const { isPreview } = storeToRefs(useFileInfoStore())
|
||||||
|
|
@ -27,7 +28,11 @@ const { getFileInfo } = useFileInfoStore()
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
<q-card-section class="column justify-center relative q-px-xl">
|
<q-card-section class="column justify-center relative q-px-xl">
|
||||||
<q-icon name="description" size="6em" color="primary" />
|
<file-icon
|
||||||
|
size="preview"
|
||||||
|
:fileMimeType="value.fileType"
|
||||||
|
ref="fileIconComp"
|
||||||
|
/>
|
||||||
<span class="text-center q-pt-md">{{ value.title }}</span>
|
<span class="text-center q-pt-md">{{ value.title }}</span>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@ import { useFileInfoStore } from '@/stores/file-info-data'
|
||||||
import FileIcon from '@/components/FileIcon.vue'
|
import FileIcon from '@/components/FileIcon.vue'
|
||||||
|
|
||||||
const { isPreview, fileInfo } = storeToRefs(useFileInfoStore())
|
const { isPreview, fileInfo } = storeToRefs(useFileInfoStore())
|
||||||
const { getType } = useFileInfoStore()
|
const { getType, getFormatDate, getSize } = useFileInfoStore()
|
||||||
const fileIconComp = ref<InstanceType<typeof FileIcon>>()
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -40,11 +39,7 @@ const fileIconComp = ref<InstanceType<typeof FileIcon>>()
|
||||||
<file-icon
|
<file-icon
|
||||||
size="preview"
|
size="preview"
|
||||||
:fileMimeType="fileInfo?.fileType"
|
:fileMimeType="fileInfo?.fileType"
|
||||||
ref="fileIconComp"
|
|
||||||
/>
|
/>
|
||||||
<div class="absolute" style="top: 0.5rem; right: 0.5rem">
|
|
||||||
<file-item-action :edit="() => {}" :delete="() => {}" />
|
|
||||||
</div>
|
|
||||||
<span class="text-center q-pt-md text-h6">{{
|
<span class="text-center q-pt-md text-h6">{{
|
||||||
fileInfo?.title
|
fileInfo?.title
|
||||||
}}</span>
|
}}</span>
|
||||||
|
|
@ -94,8 +89,8 @@ const fileIconComp = ref<InstanceType<typeof FileIcon>>()
|
||||||
<div class="col-2">
|
<div class="col-2">
|
||||||
<span>กลุ่ม/หมวดหมู่</span>
|
<span>กลุ่ม/หมวดหมู่</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-grow">
|
<div class="col-grow" v-for="category in fileInfo?.category" :key="category">
|
||||||
<span class="text-grey">{{ fileInfo?.category }}</span>
|
<span class="text-grey">{{ category }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<q-separator />
|
<q-separator />
|
||||||
|
|
@ -103,8 +98,8 @@ const fileIconComp = ref<InstanceType<typeof FileIcon>>()
|
||||||
<div class="col-2">
|
<div class="col-2">
|
||||||
<span>คำสำคัญ</span>
|
<span>คำสำคัญ</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-grow">
|
<div class="col-grow" v-for="keyword in fileInfo?.keyword" :key="keyword">
|
||||||
<span class="text-grey">{{ fileInfo?.keyword }}</span>
|
<span class="text-grey">{{ keyword }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<q-separator />
|
<q-separator />
|
||||||
|
|
@ -113,7 +108,7 @@ const fileIconComp = ref<InstanceType<typeof FileIcon>>()
|
||||||
<span>ขนาดไฟล์</span>
|
<span>ขนาดไฟล์</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-grow">
|
<div class="col-grow">
|
||||||
<span class="text-grey">{{ fileInfo?.fileSize }}</span>
|
<span class="text-grey">{{ getSize(fileInfo?.fileSize) }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<q-separator />
|
<q-separator />
|
||||||
|
|
@ -131,7 +126,7 @@ const fileIconComp = ref<InstanceType<typeof FileIcon>>()
|
||||||
<span>วันที่อัปโหลด</span>
|
<span>วันที่อัปโหลด</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-grow">
|
<div class="col-grow">
|
||||||
<span class="text-grey">{{ fileInfo?.createdAt }}</span>
|
<span class="text-grey">{{ getFormatDate(fileInfo?.createdAt) }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -6,147 +6,158 @@ import type { EhrFile } from '@/stores/tree-data'
|
||||||
export interface MimeMap {
|
export interface MimeMap {
|
||||||
[key: string]: { icon: string; color: string; type: string }
|
[key: string]: { icon: string; color: string; type: string }
|
||||||
}
|
}
|
||||||
|
export interface TypeSetting {
|
||||||
|
[key: string]: { icon: string; color: string }
|
||||||
|
}
|
||||||
|
|
||||||
export const useFileInfoStore = defineStore('info', () => {
|
export const useFileInfoStore = defineStore('info', () => {
|
||||||
const fileInfo = ref<EhrFile>()
|
const fileInfo = ref<EhrFile>()
|
||||||
const isPreview = ref<Boolean>(false)
|
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 = {
|
const mimeFileMapping: MimeMap = {
|
||||||
'application/msword': {
|
'application/msword': {
|
||||||
icon: 'mdi-file-word-outline',
|
...file.word,
|
||||||
color: 'blue-11',
|
|
||||||
type: '.doc',
|
type: '.doc',
|
||||||
},
|
},
|
||||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': {
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': {
|
||||||
icon: 'mdi-file-word-outline',
|
...file.word,
|
||||||
color: 'blue-11',
|
|
||||||
type: '.docx',
|
type: '.docx',
|
||||||
},
|
},
|
||||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.template': {
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.template': {
|
||||||
icon: 'mdi-file-word-outline',
|
...file.word,
|
||||||
color: 'blue-11',
|
|
||||||
type: '.dotx',
|
type: '.dotx',
|
||||||
},
|
},
|
||||||
'application/vnd.ms-word.document.macroEnabled.12': {
|
'application/vnd.ms-word.document.macroEnabled.12': {
|
||||||
icon: 'mdi-file-word-outline',
|
...file.word,
|
||||||
color: 'blue-11',
|
|
||||||
type: '.docm',
|
type: '.docm',
|
||||||
},
|
},
|
||||||
'application/vnd.ms-word.template.macroEnabled.12': {
|
'application/vnd.ms-word.template.macroEnabled.12': {
|
||||||
icon: 'mdi-file-word-outline',
|
...file.word,
|
||||||
color: 'blue-11',
|
|
||||||
type: '.dotm',
|
type: '.dotm',
|
||||||
},
|
},
|
||||||
|
|
||||||
'application/vnd.ms-excel': {
|
'application/vnd.ms-excel': {
|
||||||
icon: 'mdi-file-excel-outline',
|
...file.excel,
|
||||||
color: 'green-12',
|
|
||||||
type: '.xls',
|
type: '.xls',
|
||||||
},
|
},
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': {
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': {
|
||||||
icon: 'mdi-file-excel-outline',
|
...file.excel,
|
||||||
color: 'green-12',
|
|
||||||
type: '.xlsx',
|
type: '.xlsx',
|
||||||
},
|
},
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.template': {
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.template': {
|
||||||
icon: 'mdi-file-excel-outline',
|
...file.excel,
|
||||||
color: 'green-12',
|
|
||||||
type: '.xltx',
|
type: '.xltx',
|
||||||
},
|
},
|
||||||
'application/vnd.ms-excel.sheet.macroEnabled.12': {
|
'application/vnd.ms-excel.sheet.macroEnabled.12': {
|
||||||
icon: 'mdi-file-excel-outline',
|
...file.excel,
|
||||||
color: 'green-12',
|
|
||||||
type: '.xlsm',
|
type: '.xlsm',
|
||||||
},
|
},
|
||||||
'application/vnd.ms-excel.template.macroEnabled.12': {
|
'application/vnd.ms-excel.template.macroEnabled.12': {
|
||||||
icon: 'mdi-file-excel-outline',
|
...file.excel,
|
||||||
color: 'green-12',
|
|
||||||
type: '.xltm',
|
type: '.xltm',
|
||||||
},
|
},
|
||||||
'application/vnd.ms-excel.addin.macroEnabled.12': {
|
'application/vnd.ms-excel.addin.macroEnabled.12': {
|
||||||
icon: 'mdi-file-excel-outline',
|
...file.excel,
|
||||||
color: 'green-12',
|
|
||||||
type: '.xlam',
|
type: '.xlam',
|
||||||
},
|
},
|
||||||
'application/vnd.ms-excel.sheet.binary.macroEnabled.12': {
|
'application/vnd.ms-excel.sheet.binary.macroEnabled.12': {
|
||||||
icon: 'mdi-file-excel-outline',
|
...file.excel,
|
||||||
color: 'green-12',
|
|
||||||
type: '.xlsb',
|
type: '.xlsb',
|
||||||
},
|
},
|
||||||
|
|
||||||
'application/vnd.ms-powerpoint': {
|
'application/vnd.ms-powerpoint': {
|
||||||
icon: 'mdi-file-powerpoint-outline',
|
...file.powerpoint,
|
||||||
color: 'orange-12',
|
|
||||||
type: '.ppt',
|
type: '.ppt',
|
||||||
},
|
},
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation':
|
'application/vnd.openxmlformats-officedocument.presentationml.presentation':
|
||||||
{
|
{
|
||||||
icon: 'mdi-file-powerpoint-outline',
|
...file.powerpoint,
|
||||||
color: 'orange-12',
|
|
||||||
type: '.pptx',
|
type: '.pptx',
|
||||||
},
|
},
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.template': {
|
'application/vnd.openxmlformats-officedocument.presentationml.template': {
|
||||||
icon: 'mdi-file-powerpoint-outline',
|
...file.powerpoint,
|
||||||
color: 'orange-12',
|
|
||||||
type: '.potx',
|
type: '.potx',
|
||||||
},
|
},
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.slideshow': {
|
'application/vnd.openxmlformats-officedocument.presentationml.slideshow': {
|
||||||
icon: 'mdi-file-powerpoint-outline',
|
...file.powerpoint,
|
||||||
color: 'orange-12',
|
|
||||||
type: '.ppsx',
|
type: '.ppsx',
|
||||||
},
|
},
|
||||||
'application/vnd.ms-powerpoint.addin.macroEnabled.12': {
|
'application/vnd.ms-powerpoint.addin.macroEnabled.12': {
|
||||||
icon: 'mdi-file-powerpoint-outline',
|
...file.powerpoint,
|
||||||
color: 'orange-12',
|
|
||||||
type: '.ppam',
|
type: '.ppam',
|
||||||
},
|
},
|
||||||
'application/vnd.ms-powerpoint.presentation.macroEnabled.12': {
|
'application/vnd.ms-powerpoint.presentation.macroEnabled.12': {
|
||||||
icon: 'mdi-file-powerpoint-outline',
|
...file.powerpoint,
|
||||||
color: 'orange-12',
|
|
||||||
type: '.pptm',
|
type: '.pptm',
|
||||||
},
|
},
|
||||||
'application/vnd.ms-powerpoint.template.macroEnabled.12': {
|
'application/vnd.ms-powerpoint.template.macroEnabled.12': {
|
||||||
icon: 'mdi-file-powerpoint-outline',
|
...file.powerpoint,
|
||||||
color: 'orange-12',
|
|
||||||
type: '.potm',
|
type: '.potm',
|
||||||
},
|
},
|
||||||
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12': {
|
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12': {
|
||||||
icon: 'mdi-file-powerpoint-outline',
|
...file.powerpoint,
|
||||||
color: 'orange-12',
|
|
||||||
type: '.ppsm',
|
type: '.ppsm',
|
||||||
},
|
},
|
||||||
|
|
||||||
'application/pdf': {
|
'application/pdf': {
|
||||||
icon: 'mdi-file-document-outline',
|
...file.pdf,
|
||||||
color: 'red-12',
|
|
||||||
type: '.pdf',
|
type: '.pdf',
|
||||||
},
|
},
|
||||||
|
|
||||||
'text/plain': {
|
'text/plain': {
|
||||||
icon: 'mdi-file-document-outline',
|
...file.txt,
|
||||||
color: 'blue-11',
|
|
||||||
type: '.txt',
|
type: '.txt',
|
||||||
},
|
},
|
||||||
|
|
||||||
'image/x-png': {
|
'image/x-png': {
|
||||||
icon: 'mdi-file-image-outline',
|
...file.image,
|
||||||
color: 'blue-11',
|
|
||||||
type: '.png',
|
type: '.png',
|
||||||
},
|
},
|
||||||
'image/x-citrix-jpeg': {
|
'image/x-citrix-jpeg': {
|
||||||
icon: 'mdi-file-image-outline',
|
...file.image,
|
||||||
color: 'blue-11',
|
|
||||||
type: '.jpg, jpeg',
|
type: '.jpg, jpeg',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function getType(mimeType: any) {
|
function getType(mimeType: any): string {
|
||||||
if (mimeFileMapping.hasOwnProperty(mimeType)) {
|
if (mimeType === undefined) {
|
||||||
return mimeFileMapping[mimeType].type
|
|
||||||
} else {
|
|
||||||
return 'unknow type'
|
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) {
|
async function getFileInfo(data: EhrFile) {
|
||||||
fileInfo.value = data
|
fileInfo.value = data
|
||||||
}
|
}
|
||||||
|
|
@ -155,7 +166,9 @@ export const useFileInfoStore = defineStore('info', () => {
|
||||||
mimeFileMapping,
|
mimeFileMapping,
|
||||||
isPreview,
|
isPreview,
|
||||||
fileInfo,
|
fileInfo,
|
||||||
getFileInfo,
|
getSize,
|
||||||
getType,
|
getType,
|
||||||
|
getFormatDate,
|
||||||
|
getFileInfo,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue