header.vue 16 KB

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