header.vue 17 KB

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