Merge branch 'develop' of https://github.com/Frappet/bma-ehr-admin into develop

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-11-03 18:11:35 +07:00
commit 0ba254e387
4 changed files with 348 additions and 87 deletions

View file

@ -49,6 +49,11 @@ interface NodeTree {
totalRootPositionNextVacant: number; totalRootPositionNextVacant: number;
children: NodeTree[]; children: NodeTree[];
isOfficer: boolean; isOfficer: boolean;
orgRootDnaId: string;
orgChild1DnaId: string;
orgChild2DnaId: string;
orgChild3DnaId: string;
orgChild4DnaId: string;
} }
interface PosMaster { interface PosMaster {

View file

@ -1,6 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted, watch } from "vue"; import { ref, onMounted, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { storeToRefs } from "pinia";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
@ -8,6 +9,7 @@ import { useRouter } from "vue-router";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { updateCurrentPage } from "@/utils/functions"; import { updateCurrentPage } from "@/utils/functions";
import { tokenParsed } from "@/plugins/auth"; import { tokenParsed } from "@/plugins/auth";
import { usekeycloakPosition } from "@/stores/keycloakPosition";
/** importType*/ /** importType*/
import type { QTableProps } from "quasar"; import type { QTableProps } from "quasar";
@ -25,6 +27,7 @@ import DialogAddUser from "@/modules/02_users/components/Users/DialogFormUser.vu
/** use*/ /** use*/
const $q = useQuasar(); const $q = useQuasar();
const router = useRouter(); const router = useRouter();
const { dataPosition } = storeToRefs(usekeycloakPosition());
const { const {
dialogRemove, dialogRemove,
messageError, messageError,
@ -71,6 +74,11 @@ const nodeTree = ref<Array<NodeTree>>([
totalRootPositionNextVacant: 0, totalRootPositionNextVacant: 0,
children: [] as NodeTree[], children: [] as NodeTree[],
isOfficer: false, isOfficer: false,
orgRootDnaId: "",
orgChild1DnaId: "",
orgChild2DnaId: "",
orgChild3DnaId: "",
orgChild4DnaId: "",
}, },
]); ]);
const lazy = ref(nodeTree); const lazy = ref(nodeTree);
@ -428,6 +436,19 @@ watch(
} }
); );
/**
* ตรวจสอบการแสดงป action
* @param keycloakID keycloakID รหสผใชงาน
* @returns true หากผใชงานมทธในการดำเนนการ
*/
function checkhideBtnAction(keycloakID: string) {
if (dataPosition.value?.keycloak === keycloakID) {
return false;
} else {
return true;
}
}
/** /**
* hook ทำงานเมอมการเรยกใชงาน Components * hook ทำงานเมอมการเรยกใชงาน Components
* งขอมลรายชอผใชงาน * งขอมลรายชอผใชงาน
@ -667,8 +688,9 @@ onMounted(async () => {
{{ col.value ? col.value : "-" }} {{ col.value ? col.value : "-" }}
</div> </div>
</q-td> </q-td>
<q-td> <q-td auto-width>
<q-btn <q-btn
v-if="checkhideBtnAction(props.row.id)"
flat flat
dense dense
icon="mdi-dots-vertical" icon="mdi-dots-vertical"

View file

@ -3,13 +3,18 @@ import { computed, reactive, ref, watch } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { tokenParsed } from "@/plugins/auth";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
/** importType*/ /** importType*/
import type { ListApi } from "@/modules/06_webservices/interface/index/Main"; import type { ListApi } from "@/modules/06_webservices/interface/index/Main";
import type { FormCreate } from "@/modules/06_webservices/interface/request/Main"; import type {
FormCreate,
DnaId,
} from "@/modules/06_webservices/interface/request/Main";
import type { ResApiName } from "@/modules/06_webservices/interface/response/Main"; import type { ResApiName } from "@/modules/06_webservices/interface/response/Main";
import type { NodeTree } from "@/modules/02_users/interface/response/Main";
/** importComponents*/ /** importComponents*/
import DialogHeader from "@/components/DialogHeader.vue"; import DialogHeader from "@/components/DialogHeader.vue";
@ -35,24 +40,44 @@ const props = defineProps({
}); });
const topicRef = ref<any>(null); //refinput / const topicRef = ref<any>(null); //refinput /
const accessTypeRef = ref<any>(null); //ref select
const isAPIKey = ref<boolean>(false); //status API Key const isAPIKey = ref<boolean>(false); //status API Key
const apiKey = ref<string>(""); // API Key const apiKey = ref<string>(""); // API Key
const options = ref<ListApi[]>([]); // API const options = ref<ListApi[]>([]); // API
const optionsAccessType = ref([
{ label: "ทั้งหมด", value: "ALL" },
{ label: "ROOT", value: "ROOT" },
{ label: "CHILD", value: "CHILD" },
{ label: "NORMAL", value: "NORMAL" },
]);
// form API Key // form API Key
const formData = reactive<FormCreate>({ const formData = reactive<FormCreate>({
name: "", /// name: "", ///
accessType: "", //
apiId: [], //id API apiId: [], //id API
}); });
const dnaId = reactive<DnaId>({
dnaRootId: "",
dnaChild1Id: "",
dnaChild2Id: "",
dnaChild3Id: "",
dnaChild4Id: "",
});
const filter = ref<string>(""); //
const expanded = ref<string[]>([]); // tree
const orgId = ref<string>(""); //
const nodeTree = ref<Array<NodeTree>>([]);
const lazy = ref(nodeTree);
const titleName = computed<string>(() => { const titleName = computed<string>(() => {
return !isAPIKey.value ? "สร้าง API Key" : "API Key"; return !isAPIKey.value ? "สร้าง API Key" : "API Key";
}); });
/** ฟังก์ชันเรียกรายการข้อมูล API ที่เข้าถึงได้*/ /** ฟังก์ชันเรียกรายการข้อมูล API ที่เข้าถึงได้*/
function fetchListApiKeyName() { async function fetchListApiKeyName() {
showLoader(); await http
http
.get(config.API.apiKeyMain + "/name") .get(config.API.apiKeyMain + "/name")
.then(async (res) => { .then(async (res) => {
const data = (await res.data?.result) || []; const data = (await res.data?.result) || [];
@ -63,42 +88,50 @@ function fetchListApiKeyName() {
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
})
.finally(() => {
hideLoader();
}); });
} }
/** ฟังก์ชันยืนยันการสร้าง API Key */ /** ฟังก์ชันยืนยันการสร้าง API Key */
function onCreateAPIKey() { function onCreateAPIKey() {
topicRef.value.validate(); topicRef.value.validate();
accessTypeRef.value.validate();
const isCheckRootID = orgId.value ? true : false;
const isCheckAscessType = formData.accessType === "ALL" ? true : false;
// / // /
if (topicRef.value.validate()) { if (topicRef.value.validate() && accessTypeRef.value.validate()) {
// API popup API Key // API popup API Key
if (formData.apiId.length > 0) {
dialogConfirm($q, async () => { if (!isCheckAscessType && !isCheckRootID) {
showLoader(); dialogMessageNotify($q, "กรุณาเลือก หน่วยงาน/ส่วนราชการ");
await http
.post(config.API.apiKeyMain, {
...formData,
name: formData.name.replace(/\s+/g, ""), //
})
.then(async (res) => {
const data = await res.data.result;
apiKey.value = data;
success($q, "สร้าง API Key สำเร็จ");
isAPIKey.value = true;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
});
} else { } else {
// Popup API if (formData.apiId.length > 0) {
dialogMessageNotify($q, "กรุณาเลือก API ที่เข้าถึงได้"); dialogConfirm($q, async () => {
showLoader();
await http
.post(config.API.apiKeyMain, {
...formData,
name: formData.name.replace(/\s+/g, ""), //
...dnaId,
})
.then(async (res) => {
const data = await res.data.result;
apiKey.value = data;
success($q, "สร้าง API Key สำเร็จ");
isAPIKey.value = true;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
});
} else {
// Popup API
dialogMessageNotify($q, "กรุณาเลือก API ที่เข้าถึงได้");
}
} }
} }
} }
@ -120,78 +153,248 @@ function onCloseDialog() {
modal.value = false; modal.value = false;
isAPIKey.value = false; isAPIKey.value = false;
formData.name = ""; formData.name = "";
formData.accessType = "";
formData.apiId = []; formData.apiId = [];
nodeTree.value = [];
expanded.value = [];
}
/** ฟังก์ชันเรียกข้อมูลโครงสร้าง แบบปัจุบัน*/
async function fetchOrganizationActive() {
await http
.get(config.API.activeOrganization)
.then(async (res) => {
const data = res.data.result;
if (data) {
// activeId.value = data.activeId;
await fetchDataTree(data.activeId);
}
})
.catch((err) => {
messageError($q, err);
});
}
/**
* งก fetch อมลของโครงสราง
* @param id id โครงสราง
*/
async function fetchDataTree(id: string) {
const tokenParsedData = await tokenParsed();
const isSuperAdmin = tokenParsedData.role.includes("SUPER_ADMIN");
if (!isSuperAdmin) {
nodeTree.value = [];
}
await http
.get(config.API.orgByid(id.toString()))
.then(async (res) => {
const data = await res.data.result;
nodeTree.value.push(...data);
})
.catch((err) => {
messageError($q, err);
});
}
async function selectedOrg(node: NodeTree) {
if (node.orgTreeId) {
orgId.value = node.orgTreeId;
dnaId.dnaRootId = node.orgRootDnaId || "";
dnaId.dnaChild1Id = node.orgChild1DnaId || "";
dnaId.dnaChild2Id = node.orgChild2DnaId || "";
dnaId.dnaChild3Id = node.orgChild3DnaId || "";
dnaId.dnaChild4Id = node.orgChild4DnaId || "";
}
}
async function onChangeAccessType(val: string) {
if (val === "ALL") {
orgId.value = "";
dnaId.dnaRootId = "";
dnaId.dnaChild1Id = "";
dnaId.dnaChild2Id = "";
dnaId.dnaChild3Id = "";
dnaId.dnaChild4Id = "";
}
} }
/** /**
* การเปลยนแปลงขอมลของ `modal` * การเปลยนแปลงขอมลของ `modal`
* modal เป True เรยกรายการขอม API เขาถงได * modal เป True เรยกรายการขอม API เขาถงได
*/ */
watch(modal, (val) => { watch(modal, async (val) => {
if (val) { if (val) {
fetchListApiKeyName(); try {
showLoader();
await Promise.all([fetchOrganizationActive(), fetchListApiKeyName()]);
} finally {
hideLoader();
}
} }
}); });
</script> </script>
<template> <template>
<q-dialog v-model="modal" persistent> <q-dialog v-model="modal" persistent>
<q-card style="width: 700px; max-width: 80vw"> <q-card style="min-width: 70%">
<!-- header --> <!-- header -->
<DialogHeader :tittle="titleName" :close="onCloseDialog" /> <DialogHeader :tittle="titleName" :close="onCloseDialog" />
<q-separator /> <q-separator />
<q-card-section> <q-card-section :horizontal="$q.screen.gt.xs" class="row">
<div class="row q-col-gutter-sm"> <q-card-section class="col-4">
<!-- /คำอธบาย -->
<div class="col-12" v-if="!isAPIKey">
<q-input
ref="topicRef"
class="inputgreen"
dense
outlined
v-model="formData.name"
label="ชื่อ/คำอธิบาย"
hide-bottom-space
lazy-rules
:rules="[(val:string) => !!val || 'กรุณากรอกชื่อ/คำอธิบาย']"
/>
</div>
<!-- apiKey -->
<div class="col-12" v-else>
<span class="text-red">
* API Key านลางนจะแสดงเพยงครงเดยว
ขอใหทำสำเนาไวในทปลอดภ
</span>
<q-input dense outlined readonly bottom-slots v-model="apiKey">
<template v-slot:append>
<q-btn
round
dense
flat
color="primary"
icon="mdi-content-copy"
@click.pervent="onCopyToClipboard"
>
<q-tooltip>ดลอก</q-tooltip></q-btn
>
</template>
</q-input>
</div>
<!-- API เขาถงได -->
<div class="col-12"> <div class="col-12">
API เขาถงได <div class="q-gutter-sm">
<q-option-group <div class="row q-col-gutter-sm q-pl-sm">
:disable="isAPIKey" <div class="col-12">
:options="options" <q-input dense outlined v-model="filter" label="ค้นหา">
type="checkbox" <template v-slot:append>
keep-color <q-icon name="search" />
color="primary" </template>
v-model="formData.apiId" </q-input>
/> </div>
</div>
<div class="bg-white tree-container-fixed q-pa-xs">
<q-tree
class="q-pa-sm q-gutter-sm"
dense
default-expand-all
:nodes="lazy"
node-key="orgTreeId"
label-key="labelName"
:filter="filter?.trim()"
no-results-label="ไม่พบข้อมูลที่ค้นหา"
no-nodes-label="ไม่มีข้อมูล"
v-model:expanded="expanded"
>
<template v-slot:default-header="prop">
<q-item
@click.stop="
formData.accessType !== 'ALL'
? selectedOrg(prop.node)
: null
"
:active="orgId == prop.node.orgTreeId"
clickable
active-class="my-list-link text-primary text-weight-medium"
class="row col-12 items-center text-dark q-py-xs q-pl-sm rounded-borders my-list"
:disable="isAPIKey || formData.accessType === 'ALL'"
>
<div>
<div
:class="
prop.node.isOfficer
? 'text-weight-medium text-blue'
: 'text-weight-medium'
"
>
<div
v-if="
prop.node.isDeputy == true &&
prop.node.orgLevel == 0
"
class="text-info"
>
{{ prop.node.orgTreeName }}
</div>
<div v-else>
{{ prop.node.orgTreeName }}
</div>
{{ prop.node.isOfficer ? "(สกจ.)" : "" }}
</div>
<div class="text-weight-light text-grey-8">
{{
prop.node.orgCode == null ? null : prop.node.orgCode
}}
{{
prop.node.orgTreeShortName == null
? null
: prop.node.orgTreeShortName
}}
</div>
</div>
</q-item>
</template>
</q-tree>
</div>
</div>
</div> </div>
</div> </q-card-section>
<q-separator :vertical="$q.screen.gt.xs" />
<q-card-section class="col tree-container-fixed">
<div class="row q-col-gutter-sm">
<!-- /คำอธบาย -->
<div class="col-9" v-if="!isAPIKey">
<q-input
ref="topicRef"
class="inputgreen"
dense
outlined
v-model="formData.name"
label="ชื่อ/คำอธิบาย"
hide-bottom-space
lazy-rules
:rules="[(val:string) => !!val || 'กรุณากรอกชื่อ/คำอธิบาย']"
/>
</div>
<div class="col-3" v-if="!isAPIKey">
<q-select
ref="accessTypeRef"
outlined
v-model="formData.accessType"
emit-value
map-options
:options="optionsAccessType"
option-value="value"
option-label="label"
label="การเข้าถึง"
dense
lazy-rules
borderless
hide-bottom-space
:rules="[(val:string) => !!val || 'กรุณาเลือกการเข้าถึง']"
@update:model-value="onChangeAccessType"
/>
</div>
<!-- apiKey -->
<div class="col-12" v-else>
<span class="text-red">
* API Key านลางนจะแสดงเพยงครงเดยว
ขอใหทำสำเนาไวในทปลอดภ
</span>
<q-input dense outlined readonly bottom-slots v-model="apiKey">
<template v-slot:append>
<q-btn
round
dense
flat
color="primary"
icon="mdi-content-copy"
@click.pervent="onCopyToClipboard"
>
<q-tooltip>ดลอก</q-tooltip></q-btn
>
</template>
</q-input>
</div>
<!-- API เขาถงได -->
<div class="col-12">
API เขาถงได
<q-option-group
:disable="isAPIKey"
:options="options"
type="checkbox"
keep-color
color="primary"
v-model="formData.apiId"
/>
</div>
</div>
</q-card-section>
</q-card-section> </q-card-section>
<q-separator /> <q-separator />
@ -208,4 +411,26 @@ watch(modal, (val) => {
</q-dialog> </q-dialog>
</template> </template>
<style scoped></style> <style scoped>
.tree-container {
overflow: auto;
height: 76vh;
border: 1px solid #e6e6e7;
border-radius: 10px;
}
.tree-container-fixed {
overflow: auto;
height: 400px;
border: 1px solid #e6e6e7;
border-radius: 10px;
}
.my-list-link {
color: rgb(118, 168, 222);
border-radius: 5px;
background: #a3d3fb48 !important;
font-weight: 600;
border: 1px solid rgba(175, 185, 196, 0.217);
}
</style>

View file

@ -1,6 +1,15 @@
interface FormCreate { interface FormCreate {
name: string; name: string;
accessType: string;
apiId: string[]; apiId: string[];
} }
export type { FormCreate }; interface DnaId {
dnaRootId: string;
dnaChild1Id: string;
dnaChild2Id: string;
dnaChild3Id: string;
dnaChild4Id: string;
}
export type { FormCreate, DnaId };