diff --git a/src/api/api.development.ts b/src/api/api.development.ts index 63a9c04..94606b1 100644 --- a/src/api/api.development.ts +++ b/src/api/api.development.ts @@ -1,9 +1,15 @@ import env from "./index"; const development = `${env.API_URI}/development`; +const urlFile = `${env.API_URI}/salary`; export default { // portfolio portfolio: `${development}/portfolio`, portfolioId: (id: string) => `${development}/portfolio/${id}`, + + file: (name: string, group: string, id: string) => + `${urlFile}/file/${name}/${group}/${id}`, + fileByFile: (name: string, group: string, id: string, fileName: string) => + `${urlFile}/file/${name}/${group}/${id}/${fileName}`, }; diff --git a/src/modules/13_portfolio/views/Add.vue b/src/modules/13_portfolio/views/Add.vue index ce21b3b..a3044dc 100644 --- a/src/modules/13_portfolio/views/Add.vue +++ b/src/modules/13_portfolio/views/Add.vue @@ -5,6 +5,7 @@ import { useRouter, useRoute } from "vue-router"; import { useCounterMixin } from "@/stores/mixin"; import http from "@/plugins/http"; import config from "@/app.config"; +import axios from "axios"; import type { QForm } from "quasar"; const router = useRouter(); @@ -20,8 +21,8 @@ const files = ref(); const name = ref(""); const detail = ref(""); const id = ref(""); -const nameFile = ref(""); const routeName = router.currentRoute.value.name; +const fileList = ref([]); /** * เรียกฟังก์ชันทั้งหมดตอนเรียกใช้ไฟล์นี้ @@ -49,20 +50,13 @@ const saveData = async () => { */ const createTransfer = async () => { showLoader(); - // const formData = new FormData(); - // formData.append("name", name.value); - // formData.append("detail", detail.value); - // formData.append("file", files.value); await http .post(config.API.portfolio, { name: name.value, detail: detail.value }) - .then((res: any) => { - success($q, "บันทึกข้อมูลสำเร็จ"); - router.push(`/portfolio`); + .then(async (res) => { + uploadFiles(res.data.result); }) - .catch((e: any) => { + .catch((e) => { messageError($q, e); - }) - .finally(() => { hideLoader(); }); }; @@ -77,34 +71,111 @@ const fecthData = async (id: string) => { .get(config.API.portfolioId(id)) .then((res: any) => { let data = res.data.result; - name.value = data.organization; - detail.value = data.reason; - files.value = data.docs; + name.value = data.name; + detail.value = data.detail; + fetchFile(); }) .catch((e: any) => { messageError($q, e); - }) - .finally(() => { hideLoader(); }); }; /** - * ฟังก์ชั่นดาว์โหลดอัปโหลดไฟล์ + * function อัปโหลดไฟล์ + * @param id ผลงาน */ -const fileDocDataUpload = ref([]); -const filesNull = () => { - files.value = null; -}; -//อัปโหลดไฟล์ -const fileUploadDoc = async (file: any) => { - fileDocDataUpload.value.push(file); - nameFile.value = file[0].name; - files.value = file; -}; +function uploadFiles(id: string) { + showLoader(); + http + .post(config.API.file("รายการเอกสาร", "เอกสารผลงาน", id), { + replace: true, + fileList: [ + { + fileName: files.value.name, + }, + ], + }) + .then(async (res) => { + console.log(res); + const foundKey: string | undefined = Object.keys(res.data).find( + (key) => + res.data[key]?.fileName !== undefined && + res.data[key]?.fileName !== "" + ); + foundKey && uploadFileURL(res.data[foundKey]?.uploadUrl); + }) + .catch((err) => { + messageError($q, err); + hideLoader(); + }); +} -function fileOpen(url: string) { - window.open(url, "_blank"); +/** + * function บันทึกไฟล์ + * @param uploadUrl บันทึกไฟล์ + */ +function uploadFileURL(uploadUrl: string) { + const Data = new FormData(); + Data.append("file", files.value); + showLoader(); + axios + .put(uploadUrl, files.value, { + headers: { + "Content-Type": files.value.type, + }, + }) + .then(() => { + success($q, "บันทึกข้อมูลสำเร็จ"); + router.push(`/portfolio`); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + files.value = null; + }); +} + +/** + *function fetch รายการเอกสาร + */ +function fetchFile() { + showLoader(); + http + .get(config.API.file("รายการเอกสาร", "เอกสารผลงาน", id.value)) + .then((res) => { + fileList.value = res.data; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + }); +} + +/** + * ฟังก์ชั่นดาว์โหลดอัปโหลดไฟล์ + * @param fileName ชื่อไฟล์ + */ +function fileOpen(fileName: string) { + showLoader(); + http + .get( + config.API.fileByFile("รายการเอกสาร", "เอกสารผลงาน", id.value, fileName) + ) + .then((res) => { + const data = res.data.downloadUrl; + window.open(data, "_blank"); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + hideLoader(); + }); } @@ -189,7 +260,7 @@ function fileOpen(url: string) { - + {{ file.fileName }} @@ -199,7 +270,7 @@ function fileOpen(url: string) { round flat icon="mdi-download" - @click="fileOpen(file.pathName)" + @click="fileOpen(file.fileName)" > diff --git a/src/modules/13_portfolio/views/Main.vue b/src/modules/13_portfolio/views/Main.vue index 7be953d..f192473 100644 --- a/src/modules/13_portfolio/views/Main.vue +++ b/src/modules/13_portfolio/views/Main.vue @@ -11,7 +11,14 @@ const currentPage = ref(1); const router = useRouter(); const $q = useQuasar(); const mixin = useCounterMixin(); -const { date2Thai, messageError, showLoader, hideLoader } = mixin; +const { + date2Thai, + messageError, + showLoader, + hideLoader, + dialogRemove, + success, +} = mixin; const pagination = ref({ sortBy: "desc", @@ -91,6 +98,22 @@ const clickAdd = async () => { const clickBack = () => { router.push(`/`); }; + +function onDelete(id: string) { + dialogRemove($q, () => { + showLoader(); + http + .delete(config.API.portfolioId(id)) + .then((res) => { + success($q, "ลบข้อมูลสำเร็จ"); + fecthList(); + }) + .catch((err) => { + messageError($q, err); + hideLoader(); + }); + }); +} diff --git a/src/style/quasar-variables.sass b/src/style/quasar-variables.sass index 13b1d30..1930ed5 100644 --- a/src/style/quasar-variables.sass +++ b/src/style/quasar-variables.sass @@ -89,5 +89,28 @@ input.input-alert text-overflow: ellipsis width: 200px -.q-card__actions .q-btn--rectangle - padding: 0 14px !important \ No newline at end of file +.q-card__actions .q-btn--rectangle + padding: 0 14px !important + +.table_ellipsis + max-width: 200px + white-space: nowrap + overflow: hidden + text-overflow: ellipsis + +.table_ellipsis:hover + word-wrap: break-word + overflow: visible + white-space: normal + +.table_ellipsis2 + max-width: 25vw + white-space: nowrap + overflow: hidden + text-overflow: ellipsis + +.table_ellipsis2:hover + word-wrap: break-word + overflow: visible + white-space: normal + transition: width 2s