fig bug file kpi

This commit is contained in:
Warunee Tamkoo 2024-07-02 23:22:35 +07:00
parent 5d13ddb214
commit c19292adc3

View file

@ -25,7 +25,9 @@ interface ArrayFileList {
fileName: string; fileName: string;
} }
const isReadonly = ref<boolean>(route.name === "KPIEditEvaluator" ? true : false); const isReadonly = ref<boolean>(
route.name === "KPIEditEvaluator" ? true : false
);
const documentFile = ref<any>(null); const documentFile = ref<any>(null);
const fileList = ref<ArrayFileList[]>([]); const fileList = ref<ArrayFileList[]>([]);
@ -33,7 +35,7 @@ const fileList = ref<ArrayFileList[]>([]);
async function getData() { async function getData() {
showLoader(); showLoader();
await http await http
.get(config.API.KpiFile + `/KPI/ไฟล์เอกสาร/${id.value}`) .get(config.API.file("ไฟล์เอกสาร", "KPI", id.value))
.then((res) => { .then((res) => {
fileList.value = res.data; fileList.value = res.data;
}) })
@ -48,7 +50,6 @@ async function getData() {
async function uploadFileDoc(uploadUrl: string, file: any) { async function uploadFileDoc(uploadUrl: string, file: any) {
const Data = new FormData(); const Data = new FormData();
Data.append("file", documentFile.value); Data.append("file", documentFile.value);
showLoader();
await axios await axios
.put(uploadUrl, file, { .put(uploadUrl, file, {
headers: { headers: {
@ -63,8 +64,8 @@ async function uploadFileDoc(uploadUrl: string, file: any) {
messageError($q, e); messageError($q, e);
}) })
.finally(() => { .finally(() => {
hideLoader();
documentFile.value = null; documentFile.value = null;
hideLoader();
}); });
} }
async function clickUpload(file: any) { async function clickUpload(file: any) {
@ -73,11 +74,12 @@ async function clickUpload(file: any) {
dialogConfirm( dialogConfirm(
$q, $q,
async () => { async () => {
showLoader();
const selectedFile = file; const selectedFile = file;
const formdata = new FormData(); const formdata = new FormData();
formdata.append("file", selectedFile); formdata.append("file", selectedFile);
await http await http
.post(config.API.KpiFile + `/KPI/ไฟล์เอกสาร/${id.value}`, { .post(config.API.file("ไฟล์เอกสาร", "KPI", id.value), {
replace: false, replace: false,
fileList: fileName, fileList: fileName,
}) })
@ -98,7 +100,6 @@ async function clickUpload(file: any) {
"ต้องการยืนยันการอัปโหลดไฟล์นี้หรือไม่ ?" "ต้องการยืนยันการอัปโหลดไฟล์นี้หรือไม่ ?"
); );
} }
/** /**
* ดาวนโหลดลงคไฟล * ดาวนโหลดลงคไฟล
* @param fileName file name * @param fileName file name
@ -106,7 +107,7 @@ async function clickUpload(file: any) {
function downloadFile(fileName: string) { function downloadFile(fileName: string) {
showLoader(); showLoader();
http http
.get(config.API.KpiFile + `/KPI/ไฟล์เอกสาร/${id.value}/${fileName}`) .get(config.API.file("ไฟล์เอกสาร", "KPI", id.value) + `/${fileName}`)
.then((res) => { .then((res) => {
const data = res.data.downloadUrl; const data = res.data.downloadUrl;
window.open(data, "_blank"); window.open(data, "_blank");
@ -127,20 +128,17 @@ function deleteFile(fileName: string) {
dialogRemove($q, async () => { dialogRemove($q, async () => {
showLoader(); showLoader();
http http
.delete(config.API.KpiFile + `/KPI/ไฟล์เอกสาร/${id.value}/${fileName}`) .delete(config.API.file("ไฟล์เอกสาร", "KPI", id.value) + `/${fileName}`)
.then((res) => {
success($q, `ลบไฟล์สำเร็จ`);
setTimeout(() => {
getData();
hideLoader();
}, 1000);
})
.catch((e) => { .catch((e) => {
messageError($q, e); messageError($q, e);
}) })
.finally(() => { .finally(() => {
hideLoader(); getData();
setTimeout(() => {
success($q, `ลบไฟล์สำเร็จ`);
hideLoader();
}, 500);
}); });
}); });
} }