ทะเบียนประวัติ ==> uploadFile

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-03-18 15:25:08 +07:00
parent a8f0a486e3
commit 70373acacd
11 changed files with 656 additions and 42 deletions

View file

@ -1,5 +1,11 @@
import { defineStore } from "pinia";
import { ref, reactive, computed } from "vue";
import { useQuasar } from "quasar";
import axios from "axios";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useRoute } from "vue-router";
import type { DataOption } from "@/modules/04_registryPerson/interface/index/Main";
@ -9,6 +15,9 @@ import type {
} from "@/modules/04_registryPerson/interface/response/Main";
import type { FormFilter } from "@/modules/04_registryPerson/interface/request/Main";
const $q = useQuasar();
const { messageError } = useCounterMixin();
export const useRegistryNewDataStore = defineStore("registryNew", () => {
const route = useRoute();
const routerName = ref<any>();
@ -151,6 +160,82 @@ export const useRegistryNewDataStore = defineStore("registryNew", () => {
{ id: "ASC", name: "เรียงตามวันที่บรรจุแต่งตั้ง (เก่า-ล่าสุด)" },
]);
/**
* Path
* @param group
* @param profileId id
* @param id subId
* @returns Path
*/
async function createPathUploadFlie(
group: string,
profileId: string,
id: string
) {
try {
const res = await http.post(
config.API.subFile("ทะเบียนประวัติ", group, profileId, id),
{
replace: true,
fileList: [
{
fileName: "เอกสารหลักฐาน",
},
],
}
);
return res.data["เอกสารหลักฐาน"].uploadUrl;
} catch (err) {
messageError($q, err);
}
}
/**
* Path
* @param group
* @param profileId id
* @param id subId
* @returns
*/
async function getPathUploadFlie(
group: string,
profileId: string,
id: string
) {
try {
const res = await http.get(
config.API.subFileByFileName(
"ทะเบียนประวัติ",
group,
profileId,
id,
"เอกสารหลักฐาน"
)
);
return res.data;
} catch (err) {
messageError($q, err);
}
}
/**
*
* @param uploadUrl Path
* @param file
*/
async function uploadFile(uploadUrl: string, file: any) {
try {
await axios.put(uploadUrl, file, {
headers: {
"Content-Type": file.type,
},
});
} catch (err) {
messageError($q, err);
}
}
return {
fetchType,
fetchLevel,
@ -172,5 +257,8 @@ export const useRegistryNewDataStore = defineStore("registryNew", () => {
citizenId,
displayOrderOps,
routerName,
createPathUploadFlie,
getPathUploadFlie,
uploadFile,
};
});