From f68c4af30b30b06e9e1429576aac57d971c67842 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Wed, 11 Sep 2024 18:06:04 +0700 Subject: [PATCH] updated --- .../05_command/components/FormTemplate.vue | 151 ++++++++++++++++++ src/modules/05_command/components/ViewPdf.vue | 86 ++++++++-- .../05_command/interface/index/Main.ts | 2 +- src/modules/05_command/stores/main.ts | 8 +- src/modules/05_command/views/lists.vue | 46 ++++-- src/plugins/genreport.ts | 2 +- 6 files changed, 261 insertions(+), 34 deletions(-) create mode 100644 src/modules/05_command/components/FormTemplate.vue diff --git a/src/modules/05_command/components/FormTemplate.vue b/src/modules/05_command/components/FormTemplate.vue new file mode 100644 index 00000000..00def0f9 --- /dev/null +++ b/src/modules/05_command/components/FormTemplate.vue @@ -0,0 +1,151 @@ + + + diff --git a/src/modules/05_command/components/ViewPdf.vue b/src/modules/05_command/components/ViewPdf.vue index d087bcc5..060d6ae3 100644 --- a/src/modules/05_command/components/ViewPdf.vue +++ b/src/modules/05_command/components/ViewPdf.vue @@ -4,8 +4,10 @@ import { VuePDF, usePDF } from "@tato30/vue-pdf"; import { useQuasar } from "quasar"; import { useCounterMixin } from "@/stores/mixin"; -import http from "@/plugins/http"; import config from "@/app.config"; +import axios from "axios"; + +// import genReport from "@/plugins/genreport"; const $q = useQuasar(); const mixin = useCounterMixin(); @@ -48,25 +50,77 @@ function backPage() { } } -const showDocument = (url: any) => { - const pdfData = usePDF(url); - setTimeout(() => { - pdfSrc.value = pdfData.pdf.value; - numOfPages.value = pdfData.pages.value; - }, 1000); -}; +function replaceAllTag(html: string) { + return html.replace("div", "p"); +} + +async function fetchDocumentTemplate() { + showLoader(); + let textEditHeader = ""; + let textEditBody = ""; + let textEditFooter = ""; + textEditHeader += + "อาศัยอำนาจตามความในมาตรา ๔๔ และมาตรา ๕๒ (๔) แห่งพระราชบัญญัติระเบียบข้าราชการ-กรุงเทพมหานครและบุคลากรกรุงเทพมหานคร พ.ศ. ๒๕๕๔ ประกอบกับกฎ ก.ก. ว่าด้วยการทดลองปฏิบัติ-หน้าที่ราชการและการพัฒนาข้าราชการกรุงเทพมหานครสามัญที่อยู่ระหว่างทดลองปฏิบัติหน้าที่ราชการ พ.ศ. ๒๕๕๕ มติคณะกรรมการข้าราชการกรุงเทพมหานครและบุคลากรกรุงเทพมหานคร ครั้งที่ ๑/๒๕๕๔ เมื่อวันที่ ๒๒ ธันวาคม ๒๕๕๔ มติ อ.ก.ก. วิสามัญเกี่ยวกับระบบราชการ การจัดส่วนราชการ และค่าตอบแทน ครั้งที่ ๙/๒๕๕๖"; + + textEditBody += + "เมื่อวันที่ ๑๘ กันยายน ๒๕๕๖ ประกาศผลการสอบแข่งขันสำนักงานคณะกรรมการ-ข้าราชการกรุงเทพมหานคร ครั้งที่ ๑/๒๕๖๔ ลงวันที่ ๒๙ เมษายน ๒๕๖๕ ตำแหน่งนักทรัพยากรบุคคลปฏิบัติการ จึงบรรจุและแต่งตั้งผู้สอบแข่งขันได้เข้ารับราชการเป็นข้าราชการกรุงเทพมหานครสามัญ และแต่งตั้งให้ดำรงตำแหน่งนักทรัพยากรบุคคลปฏิบัติการ จำนวน ๔ ราย"; + + textEditFooter += "ดังบัญชีรายละเอียดแนบท้ายคำสั่งนี้"; + const data = await { + template: "command_test", + reportName: "docx-report", + data: { + commandNo: "๑๒", + commandYear: "๒๕๖๗", + commandTitle: "บรรจุและแต่งตั้งผู้สอบแข่งขันได้", + detailHeader: textEditHeader, + detailBody: + '

' + + replaceAllTag(textEditBody) + + "

", + detailFooter: + '

' + + replaceAllTag(textEditFooter) + + "

