Pinia Store data positionPath
This commit is contained in:
parent
c1b7b25981
commit
cb52aec394
2 changed files with 137 additions and 32 deletions
|
|
@ -217,7 +217,8 @@ const { loaderPage } = dataStore;
|
|||
const mixin = useCounterMixin();
|
||||
const { success, dateText, messageError, showLoader, hideLoader } = mixin;
|
||||
const store = useManageDataStore();
|
||||
const { manageData, changeManageColumns } = store;
|
||||
const { manageData, changeManageColumns, getPositionPath, dataPositionPath } =
|
||||
store;
|
||||
const rows = ref<RequestItemsHistoryObject[]>([]); //list data table
|
||||
const rowsHistory = ref<RequestItemsHistoryObject[]>([]); //select data history
|
||||
const rawHistory = ref<RequestItemsHistoryObject[]>([]); //raw data history
|
||||
|
|
@ -400,38 +401,43 @@ const $q = useQuasar();
|
|||
/**
|
||||
* ฟังก์ชัน get data ล่าสุด
|
||||
*/
|
||||
const fetchData = async () => {
|
||||
const fetchData = async (load: boolean = false) => {
|
||||
await props.fetchDataComponent();
|
||||
rows.value.splice(0);
|
||||
showLoader();
|
||||
await http
|
||||
.get(config.API.listPositionPathHistory)
|
||||
.then((res) => {
|
||||
let data = res.data.result;
|
||||
version.value = data.version; //ตัวแปรที่บอกว่าข้อมูลเผยแพร่ไปหรือยัง published=เผยแพร่แล้ว draft=ยังไม่เผยแพร่
|
||||
idVersion.value = data.id; //เลข id ใน mongodb
|
||||
data.items.map((e: RequestItemsHistoryObject) => {
|
||||
rows.value.push({
|
||||
id: e.id,
|
||||
name: e.name,
|
||||
createdAt: e.createdAt,
|
||||
lastUpdatedAt: e.lastUpdatedAt,
|
||||
lastUpdateFullName: e.lastUpdateFullName,
|
||||
isActive: e.isActive,
|
||||
createdFullName: e.createdFullName,
|
||||
createdUserId: e.createdUserId,
|
||||
lastUpdateUserId: e.lastUpdateUserId,
|
||||
note: e.note,
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch((e) => {
|
||||
messageError($q, e);
|
||||
})
|
||||
.finally(() => {
|
||||
updateData.value = false;
|
||||
hideLoader();
|
||||
});
|
||||
const result = await getPositionPath(false, load);
|
||||
version.value = result.version; //ตัวแปรที่บอกว่าข้อมูลเผยแพร่ไปหรือยัง published=เผยแพร่แล้ว draft=ยังไม่เผยแพร่
|
||||
idVersion.value = result.idversion; //เลข id ใน mongodb
|
||||
rows.value = result.data;
|
||||
updateData.value = false;
|
||||
// rows.value.splice(0);
|
||||
// showLoader();
|
||||
// await http
|
||||
// .get(config.API.listPositionPathHistory)
|
||||
// .then((res) => {
|
||||
// let data = res.data.result;
|
||||
// version.value = data.version; //ตัวแปรที่บอกว่าข้อมูลเผยแพร่ไปหรือยัง published=เผยแพร่แล้ว draft=ยังไม่เผยแพร่
|
||||
// idVersion.value = data.id; //เลข id ใน mongodb
|
||||
// data.items.map((e: RequestItemsHistoryObject) => {
|
||||
// rows.value.push({
|
||||
// id: e.id,
|
||||
// name: e.name,
|
||||
// createdAt: e.createdAt,
|
||||
// lastUpdatedAt: e.lastUpdatedAt,
|
||||
// lastUpdateFullName: e.lastUpdateFullName,
|
||||
// isActive: e.isActive,
|
||||
// createdFullName: e.createdFullName,
|
||||
// createdUserId: e.createdUserId,
|
||||
// lastUpdateUserId: e.lastUpdateUserId,
|
||||
// note: e.note,
|
||||
// });
|
||||
// });
|
||||
// })
|
||||
// .catch((e) => {
|
||||
// messageError($q, e);
|
||||
// })
|
||||
// .finally(() => {
|
||||
// updateData.value = false;
|
||||
// hideLoader();
|
||||
// });
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import type { RequestItemsHistoryObject as positionEmployeeGroupResponse } from
|
|||
import type { RequestItemsHistoryObject as positionEmployeeLineResponse } from "@/modules/01_metadata/interface/request/positionEmployee/Line";
|
||||
import type { RequestItemsHistoryObject as positionEmployeeLevelResponse } from "@/modules/01_metadata/interface/request/positionEmployee/Level";
|
||||
import type { RequestItemsHistoryObject as positionEmployeeStatusResponse } from "@/modules/01_metadata/interface/request/positionEmployee/Status";
|
||||
import type { RequestItemsHistoryObject as positionPathResponse } from "@/modules/01_metadata/interface/request/position/Path";
|
||||
|
||||
const $q = useQuasar();
|
||||
const mixin = useCounterMixin();
|
||||
|
|
@ -37,6 +38,8 @@ export const useManageDataStore = defineStore("manage", () => {
|
|||
const draftPositionEmployeeLevel = ref<positionEmployeeLevelResponse[]>([]); //list data table
|
||||
const dataPositionEmployeeStatus = ref<positionEmployeeStatusResponse[]>([]); //list data table
|
||||
const draftPositionEmployeeStatus = ref<positionEmployeeStatusResponse[]>([]); //list data table
|
||||
const dataPositionPath = ref<positionPathResponse[]>([]); //list data table
|
||||
const draftPositionPath = ref<positionPathResponse[]>([]); //list data table
|
||||
|
||||
const storeIdVersion = ref<string>(""); //id data ใน mongodb
|
||||
const storeVersion = ref<string>("published"); //รายการข้อมูลล่าสุดได้เผยแพร่หรือยัง published=เผยแพร่แล้ว draft=ยังไม่เผยแพร่
|
||||
|
|
@ -526,6 +529,35 @@ export const useManageDataStore = defineStore("manage", () => {
|
|||
}
|
||||
};
|
||||
|
||||
const getPositionPath = async (
|
||||
selector: boolean = false,
|
||||
newFetch: boolean = false
|
||||
) => {
|
||||
if (dataPositionPath.value.length === 0) {
|
||||
await fetchPositionPath(true, selector);
|
||||
return {
|
||||
data: draftPositionPath.value,
|
||||
version: storeVersion.value,
|
||||
idversion: storeIdVersion.value,
|
||||
};
|
||||
} else {
|
||||
if (newFetch) {
|
||||
await fetchPositionPath(true, selector);
|
||||
return {
|
||||
data: draftPositionPath.value,
|
||||
version: storeVersion.value,
|
||||
idversion: storeIdVersion.value,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
data: draftPositionPath.value,
|
||||
version: storeVersion.value,
|
||||
idversion: storeIdVersion.value,
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const fetchPrefix = async (loader: boolean, selector: boolean) => {
|
||||
let apiPrefix = "";
|
||||
if (loader) {
|
||||
|
|
@ -1105,6 +1137,71 @@ export const useManageDataStore = defineStore("manage", () => {
|
|||
});
|
||||
};
|
||||
|
||||
const fetchPositionPath = async (loader: boolean, selector: boolean) => {
|
||||
let apiPositionPath = "";
|
||||
if (loader) {
|
||||
showLoader();
|
||||
}
|
||||
if (selector) {
|
||||
apiPositionPath = config.API.positionPath;
|
||||
} else {
|
||||
apiPositionPath = config.API.listPositionPathHistory;
|
||||
}
|
||||
await http
|
||||
.get(apiPositionPath)
|
||||
.then((res) => {
|
||||
const data = res.data.result;
|
||||
let rows: positionPathResponse[] = [];
|
||||
if (selector) {
|
||||
data.map((e: positionPathResponse) => {
|
||||
rows.push({
|
||||
id: e.id,
|
||||
name: e.name,
|
||||
createdAt: e.createdAt,
|
||||
lastUpdatedAt: e.lastUpdatedAt,
|
||||
lastUpdateFullName: e.lastUpdateFullName,
|
||||
isActive: e.isActive,
|
||||
createdFullName: e.createdFullName,
|
||||
createdUserId: e.createdUserId,
|
||||
lastUpdateUserId: e.lastUpdateUserId,
|
||||
note: e.note,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
storeVersion.value = data.version; //ตัวแปรที่บอกว่าข้อมูลเผยแพร่ไปหรือยัง published=เผยแพร่แล้ว draft=ยังไม่เผยแพร่
|
||||
storeIdVersion.value = data.id; //เลข id ใน mongodb
|
||||
|
||||
data.items.map((e: positionPathResponse) => {
|
||||
rows.push({
|
||||
id: e.id,
|
||||
name: e.name,
|
||||
createdAt: e.createdAt,
|
||||
lastUpdatedAt: e.lastUpdatedAt,
|
||||
lastUpdateFullName: e.lastUpdateFullName,
|
||||
isActive: e.isActive,
|
||||
createdFullName: e.createdFullName,
|
||||
createdUserId: e.createdUserId,
|
||||
lastUpdateUserId: e.lastUpdateUserId,
|
||||
note: e.note,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
draftPositionPath.value = rows;
|
||||
if (loader) {
|
||||
dataPositionPath.value = rows;
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
messageError($q, e);
|
||||
})
|
||||
.finally(() => {
|
||||
if (loader) {
|
||||
hideLoader();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
dataPrefix,
|
||||
dataInsignia,
|
||||
|
|
@ -1115,6 +1212,7 @@ export const useManageDataStore = defineStore("manage", () => {
|
|||
dataPositionEmployeeLine,
|
||||
dataPositionEmployeeLevel,
|
||||
dataPositionEmployeeStatus,
|
||||
dataPositionPath,
|
||||
storeIdVersion,
|
||||
storeVersion,
|
||||
manageData,
|
||||
|
|
@ -1130,5 +1228,6 @@ export const useManageDataStore = defineStore("manage", () => {
|
|||
getPositionEmployeeLine,
|
||||
getPositionEmployeeLevel,
|
||||
getPositionEmployeeStatus,
|
||||
getPositionPath,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue