header.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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 = (userId) => {
  277. router.push({
  278. path: "/view/mng/mngAdd",
  279. });
  280. useDtStore.adminInfo.adminId = userId;
  281. useDtStore.adminInfo.pageType = "U";
  282. };
  283. const withdrawal = () => {
  284. let _req = {
  285. SEQ: useStoreAuth.getSnsTempData.user.SEQ,
  286. GOOGLE_REFRESH_TOKEN: useStoreAuth.getSnsTempData.user.GOOGLE_REFRESH_TOKEN,
  287. KAKAO_REFRESH_TOKEN: useStoreAuth.getSnsTempData.user.KAKAO_REFRESH_TOKEN,
  288. NAVER_REFRESH_TOKEN: useStoreAuth.getSnsTempData.user.NAVER_REFRESH_TOKEN,
  289. };
  290. let _uri = useStoreAuth.getSnsTempData.user.GOOGLE_REFRESH_TOKEN
  291. ? "/auth/withdrawal"
  292. : useStoreAuth.getSnsTempData.user.KAKAO_REFRESH_TOKEN
  293. ? "/auth/kakaowithdrawal"
  294. : useStoreAuth.getSnsTempData.user.NAVER_REFRESH_TOKEN
  295. ? "/auth/naverwithdrawal"
  296. : "/auth/withdrawal";
  297. useAxios()
  298. .post(_uri, _req)
  299. .then((res) => {
  300. localStorage.removeItem("tempAccess");
  301. useStore.getSnsTempData = "";
  302. useAuthStore().setLogout();
  303. router.push({
  304. path: "/",
  305. });
  306. })
  307. .catch((error) => {
  308. if (error.response) {
  309. console.log("status:", error.response.status, "data:", error.response.data);
  310. // 안전하게 errCode, message 접근
  311. const errData = error.response.data || {};
  312. const errCode = errData.errCode || errData.errorCode || errData.code || "";
  313. const errMsg = errData.message || "알 수 없는 오류가 발생했습니다.";
  314. console.log("errCode:", errCode, "message:", errMsg);
  315. } else {
  316. console.log("error:", error.message, error.code);
  317. }
  318. if (error.response?.status) {
  319. fnLoginSet(error.response.data.messages.message);
  320. }
  321. $log.debug("[withdrawal][fnIdPwCheck][error]");
  322. })
  323. .finally(() => {
  324. $log.debug("[withdrawal][fnIdPwCheck][finished]");
  325. });
  326. };
  327. // 페이지 변경 시 아코디언 상태 관리 (간단한 ref 기반)
  328. const currentActivePage = ref(route.path);
  329. /************************************************************************
  330. | 라이프사이클 : onMounted
  331. ************************************************************************/
  332. onMounted(() => {
  333. console.log(useStoreAuth.getSnsTempData.user);
  334. userId.value = localStorage.getItem("tempAccess");
  335. // userName.value = JSON.parse(localStorage.getItem("authStore"))?.auth.name;
  336. // userCompanyName.value = JSON.parse(
  337. // localStorage.getItem("authStore")
  338. // )?.auth.companyName;
  339. fnSetMenu();
  340. });
  341. </script>
  342. <style scoped>
  343. .new--header {
  344. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  345. box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  346. border-radius: 0 0 12px 12px;
  347. overflow: hidden;
  348. }
  349. .pro--wrap {
  350. display: flex;
  351. align-items: center;
  352. padding: 16px 24px;
  353. background: rgba(255, 255, 255, 0.95);
  354. backdrop-filter: blur(10px);
  355. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  356. }
  357. .pro--img {
  358. width: 40px;
  359. height: 40px;
  360. border-radius: 50%;
  361. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  362. display: flex;
  363. align-items: center;
  364. justify-content: center;
  365. margin-right: 12px;
  366. box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
  367. }
  368. /* .pro--img::before {
  369. content: "👤";
  370. color: white;
  371. font-size: 18px;
  372. } */
  373. .pro--id {
  374. position: relative;
  375. color: #374151;
  376. font-weight: 500;
  377. font-size: 16px;
  378. cursor: pointer;
  379. padding: 8px 12px;
  380. border-radius: 8px;
  381. transition: all 0.2s ease;
  382. }
  383. .pro--id:hover {
  384. background: rgba(102, 126, 234, 0.1);
  385. color: #667eea;
  386. }
  387. .ico {
  388. margin-left: 8px;
  389. transition: transform 0.2s ease;
  390. color: #9ca3af;
  391. }
  392. .ico.on {
  393. transform: rotate(90deg);
  394. color: #667eea;
  395. }
  396. .id--box {
  397. position: absolute;
  398. top: 100%;
  399. left: 0;
  400. margin-top: 8px;
  401. background: white;
  402. border: 1px solid #e5e7eb;
  403. border-radius: 12px;
  404. box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  405. z-index: 1000;
  406. overflow: hidden;
  407. min-width: 160px;
  408. }
  409. .btn-profile,
  410. .btn-logout {
  411. width: 100%;
  412. padding: 16px 20px;
  413. border: none;
  414. background: none;
  415. text-align: left;
  416. cursor: pointer;
  417. transition: all 0.2s ease;
  418. font-size: 14px;
  419. color: #374151;
  420. }
  421. .btn-profile:hover {
  422. background: #f3f4f6;
  423. color: #667eea;
  424. }
  425. .btn-logout:hover {
  426. background: #fef2f2;
  427. color: #dc2626;
  428. }
  429. .pro--info {
  430. margin-left: auto;
  431. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  432. color: white;
  433. padding: 6px 16px;
  434. border-radius: 20px;
  435. font-size: 14px;
  436. font-weight: 500;
  437. box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
  438. }
  439. .gnb {
  440. background: rgba(255, 255, 255, 0.98);
  441. backdrop-filter: blur(10px);
  442. }
  443. .depth1 {
  444. display: flex;
  445. flex-direction: column;
  446. width: 100%;
  447. list-style: none;
  448. margin: 0;
  449. padding: 0;
  450. }
  451. .depth1 button {
  452. width: 100%;
  453. padding: 16px 24px;
  454. border: none;
  455. background: none;
  456. font-size: 15px;
  457. font-weight: 500;
  458. color: #6b7280;
  459. cursor: pointer;
  460. transition: all 0.3s ease;
  461. position: relative;
  462. border-bottom: 3px solid transparent;
  463. text-align: left;
  464. }
  465. .depth1 button:hover {
  466. color: #667eea;
  467. transform: translateY(-1px);
  468. }
  469. .depth1 button.actv {
  470. color: #667eea;
  471. border-bottom-color: #667eea;
  472. font-weight: 600;
  473. }
  474. .depth1 button.actv::before {
  475. content: "";
  476. position: absolute;
  477. bottom: -3px;
  478. left: 50%;
  479. transform: translateX(-50%);
  480. width: 60%;
  481. height: 3px;
  482. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  483. border-radius: 2px;
  484. }
  485. /* 하위 메뉴가 있는 항목 스타일 */
  486. .has-submenu {
  487. position: relative;
  488. }
  489. .ico-arrow {
  490. font-size: 10px;
  491. margin-left: 6px;
  492. transition: transform 0.2s ease;
  493. font-style: normal;
  494. position: absolute;
  495. right: 24px;
  496. top: 50%;
  497. transform: translateY(-50%);
  498. }
  499. .ico-arrow.rotate {
  500. transform: rotate(180deg);
  501. }
  502. /* 하위 메뉴 스타일 */
  503. .submenu-item {
  504. background: #f8f9fa;
  505. }
  506. .submenu-item button {
  507. width: 100%;
  508. padding: 12px 24px 12px 40px !important;
  509. border: none;
  510. background: none;
  511. font-size: 14px !important;
  512. font-weight: 400 !important;
  513. color: #555;
  514. cursor: pointer;
  515. transition: all 0.2s ease;
  516. text-align: left;
  517. border-bottom: none !important;
  518. }
  519. .submenu-item button:hover {
  520. background: #e9ecef;
  521. color: #667eea;
  522. transform: none !important;
  523. }
  524. .submenu-item button.actv {
  525. background: #e3f2fd;
  526. color: #667eea;
  527. font-weight: 500 !important;
  528. border-bottom: none !important;
  529. }
  530. .submenu-item button.actv::before {
  531. display: none;
  532. }
  533. </style>