", + commandDate: "๑ สิงหาคม ๒๕๖๗", + name: "Admin Administrator", + position: "Admin Administrator", + }, + }; + + // genReport(data, `คำสั่ง`); + + await axios + .post(config.API.reportTemplate + `/docx/html`, data, { + headers: { + accept: "application/pdf", + "content-Type": "application/json", + }, + responseType: "blob", + }) + .then(async (res) => { + const blob = new Blob([res.data]); + const objectUrl = URL.createObjectURL(blob); + + const pdfData = await usePDF(`${objectUrl}`); + showLoader(); + setTimeout(() => { + pdfSrc.value = pdfData.pdf.value; + numOfPages.value = pdfData.pages.value; + hideLoader(); + }, 1500); + }) + .catch(async (e) => { + messageError($q, e); + hideLoader(); + }); +} watch( () => idOrder.value, (newValue, oldValue) => { if (newValue && newValue !== oldValue) { - showLoader(); - setTimeout(() => { - const url = - "https://s3cluster.frappet.com/public/template-command.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=A3O4SZ1Q1L0A2SPWLMDY%2F20240909%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240909T064638Z&X-Amz-Expires=604800&X-Amz-Security-Token=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3NLZXkiOiJBM080U1oxUTFMMEEyU1BXTE1EWSIsImV4cCI6MTcyNTkwNzE4MiwicGFyZW50IjoiZnJhcHBldCJ9.4opHdRH9VegUbtcHsIucy-SpWyboCcuhg2jjtLT4Ypvg2Yg8WvvLoyL92-IabqEYlNvv_sMJMa7P8oQkMqpsSA&X-Amz-SignedHeaders=host&versionId=null&X-Amz-Signature=fce8a76e6d5d3e83eac102402b07ba2a8ac8c2a1e0a055f1d8a5ecc74434c0e0"; - showDocument(url); - hideLoader(); - }, 1000); + fetchDocumentTemplate(); } }, { immediate: true } @@ -81,7 +135,7 @@ watch( outlined dense v-model="documentFile" - label="ไฟล์เอกสารหลักฐาน" + :label="`ไฟล์ต้นแบบ${type == 'order' ? 'คำสั่ง' : 'บัญชีแนบท้าย'}`" hide-bottom-space :accept="type == 'order' ? '.docx' : '.pdf'" clearable diff --git a/src/modules/05_command/interface/index/Main.ts b/src/modules/05_command/interface/index/Main.ts index 86940184..5e8957ec 100644 --- a/src/modules/05_command/interface/index/Main.ts +++ b/src/modules/05_command/interface/index/Main.ts @@ -3,7 +3,7 @@ interface Pagination { } interface ActiveOptions { - value: string; + value: boolean; label: string; } diff --git a/src/modules/05_command/stores/main.ts b/src/modules/05_command/stores/main.ts index 6cfa100a..b8660b95 100644 --- a/src/modules/05_command/stores/main.ts +++ b/src/modules/05_command/stores/main.ts @@ -3,7 +3,13 @@ import { ref } from "vue"; export const useDataStore = defineStore("commandStore", () => { const currentTab = ref("order"); + const toolbarOptions = ref([ + ["left", "center", "right", "justify"], + ["token", "bold", "italic", "underline", "subscript", "superscript"], + ]); + return { - currentTab + currentTab, + toolbarOptions, }; }); diff --git a/src/modules/05_command/views/lists.vue b/src/modules/05_command/views/lists.vue index fb37d6a9..d52c8d4d 100644 --- a/src/modules/05_command/views/lists.vue +++ b/src/modules/05_command/views/lists.vue @@ -15,6 +15,7 @@ import type { import Header from "@/components/DialogHeader.vue"; import PageOrder from "@/modules/05_command/components/ViewPdf.vue"; +import TemplateDetail from "@/modules/05_command/components/FormTemplate.vue"; const $q = useQuasar(); const mixin = useCounterMixin(); @@ -28,18 +29,20 @@ const { messageError, } = mixin; -const inActive = ref(""); //Select Active/InActive +const isActive = ref(""); // สถานะของรายการคำสั่ง +// options สถานะการใช้งาน const activeOptions = ref([ { - value: "Active", + value: true, label: "Active", }, { - value: "InActive", + value: false, label: "InActive", }, ]); +// Tabs const tabs = ref([ { value: "order", @@ -49,25 +52,32 @@ const tabs = ref([ value: "account", label: "บัญชีแนบท้าย", }, + { + value: "template", + label: "ข้อความต้นแบบ", + }, ]); -const idOrder = ref(""); -const activeOrderId = ref(""); +const idOrder = ref(""); // Id คำสั่ง +const activeOrderId = ref(""); // Id คำสั่งที่เลือก const name = ref(""); // ชื่อคำสั่ง const listOrder = ref([]); // list คำสั่ง const status = ref(false); // สถานะ const isEdit = ref(false); //เก็บ true/false เช็คแก้ไข -const modelDialogActive = ref(false); // model คำสั่ง +const dialogFormCommand = ref(false); // model คำสั่ง -/** search Active / InActive */ -function searchActive(val: string) { +/** + * ฟังก์ชั่นค้นหาคำสั่ง ตามสถานะ + * @param val สถานะ true/false + */ +function searchByStatus(val: string) { console.log(val); } /** เปิด dialog */ function onDialogAdd() { isEdit.value = false; - modelDialogActive.value = true; + dialogFormCommand.value = true; } /** * เปิด dialog Edit @@ -79,7 +89,7 @@ function onDialogEdit(data: ListOrder) { status.value = data.status; isEdit.value = true; - modelDialogActive.value = true; + dialogFormCommand.value = true; } /** @@ -102,7 +112,7 @@ function onDelete(id: string) { function closeDialog() { idOrder.value = ""; isEdit.value = false; - modelDialogActive.value = false; + dialogFormCommand.value = false; name.value = ""; status.value = false; } @@ -174,14 +184,14 @@ onMounted(() => { @@ -294,6 +304,12 @@ onMounted(() => { :id-order="activeOrderId" /> + + +
@@ -315,11 +331,11 @@ onMounted(() => {
- +
diff --git a/src/plugins/genreport.ts b/src/plugins/genreport.ts index 0673a76a..4886a895 100644 --- a/src/plugins/genreport.ts +++ b/src/plugins/genreport.ts @@ -12,7 +12,7 @@ const { showLoader, hideLoader, messageError } = mixin; async function genReport(data: any, fileName: string, type: string = "docx") { showLoader(); await axios - .post(`${config.API.reportTemplate}/docx`, data, { + .post(`${config.API.reportTemplate}/docx/html`, data, { headers: type == "docx" ? {