header.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. <template>
  2. <header class="new--header">
  3. <div class="pro--wrap">
  4. <div class="pro--img"></div>
  5. <div class="pro--id" @click="proOn ? (proOn = false) : (proOn = true)">
  6. {{ useStoreAuth.getSnsTempData?.user?.NICK_NAME || "사용자" }}
  7. <i class="ico" :class="[proOn ? 'on' : '']">></i>
  8. <div class="id--box" v-show="proOn">
  9. <button type="button" class="btn-profile" @click="myPage(userId)">
  10. 마이페이지
  11. </button>
  12. <!--
  13. <button type="button" class="btn-profile" @click="withdrawal">회원탈퇴</button>
  14. -->
  15. <button type="button" class="btn-logout" @click="fnLoguOut">로그아웃</button>
  16. </div>
  17. </div>
  18. <div class="pro--info inf">{{ memberTypeText }}</div>
  19. <!-- 알림 센터 추가 -->
  20. <NotificationCenter />
  21. </div>
  22. <nav class="gnb">
  23. <ul class="depth1">
  24. <template v-for="(menu, index) in arrMenuInfo" :key="index">
  25. <li :class="{ 'has-submenu': menu.subMenus && menu.subMenus.length > 0 }">
  26. <button @click="handleMenuClick(menu)" :class="{ actv: isMenuActive(menu) }">
  27. {{ menu.menuName }}
  28. <i
  29. v-if="menu.subMenus && menu.subMenus.length > 0"
  30. class="ico-arrow"
  31. :class="{ rotate: activeSubmenu === menu.menuId }"
  32. >▼</i
  33. >
  34. </button>
  35. </li>
  36. <!-- 하위 메뉴들을 별도 li로 삽입 -->
  37. <template
  38. v-if="
  39. menu.subMenus && menu.subMenus.length > 0 && activeSubmenu === menu.menuId
  40. "
  41. >
  42. <li
  43. v-for="(subMenu, subIndex) in menu.subMenus"
  44. :key="`${index}-sub-${subIndex}`"
  45. class="submenu-item"
  46. >
  47. <button
  48. @click="handleSubMenuClick(subMenu)"
  49. :class="{ actv: subMenu.linkType === $route.path }"
  50. >
  51. {{ subMenu.menuName }}
  52. </button>
  53. </li>
  54. </template>
  55. </template>
  56. </ul>
  57. </nav>
  58. </header>
  59. </template>
  60. <script setup>
  61. /************************************************************************
  62. | 전역
  63. ************************************************************************/
  64. const { $log } = useNuxtApp();
  65. const proOn = ref(false);
  66. const pageId = "header";
  67. const arrMenuInfo = ref([]); // 메뉴정보
  68. const useStore = useDetailStore();
  69. const useStoreAuth = useAuthStore();
  70. const userName = ref("");
  71. const userCompanyName = ref("");
  72. const userId = ref("");
  73. const memberTypeText = ref("사용자");
  74. const route = useRoute();
  75. const router = useRouter();
  76. const activeSubmenu = ref("");
  77. /************************************************************************
  78. | 함수 : 세팅
  79. ************************************************************************/
  80. const fnSetMenu = () => {
  81. let info = [];
  82. arrMenuInfo.value = [];
  83. // 사용자 타입 확인 (memberType으로 구분)
  84. const snsUser = useStoreAuth.getSnsTempData?.user;
  85. const authUser = JSON.parse(localStorage.getItem("authStore"))?.auth;
  86. const currentUser = snsUser || authUser;
  87. let memberType = currentUser?.memberType || currentUser?.MEMBER_TYPE;
  88. // memberType이 없으면 URL로 판단
  89. if (!memberType) {
  90. const currentPath = route.path;
  91. const companyNumber = currentUser?.COMPANY_NUMBER;
  92. // 벤더 대시보드 경로이거나 COMPANY_NUMBER가 있으면 벤더사로 판단
  93. if (currentPath.includes("/vendor/dashboard") || companyNumber) {
  94. memberType = "VENDOR";
  95. } else {
  96. memberType = "INFLUENCER";
  97. }
  98. }
  99. console.log("=== 헤더 메뉴 디버깅 ===");
  100. console.log("SNS 사용자:", snsUser);
  101. console.log("Auth 사용자:", authUser);
  102. console.log("현재 사용자:", currentUser);
  103. console.log("원본 memberType:", currentUser?.memberType);
  104. console.log("원본 MEMBER_TYPE:", currentUser?.MEMBER_TYPE);
  105. console.log("최종 memberType:", memberType);
  106. console.log("현재 경로:", route.path);
  107. console.log("COMPANY_NUMBER:", currentUser?.COMPANY_NUMBER);
  108. if (memberType === "VENDOR") {
  109. // 벤더사 메뉴
  110. memberTypeText.value = "벤더사";
  111. info.push(
  112. {
  113. menuId: "menu00",
  114. parentMenuId: "menu00",
  115. menuName: "주문 관리",
  116. linkType: "/view/vendor/dashboard",
  117. },
  118. {
  119. menuId: "menu01",
  120. parentMenuId: "menu01",
  121. menuName: "제품 관리",
  122. linkType: "/view/common/item",
  123. },
  124. {
  125. menuId: "menu02",
  126. parentMenuId: "menu02",
  127. menuName: "배송 관리",
  128. linkType: "/view/common/deli",
  129. subMenus: [
  130. {
  131. menuId: "menu02-1",
  132. menuName: "배송 관리",
  133. linkType: "/view/common/deli",
  134. },
  135. {
  136. menuId: "menu02-2",
  137. menuName: "배송중",
  138. linkType: "/view/common/deli/shipping",
  139. },
  140. {
  141. menuId: "menu02-3",
  142. menuName: "배송완료",
  143. linkType: "/view/common/deli/delivered",
  144. },
  145. ],
  146. },
  147. {
  148. menuId: "menu03",
  149. parentMenuId: "menu03",
  150. menuName: "인플루언서 관리",
  151. linkType: "/view/vendor/dashboard/influencer-requests",
  152. },
  153. {
  154. menuId: "menu04",
  155. parentMenuId: "menu04",
  156. menuName: "정산 관리",
  157. linkType: "/view/common/settlement",
  158. },
  159. {
  160. menuId: "menu05",
  161. parentMenuId: "menu05",
  162. menuName: "고객센터",
  163. linkType: "/view/common/cs",
  164. }
  165. );
  166. } else {
  167. // 인플루언서 메뉴
  168. memberTypeText.value = "인플루언서";
  169. info.push(
  170. {
  171. menuId: "menu01",
  172. parentMenuId: "menu01",
  173. menuName: "제품 관리",
  174. linkType: "/view/common/item",
  175. },
  176. {
  177. menuId: "menu02",
  178. parentMenuId: "menu02",
  179. menuName: "배송 관리",
  180. linkType: "/view/common/deli",
  181. subMenus: [
  182. {
  183. menuId: "menu02-1",
  184. menuName: "배송 관리",
  185. linkType: "/view/common/deli",
  186. },
  187. {
  188. menuId: "menu02-2",
  189. menuName: "배송중",
  190. linkType: "/view/common/deli/shipping",
  191. },
  192. {
  193. menuId: "menu02-3",
  194. menuName: "배송완료",
  195. linkType: "/view/common/deli/delivered",
  196. },
  197. ],
  198. },
  199. {
  200. menuId: "menu03",
  201. parentMenuId: "menu03",
  202. menuName: "벤더 관리",
  203. linkType: "/view/influencer/search",
  204. },
  205. {
  206. menuId: "menu04",
  207. parentMenuId: "menu04",
  208. menuName: "정산 관리",
  209. linkType: "/view/common/settlement",
  210. },
  211. {
  212. menuId: "menu05",
  213. parentMenuId: "menu05",
  214. menuName: "고객센터",
  215. linkType: "/view/common/cs",
  216. }
  217. );
  218. }
  219. arrMenuInfo.value = info;
  220. $log.debug("[header][fnSetMenu][success] - MEMBER_TYPE:", memberType);
  221. };
  222. const handleMenuClick = (menu) => {
  223. // 하위 메뉴가 있는 경우 아코디언 토글
  224. if (menu.subMenus && menu.subMenus.length > 0) {
  225. // 다른 메뉴가 열려있으면 닫고 현재 메뉴 열기
  226. if (activeSubmenu.value === menu.menuId) {
  227. activeSubmenu.value = ""; // 같은 메뉴면 닫기
  228. } else {
  229. activeSubmenu.value = menu.menuId; // 다른 메뉴면 현재 메뉴 열기
  230. }
  231. } else {
  232. // 하위 메뉴가 없는 경우 모든 아코디언 닫고 페이지 이동
  233. activeSubmenu.value = "";
  234. menuAction(menu.menuId, menu.menuName, menu.linkType);
  235. }
  236. };
  237. const handleSubMenuClick = (subMenu) => {
  238. // 하위 메뉴 클릭 시 페이지 이동만 (아코디언은 유지)
  239. menuAction(subMenu.menuId, subMenu.menuName, subMenu.linkType);
  240. };
  241. const isMenuActive = (menu) => {
  242. // 아코디언이 열려있는 경우 해당 메뉴만 활성화
  243. if (activeSubmenu.value === menu.menuId) {
  244. return true;
  245. }
  246. // 아코디언이 열려있지 않을 때만 페이지 기준으로 활성화 판단
  247. if (!activeSubmenu.value) {
  248. // 현재 페이지 경로와 일치하는 경우
  249. if (menu.linkType === route.path) {
  250. return true;
  251. }
  252. // 하위 메뉴 중 하나가 현재 페이지인 경우
  253. if (menu.subMenus && menu.subMenus.length > 0) {
  254. const hasActiveSubMenu = menu.subMenus.some(
  255. (subMenu) => subMenu.linkType === route.path
  256. );
  257. if (hasActiveSubMenu) {
  258. return true;
  259. }
  260. }
  261. }
  262. return false;
  263. };
  264. const menuAction = (__MENUID, _MENUROOTNAME, __URL) => {
  265. useStore.menuInfo.menuIndex = "0";
  266. useStore.menuInfo.menuId = __MENUID;
  267. useStore.menuInfo.pageRtName = _MENUROOTNAME;
  268. useStore.menuInfo.pageStatus = null;
  269. useUtil.setPageMove(__URL);
  270. };
  271. const fnLoguOut = () => {
  272. const { logout } = useLogout();
  273. logout();
  274. };
  275. const myPage = (userId) => {
  276. router.push({
  277. path: "/view/mng/mngAdd",
  278. });
  279. useDtStore.adminInfo.adminId = userId;
  280. useDtStore.adminInfo.pageType = "U";
  281. };
  282. const withdrawal = () => {
  283. let _req = {
  284. SEQ: useStoreAuth.getSnsTempData.user.SEQ,
  285. GOOGLE_REFRESH_TOKEN: useStoreAuth.getSnsTempData.user.GOOGLE_REFRESH_TOKEN,
  286. KAKAO_REFRESH_TOKEN: useStoreAuth.getSnsTempData.user.KAKAO_REFRESH_TOKEN,
  287. NAVER_REFRESH_TOKEN: useStoreAuth.getSnsTempData.user.NAVER_REFRESH_TOKEN,
  288. };
  289. let _uri = useStoreAuth.getSnsTempData.user.GOOGLE_REFRESH_TOKEN
  290. ? "/auth/withdrawal"
  291. : useStoreAuth.getSnsTempData.user.KAKAO_REFRESH_TOKEN
  292. ? "/auth/kakaowithdrawal"
  293. : useStoreAuth.getSnsTempData.user.NAVER_REFRESH_TOKEN
  294. ? "/auth/naverwithdrawal"
  295. : "/auth/withdrawal";
  296. useAxios()
  297. .post(_uri, _req)
  298. .then((res) => {
  299. localStorage.removeItem("tempAccess");
  300. useStore.getSnsTempData = "";
  301. useAuthStore().setLogout();
  302. router.push({
  303. path: "/",
  304. });
  305. })
  306. .catch((error) => {
  307. if (error.response) {
  308. console.log("status:", error.response.status, "data:", error.response.data);
  309. // 안전하게 errCode, message 접근
  310. const errData = error.response.data || {};
  311. const errCode = errData.errCode || errData.errorCode || errData.code || "";
  312. const errMsg = errData.message || "알 수 없는 오류가 발생했습니다.";
  313. console.log("errCode:", errCode, "message:", errMsg);
  314. } else {
  315. console.log("error:", error.message, error.code);
  316. }
  317. if (error.response?.status) {
  318. fnLoginSet(error.response.data.messages.message);
  319. }
  320. $log.debug("[withdrawal][fnIdPwCheck][error]");
  321. })
  322. .finally(() => {
  323. $log.debug("[withdrawal][fnIdPwCheck][finished]");
  324. });
  325. };
  326. // 페이지 변경 시 아코디언 상태 관리 (간단한 ref 기반)
  327. const currentActivePage = ref(route.path);
  328. /************************************************************************
  329. | 라이프사이클 : onMounted
  330. ************************************************************************/
  331. onMounted(() => {
  332. console.log(useStoreAuth.getSnsTempData.user);
  333. userId.value = localStorage.getItem("tempAccess");
  334. userName.value = JSON.parse(localStorage.getItem("authStore"))?.auth.name;
  335. userCompanyName.value = JSON.parse(
  336. localStorage.getItem("authStore")
  337. )?.auth.companyName;
  338. fnSetMenu();
  339. });
  340. </script>
  341. <style scoped>
  342. .new--header {
  343. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  344. box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  345. border-radius: 0 0 12px 12px;
  346. overflow: hidden;
  347. }
  348. .pro--wrap {
  349. display: flex;
  350. align-items: center;
  351. padding: 16px 24px;
  352. background: rgba(255, 255, 255, 0.95);
  353. backdrop-filter: blur(10px);
  354. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  355. }
  356. .pro--img {
  357. width: 40px;
  358. height: 40px;
  359. border-radius: 50%;
  360. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  361. display: flex;
  362. align-items: center;
  363. justify-content: center;
  364. margin-right: 12px;
  365. box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
  366. }
  367. /* .pro--img::before {
  368. content: "👤";
  369. color: white;
  370. font-size: 18px;
  371. } */
  372. .pro--id {
  373. position: relative;
  374. color: #374151;
  375. font-weight: 500;
  376. font-size: 16px;
  377. cursor: pointer;
  378. padding: 8px 12px;
  379. border-radius: 8px;
  380. transition: all 0.2s ease;
  381. }
  382. .pro--id:hover {
  383. background: rgba(102, 126, 234, 0.1);
  384. color: #667eea;
  385. }
  386. .ico {
  387. margin-left: 8px;
  388. transition: transform 0.2s ease;
  389. color: #9ca3af;
  390. }
  391. .ico.on {
  392. transform: rotate(90deg);
  393. color: #667eea;
  394. }
  395. .id--box {
  396. position: absolute;
  397. top: 100%;
  398. left: 0;
  399. margin-top: 8px;
  400. background: white;
  401. border: 1px solid #e5e7eb;
  402. border-radius: 12px;
  403. box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  404. z-index: 1000;
  405. overflow: hidden;
  406. min-width: 160px;
  407. }
  408. .btn-profile,
  409. .btn-logout {
  410. width: 100%;
  411. padding: 16px 20px;
  412. border: none;
  413. background: none;
  414. text-align: left;
  415. cursor: pointer;
  416. transition: all 0.2s ease;
  417. font-size: 14px;
  418. color: #374151;
  419. }
  420. .btn-profile:hover {
  421. background: #f3f4f6;
  422. color: #667eea;
  423. }
  424. .btn-logout:hover {
  425. background: #fef2f2;
  426. color: #dc2626;
  427. }
  428. .pro--info {
  429. margin-left: auto;
  430. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  431. color: white;
  432. padding: 6px 16px;
  433. border-radius: 20px;
  434. font-size: 14px;
  435. font-weight: 500;
  436. box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
  437. }
  438. .gnb {
  439. background: rgba(255, 255, 255, 0.98);
  440. backdrop-filter: blur(10px);
  441. }
  442. .depth1 {
  443. display: flex;
  444. flex-direction: column;
  445. width: 100%;
  446. list-style: none;
  447. margin: 0;
  448. padding: 0;
  449. }
  450. .depth1 button {
  451. width: 100%;
  452. padding: 16px 24px;
  453. border: none;
  454. background: none;
  455. font-size: 15px;
  456. font-weight: 500;
  457. color: #6b7280;
  458. cursor: pointer;
  459. transition: all 0.3s ease;
  460. position: relative;
  461. border-bottom: 3px solid transparent;
  462. text-align: left;
  463. }
  464. .depth1 button:hover {
  465. color: #667eea;
  466. transform: translateY(-1px);
  467. }
  468. .depth1 button.actv {
  469. color: #667eea;
  470. border-bottom-color: #667eea;
  471. font-weight: 600;
  472. }
  473. .depth1 button.actv::before {
  474. content: "";
  475. position: absolute;
  476. bottom: -3px;
  477. left: 50%;
  478. transform: translateX(-50%);
  479. width: 60%;
  480. height: 3px;
  481. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  482. border-radius: 2px;
  483. }
  484. /* 하위 메뉴가 있는 항목 스타일 */
  485. .has-submenu {
  486. position: relative;
  487. }
  488. .ico-arrow {
  489. font-size: 10px;
  490. margin-left: 6px;
  491. transition: transform 0.2s ease;
  492. font-style: normal;
  493. position: absolute;
  494. right: 24px;
  495. top: 50%;
  496. transform: translateY(-50%);
  497. }
  498. .ico-arrow.rotate {
  499. transform: rotate(180deg);
  500. }
  501. /* 하위 메뉴 스타일 */
  502. .submenu-item {
  503. background: #f8f9fa;
  504. }
  505. .submenu-item button {
  506. width: 100%;
  507. padding: 12px 24px 12px 40px !important;
  508. border: none;
  509. background: none;
  510. font-size: 14px !important;
  511. font-weight: 400 !important;
  512. color: #555;
  513. cursor: pointer;
  514. transition: all 0.2s ease;
  515. text-align: left;
  516. border-bottom: none !important;
  517. }
  518. .submenu-item button:hover {
  519. background: #e9ecef;
  520. color: #667eea;
  521. transform: none !important;
  522. }
  523. .submenu-item button.actv {
  524. background: #e3f2fd;
  525. color: #667eea;
  526. font-weight: 500 !important;
  527. border-bottom: none !important;
  528. }
  529. .submenu-item button.actv::before {
  530. display: none;
  531. }
  532. </style>