header.vue 16 KB

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