hrms-edm/Services/client/src/components/FileItem.vue

300 lines
8.5 KiB
Vue
Raw Normal View History

2023-11-23 08:47:44 +07:00
<script setup lang="ts">
import { computed, ref } from 'vue'
import { storeToRefs } from 'pinia'
2023-11-28 09:22:44 +07:00
import FileIcon from '@/components/FileIcon.vue'
2023-11-23 08:47:44 +07:00
import FileItemAction from '@/components/FileItemAction.vue'
2023-11-28 09:22:44 +07:00
import FromEdit from '@/components/FromEdit.vue'
2023-11-28 09:24:20 +07:00
import FormUpload from '@/components/FormUpload.vue'
2023-11-23 08:47:44 +07:00
import { useTreeDataStore } from '@/stores/tree-data'
import { useFileInfoStore } from '@/stores/file-info-data'
2023-11-23 08:47:44 +07:00
const { isPreview } = storeToRefs(useFileInfoStore())
const { getFileInfo } = useFileInfoStore()
2023-11-23 08:47:44 +07:00
const DEPT_NAME = ['ตู้เอกสาร', 'ลิ้นชัก', 'แฟ้ม', 'แฟ้มย่อย']
2023-11-28 09:22:44 +07:00
const { currentFolder, currentFile, currentDept, currentPath } = storeToRefs(
2023-11-23 08:47:44 +07:00
useTreeDataStore()
)
2023-11-28 09:24:20 +07:00
const { getFolder, uploadFile } = useTreeDataStore()
2023-11-28 09:22:44 +07:00
2023-11-23 08:47:44 +07:00
const drawer = ref<boolean>(false)
2023-11-23 17:33:15 +07:00
const drawerFile = ref<boolean>(false)
2023-11-23 08:47:44 +07:00
const drawerStatus = ref<'edit' | 'create'>('create')
const editPathname = ref<string>('')
2023-11-28 09:22:44 +07:00
2023-11-23 08:47:44 +07:00
const currentIcon = computed(() =>
currentDept.value === 0
? 'mdi-file-cabinet'
: currentDept.value === 1
? 'inbox'
: 'o_folder_open'
)
const props = withDefaults(
defineProps<{ action: boolean; viewMode: 'view_list' | 'view_module' }>(),
{
action: false,
}
)
</script>
<template>
<div class="q-mt-md">
2023-11-28 09:24:20 +07:00
<span class="text-h6 text-weight-light" v-if="currentDept === 3"
>แฟมยอย</span>
<div class="q-gutter-md" v-if="currentDept < 3">
2023-11-23 08:47:44 +07:00
<div
:key="value.name"
v-for="value in currentFolder"
class="inline-block"
>
<div class="box border-radius-inherit">
<q-card flat @click="() => getFolder(value.pathname)">
2023-11-28 09:24:20 +07:00
<q-card-section
class="column justify-center relative q-px-xl"
2023-11-28 09:24:20 +07:00
style="max-width: 225px"
2023-11-28 09:24:20 +07:00
:title="value.name"
>
2023-11-28 09:24:20 +07:00
<q-icon
:name="currentIcon"
size="6em"
color="primary"
class="column justify-center relative q-px-lg"
/>
2023-11-23 08:47:44 +07:00
<div
class="absolute"
style="top: 0.5rem; right: 0.5rem"
v-if="props.action"
>
<file-item-action
:editname="value.name"
:pathname="value.pathname"
@editname="
() => {
drawer = !drawer
drawerStatus = 'edit'
editPathname = value.pathname
}
"
/>
</div>
2023-11-28 09:24:20 +07:00
<span
class="text-center q-pt-md text-overflow-handle"
style="max-width: 150px"
>{{ value.name }}</span
>
2023-11-23 08:47:44 +07:00
</q-card-section>
</q-card>
</div>
</div>
2023-11-23 17:33:15 +07:00
<div
class="inline-block"
v-if="props.action && currentDept < 4"
tabindex="0"
>
2023-11-23 08:47:44 +07:00
<div class="dashed border-radius-inherit">
<q-card
flat
@click="
() => {
drawer = !drawer
drawerStatus = 'create'
2023-11-23 17:33:15 +07:00
drawerFile = false
2023-11-23 08:47:44 +07:00
}
"
>
<q-card-section class="column justify-center relative q-px-xl">
<q-icon
:name="currentIcon"
class="add-icon"
size="6em"
color="primary"
/>
<q-btn round class="add-button" color="white" size="10px">
<q-icon name="add" color="primary" size="1.5rem"></q-icon>
</q-btn>
<span class="text-center q-pt-md"
>สราง{{ DEPT_NAME[currentDept] }}ใหม</span
>
</q-card-section>
</q-card>
</div>
</div>
</div>
2023-11-28 09:24:20 +07:00
<div class="q-gutter-md q-mt-sm" v-if="currentDept === 3">
<div
:key="value.name"
v-for="value in currentFolder"
class="inline-block"
>
<div class="box border-radius-inherit q-px-sm q-py-sm">
<q-card flat @click="() => getFolder(value.pathname)">
<q-td>
<q-icon :name="currentIcon" size="3em" color="primary" class="col" />
<span class="q-mx-md">{{ value.name }}</span>
<file-item-action
:editname="value.name"
:pathname="value.pathname"
@editname="
() => {
drawer = !drawer
drawerStatus = 'edit'
editPathname = value.pathname
}
"
/>
</q-td>
</q-card>
</div>
</div>
<div
class="inline-block"
v-if="props.action && currentDept < 4"
tabindex="0"
>
<div class="dashed border-radius-inherit q-px-lg q-py-sm">
<q-card
flat
@click="
() => {
drawer = !drawer
drawerStatus = 'create'
drawerFile = false
}
"
>
<q-td>
<q-icon :name="currentIcon" size="3em" color="primary" class="col" />
<q-btn round class="add-button-folder-level" color="white" size="6px">
<q-icon name="add" color="primary" size="1.2rem"></q-icon>
</q-btn>
<span class="q-mx-md">สราง{{ DEPT_NAME[currentDept] }}ใหม</span>
</q-td>
</q-card>
</div>
</div>
</div>
2023-11-23 08:47:44 +07:00
</div>
2023-11-28 09:24:20 +07:00
<div class="q-mt-xl">
2023-11-28 09:24:20 +07:00
<span class="text-h6 text-weight-light" v-if="currentDept > 2">เอกสาร</span>
<div class="q-gutter-md q-mt-xs">
<div
v-for="(value, index) in currentFile"
:key="value.title"
class="inline-block"
>
2023-11-23 08:47:44 +07:00
<div class="box border-radius-inherit">
<q-card
flat
@click="
() => {
getFileInfo(currentFile[index])
isPreview = true
}
"
>
2023-11-23 08:47:44 +07:00
<q-card-section class="column justify-center relative q-px-xl">
2023-11-28 09:22:44 +07:00
<file-icon
size="preview"
:fileMimeType="value.fileType"
ref="fileIconComp"
/>
2023-11-23 08:47:44 +07:00
<div
class="absolute"
style="top: 0.5rem; right: 0.5rem"
v-if="props.action"
>
<!-- TODO: Edit file data -->
</div>
<span class="text-center q-pt-md">{{ value.title }}</span>
</q-card-section>
</q-card>
</div>
</div>
<div class="inline-block" v-if="props.action && currentDept > 2">
<div class="dashed border-radius-inherit">
2023-11-23 17:33:15 +07:00
<q-card
flat
@click="
() => {
drawerFile = !drawerFile
drawer = false
}
"
>
2023-11-23 08:47:44 +07:00
<q-card-section class="column justify-center relative q-px-xl">
<q-icon
2023-11-28 09:22:44 +07:00
name="mdi-file"
2023-11-23 08:47:44 +07:00
class="add-icon"
size="6em"
color="primary"
/>
<q-btn round class="add-button" color="white" size="10px">
<q-icon name="add" color="primary" size="1.5rem"></q-icon>
</q-btn>
<span class="text-center q-pt-md">สรางไฟลใหม</span>
</q-card-section>
</q-card>
</div>
</div>
</div>
</div>
<from-edit
:drawer="drawer"
:drawerStatus="drawerStatus"
:DEPT_NAME="DEPT_NAME"
:currentDept="currentDept"
:editPathname="editPathname"
2023-11-28 09:22:44 +07:00
@update:drawer="() => (drawer = false)"
/>
2023-11-28 09:22:44 +07:00
2023-11-28 09:24:20 +07:00
<form-upload
:drawerFile="drawerFile"
@update:drawerFile="() => (drawerFile = false)"
/>
2023-11-23 08:47:44 +07:00
</template>
<style lang="scss" scoped>
.box {
display: inline-block;
2023-11-28 09:24:20 +07:00
border: 2px solid $separator-color;
2023-11-23 08:47:44 +07:00
border-radius: 8px;
cursor: pointer;
}
.dashed {
opacity: 0.4;
display: inline-block;
2023-11-28 09:24:20 +07:00
border: 2px solid #6985c2;
2023-11-23 08:47:44 +07:00
border-radius: 8px;
cursor: pointer;
border-style: dashed;
}
.add-icon {
margin: auto auto;
}
.add-button {
position: absolute;
top: 75px;
right: 45px;
background-color: white;
}
2023-11-28 09:24:20 +07:00
.add-button-folder-level {
position: absolute;
left: 30px;
top: 22px;
background-color: white;
}
2023-11-28 09:24:20 +07:00
.text-overflow-handle {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
2023-11-23 08:47:44 +07:00
</style>