header.vue 16 KB

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