fixing
This commit is contained in:
parent
a201594756
commit
216a3ff8d7
5 changed files with 78 additions and 9 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import http from "@/plugins/http";
|
||||||
|
import config from "@/app.config";
|
||||||
import DialogHeader from "@/components/DialogHeader.vue";
|
import DialogHeader from "@/components/DialogHeader.vue";
|
||||||
|
|
||||||
const openDialog = defineModel<boolean>("openDialog", {
|
const openDialog = defineModel<boolean>("openDialog", {
|
||||||
|
|
@ -9,7 +11,7 @@ const openDialog = defineModel<boolean>("openDialog", {
|
||||||
defineProps<{
|
defineProps<{
|
||||||
title: string;
|
title: string;
|
||||||
close?: (...args: unknown[]) => void;
|
close?: (...args: unknown[]) => void;
|
||||||
onSend: Function;
|
downloadTxt: Function;
|
||||||
}>();
|
}>();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -33,7 +35,7 @@ defineProps<{
|
||||||
color="blue"
|
color="blue"
|
||||||
type="submit"
|
type="submit"
|
||||||
icon="download"
|
icon="download"
|
||||||
@click="onSend"
|
@click="() => downloadTxt()"
|
||||||
><q-tooltip>ดาวน์โหลด (.TXT)</q-tooltip></q-btn
|
><q-tooltip>ดาวน์โหลด (.TXT)</q-tooltip></q-btn
|
||||||
>
|
>
|
||||||
</q-card-actions>
|
</q-card-actions>
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,13 @@ import DialogDataDiff from "@/modules/03_logs/components/DialogDataDiff.vue";
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
import type { ResLog } from "@/modules/03_logs/interface/response/Main";
|
import type { ResLog } from "@/modules/03_logs/interface/response/Main";
|
||||||
|
import generateTxt from "@/plugins/generateTxt";
|
||||||
|
|
||||||
/** use*/
|
/** use*/
|
||||||
const $q = useQuasar();
|
const $q = useQuasar();
|
||||||
const storeData = useDataStore();
|
const storeData = useDataStore();
|
||||||
const { logData, size, searchAfter, systemName, date } = storeToRefs(storeData);
|
const { logData, size, searchAfter, systemName, date } = storeToRefs(storeData);
|
||||||
const { date2Thai, messageError, hideLoader,dateToISO } = useCounterMixin();
|
const { date2Thai, messageError, hideLoader, dateToISO } = useCounterMixin();
|
||||||
|
|
||||||
const startTime = ref<Date | null>(null); // เวลาเริ่มต้น
|
const startTime = ref<Date | null>(null); // เวลาเริ่มต้น
|
||||||
const endTime = ref<Date | null>(null); //เวลาสินสุด
|
const endTime = ref<Date | null>(null); //เวลาสินสุด
|
||||||
|
|
@ -452,16 +453,31 @@ function onSendCSV() {
|
||||||
params: queryString,
|
params: queryString,
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const data = res.data
|
const data = res.data;
|
||||||
genReportXLSX(data,`LOG_${date2Thai(new Date(startDate.value))}`)
|
genReportXLSX(data, `LOG_${date2Thai(new Date(startDate.value))}`);
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
messageError($q, e);
|
messageError($q, e);
|
||||||
})
|
})
|
||||||
.finally(() => {});
|
.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 () => {
|
onBeforeMount(async () => {
|
||||||
|
|
@ -872,6 +888,7 @@ onMounted(async () => {
|
||||||
() => {
|
() => {
|
||||||
currentDataDiff = col.value;
|
currentDataDiff = col.value;
|
||||||
currentlogData = {
|
currentlogData = {
|
||||||
|
id: props.row.id,
|
||||||
startTimeStamp: props.row.startTimeStamp,
|
startTimeStamp: props.row.startTimeStamp,
|
||||||
username: props.row.userName,
|
username: props.row.userName,
|
||||||
host: props.row.host,
|
host: props.row.host,
|
||||||
|
|
@ -911,7 +928,7 @@ onMounted(async () => {
|
||||||
<DialogDataDiff
|
<DialogDataDiff
|
||||||
v-model:open-dialog="openDialog"
|
v-model:open-dialog="openDialog"
|
||||||
title="รายละเอียดข้อมูล"
|
title="รายละเอียดข้อมูล"
|
||||||
:onSend="onSend"
|
:downloadTxt="downloadTxt"
|
||||||
:close="
|
:close="
|
||||||
() => {
|
() => {
|
||||||
openDialog = false;
|
openDialog = false;
|
||||||
|
|
@ -940,6 +957,7 @@ onMounted(async () => {
|
||||||
>
|
>
|
||||||
{{
|
{{
|
||||||
{
|
{
|
||||||
|
id: "ID",
|
||||||
startTimeStamp: "เวลา",
|
startTimeStamp: "เวลา",
|
||||||
username: "ผู้ใช้",
|
username: "ผู้ใช้",
|
||||||
host: "Host",
|
host: "Host",
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ interface ResRound {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ResLog {
|
interface ResLog {
|
||||||
|
id: string;
|
||||||
endTimeStamp: Date;
|
endTimeStamp: Date;
|
||||||
dataDiff?: {
|
dataDiff?: {
|
||||||
//
|
//
|
||||||
|
|
|
||||||
49
src/plugins/generateTxt.ts
Normal file
49
src/plugins/generateTxt.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
import axios from "axios";
|
||||||
|
import config from "@/app.config";
|
||||||
|
|
||||||
|
import { useQuasar } from "quasar";
|
||||||
|
import { useCounterMixin } from "@/stores/mixin";
|
||||||
|
|
||||||
|
const $q = useQuasar();
|
||||||
|
|
||||||
|
const mixin = useCounterMixin();
|
||||||
|
const { showLoader, hideLoader, messageError } = mixin;
|
||||||
|
|
||||||
|
async function generateTxt(data: any, fileName: string) {
|
||||||
|
showLoader();
|
||||||
|
await axios
|
||||||
|
.post(`${config.API.reportTemplate}/txt`, data, {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "text/plain;charset=utf-8",
|
||||||
|
},
|
||||||
|
responseType: "blob",
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
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;
|
||||||
|
|
@ -27,5 +27,4 @@ export default defineConfig({
|
||||||
server: {
|
server: {
|
||||||
port: 3005,
|
port: 3005,
|
||||||
},
|
},
|
||||||
base: "./",
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue