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

356 lines
9.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'
import FileItemAction from '@/components/FileItemAction.vue'
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 = ['ตู้เอกสาร', 'ลิ้นชัก', 'แฟ้ม', 'แฟ้มย่อย']
const { currentFolder, currentFile, currentDept } = storeToRefs(
useTreeDataStore()
)
const { getFolder, createFolder, editFolder } = useTreeDataStore()
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 input = ref<string>('')
2023-11-23 17:33:15 +07:00
const inputFile = ref<File>()
const fileTitle = ref<string>('')
const fileDesc = ref<string>('')
const fileCategory = ref<string>('')
const optionsCategory = [
{ label: 'ศิลปะ', value: 'art' },
{ label: 'ภาพวาด', value: 'drawing' },
{ label: 'ภาษาไทย', value: 'thai' },
]
const fileKeyword = ref<string>('')
2023-11-23 08:47:44 +07:00
const editPathname = ref<string>('')
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">
<div class="q-gutter-md">
<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)">
<q-card-section class="column justify-center relative q-px-xl">
<q-icon :name="currentIcon" size="6em" color="primary" />
<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>
<span class="text-center q-pt-md">{{ value.name }}</span>
</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"
@keydown.esc="() => (drawer = false)"
>
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>
</div>
<div class="q-mt-md">
<div class="q-gutter-md">
<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">
<q-icon name="description" size="6em" color="primary" />
<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
name="description"
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>
<q-drawer
class="q-pa-md"
side="right"
v-model="drawer"
bordered
:width="300"
:breakpoint="500"
overlay
2023-11-23 17:33:15 +07:00
behavior="mobile"
tabindex="0"
@keydown.esc="
() => {
drawer = false
input = ''
}
"
@keyup.enter="
() => {
drawer = false
drawerStatus === 'create'
? createFolder(input)
: editFolder(input, editPathname)
input = ''
}
"
2023-11-23 08:47:44 +07:00
>
2023-11-23 17:33:15 +07:00
<q-toolbar class="q-mb-md q-pa-none" @keydown.esc="() => (drawer = false)">
2023-11-23 08:47:44 +07:00
<q-toolbar-title>
<span class="text-weight-bold" v-if="drawerStatus == 'edit'"
>แกไขช{{ DEPT_NAME[currentDept] }}</span
>
<span class="text-weight-bold" v-if="drawerStatus == 'create'"
>สราง{{ DEPT_NAME[currentDept] }}</span
>
</q-toolbar-title>
<q-btn
flat
round
dense
icon="close"
v-close-popup
color="red"
2023-11-23 17:33:15 +07:00
@click="() => (drawer = !drawer)"
2023-11-23 08:47:44 +07:00
/>
</q-toolbar>
<span class="text-weight-bold">{{ DEPT_NAME[currentDept] }}</span>
<q-input
class="q-my-md"
outlined
v-model="input"
:placeholder="`กรอกชื่อ${DEPT_NAME[currentDept]}`"
dense
/>
<q-btn
class="q-px-md"
label="บันทึก"
type="submit"
color="primary"
dense
@click="
() => {
drawer = !drawer
drawerStatus === 'create'
? createFolder(input)
: editFolder(input, editPathname)
input = ''
}
"
/>
</q-drawer>
2023-11-23 17:33:15 +07:00
<q-drawer
class="q-pa-md"
side="right"
v-model="drawerFile"
bordered
:width="300"
:breakpoint="500"
overlay
>
<q-toolbar class="q-mb-md q-pa-none">
<q-toolbar-title>
<span class="text-weight-bold">สรางเอกสาร</span>
</q-toolbar-title>
<q-btn
flat
round
dense
icon="close"
v-close-popup
color="red"
@click="() => (drawerFile = !drawerFile)"
/>
</q-toolbar>
<span class="text-weight-bold">พโหลดไฟล</span>
<q-input
model-value="inputfile"
class="q-my-md"
outlined
type="file"
:placeholder="`กรอกชื่อ${DEPT_NAME[currentDept]}`"
dense
/>
<span class="text-weight-bold">อเรอง</span>
<q-input
class="q-my-md"
outlined
v-model="fileTitle"
placeholder="กรอกชื่อเรื่อง"
dense
/>
<span class="text-weight-bold">รายละเอยดของเอกสาร</span>
<q-input
class="q-my-md"
outlined
type="textarea"
v-model="fileDesc"
placeholder="กรอกรายละเอียด"
dense
/>
<span class="text-weight-bold">กล/หมวดหม</span>
<q-select
class="q-my-md"
outlined
:options="optionsCategory"
v-model="fileCategory"
placeholder="เลือกกลุ่ม/หมวดหมู่"
dense
/>
<span class="text-weight-bold">คำสำค</span>
<q-input
class="q-my-md"
outlined
v-model="fileKeyword"
placeholder="กรอกคำสำคัญ"
dense
/>
<q-btn
class="q-px-md"
label="บันทึก"
type="submit"
color="primary"
dense
@click="
() => {
drawerFile = !drawerFile
}
"
/>
</q-drawer>
2023-11-23 08:47:44 +07:00
</template>
<style lang="scss" scoped>
.box {
display: inline-block;
border: 2px solid #f1f2f4;
border-radius: 8px;
cursor: pointer;
}
.dashed {
opacity: 0.4;
display: inline-block;
border: 2px solid #babdc3;
border-radius: 8px;
cursor: pointer;
border-style: dashed;
}
.add-icon {
margin: auto auto;
}
.add-button {
position: absolute;
top: 75px;
right: 45px;
background-color: white;
}
</style>