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">
|
||||
import http from "@/plugins/http";
|
||||
import config from "@/app.config";
|
||||
import DialogHeader from "@/components/DialogHeader.vue";
|
||||
|
||||
const openDialog = defineModel<boolean>("openDialog", {
|
||||
|
|
@ -9,7 +11,7 @@ const openDialog = defineModel<boolean>("openDialog", {
|
|||
defineProps<{
|
||||
title: string;
|
||||
close?: (...args: unknown[]) => void;
|
||||
onSend: Function;
|
||||
downloadTxt: Function;
|
||||
}>();
|
||||
</script>
|
||||
|
||||
|
|
@ -33,7 +35,7 @@ defineProps<{
|
|||
color="blue"
|
||||
type="submit"
|
||||
icon="download"
|
||||
@click="onSend"
|
||||
@click="() => downloadTxt()"
|
||||
><q-tooltip>ดาวน์โหลด (.TXT)</q-tooltip></q-btn
|
||||
>
|
||||
</q-card-actions>
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ 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();
|
||||
|
|
@ -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 () => {
|
|||
<DialogDataDiff
|
||||
v-model:open-dialog="openDialog"
|
||||
title="รายละเอียดข้อมูล"
|
||||
:onSend="onSend"
|
||||
:downloadTxt="downloadTxt"
|
||||
:close="
|
||||
() => {
|
||||
openDialog = false;
|
||||
|
|
@ -940,6 +957,7 @@ onMounted(async () => {
|
|||
>
|
||||
{{
|
||||
{
|
||||
id: "ID",
|
||||
startTimeStamp: "เวลา",
|
||||
username: "ผู้ใช้",
|
||||
host: "Host",
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ interface ResRound {
|
|||
}
|
||||
|
||||
interface ResLog {
|
||||
id: string;
|
||||
endTimeStamp: Date;
|
||||
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: {
|
||||
port: 3005,
|
||||
},
|
||||
base: "./",
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue