diff --git a/src/modules/03_logs/components/DialogDataDiff.vue b/src/modules/03_logs/components/DialogDataDiff.vue
index bf10dde1..4c1bbdeb 100644
--- a/src/modules/03_logs/components/DialogDataDiff.vue
+++ b/src/modules/03_logs/components/DialogDataDiff.vue
@@ -1,4 +1,6 @@
@@ -33,7 +35,7 @@ defineProps<{
color="blue"
type="submit"
icon="download"
- @click="onSend"
+ @click="() => downloadTxt()"
>ดาวน์โหลด (.TXT)
diff --git a/src/modules/03_logs/components/LogTable.vue b/src/modules/03_logs/components/LogTable.vue
index f2936ad7..9eec6833 100644
--- a/src/modules/03_logs/components/LogTable.vue
+++ b/src/modules/03_logs/components/LogTable.vue
@@ -22,12 +22,13 @@ import DialogDataDiff from "@/modules/03_logs/components/DialogDataDiff.vue";
const route = useRoute();
import type { ResLog } from "@/modules/03_logs/interface/response/Main";
+import generateTxt from "@/plugins/generateTxt";
/** use*/
const $q = useQuasar();
const storeData = useDataStore();
const { logData, size, searchAfter, systemName, date } = storeToRefs(storeData);
-const { date2Thai, messageError, hideLoader,dateToISO } = useCounterMixin();
+const { date2Thai, messageError, hideLoader, dateToISO } = useCounterMixin();
const startTime = ref(null); // เวลาเริ่มต้น
const endTime = ref(null); //เวลาสินสุด
@@ -452,16 +453,31 @@ function onSendCSV() {
params: queryString,
})
.then((res) => {
- const data = res.data
- genReportXLSX(data,`LOG_${date2Thai(new Date(startDate.value))}`)
+ const data = res.data;
+ genReportXLSX(data, `LOG_${date2Thai(new Date(startDate.value))}`);
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {});
}
-function onSend() {
- console.log(1);
+
+function downloadTxt() {
+ const queryString = {
+ id: currentlogData.value?.id,
+ };
+ http
+ .get(`${config.API.log}/report/logsDetail`, {
+ params: queryString,
+ })
+ .then((res) => {
+ const data = res.data;
+ generateTxt(data, `LOG_${date2Thai(new Date(startDate.value))}`);
+ })
+ .catch((e) => {
+ messageError($q, e);
+ })
+ .finally(() => {});
}
onBeforeMount(async () => {
@@ -872,6 +888,7 @@ onMounted(async () => {
() => {
currentDataDiff = col.value;
currentlogData = {
+ id: props.row.id,
startTimeStamp: props.row.startTimeStamp,
username: props.row.userName,
host: props.row.host,
@@ -911,7 +928,7 @@ onMounted(async () => {
{
+ const data = res.data;
+ if (data) {
+ // สร้าง Blob จาก array buffer
+ const blob = new Blob([data], { type: "text/plain;charset=utf-8" });
+
+ // สร้าง URL สำหรับไฟล์ Blob
+ const url = URL.createObjectURL(blob);
+
+ // สร้างลิงก์เพื่อดาวน์โหลดไฟล์
+ const link = document.createElement("a");
+ link.href = url;
+ link.download = `${fileName}.txt`; // กำหนดชื่อไฟล์ที่จะดาวน์โหลด
+ document.body.appendChild(link);
+ link.click();
+
+ // ลบ URL ที่สร้างขึ้นหลังจากใช้งาน
+ URL.revokeObjectURL(url);
+ }
+ })
+ .catch((err) => {
+ messageError($q, err);
+ })
+ .finally(() => {
+ hideLoader();
+ });
+}
+
+export default generateTxt;
diff --git a/vite.config.ts b/vite.config.ts
index b7e8a8b8..4ca2354a 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -27,5 +27,4 @@ export default defineConfig({
server: {
port: 3005,
},
- base: "./",
});