2023-12-13 16:56:43 +07:00
|
|
|
<script setup lang="ts">
|
2023-12-22 16:00:05 +07:00
|
|
|
import { onMounted, ref } from "vue";
|
2023-12-27 12:08:36 +07:00
|
|
|
import { useRoute } from "vue-router";
|
2023-12-22 16:00:05 +07:00
|
|
|
import http from "@/plugins/http";
|
|
|
|
|
import config from "@/app.config";
|
|
|
|
|
import { useQuasar } from "quasar";
|
|
|
|
|
import axios from "axios";
|
2023-12-13 16:56:43 +07:00
|
|
|
|
|
|
|
|
import { useCounterMixin } from "@/stores/mixin";
|
2023-12-14 14:49:27 +07:00
|
|
|
import { useEvaluateStore } from "@/modules/06_evaluate/store";
|
2023-12-13 16:56:43 +07:00
|
|
|
|
2023-12-14 14:49:27 +07:00
|
|
|
const store = useEvaluateStore();
|
2023-12-13 16:56:43 +07:00
|
|
|
const mixin = useCounterMixin();
|
2023-12-22 16:00:05 +07:00
|
|
|
const $q = useQuasar();
|
2023-12-27 12:08:36 +07:00
|
|
|
const route = useRoute();
|
|
|
|
|
|
|
|
|
|
const evaluateId = ref<string>(route.params.id.toString());
|
2023-12-22 16:00:05 +07:00
|
|
|
|
|
|
|
|
const { showLoader, hideLoader, messageError } = mixin;
|
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
evaluateId: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(["update:file"]);
|
2023-12-13 16:56:43 +07:00
|
|
|
|
|
|
|
|
const selectedItem = ref(1);
|
|
|
|
|
|
2023-12-22 16:00:05 +07:00
|
|
|
async function fetchDocument() {
|
|
|
|
|
showLoader();
|
2023-12-27 12:08:36 +07:00
|
|
|
evaluateId.value &&
|
2023-12-22 16:00:05 +07:00
|
|
|
(await http
|
|
|
|
|
.get(
|
|
|
|
|
config.API.loadFileDocument(
|
|
|
|
|
"เล่ม 2",
|
2023-12-27 12:08:36 +07:00
|
|
|
evaluateId.value,
|
2023-12-22 16:00:05 +07:00
|
|
|
"1-เอกสารเล่ม 2"
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
downloadFile(res.data.downloadUrl);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
}));
|
2023-12-13 16:56:43 +07:00
|
|
|
}
|
2023-12-22 16:00:05 +07:00
|
|
|
|
|
|
|
|
async function downloadFile(url: string) {
|
|
|
|
|
await axios
|
|
|
|
|
.get(url, {
|
|
|
|
|
responseType: "blob",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.then((res) => {
|
|
|
|
|
const blob = new Blob([res.data]);
|
|
|
|
|
const objectUrl = URL.createObjectURL(blob);
|
|
|
|
|
|
2024-01-03 17:03:25 +07:00
|
|
|
emit("update:file", objectUrl, url);
|
2023-12-22 16:00:05 +07:00
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
hideLoader();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
await fetchDocument();
|
|
|
|
|
});
|
2023-12-13 16:56:43 +07:00
|
|
|
</script>
|
2023-12-13 15:24:59 +07:00
|
|
|
|
|
|
|
|
<template>
|
2023-12-13 16:56:43 +07:00
|
|
|
<q-list separator>
|
|
|
|
|
<q-item
|
|
|
|
|
clickable
|
|
|
|
|
v-ripple
|
|
|
|
|
:active="selectedItem === 1 ? true : false"
|
|
|
|
|
active-class="text-primary"
|
|
|
|
|
>
|
|
|
|
|
<q-item-section>เอกสารเล่ม 2</q-item-section>
|
|
|
|
|
</q-item>
|
|
|
|
|
</q-list>
|
2023-12-13 15:24:59 +07:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped></style>
|