โครงสร้างอัตรากำลัง => เพิ่ม permission
This commit is contained in:
parent
0f87ad1b5b
commit
0cc0b224c4
9 changed files with 84 additions and 49 deletions
|
|
@ -20,6 +20,7 @@ export default {
|
||||||
orgSetDateTime: (id: string) => `${organization}/set/publish/${id}`,
|
orgSetDateTime: (id: string) => `${organization}/set/publish/${id}`,
|
||||||
organizationHistoryNew: `${organization}/history`,
|
organizationHistoryNew: `${organization}/history`,
|
||||||
organizationHistoryPostNew: `${organization}/history/publish`,
|
organizationHistoryPostNew: `${organization}/history/publish`,
|
||||||
|
orgChart: (id: string) => `${organization}/org-chart/${id}`,
|
||||||
|
|
||||||
/** position*/
|
/** position*/
|
||||||
orgPosPosition: `${orgPos}/position`,
|
orgPosPosition: `${orgPos}/position`,
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,9 @@ export default {
|
||||||
file: (name: string, group: string, id: string) =>
|
file: (name: string, group: string, id: string) =>
|
||||||
`${url}/file/${name}/${group}/${id}`,
|
`${url}/file/${name}/${group}/${id}`,
|
||||||
KpiFile,
|
KpiFile,
|
||||||
fileByPath: (name: string) =>
|
fileByPath: (name: string) => `${url}/file/${name}`,
|
||||||
`${url}/file/${name}`,
|
|
||||||
fileByFile: (name: string, group: string, id: string, fileName: string) =>
|
fileByFile: (name: string, group: string, id: string, fileName: string) =>
|
||||||
`${url}/file/${name}/${group}/${id}/${fileName}`,
|
`${url}/file/${name}/${group}/${id}/${fileName}`,
|
||||||
|
|
||||||
|
filefullPath: (path: string) => `${url}/file/${path}`,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -832,7 +832,7 @@ async function emitSearch(keyword: string, typeSelect: string) {
|
||||||
</q-tr>
|
</q-tr>
|
||||||
</template>
|
</template>
|
||||||
<template v-slot:body="props">
|
<template v-slot:body="props">
|
||||||
<q-tr :props="props">
|
<q-tr :props="props" class="cursor-pointer">
|
||||||
<q-td auto-width>
|
<q-td auto-width>
|
||||||
<q-btn
|
<q-btn
|
||||||
flat
|
flat
|
||||||
|
|
|
||||||
|
|
@ -8,60 +8,36 @@ import config from "@/app.config";
|
||||||
import { OrgChart } from "bma-org-chart";
|
import { OrgChart } from "bma-org-chart";
|
||||||
import "bma-org-chart/org-chart.css";
|
import "bma-org-chart/org-chart.css";
|
||||||
import { useCounterMixin } from "@/stores/mixin";
|
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";
|
import chartData from "@/assets/orgChartData";
|
||||||
|
|
||||||
const mixin = useCounterMixin();
|
const mixin = useCounterMixin();
|
||||||
|
const store = useOrganizational();
|
||||||
const { showLoader, hideLoader, messageError } = mixin;
|
const { showLoader, hideLoader, messageError } = mixin;
|
||||||
const $q = useQuasar(); // show dialog
|
const $q = useQuasar(); // show dialog
|
||||||
|
|
||||||
const dataSource = ref(chartData);
|
const dataSource = ref(chartData); // ข้อมูล Chart
|
||||||
// const dataSource = ref() // ข้อมูล Chart
|
|
||||||
|
|
||||||
const rootOrgID = ref(); // org id ของ root ตัวปัจจุบันที่เลือกอยู่
|
const rootOrgID = ref(); // org id ของ root ตัวปัจจุบันที่เลือกอยู่
|
||||||
const dataSourceLock = ref(); // ข้อมูลตั้งต้นของ Chart ใช้ให้กดกลับไปที่ home
|
const dataSourceLock = ref(); // ข้อมูลตั้งต้นของ Chart ใช้ให้กดกลับไปที่ home
|
||||||
const chartRef = ref(); // อ้างอิงไปที่ตัว chart
|
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();
|
showLoader();
|
||||||
let urlRequest = config.API.chartGetTreeRoot;
|
let urlRequest = config.API.orgChart(rootOrgID.value);
|
||||||
await http
|
http
|
||||||
.get(urlRequest)
|
.get(urlRequest)
|
||||||
.then((response) => {
|
.then(async (response) => {
|
||||||
if (response.data.result.length > 0) {
|
if (response.data.result.length > 0) {
|
||||||
rootOrgID.value = response.data.result[0].organizationId;
|
const data = response.data.result;
|
||||||
}
|
|
||||||
})
|
const updatedData = await Promise.all(data.map(addAvatarToData));
|
||||||
.catch((e) => {
|
dataSource.value = updatedData[0];
|
||||||
messageError($q, e);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
hideLoader();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
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)
|
if (dataSourceLock.value === undefined)
|
||||||
dataSourceLock.value = dataSource.value;
|
dataSourceLock.value = dataSource.value;
|
||||||
}
|
}
|
||||||
|
|
@ -72,24 +48,79 @@ const fetchOrgChart = async () => {
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
hideLoader();
|
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
|
* เมื่อมีการคลิกที่ Chart ให้อ่าน ID ของหน่วยงานที่ถูกคลิก แล้วดึงข้อมูล Chart ของหน่วยงานนั้น ๆ จาก API
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
const refreshChart = async (data: any) => {
|
async function refreshChart(data: any) {
|
||||||
if (data.value !== undefined) rootOrgID.value = data.value;
|
if (data.value !== undefined) rootOrgID.value = data.value;
|
||||||
else rootOrgID.value = data;
|
else rootOrgID.value = data;
|
||||||
if (rootOrgID.value !== 0) await fetchOrgChart();
|
if (rootOrgID.value !== 0) await fetchOrgChart();
|
||||||
if (data.value !== undefined) data.value = 0;
|
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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<!-- <div class="toptitle text-dark col-12 row items-center">แผนภูมิองค์กร</div> -->
|
<!-- <div class="toptitle text-dark col-12 row items-center">แผนภูมิองค์กร</div> -->
|
||||||
<div class="text-dark">
|
<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">
|
<div class="q-pa-sm">
|
||||||
<q-btn flat round color="primary" @click="savePNG()" icon="mdi-image">
|
<q-btn flat round color="primary" @click="savePNG()" icon="mdi-image">
|
||||||
<q-tooltip> ดาวน์โหลด PNG </q-tooltip>
|
<q-tooltip> ดาวน์โหลด PNG </q-tooltip>
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { ref, watch } from "vue";
|
||||||
import { useQuasar } from "quasar";
|
import { useQuasar } from "quasar";
|
||||||
import http from "@/plugins/http";
|
import http from "@/plugins/http";
|
||||||
import config from "@/app.config";
|
import config from "@/app.config";
|
||||||
|
import { checkPermission } from "@/utils/permissions";
|
||||||
|
|
||||||
/** importType*/
|
/** importType*/
|
||||||
import type { ListMenu } from "@/modules/02_organization/interface/index/Main";
|
import type { ListMenu } from "@/modules/02_organization/interface/index/Main";
|
||||||
|
|
@ -547,7 +548,7 @@ watch(
|
||||||
</q-btn>
|
</q-btn>
|
||||||
|
|
||||||
<q-btn
|
<q-btn
|
||||||
v-else
|
v-else-if="checkPermission($route)?.attrIsGet"
|
||||||
flat
|
flat
|
||||||
dense
|
dense
|
||||||
color="grey-13"
|
color="grey-13"
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { useQuasar } from "quasar";
|
||||||
import config from "@/app.config";
|
import config from "@/app.config";
|
||||||
import http from "@/plugins/http";
|
import http from "@/plugins/http";
|
||||||
import genreport from "@/plugins/genreportxlsx";
|
import genreport from "@/plugins/genreportxlsx";
|
||||||
|
import { checkPermission } from "@/utils/permissions";
|
||||||
|
|
||||||
/** importType*/
|
/** importType*/
|
||||||
import type { QTableProps } from "quasar";
|
import type { QTableProps } from "quasar";
|
||||||
|
|
@ -683,7 +684,7 @@ watch(
|
||||||
</q-btn>
|
</q-btn>
|
||||||
|
|
||||||
<q-btn
|
<q-btn
|
||||||
v-else
|
v-else-if="checkPermission($route)?.attrIsGet"
|
||||||
flat
|
flat
|
||||||
dense
|
dense
|
||||||
color="deep-purple"
|
color="deep-purple"
|
||||||
|
|
|
||||||
|
|
@ -477,7 +477,7 @@ watch(
|
||||||
</q-tr>
|
</q-tr>
|
||||||
</template>
|
</template>
|
||||||
<template v-slot:body="props">
|
<template v-slot:body="props">
|
||||||
<q-tr :props="props" class="cursor-pointer">
|
<q-tr :props="props">
|
||||||
<q-td
|
<q-td
|
||||||
v-for="col in props.cols"
|
v-for="col in props.cols"
|
||||||
:key="col.name"
|
:key="col.name"
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ watch(
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template v-slot:body="props">
|
<template v-slot:body="props">
|
||||||
<q-tr :props="props" class="cursor-pointer">
|
<q-tr :props="props">
|
||||||
<q-td>
|
<q-td>
|
||||||
<q-checkbox
|
<q-checkbox
|
||||||
keep-color
|
keep-color
|
||||||
|
|
|
||||||
|
|
@ -444,7 +444,7 @@ watch(
|
||||||
</q-tr>
|
</q-tr>
|
||||||
</template>
|
</template>
|
||||||
<template v-slot:body="props">
|
<template v-slot:body="props">
|
||||||
<q-tr :props="props" class="cursor-pointer">
|
<q-tr :props="props">
|
||||||
<q-td>
|
<q-td>
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="
|
v-if="
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue