header.vue 16 KB

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