โครงสร้างอัตรากำลัง => เพิ่ม permission

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-08-20 10:37:03 +07:00
parent 0f87ad1b5b
commit 0cc0b224c4
9 changed files with 84 additions and 49 deletions

View file

@ -8,60 +8,36 @@ import config from "@/app.config";
import { OrgChart } from "bma-org-chart";
import "bma-org-chart/org-chart.css";
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
import avatar from "@/assets/avatar_user.jpg";
import chartData from "@/assets/orgChartData";
const mixin = useCounterMixin();
const store = useOrganizational();
const { showLoader, hideLoader, messageError } = mixin;
const $q = useQuasar(); // show dialog
const dataSource = ref(chartData);
// const dataSource = ref() // Chart
const dataSource = ref(chartData); // Chart
const rootOrgID = ref(); // org id root
const dataSourceLock = ref(); // Chart home
const chartRef = ref(); // chart
const savePNG = () => {
chartRef.value.savePNG();
};
const savePDF = () => {
chartRef.value.savePDF();
};
onMounted(async () => {
await fetchTreeRoot();
await fetchOrgChart();
});
/**
* าน Root ของขอมลทงหมดกอน
* fetch อม Chart โครงสราง
*/
const fetchTreeRoot = async () => {
function fetchOrgChart() {
showLoader();
let urlRequest = config.API.chartGetTreeRoot;
await http
let urlRequest = config.API.orgChart(rootOrgID.value);
http
.get(urlRequest)
.then((response) => {
.then(async (response) => {
if (response.data.result.length > 0) {
rootOrgID.value = response.data.result[0].organizationId;
}
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
};
const data = response.data.result;
const updatedData = await Promise.all(data.map(addAvatarToData));
dataSource.value = updatedData[0];
const fetchOrgChart = async () => {
showLoader();
let urlRequest = config.API.chartGetOrg(rootOrgID.value);
await http
.get(urlRequest)
.then((response) => {
if (response.data.result.length > 0) {
dataSource.value = response.data.result[0];
if (dataSourceLock.value === undefined)
dataSourceLock.value = dataSource.value;
}
@ -72,24 +48,79 @@ const fetchOrgChart = async () => {
.finally(() => {
hideLoader();
});
};
}
/**
* map อม Chart
* @param item อม Chart
*/
async function addAvatarToData(item: any) {
// avatar item
const updatedItem = {
...item,
avatar: item.avatar ? await fetchProfile(item.avatar) : avatar,
// item children
children: item.children
? await Promise.all(item.children.map(addAvatarToData))
: [],
};
return updatedItem;
}
/**
* fetch ปโปรไฟล return งค download ไฟล
* @param path ไฟล
*/
async function fetchProfile(path: string) {
try {
const res = await http.get(config.API.filefullPath(path));
return res.data.downloadUrl; // URL avatar
} catch (err) {
return avatar; // default avatar
}
}
/**
* เมอมการคลกท Chart ใหาน ID ของหนวยงานทกคล แลวดงขอม Chart ของหนวยงานน จาก API
* @param data
*/
const refreshChart = async (data: any) => {
async function refreshChart(data: any) {
if (data.value !== undefined) rootOrgID.value = data.value;
else rootOrgID.value = data;
if (rootOrgID.value !== 0) await fetchOrgChart();
if (data.value !== undefined) data.value = 0;
};
}
/**
* โหลด Chart
*/
function savePNG() {
chartRef.value.savePNG();
}
/**
* โหลด Chart PDF
*/
function savePDF() {
chartRef.value.savePDF();
}
onMounted(async () => {
rootOrgID.value =
store.typeOrganizational === "current"
? store.activeId
: store.typeOrganizational === "draft"
? store.draftId
: store.historyId;
await fetchOrgChart();
});
</script>
<template>
<!-- <div class="toptitle text-dark col-12 row items-center">แผนภองคกร</div> -->
<div class="text-dark">
<q-card flat bordered class="col-12 q-mt-sm">
<q-card class="col-12 q-mt-sm">
<div class="q-pa-sm">
<q-btn flat round color="primary" @click="savePNG()" icon="mdi-image">
<q-tooltip> ดาวนโหลด PNG </q-tooltip>