fix fetch

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-07-24 11:39:09 +07:00
parent 1888ce2f8b
commit 6824988322
9 changed files with 111 additions and 61 deletions

View file

@ -10,7 +10,7 @@ interface ProfileData {
posNo: string; posNo: string;
profileId: string; profileId: string;
citizenId?: string; citizenId?: string;
salary?: number|null; salary?: number | null;
birthDate?: string; birthDate?: string;
keycloakId?: string; keycloakId?: string;
org?: string; org?: string;
@ -35,4 +35,36 @@ interface InformationData {
email: string; email: string;
} }
export type { ProfileData, InformationData }; interface DataProfile {
profileId: string | null;
prefix: string;
rank: string;
firstName: string;
lastName: string;
citizenId: string;
position: string;
posMaster: string | null;
posLevelName: string | null;
posLevelRank: string | null;
posLevelId: string | null;
posTypeName: string | null;
posTypeRank: string | null;
posTypeId: string | null;
posExecutiveName: string;
posExecutivePriority: string | null;
posExecutiveId: string | null;
rootId: string | null;
root: string;
child1Id: string | null;
child1: string | null;
child2Id: string | null;
child2: string | null;
child3Id: string | null;
child3: string | null;
child4Id: string | null;
child4: string | null;
node: string | null;
nodeId: string | null;
}
export type { ProfileData, InformationData, DataProfile };

View file

@ -86,7 +86,6 @@ async function fetchEvaluteList() {
); );
total.value = res.data.result.total; total.value = res.data.result.total;
store.fetchEvaluateList(res.data.result.data); store.fetchEvaluateList(res.data.result.data);
await getProfileCheck();
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
@ -191,6 +190,7 @@ watch(
/** hook lifecycle*/ /** hook lifecycle*/
onMounted(async () => { onMounted(async () => {
await fetchEvaluteList(); await fetchEvaluteList();
await getProfileCheck();
}); });
</script> </script>

View file

@ -2,6 +2,7 @@ import { defineStore } from "pinia";
import { ref, reactive } from "vue"; import { ref, reactive } from "vue";
import type { DataOptions } from "./interface/index/Main"; import type { DataOptions } from "./interface/index/Main";
import type { FormQuery } from "@/modules/08_KPI/interface/request/index"; import type { FormQuery } from "@/modules/08_KPI/interface/request/index";
import type { DataProfile } from "@/interface/Main";
export const useKpiDataStore = defineStore("KPIDate", () => { export const useKpiDataStore = defineStore("KPIDate", () => {
const mainRowData = ref<any>(); const mainRowData = ref<any>();
@ -17,7 +18,7 @@ export const useKpiDataStore = defineStore("KPIDate", () => {
const selected = ref([]); const selected = ref([]);
const work = ref<boolean>(false); const work = ref<boolean>(false);
const tabMain = ref<string>(""); const tabMain = ref<string>("");
const dataProfile = ref<any>({ const dataProfile = ref<DataProfile>({
profileId: null, profileId: null,
prefix: "", prefix: "",
rank: "", rank: "",

View file

@ -478,15 +478,17 @@ async function fetchProfileEvaluator(id: string) {
/** ดึงข้อมูลโปรไฟล์ */ /** ดึงข้อมูลโปรไฟล์ */
async function getProfile() { async function getProfile() {
await http if (store.dataProfile.profileId) {
.get(config.API.profilePosition()) await http
.then(async (res) => { .get(config.API.profilePosition())
const data = await res.data.result; .then(async (res) => {
store.dataProfile = await data; const data = await res.data.result;
}) store.dataProfile = await data;
.catch((e) => { })
messageError($q, e); .catch((e) => {
}); messageError($q, e);
});
}
} }
async function downloadReport() { async function downloadReport() {

View file

@ -9,6 +9,7 @@ import http from "@/plugins/http";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useKpiDataStore } from "@/modules/08_KPI/store"; import { useKpiDataStore } from "@/modules/08_KPI/store";
import type { DataProfile } from "@/interface/Main";
import type { import type {
DataOptions, DataOptions,
MainListKpi, MainListKpi,
@ -285,26 +286,34 @@ function onSubmit() {
} }
/** ดึงข้อมูล */ /** ดึงข้อมูล */
function getProfile() { async function getProfile() {
http if (store.dataProfile.profileId) {
.get(config.API.profilePosition()) assignProfileToForm(store.dataProfile);
.then(async (res) => { } else {
const data = await res.data.result; await http
store.dataProfile = data; .get(config.API.profilePosition())
.then(async (res) => {
const data = await res.data.result;
store.dataProfile = data;
assignProfileToForm(data);
})
.catch((e) => {
messageError($q, e);
});
}
}
formRound.profileId = data.profileId; function assignProfileToForm(profile: DataProfile) {
formRound.prefix = data.prefix; formRound.profileId = profile.profileId ? profile.profileId : "";
formRound.firstName = data.firstName; formRound.prefix = profile.prefix ? profile.prefix : "";
formRound.lastName = data.lastName; formRound.firstName = profile.firstName ? profile.firstName : "";
formRound.position = data.position; formRound.lastName = profile.lastName ? profile.lastName : "";
formRound.posLevelName = data.posLevelName; formRound.position = profile.position ? profile.position : "";
formRound.posTypeName = data.posTypeName; formRound.posLevelName = profile.posLevelName ? profile.posLevelName : "";
formRound.posExecutiveName = data.posExecutiveName; formRound.posTypeName = profile.posTypeName ? profile.posTypeName : "";
}) formRound.posExecutiveName = profile.posExecutiveName
.catch((e) => { ? profile.posExecutiveName
messageError($q, e); : "";
})
.finally(() => {});
} }
/** เช็ครอบการประเมิน ปิด */ /** เช็ครอบการประเมิน ปิด */

View file

@ -5,6 +5,7 @@ import { useQuasar, type QTableProps } from "quasar";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useDataStore } from "@/stores/data";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import type { import type {
@ -17,7 +18,7 @@ const { showLoader, hideLoader, messageError } = mixin;
const router = useRouter(); const router = useRouter();
const $q = useQuasar(); const $q = useQuasar();
const dataStore = useDataStore();
const profilId = ref<string>(""); const profilId = ref<string>("");
const currentPage = ref<number>(1); const currentPage = ref<number>(1);
const page = ref<number>(1); const page = ref<number>(1);
@ -123,19 +124,22 @@ function onEdit(id: string) {
// ); // );
async function getProfileId() { async function getProfileId() {
showLoader(); if (dataStore.profileId) {
await http profilId.value = dataStore.profileId;
.get(config.API.profilePosition()) } else {
.then(async (res) => { showLoader();
profilId.value = res.data.result.profileId; try {
await getData(); const res = await http.get(config.API.profilePosition());
}) dataStore.profileId = res.data.result.profileId;
.catch((e) => { profilId.value = dataStore.profileId;
} catch (e) {
messageError($q, e); messageError($q, e);
}) } finally {
.finally(() => {
hideLoader(); hideLoader();
}); }
}
await getData();
} }
function convertType(val: string) { function convertType(val: string) {

View file

@ -16,7 +16,7 @@ import { useCounterMixin } from "@/stores/mixin";
* use * use
*/ */
const $q = useQuasar(); const $q = useQuasar();
const link = ref<string>('') const link = ref<string>("");
const store = useRequestEditStore(); const store = useRequestEditStore();
const dataStore = useDataStore(); const dataStore = useDataStore();
const { dialogConfirm, showLoader, hideLoader, messageError, success } = const { dialogConfirm, showLoader, hideLoader, messageError, success } =
@ -167,20 +167,16 @@ function filterOption(val: string, update: Function) {
/** /**
* function fetch profileId * function fetch profileId
*/ */
function fetchProfile() { async function fetchProfile() {
showLoader(); try {
http isReadOnly.value = dataStore.officerType === "OFFICER";
.get(config.API.profilePosition()) const res = await http.get(config.API.profilePosition());
.then((res) => { return res.data.result.profileId;
const data = res.data.result; } catch (err) {
profileId.value = data.profileId; messageError($q, err);
}) } finally {
.catch((err) => { hideLoader();
messageError($q, err); }
})
.finally(() => {
hideLoader();
});
} }
/** popup รายละเอียดของ ขอปรับปรุงข้อมูลจากกรมการปกครอง */ /** popup รายละเอียดของ ขอปรับปรุงข้อมูลจากกรมการปกครอง */
@ -194,7 +190,10 @@ function onInfo(val: string) {
watch( watch(
() => modal.value, () => modal.value,
async () => { async () => {
modal.value && fetchProfile(); profileId.value = dataStore.profileId
? dataStore.profileId
: await fetchProfile();
link.value = await dataStore.getProFileType(); link.value = await dataStore.getProFileType();
} }
); );

View file

@ -23,7 +23,7 @@ const {
showLoader, showLoader,
hideLoader, hideLoader,
date2Thai, date2Thai,
onSearchDataTable onSearchDataTable,
} = mixin; } = mixin;
const filter = ref<string>(""); const filter = ref<string>("");

View file

@ -16,6 +16,7 @@ export const useDataStore = defineStore("dataMain", () => {
const { messageError, showLoader, hideLoader, findPosMasterNo, findOrgName } = const { messageError, showLoader, hideLoader, findPosMasterNo, findOrgName } =
mixin; mixin;
// ref() คือการประกาศ state เหมือน vuex // ref() คือการประกาศ state เหมือน vuex
const profileId = ref<string>("");
const formData = reactive<ProfileData>({ const formData = reactive<ProfileData>({
profileId: "", profileId: "",
rank: "", rank: "",
@ -101,6 +102,7 @@ export const useDataStore = defineStore("dataMain", () => {
async function getData(dataPerson: any) { async function getData(dataPerson: any) {
const data = await dataPerson; const data = await dataPerson;
profileId.value = data.profileId;
isProbation.value = data.isProbation; isProbation.value = data.isProbation;
formData.profileId = data.profileId; formData.profileId = data.profileId;
formData.rank = data.rank; formData.rank = data.rank;
@ -166,6 +168,7 @@ export const useDataStore = defineStore("dataMain", () => {
officerLink, officerLink,
getProFileType, getProFileType,
dataProfile, dataProfile,
profileId,
}; };
}); });