header.vue 16 KB

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