diff --git a/src/components/atoms/organisms/WorkflowsBaseDialog.vue b/src/components/atoms/organisms/WorkflowsBaseDialog.vue index 5fd2423..0ab00e2 100644 --- a/src/components/atoms/organisms/WorkflowsBaseDialog.vue +++ b/src/components/atoms/organisms/WorkflowsBaseDialog.vue @@ -13,9 +13,8 @@ import { useAutoflowStore } from "@/stores/autoflowStore"; const { projectId } = storeToRefs(useAutoflowStore()); const props = defineProps<{ - editData?: any; - mode?: "create" | "edit"; - userOption?: any[]; + editData: any; + mode: "create" | "edit"; }>(); const emit = defineEmits<{ diff --git a/src/components/common/LayoutComponent.vue b/src/components/common/LayoutComponent.vue index 7ce78f9..7d4fe25 100644 --- a/src/components/common/LayoutComponent.vue +++ b/src/components/common/LayoutComponent.vue @@ -2,89 +2,83 @@ import { useRoute, useRouter } from "vue-router"; import { storage } from "@/utils/storage.js"; import DrawerComponent from "@/components/common/DrawerComponent.vue"; -import { ref, watchEffect } from "vue"; -import Select from "@/views/Select.vue"; +import { ref, computed, onMounted, onBeforeUnmount, watch } from "vue"; import { UserManagerService } from "@/components/service/management/userManagerService"; -import { storeToRefs } from "pinia"; -import { useAutoflowStore } from "@/stores/autoflowStore"; - const route = useRoute(); const router = useRouter(); -const username = ref(""); -const autoflow = useAutoflowStore(); -const showPasswordModal = ref(false); -const selectedUserData = ref({}); - -const menu = ref([]); +const username = ref(""); const projectName = ref(localStorage.getItem("projectName") || ""); -const updateUsername = () => { - // storage 구조: { userInfo: { username, ... }, ... } 라고 가정 - const auth = storage.getAuth?.() ?? null; - username.value = - auth?.userInfo?.username ?? - auth?.username ?? // 혹시 평문으로 저장한 경우 - ""; // 없으면 빈값 -}; +// ---------------------- +// Admin 판별 + Admin 모드 +// ---------------------- +const isAdmin = ref(false); // 관리자 계정 여부 +const adminMode = ref(false); // 관리자 메뉴 표시 여부(설정 버튼을 눌렀을 때 true) + +function computeIsAdmin() { + try { + const raw = + typeof storage?.getAuth === "function" + ? storage.getAuth() + : JSON.parse(localStorage.getItem("autoflow-auth") || "null"); + + const roles = raw?.userInfo?.roles ?? raw?.roles ?? []; + const authCd = raw?.userInfo?.authCd ?? raw?.authCd ?? raw?.auth; + + const inRoles = Array.isArray(roles) + ? roles.includes("ROLE_ADMIN") + : roles === "ROLE_ADMIN"; + + isAdmin.value = inRoles || authCd === "ADMIN"; + } catch { + isAdmin.value = false; + } +} + +function enterAdmin() { + if (!isAdmin.value) return; // 혹시라도 가드 + adminMode.value = true; // 사이드바를 관리자 메뉴로 전환 + router.push("/project"); // 관리자 첫 화면으로 이동 +} +function exitAdmin() { + adminMode.value = false; // 일반 메뉴로 복귀 + // 필요 시 원래 화면으로 유지하거나 홈으로 이동해도 됨 + // router.push("/home"); +} + +// ---------------------- +// 상단 드롭다운 메뉴 +// ---------------------- +const menu = ref([]); const menuItems = [ - { - title: "Select Project", - click: () => { - goSelect(); - }, - }, + { title: "Select Project", click: () => goSelect() }, { title: "Change Password", click: () => { - showPasswordModal.value = true; - }, - }, - { - title: "Logout", - icon: "mdi-logout", - click: () => { - logOut(); - }, - }, -]; - -const userMenuItems = [ - { - title: "Select Project", - }, - { - title: "Change Password", - }, - { - title: "Logout", - icon: "mdi-logout", - click: () => { - logOut(); + /* 비밀번호 모달 열기 등 */ }, }, + { title: "Logout", icon: "mdi-logout", click: () => logOut() }, ]; const drawer = ref(null); -const pageTitle = computed(() => { - return route.meta.title; -}); +const pageTitle = computed(() => route.meta.title); +const pagePath = computed(() => route.path); -const pagePath = computed(() => { - return route.path; -}); - -const refreshProjectName = () => { +function updateUsername() { + const auth = storage.getAuth?.() ?? null; + username.value = auth?.userInfo?.username ?? auth?.username ?? ""; +} +function refreshProjectName() { const v = localStorage.getItem("projectName"); projectName.value = v ? v : ""; -}; - -const goSelect = () => { +} +function goSelect() { router.push("/select"); -}; - -const logOut = () => { +} +function logOut() { UserManagerService.signOut() .catch(console.error) .finally(() => { @@ -94,49 +88,41 @@ const logOut = () => { username.value = ""; projectName.value = ""; sessionStorage.removeItem("initialRedirectDone"); + adminMode.value = false; // 로그아웃 시 관리자모드 해제 router.push("/login"); }); -}; - +} + +// storage 변경 반영 +function onStorage(e) { + if (!e.key || e.key === "projectName") refreshProjectName(); + if (!e.key || e.key === "autoflow-auth" || e.key === "auth") { + updateUsername(); + computeIsAdmin(); + } +} + +// mount onMounted(() => { updateUsername(); + computeIsAdmin(); refreshProjectName(); menu.value = menuItems; - - // 다른 탭에서 projectName이 바뀌면 반영 - window.addEventListener("storage", (e) => { - if (!e.key || e.key === "projectName") refreshProjectName(); - if (!e.key || e.key === "autoflow-auth" || e.key === "auth") - updateUsername(); - }); -}); - -onMounted(() => { - updateUsername(); - // 다른 탭/창에서 로그인 상태가 바뀔 때도 반영 - window.addEventListener("storage", (e) => { - if (!e.key || e.key === "auth") updateUsername(); - }); + window.addEventListener("storage", onStorage); }); onBeforeUnmount(() => { - window.removeEventListener("storage", updateUsername); + window.removeEventListener("storage", onStorage); }); +// 라우트 바뀔 때 프로젝트명 갱신 watch( () => route.fullPath, () => refreshProjectName(), ); -watchEffect(() => { - // const auth = storage.getAuth().auth; - // if (auth === "ADMIN") { - menu.value = menuItems; - // } else { - // menu.value = userMenuItems; - // } -});