fix ==> view โครงสร้างอัตรากำลัง

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-12-17 17:00:19 +07:00
parent db9546b389
commit 7321bd2cd9
2 changed files with 79 additions and 28 deletions

View file

@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, onMounted, watch } from "vue";
import { ref, onMounted, watch, nextTick } from "vue";
import { useQuasar } from "quasar";
import { StructChart } from "structure-chart";
import "structure-chart/structure-chart.css";
@ -19,19 +19,22 @@ const rootOrgID = ref(); // org id ของ root ตัวปัจจุบั
const dataSourceLock = ref(); // Chart home
const chartRef = ref(); // chart
const loader = ref<boolean>(false); // Loader
const scrollContainer = ref<HTMLElement | null>(null);
/**
* function ดาวนโหลดไฟลโครงสราง PNG
*/
function savePNG() {
chartRef.value.savePNG();
/** function ดาวน์โหลดไฟล์โครงสร้าง PNG*/
async function savePNG() {
showLoader();
await scrollToCenter();
await chartRef.value.savePNG();
hideLoader();
}
/**
* function ดาวนโหลดไฟลโครงสราง PDF
*/
function savePDF() {
chartRef.value.savePDF();
/** function ดาวน์โหลดไฟล์โครงสร้าง PDF*/
async function savePDF() {
showLoader();
await scrollToCenter();
await chartRef.value.savePDF();
hideLoader();
}
/**
@ -178,6 +181,26 @@ watch(
}
);
/** ฟังก์ชันเลื่อน scroll ไปที่กึ่งกลาง*/
async function scrollToCenter() {
const container = scrollContainer.value;
if (container) {
container.scrollLeft = (container.scrollWidth - container.clientWidth) / 2;
}
}
// Watch dataSource
watch(
dataSource,
() => {
// nextTick DOM scroll
nextTick(() => {
scrollToCenter();
});
},
{ deep: true } //
);
onMounted(async () => {
const id =
store.typeOrganizational === "current"
@ -221,7 +244,16 @@ onMounted(async () => {
</div>
</div>
<q-separator />
<div style="overflow-x: auto; overflow-y: auto" class="q-pt-md">
<div
ref="scrollContainer"
style="
overflow-x: auto;
overflow-y: auto;
height: 70vh;
position: relative;
"
class="q-pt-md"
>
<StructChart
style="height: 70vh"
ref="chartRef"

View file

@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, onMounted, watch, onBeforeMount } from "vue";
import { ref, onMounted, watch, onBeforeMount, nextTick } from "vue";
import { useQuasar } from "quasar";
import { OrgChart } from "bma-org-chart";
import "bma-org-chart/org-chart.css";
@ -24,10 +24,9 @@ const dataSource = ref(chartData); // ข้อมูล Chart
const rootOrgID = ref(); // org id root
const dataSourceLock = ref(); // Chart home
const chartRef = ref(); // chart
const scrollContainer = ref<HTMLElement | null>(null);
/**
* fetch อม Chart โครงสราง
*/
/** fetch ข้อมูล Chart โครงสร้าง*/
async function fetchOrgChart() {
if (rootOrgID.value) {
showLoader();
@ -97,18 +96,20 @@ async function refreshChart(data: any) {
if (data.value !== undefined) data.value = 0;
}
/**
* โหลด Chart
*/
function savePNG() {
chartRef.value.savePNG();
/** โหลด Chart รูป*/
async function savePNG() {
showLoader();
await scrollToCenter();
await chartRef.value.savePNG();
hideLoader();
}
/**
* โหลด Chart PDF
*/
function savePDF() {
chartRef.value.savePDF();
/** โหลด Chart PDF*/
async function savePDF() {
showLoader();
await scrollToCenter();
await chartRef.value.savePDF();
hideLoader();
}
watch(
@ -129,6 +130,14 @@ watch(
}
);
/** ฟังก์ชันเลื่อน scroll ไปที่กึ่งกลาง*/
async function scrollToCenter() {
const container = scrollContainer.value;
if (container) {
container.scrollLeft = (container.scrollWidth - container.clientWidth) / 2;
}
}
onMounted(async () => {
rootOrgID.value =
store.typeOrganizational === "current"
@ -137,7 +146,8 @@ onMounted(async () => {
? store.draftId
: store.historyId;
fetchOrgChart();
await fetchOrgChart();
await scrollToCenter();
});
onBeforeMount(() => {
@ -164,7 +174,16 @@ onBeforeMount(() => {
</q-btn>
</div>
<q-separator />
<div style="overflow-x: auto; overflow-y: auto" class="q-pt-md">
<div
ref="scrollContainer"
style="
overflow-x: auto;
overflow-y: auto;
height: 70vh;
position: relative;
"
class="q-pt-md"
>
<OrgChart
v-if="storeOrg.dataSource"
style="height: 70vh"