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 16:30:48 +07:00
|
|
|
import FileForm from './FileForm.vue'
|
|
|
|
|
import FolderForm from './FolderForm.vue'
|
2023-11-23 08:47:44 +07:00
|
|
|
import { useTreeDataStore } from '@/stores/tree-data'
|
2023-11-23 18:00:43 +07:00
|
|
|
import { useFileInfoStore } from '@/stores/file-info-data'
|
2023-11-23 08:47:44 +07:00
|
|
|
|
2023-11-28 16:30:48 +07:00
|
|
|
const props = withDefaults(
|
|
|
|
|
defineProps<{ action: boolean; viewMode: 'view_list' | 'view_module' }>(),
|
|
|
|
|
{
|
|
|
|
|
action: false,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const DEPT_NAME = ['ตู้เอกสาร', 'ลิ้นชัก', 'แฟ้ม', 'แฟ้มย่อย'] as const
|
|
|
|
|
|
2023-11-23 18:00:43 +07:00
|
|
|
const { isPreview } = storeToRefs(useFileInfoStore())
|
|
|
|
|
const { getFileInfo } = useFileInfoStore()
|
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 16:30:48 +07:00
|
|
|
const {
|
|
|
|
|
createFolder,
|
|
|
|
|
editFolder,
|
|
|
|
|
getFolder,
|
|
|
|
|
deleteFolder,
|
|
|
|
|
uploadFile,
|
|
|
|
|
updateFile,
|
|
|
|
|
deleteFile,
|
|
|
|
|
} = useTreeDataStore()
|
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'
|
|
|
|
|
)
|
2023-11-28 16:30:48 +07:00
|
|
|
|
|
|
|
|
const folderFormState = ref<boolean>(false)
|
|
|
|
|
const folderFormPath = ref<string>('')
|
|
|
|
|
const folderFormData = ref<{
|
|
|
|
|
name?: string
|
|
|
|
|
}>({})
|
|
|
|
|
const folderFormType = ref<'edit' | 'create'>('create')
|
|
|
|
|
const fileFormState = ref<boolean>(false)
|
|
|
|
|
const fileFormPath = ref<string>('')
|
|
|
|
|
const fileFormData = ref<{
|
|
|
|
|
file?: File
|
|
|
|
|
title?: string
|
|
|
|
|
description?: string
|
|
|
|
|
keyword?: string
|
|
|
|
|
category?: string
|
|
|
|
|
}>({})
|
|
|
|
|
const fileFormType = ref<'edit' | 'create'>('create')
|
|
|
|
|
|
|
|
|
|
function triggerFolderCreate() {
|
|
|
|
|
folderFormType.value = 'create'
|
|
|
|
|
folderFormData.value = {}
|
|
|
|
|
folderFormState.value = !folderFormState.value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function triggerFolderEdit(name: string, pathname: string) {
|
|
|
|
|
folderFormType.value = 'edit'
|
|
|
|
|
folderFormPath.value = pathname
|
|
|
|
|
folderFormData.value.name = name
|
|
|
|
|
folderFormState.value = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function submitFolderForm(value: {
|
|
|
|
|
mode: 'create' | 'edit'
|
|
|
|
|
name: string
|
|
|
|
|
}) {
|
|
|
|
|
if (value.mode === 'create') {
|
|
|
|
|
await createFolder(value.name)
|
|
|
|
|
} else {
|
|
|
|
|
await editFolder(value.name, folderFormPath.value)
|
2023-11-23 08:47:44 +07:00
|
|
|
}
|
2023-11-28 16:30:48 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function triggerFileCreate() {
|
|
|
|
|
fileFormType.value = 'create'
|
|
|
|
|
fileFormData.value = {}
|
|
|
|
|
fileFormState.value = !fileFormState.value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function triggerFileEdit(
|
|
|
|
|
value: {
|
|
|
|
|
title: string
|
|
|
|
|
description: string
|
|
|
|
|
keyword: string
|
|
|
|
|
category: string
|
|
|
|
|
},
|
|
|
|
|
pathname: string
|
|
|
|
|
) {
|
|
|
|
|
fileFormState.value = true
|
|
|
|
|
fileFormType.value = 'edit'
|
|
|
|
|
fileFormPath.value = pathname
|
|
|
|
|
fileFormData.value = {
|
|
|
|
|
title: value.title,
|
|
|
|
|
description: value.description,
|
|
|
|
|
keyword: value.keyword,
|
|
|
|
|
category: value.keyword,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-28 18:07:56 +07:00
|
|
|
function getFileNameFormat(fileName: string): string {
|
|
|
|
|
const dotIndex = fileName.lastIndexOf('.')
|
|
|
|
|
const fileNameOnly = fileName.substring(0, dotIndex)
|
|
|
|
|
|
|
|
|
|
return fileNameOnly
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-28 16:30:48 +07:00
|
|
|
async function submitFileForm(value: {
|
|
|
|
|
mode: 'create' | 'edit'
|
|
|
|
|
file: File
|
|
|
|
|
title: string
|
|
|
|
|
description: string
|
|
|
|
|
keyword: string
|
|
|
|
|
category: string
|
|
|
|
|
}) {
|
|
|
|
|
if (value.mode === 'create') {
|
|
|
|
|
await uploadFile(currentPath.value, value.file, {
|
|
|
|
|
title: value.title,
|
|
|
|
|
description: value.description,
|
|
|
|
|
keyword: value.keyword,
|
|
|
|
|
category: value.category,
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
await updateFile(
|
|
|
|
|
fileFormPath.value,
|
|
|
|
|
{
|
|
|
|
|
title: value.title,
|
|
|
|
|
description: value.description,
|
|
|
|
|
keyword: value.keyword,
|
|
|
|
|
category: value.category,
|
|
|
|
|
},
|
|
|
|
|
value.file
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
fileFormData.value = {}
|
|
|
|
|
fileFormState.value = false
|
|
|
|
|
}
|
2023-11-23 08:47:44 +07:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2023-11-28 13:02:25 +07:00
|
|
|
<div class="q-my-md">
|
2023-11-28 16:30:48 +07:00
|
|
|
<span class="text-h6 text-weight-light" v-if="currentDept === 3">
|
|
|
|
|
แฟ้มย่อย
|
|
|
|
|
</span>
|
2023-11-28 09:24:20 +07:00
|
|
|
<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
|
2023-11-28 16:30:48 +07:00
|
|
|
@delete="() => deleteFolder(value.pathname)"
|
|
|
|
|
@edit="() => triggerFolderEdit(value.name, value.pathname)"
|
2023-11-23 08:47:44 +07:00
|
|
|
/>
|
|
|
|
|
</div>
|
2023-11-28 09:24:20 +07:00
|
|
|
<span
|
|
|
|
|
class="text-center q-pt-md text-overflow-handle"
|
2023-11-28 13:02:25 +07:00
|
|
|
style="max-width: 132px"
|
2023-11-28 09:24:20 +07:00
|
|
|
>
|
2023-11-28 16:30:48 +07:00
|
|
|
{{ 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">
|
2023-11-28 16:30:48 +07:00
|
|
|
<q-card flat @click="() => triggerFolderCreate()">
|
2023-11-23 08:47:44 +07:00
|
|
|
<q-card-section class="column justify-center relative q-px-xl">
|
|
|
|
|
<q-icon
|
|
|
|
|
:name="currentIcon"
|
2023-11-28 13:02:25 +07:00
|
|
|
class="column justify-center relative q-px-lg"
|
2023-11-23 08:47:44 +07:00
|
|
|
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"
|
|
|
|
|
>
|
2023-11-28 13:02:25 +07:00
|
|
|
<div class="box border-radius-inherit q-px-sm q-py-sm">
|
2023-11-28 09:24:20 +07:00
|
|
|
<q-card flat @click="() => getFolder(value.pathname)">
|
2023-11-28 13:02:25 +07:00
|
|
|
<q-td>
|
|
|
|
|
<q-icon
|
|
|
|
|
:name="currentIcon"
|
|
|
|
|
size="3em"
|
|
|
|
|
color="primary"
|
|
|
|
|
class="col"
|
|
|
|
|
/>
|
|
|
|
|
<span class="q-mx-md">{{ value.name }}</span>
|
|
|
|
|
<file-item-action
|
2023-11-28 16:30:48 +07:00
|
|
|
@delete="() => deleteFolder(value.pathname)"
|
|
|
|
|
@edit="() => triggerFolderEdit(value.name, value.pathname)"
|
2023-11-28 13:02:25 +07:00
|
|
|
/>
|
|
|
|
|
</q-td>
|
|
|
|
|
</q-card>
|
2023-11-28 09:24:20 +07:00
|
|
|
</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">
|
2023-11-28 16:30:48 +07:00
|
|
|
<q-card flat @click="() => triggerFolderCreate()">
|
2023-11-28 13:02:25 +07:00
|
|
|
<q-td>
|
|
|
|
|
<q-icon
|
|
|
|
|
:name="currentIcon"
|
|
|
|
|
size="3em"
|
|
|
|
|
color="primary"
|
|
|
|
|
class="col"
|
|
|
|
|
/>
|
|
|
|
|
<q-btn
|
|
|
|
|
round
|
|
|
|
|
class="add-button-folder-level"
|
|
|
|
|
color="white"
|
|
|
|
|
size="6px"
|
|
|
|
|
>
|
2023-11-28 09:24:20 +07:00
|
|
|
<q-icon name="add" color="primary" size="1.2rem"></q-icon>
|
|
|
|
|
</q-btn>
|
2023-11-28 13:02:25 +07:00
|
|
|
<span class="q-mx-md">สร้าง{{ DEPT_NAME[currentDept] }}ใหม่</span>
|
|
|
|
|
</q-td>
|
2023-11-28 09:24:20 +07:00
|
|
|
</q-card>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2023-11-23 08:47:44 +07:00
|
|
|
</div>
|
2023-11-28 16:30:48 +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-28 13:02:25 +07:00
|
|
|
>
|
2023-11-28 16:30:48 +07:00
|
|
|
<div class="box border-radius-inherit">
|
|
|
|
|
<q-card
|
|
|
|
|
flat
|
|
|
|
|
@click="() => (getFileInfo(currentFile[index]), (isPreview = true))"
|
|
|
|
|
>
|
|
|
|
|
<q-card-section class="column justify-center relative q-px-xl">
|
|
|
|
|
<file-icon
|
|
|
|
|
size="preview"
|
2023-11-28 18:07:56 +07:00
|
|
|
:fileMimeType="value.fileType ? value.fileType : 'unknow'"
|
2023-11-28 16:30:48 +07:00
|
|
|
ref="fileIconComp"
|
|
|
|
|
/>
|
|
|
|
|
<div
|
|
|
|
|
class="absolute"
|
|
|
|
|
style="top: 0.5rem; right: 0.5rem"
|
|
|
|
|
v-if="props.action"
|
|
|
|
|
>
|
|
|
|
|
<file-item-action
|
|
|
|
|
@edit="
|
|
|
|
|
() =>
|
|
|
|
|
triggerFileEdit(
|
|
|
|
|
{
|
|
|
|
|
title: value.title,
|
|
|
|
|
description: value.description,
|
|
|
|
|
keyword: value.keyword.join(','),
|
|
|
|
|
category: value.category.join(','),
|
|
|
|
|
},
|
|
|
|
|
value.pathname
|
|
|
|
|
)
|
|
|
|
|
"
|
|
|
|
|
@delete="() => deleteFile(value.pathname)"
|
2023-11-28 09:22:44 +07:00
|
|
|
/>
|
2023-11-28 16:30:48 +07:00
|
|
|
</div>
|
2023-11-28 18:07:56 +07:00
|
|
|
<span class="text-center q-pt-md">{{
|
|
|
|
|
getFileNameFormat(value.fileName)
|
|
|
|
|
}}</span>
|
2023-11-28 16:30:48 +07:00
|
|
|
</q-card-section>
|
|
|
|
|
</q-card>
|
2023-11-23 08:47:44 +07:00
|
|
|
</div>
|
2023-11-28 16:30:48 +07:00
|
|
|
</div>
|
|
|
|
|
<div class="inline-block" v-if="props.action && currentDept > 2">
|
|
|
|
|
<div class="dashed border-radius-inherit">
|
|
|
|
|
<q-card flat @click="() => triggerFileCreate()">
|
|
|
|
|
<q-card-section class="column justify-center relative q-px-xl">
|
|
|
|
|
<q-icon
|
|
|
|
|
name="mdi-file"
|
|
|
|
|
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>
|
2023-11-23 08:47:44 +07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2023-11-28 16:30:48 +07:00
|
|
|
</div>
|
2023-11-23 08:47:44 +07:00
|
|
|
|
2023-11-28 16:30:48 +07:00
|
|
|
<file-form
|
|
|
|
|
:mode="fileFormType"
|
|
|
|
|
v-model:open="fileFormState"
|
|
|
|
|
v-model:title="fileFormData.title"
|
|
|
|
|
v-model:description="fileFormData.description"
|
|
|
|
|
v-model:keyword="fileFormData.keyword"
|
|
|
|
|
v-model:category="fileFormData.category"
|
|
|
|
|
@submit="submitFileForm"
|
2023-11-28 09:22:44 +07:00
|
|
|
/>
|
2023-11-28 09:22:44 +07:00
|
|
|
|
2023-11-28 16:30:48 +07:00
|
|
|
<folder-form
|
|
|
|
|
:mode="folderFormType"
|
|
|
|
|
:tree="DEPT_NAME[currentDept]"
|
|
|
|
|
v-if="currentDept < 4"
|
|
|
|
|
v-model:open="folderFormState"
|
|
|
|
|
v-model:name="folderFormData.name"
|
|
|
|
|
@submit="submitFolderForm"
|
2023-11-28 09:24:20 +07:00
|
|
|
/>
|
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;
|
2023-11-28 13:02:25 +07:00
|
|
|
right: 70px;
|
2023-11-23 08:47:44 +07:00
|
|
|
background-color: white;
|
|
|
|
|
}
|
2023-11-28 16:30:48 +07:00
|
|
|
|
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>
|