header.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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: "menu00",
  172. parentMenuId: "menu00",
  173. menuName: "주문 관리",
  174. linkType: "/view/vendor/dashboard",
  175. },
  176. {
  177. menuId: "menu01",
  178. parentMenuId: "menu01",
  179. menuName: "제품 관리",
  180. linkType: "/view/common/item",
  181. },
  182. {
  183. menuId: "menu02",
  184. parentMenuId: "menu02",
  185. menuName: "배송 관리",
  186. linkType: "/view/common/deli",
  187. subMenus: [
  188. {
  189. menuId: "menu02-1",
  190. menuName: "배송 관리",
  191. linkType: "/view/common/deli",
  192. },
  193. {
  194. menuId: "menu02-2",
  195. menuName: "배송중",
  196. linkType: "/view/common/deli/shipping",
  197. },
  198. {
  199. menuId: "menu02-3",
  200. menuName: "배송완료",
  201. linkType: "/view/common/deli/delivered",
  202. },
  203. ],
  204. },
  205. {
  206. menuId: "menu03",
  207. parentMenuId: "menu03",
  208. menuName: "벤더 관리",
  209. linkType: "/view/influencer/search",
  210. },
  211. {
  212. menuId: "menu04",
  213. parentMenuId: "menu04",
  214. menuName: "정산 관리",
  215. linkType: "/view/common/settlement",
  216. },
  217. {
  218. menuId: "menu05",
  219. parentMenuId: "menu05",
  220. menuName: "고객센터",
  221. linkType: "/view/common/cs",
  222. }
  223. );
  224. }
  225. arrMenuInfo.value = info;
  226. $log.debug("[header][fnSetMenu][success] - MEMBER_TYPE:", memberType);
  227. };
  228. const handleMenuClick = (menu) => {
  229. // 하위 메뉴가 있는 경우 아코디언 토글
  230. if (menu.subMenus && menu.subMenus.length > 0) {
  231. // 다른 메뉴가 열려있으면 닫고 현재 메뉴 열기
  232. if (activeSubmenu.value === menu.menuId) {
  233. activeSubmenu.value = ""; // 같은 메뉴면 닫기
  234. } else {
  235. activeSubmenu.value = menu.menuId; // 다른 메뉴면 현재 메뉴 열기
  236. }
  237. } else {
  238. // 하위 메뉴가 없는 경우 모든 아코디언 닫고 페이지 이동
  239. activeSubmenu.value = "";
  240. menuAction(menu.menuId, menu.menuName, menu.linkType);
  241. }
  242. };
  243. const handleSubMenuClick = (subMenu) => {
  244. // 하위 메뉴 클릭 시 페이지 이동만 (아코디언은 유지)
  245. menuAction(subMenu.menuId, subMenu.menuName, subMenu.linkType);
  246. };
  247. const isMenuActive = (menu) => {
  248. // 아코디언이 열려있는 경우 해당 메뉴만 활성화
  249. if (activeSubmenu.value === menu.menuId) {
  250. return true;
  251. }
  252. // 아코디언이 열려있지 않을 때만 페이지 기준으로 활성화 판단
  253. if (!activeSubmenu.value) {
  254. // 현재 페이지 경로와 일치하는 경우
  255. if (menu.linkType === route.path) {
  256. return true;
  257. }
  258. // 하위 메뉴 중 하나가 현재 페이지인 경우
  259. if (menu.subMenus && menu.subMenus.length > 0) {
  260. const hasActiveSubMenu = menu.subMenus.some(
  261. (subMenu) => subMenu.linkType === route.path
  262. );
  263. if (hasActiveSubMenu) {
  264. return true;
  265. }
  266. }
  267. }
  268. return false;
  269. };
  270. const menuAction = (__MENUID, _MENUROOTNAME, __URL) => {
  271. useStore.menuInfo.menuIndex = "0";
  272. useStore.menuInfo.menuId = __MENUID;
  273. useStore.menuInfo.pageRtName = _MENUROOTNAME;
  274. useStore.menuInfo.pageStatus = null;
  275. useUtil.setPageMove(__URL);
  276. };
  277. const fnLoguOut = () => {
  278. const { logout } = useLogout();
  279. logout();
  280. };
  281. const myPage = (userId) => {
  282. router.push({
  283. path: "/view/mng/mngAdd",
  284. });
  285. useDtStore.adminInfo.adminId = userId;
  286. useDtStore.adminInfo.pageType = "U";
  287. };
  288. const withdrawal = () => {
  289. let _req = {
  290. SEQ: useStoreAuth.getSnsTempData.user.SEQ,
  291. GOOGLE_REFRESH_TOKEN: useStoreAuth.getSnsTempData.user.GOOGLE_REFRESH_TOKEN,
  292. KAKAO_REFRESH_TOKEN: useStoreAuth.getSnsTempData.user.KAKAO_REFRESH_TOKEN,
  293. NAVER_REFRESH_TOKEN: useStoreAuth.getSnsTempData.user.NAVER_REFRESH_TOKEN,
  294. };
  295. let _uri = useStoreAuth.getSnsTempData.user.GOOGLE_REFRESH_TOKEN
  296. ? "/auth/withdrawal"
  297. : useStoreAuth.getSnsTempData.user.KAKAO_REFRESH_TOKEN
  298. ? "/auth/kakaowithdrawal"
  299. : useStoreAuth.getSnsTempData.user.NAVER_REFRESH_TOKEN
  300. ? "/auth/naverwithdrawal"
  301. : "/auth/withdrawal";
  302. useAxios()
  303. .post(_uri, _req)
  304. .then((res) => {
  305. localStorage.removeItem("tempAccess");
  306. useStore.getSnsTempData = "";
  307. useAuthStore().setLogout();
  308. router.push({
  309. path: "/",
  310. });
  311. })
  312. .catch((error) => {
  313. if (error.response) {
  314. console.log("status:", error.response.status, "data:", error.response.data);
  315. // 안전하게 errCode, message 접근
  316. const errData = error.response.data || {};
  317. const errCode = errData.errCode || errData.errorCode || errData.code || "";
  318. const errMsg = errData.message || "알 수 없는 오류가 발생했습니다.";
  319. console.log("errCode:", errCode, "message:", errMsg);
  320. } else {
  321. console.log("error:", error.message, error.code);
  322. }
  323. if (error.response?.status) {
  324. fnLoginSet(error.response.data.messages.message);
  325. }
  326. $log.debug("[withdrawal][fnIdPwCheck][error]");
  327. })
  328. .finally(() => {
  329. $log.debug("[withdrawal][fnIdPwCheck][finished]");
  330. });
  331. };
  332. // 페이지 변경 시 아코디언 상태 관리 (간단한 ref 기반)
  333. const currentActivePage = ref(route.path);
  334. /************************************************************************
  335. | 라이프사이클 : onMounted
  336. ************************************************************************/
  337. onMounted(() => {
  338. console.log(useStoreAuth.getSnsTempData.user);
  339. userId.value = localStorage.getItem("tempAccess");
  340. userName.value = JSON.parse(localStorage.getItem("authStore"))?.auth.name;
  341. userCompanyName.value = JSON.parse(
  342. localStorage.getItem("authStore")
  343. )?.auth.companyName;
  344. fnSetMenu();
  345. });
  346. </script>
  347. <style scoped>
  348. .new--header {
  349. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  350. box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  351. border-radius: 0 0 12px 12px;
  352. overflow: hidden;
  353. }
  354. .pro--wrap {
  355. display: flex;
  356. align-items: center;
  357. padding: 16px 24px;
  358. background: rgba(255, 255, 255, 0.95);
  359. backdrop-filter: blur(10px);
  360. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  361. }
  362. .pro--img {
  363. width: 40px;
  364. height: 40px;
  365. border-radius: 50%;
  366. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  367. display: flex;
  368. align-items: center;
  369. justify-content: center;
  370. margin-right: 12px;
  371. box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
  372. }
  373. /* .pro--img::before {
  374. content: "👤";
  375. color: white;
  376. font-size: 18px;
  377. } */
  378. .pro--id {
  379. position: relative;
  380. color: #374151;
  381. font-weight: 500;
  382. font-size: 16px;
  383. cursor: pointer;
  384. padding: 8px 12px;
  385. border-radius: 8px;
  386. transition: all 0.2s ease;
  387. }
  388. .pro--id:hover {
  389. background: rgba(102, 126, 234, 0.1);
  390. color: #667eea;
  391. }
  392. .ico {
  393. margin-left: 8px;
  394. transition: transform 0.2s ease;
  395. color: #9ca3af;
  396. }
  397. .ico.on {
  398. transform: rotate(90deg);
  399. color: #667eea;
  400. }
  401. .id--box {
  402. position: absolute;
  403. top: 100%;
  404. left: 0;
  405. margin-top: 8px;
  406. background: white;
  407. border: 1px solid #e5e7eb;
  408. border-radius: 12px;
  409. box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  410. z-index: 1000;
  411. overflow: hidden;
  412. min-width: 160px;
  413. }
  414. .btn-profile,
  415. .btn-logout {
  416. width: 100%;
  417. padding: 16px 20px;
  418. border: none;
  419. background: none;
  420. text-align: left;
  421. cursor: pointer;
  422. transition: all 0.2s ease;
  423. font-size: 14px;
  424. color: #374151;
  425. }
  426. .btn-profile:hover {
  427. background: #f3f4f6;
  428. color: #667eea;
  429. }
  430. .btn-logout:hover {
  431. background: #fef2f2;
  432. color: #dc2626;
  433. }
  434. .pro--info {
  435. margin-left: auto;
  436. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  437. color: white;
  438. padding: 6px 16px;
  439. border-radius: 20px;
  440. font-size: 14px;
  441. font-weight: 500;
  442. box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
  443. }
  444. .gnb {
  445. background: rgba(255, 255, 255, 0.98);
  446. backdrop-filter: blur(10px);
  447. }
  448. .depth1 {
  449. display: flex;
  450. flex-direction: column;
  451. width: 100%;
  452. list-style: none;
  453. margin: 0;
  454. padding: 0;
  455. }
  456. .depth1 button {
  457. width: 100%;
  458. padding: 16px 24px;
  459. border: none;
  460. background: none;
  461. font-size: 15px;
  462. font-weight: 500;
  463. color: #6b7280;
  464. cursor: pointer;
  465. transition: all 0.3s ease;
  466. position: relative;
  467. border-bottom: 3px solid transparent;
  468. text-align: left;
  469. }
  470. .depth1 button:hover {
  471. color: #667eea;
  472. transform: translateY(-1px);
  473. }
  474. .depth1 button.actv {
  475. color: #667eea;
  476. border-bottom-color: #667eea;
  477. font-weight: 600;
  478. }
  479. .depth1 button.actv::before {
  480. content: "";
  481. position: absolute;
  482. bottom: -3px;
  483. left: 50%;
  484. transform: translateX(-50%);
  485. width: 60%;
  486. height: 3px;
  487. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  488. border-radius: 2px;
  489. }
  490. /* 하위 메뉴가 있는 항목 스타일 */
  491. .has-submenu {
  492. position: relative;
  493. }
  494. .ico-arrow {
  495. font-size: 10px;
  496. margin-left: 6px;
  497. transition: transform 0.2s ease;
  498. font-style: normal;
  499. position: absolute;
  500. right: 24px;
  501. top: 50%;
  502. transform: translateY(-50%);
  503. }
  504. .ico-arrow.rotate {
  505. transform: rotate(180deg);
  506. }
  507. /* 하위 메뉴 스타일 */
  508. .submenu-item {
  509. background: #f8f9fa;
  510. }
  511. .submenu-item button {
  512. width: 100%;
  513. padding: 12px 24px 12px 40px !important;
  514. border: none;
  515. background: none;
  516. font-size: 14px !important;
  517. font-weight: 400 !important;
  518. color: #555;
  519. cursor: pointer;
  520. transition: all 0.2s ease;
  521. text-align: left;
  522. border-bottom: none !important;
  523. }
  524. .submenu-item button:hover {
  525. background: #e9ecef;
  526. color: #667eea;
  527. transform: none !important;
  528. }
  529. .submenu-item button.actv {
  530. background: #e3f2fd;
  531. color: #667eea;
  532. font-weight: 500 !important;
  533. border-bottom: none !important;
  534. }
  535. .submenu-item button.actv::before {
  536. display: none;
  537. }
  538. </style>