Merge branch 'dev/methapon' into development
This commit is contained in:
commit
f154a9c32f
5 changed files with 88 additions and 268 deletions
|
|
@ -1,160 +0,0 @@
|
|||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { useTreeDataStore } from '@/stores/tree-data'
|
||||
import TagInput from '@/components/TagInput.vue'
|
||||
|
||||
const { currentPath } = storeToRefs(useTreeDataStore())
|
||||
const { uploadFile, checkFile } = useTreeDataStore()
|
||||
|
||||
const inputFile = ref<File>()
|
||||
const fileTitle = ref<string>('')
|
||||
const fileDesc = ref<string>('')
|
||||
const fileCategory = ref<string>('')
|
||||
const fileKeyword = ref<string>('')
|
||||
const notification = ref<boolean>(false)
|
||||
const emit = defineEmits(['update:drawerFile'])
|
||||
const props = withDefaults(defineProps<{ drawerFile: boolean }>(), {
|
||||
drawerFile: false,
|
||||
})
|
||||
|
||||
const tag = ref('')
|
||||
const tagList = ref<Array<string>>([])
|
||||
|
||||
function deleteTag(index?: string) {
|
||||
console.log(index)
|
||||
|
||||
if (index === undefined) {
|
||||
tagList.value.pop()
|
||||
} else {
|
||||
tagList.value = tagList.value.filter((t) => t !== index)
|
||||
}
|
||||
}
|
||||
|
||||
function saveTag() {
|
||||
if (!!tag.value?.trim()) {
|
||||
tagList.value.push(tag.value)
|
||||
tag.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSubmit(continueUpload: boolean = false) {
|
||||
if (!inputFile.value) return
|
||||
|
||||
if (checkFile(inputFile.value.name) || continueUpload) {
|
||||
await uploadFile(currentPath.value, inputFile.value, {
|
||||
title: fileTitle.value,
|
||||
description: fileDesc.value,
|
||||
keyword: fileKeyword.value,
|
||||
category: fileCategory.value,
|
||||
})
|
||||
} else notification.value = true
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<q-drawer
|
||||
class="q-pa-md"
|
||||
side="right"
|
||||
v-model="props.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="() => $emit('update:drawerFile')"
|
||||
/>
|
||||
</q-toolbar>
|
||||
<span class="text-weight-bold">อัพโหลดไฟล์</span>
|
||||
<q-file
|
||||
v-model="inputFile"
|
||||
class="q-my-md"
|
||||
label="Pick files"
|
||||
dense
|
||||
outlined
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon name="attach_file" />
|
||||
</template>
|
||||
</q-file>
|
||||
<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-input
|
||||
class="q-my-md"
|
||||
outlined
|
||||
v-model="fileCategory"
|
||||
placeholder="เลือกกลุ่ม/หมวดหมู่"
|
||||
dense
|
||||
/>
|
||||
|
||||
<tag-input />
|
||||
</q-drawer>
|
||||
|
||||
<q-dialog
|
||||
v-model="notification"
|
||||
transition-show="scale"
|
||||
transition-hide="scale"
|
||||
>
|
||||
<q-card style="width: 400px">
|
||||
<q-card-section>
|
||||
<div class="text-h6">
|
||||
<q-icon
|
||||
name="error"
|
||||
color="negative"
|
||||
size="2.5rem"
|
||||
/>เตือนพบไฟล์ชื่อซ้ำในระบบ
|
||||
</div>
|
||||
</q-card-section>
|
||||
|
||||
<q-card-section class="q-pt-none">
|
||||
ถ้าดำเนินการต่อจะอัพข้อมูลทับกับอันเก่า
|
||||
</q-card-section>
|
||||
|
||||
<q-card-actions align="right" class="bg-white text-primary">
|
||||
<q-space />
|
||||
<q-btn flat label="ยกเลิก" v-close-popup />
|
||||
|
||||
<q-btn
|
||||
flat
|
||||
label="ดำเนินการต่อ"
|
||||
v-close-popup
|
||||
class="text-red"
|
||||
@click="() => handleSubmit(true)"
|
||||
/>
|
||||
</q-card-actions>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.cursor {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -1,108 +0,0 @@
|
|||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, ref } from 'vue'
|
||||
|
||||
import { useTreeDataStore } from '@/stores/tree-data'
|
||||
const { createFolder, editFolder } = useTreeDataStore()
|
||||
|
||||
const input = ref<string>('')
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
drawer: boolean
|
||||
drawerStatus: 'edit' | 'create'
|
||||
DEPT_NAME: string[]
|
||||
currentDept: number
|
||||
editPathname: string
|
||||
}>(),
|
||||
{
|
||||
drawer: false,
|
||||
drawerStatus: 'create',
|
||||
}
|
||||
)
|
||||
|
||||
let isListenerAdded = false
|
||||
const emit = defineEmits(['update:drawer'])
|
||||
const handleClose = (event: any) => {
|
||||
console.log('key close event')
|
||||
if (event.key === 'Escape') {
|
||||
emit('update:drawer')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (!isListenerAdded) {
|
||||
document.addEventListener('keyup', handleClose)
|
||||
isListenerAdded = true
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<q-drawer
|
||||
class="q-pa-md"
|
||||
side="right"
|
||||
v-model="props.drawer"
|
||||
bordered
|
||||
:width="300"
|
||||
:breakpoint="500"
|
||||
overlay
|
||||
behavior="mobile"
|
||||
>
|
||||
<q-toolbar class="q-mb-md q-pa-none">
|
||||
<q-toolbar-title>
|
||||
<span class="text-weight-bold" v-if="props.drawerStatus == 'edit'"
|
||||
>แก้ไขชื่อ{{ props.DEPT_NAME[props.currentDept] }}</span
|
||||
>
|
||||
<span class="text-weight-bold" v-if="props.drawerStatus == 'create'"
|
||||
>สร้าง{{ props.DEPT_NAME[props.currentDept] }}</span
|
||||
>
|
||||
</q-toolbar-title>
|
||||
<q-btn
|
||||
flat
|
||||
round
|
||||
dense
|
||||
icon="close"
|
||||
v-close-popup
|
||||
color="red"
|
||||
@click="() => $emit('update:drawer')"
|
||||
/>
|
||||
</q-toolbar>
|
||||
<span class="text-weight-bold"
|
||||
>ชื่อ{{ props.DEPT_NAME[props.currentDept] }}</span
|
||||
>
|
||||
<q-input
|
||||
class="q-my-md"
|
||||
outlined
|
||||
v-model="input"
|
||||
:placeholder="`กรอกชื่อ${props.DEPT_NAME[props.currentDept]}`"
|
||||
dense
|
||||
@keyup.enter="
|
||||
() => {
|
||||
$emit('update:drawer')
|
||||
props.drawerStatus === 'create'
|
||||
? createFolder(input)
|
||||
: editFolder(input, editPathname)
|
||||
input = ''
|
||||
}
|
||||
"
|
||||
/>
|
||||
<q-btn
|
||||
class="q-px-md"
|
||||
label="บันทึก"
|
||||
type="submit"
|
||||
color="primary"
|
||||
dense
|
||||
@click="
|
||||
() => {
|
||||
$emit('update:drawer')
|
||||
props.drawerStatus === 'create'
|
||||
? createFolder(input)
|
||||
: editFolder(input, editPathname)
|
||||
input = ''
|
||||
}
|
||||
"
|
||||
/>
|
||||
</q-drawer>
|
||||
</template>
|
||||
|
||||
<style lang="scss"></style>
|
||||
39
Services/client/src/components/GlobalErrorDialog.vue
Normal file
39
Services/client/src/components/GlobalErrorDialog.vue
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<script setup lang="ts">
|
||||
import { watch } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { useErrorStore } from '@/stores/error'
|
||||
import { useLoader } from '@/stores/loader'
|
||||
|
||||
const { visible, title, msg } = storeToRefs(useErrorStore())
|
||||
const loader = useLoader()
|
||||
|
||||
watch(visible, () => {
|
||||
loader.hide()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<q-dialog transition-show="scale" transition-hide="scale" v-model="visible">
|
||||
<q-card style="width: 400px">
|
||||
<q-card-section>
|
||||
<span class="text-h6">
|
||||
<q-icon name="error" color="negative" size="2.5rem" />{{
|
||||
title
|
||||
}}</span
|
||||
>
|
||||
</q-card-section>
|
||||
|
||||
<q-card-section class="q-pt-none">{{ msg }}</q-card-section>
|
||||
|
||||
<q-card-actions align="right" class="bg-white text-primary">
|
||||
<q-space />
|
||||
<q-btn
|
||||
flat
|
||||
v-close-popup
|
||||
label="ปิด"
|
||||
@click="() => (visible = !visible)"
|
||||
/>
|
||||
</q-card-actions>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
</template>
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
import axios from 'axios'
|
||||
import { getToken } from './KeyCloakService'
|
||||
import { useErrorStore } from '@/stores/error'
|
||||
|
||||
const error = useErrorStore()
|
||||
|
||||
const instance = axios.create()
|
||||
|
||||
|
|
@ -8,4 +11,22 @@ instance.interceptors.request.use(async (config) => {
|
|||
return config
|
||||
})
|
||||
|
||||
instance.interceptors.response.use(
|
||||
(res) => res,
|
||||
(err) => {
|
||||
const status = err.response.status
|
||||
const data = err.response.data
|
||||
|
||||
error.title = 'เกิดข้อผิดพลาด'
|
||||
|
||||
if (status === 500) {
|
||||
error.msg = 'เกิดข้อผิดพลาด ไม่สามารถดำเนินการต่อได้ กรุณาลองใหม่อีกครั้ง'
|
||||
} else {
|
||||
error.msg = data.message
|
||||
}
|
||||
|
||||
error.show()
|
||||
},
|
||||
)
|
||||
|
||||
export default instance
|
||||
|
|
|
|||
28
Services/client/src/stores/error.ts
Normal file
28
Services/client/src/stores/error.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
export const useErrorStore = defineStore('error-data', () => {
|
||||
const visible = ref<boolean>(false)
|
||||
const title = ref<string>('')
|
||||
const msg = ref<string>('')
|
||||
|
||||
function set(obj: { title: string; msg: string }, timeout?: number) {
|
||||
title.value = obj.title
|
||||
msg.value = obj.msg
|
||||
show(timeout)
|
||||
}
|
||||
|
||||
function show(timeout: number = -1) {
|
||||
visible.value = true
|
||||
|
||||
if (timeout > 0) {
|
||||
setTimeout(() => (visible.value = false), timeout)
|
||||
}
|
||||
}
|
||||
|
||||
function hide() {
|
||||
visible.value = false
|
||||
}
|
||||
|
||||
return { visible, title, msg, show, hide, set }
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue