hrms-user/src/modules/06_evaluate/components/step/step7.vue

94 lines
2 KiB
Vue
Raw Normal View History

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";
2024-01-08 14:19:08 +07:00
import { useQuasar } from "quasar";
2023-12-22 16:00:05 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
import axios from "axios";
2023-12-13 16:56:43 +07:00
2024-01-08 14:19:08 +07:00
/** importStroe*/
2023-12-13 16:56:43 +07:00
import { useCounterMixin } from "@/stores/mixin";
2024-01-08 14:19:08 +07:00
/** use*/
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();
2023-12-22 16:00:05 +07:00
const { showLoader, hideLoader, messageError } = mixin;
2024-01-08 14:19:08 +07:00
/** emit*/
2023-12-22 16:00:05 +07:00
const emit = defineEmits(["update:file"]);
2023-12-13 16:56:43 +07:00
2024-01-08 14:19:08 +07:00
/** id ประเมิน*/
const evaluateId = ref<string>(route.params.id.toString());
2023-12-13 16:56:43 +07:00
const selectedItem = ref(1);
2024-01-08 14:19:08 +07:00
/** function เรีกยเอกสาร*/
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
2024-01-08 14:19:08 +07:00
/**
* function ดาวนโหลดไฟล
* @param url งกดาวนโหลดไฟล
*/
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);
emit("update:file", objectUrl, url);
2023-12-22 16:00:05 +07:00
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
2024-01-08 14:19:08 +07:00
/** HooK lifecycle*/
2023-12-22 16:00:05 +07:00
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"
class=" cursor-pointer"
2023-12-13 16:56:43 +07:00
>
<q-item-section>เอกสารเล 2</q-item-section>
</q-item>
</q-list>
2023-12-13 15:24:59 +07:00
</template>
<style scoped></style>