header.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. {{ useStoreAuth.getSnsTempData?.user?.NICK_NAME || "사용자" }}
  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. </div>
  20. <nav class="gnb">
  21. <ul class="depth1">
  22. <li v-for="(menu, index) in arrMenuInfo" :key="index">
  23. <button
  24. @click="menuAction(menu.menuId, menu.menuName, menu.linkType)"
  25. :class="{ actv: menu.linkType === $route.path }"
  26. >
  27. {{ menu.menuName }}
  28. </button>
  29. </li>
  30. </ul>
  31. </nav>
  32. </header>
  33. </template>
  34. <script setup>
  35. /************************************************************************
  36. | 전역
  37. ************************************************************************/
  38. const { $log } = useNuxtApp();
  39. const proOn = ref(false);
  40. const pageId = "header";
  41. const arrMenuInfo = ref([]); // 메뉴정보
  42. const useStore = useDetailStore();
  43. const useStoreAuth = useAuthStore();
  44. const userName = ref("");
  45. const userCompanyName = ref("");
  46. const userId = ref("");
  47. const memberTypeText = ref("사용자");
  48. const route = useRoute();
  49. const router = useRouter();
  50. /************************************************************************
  51. | 함수 : 세팅
  52. ************************************************************************/
  53. const fnSetMenu = () => {
  54. let info = [];
  55. arrMenuInfo.value = [];
  56. // 사용자 타입 확인 (memberType으로 구분)
  57. const snsUser = useStoreAuth.getSnsTempData?.user;
  58. const authUser = JSON.parse(localStorage.getItem("authStore"))?.auth;
  59. const currentUser = snsUser || authUser;
  60. let memberType = currentUser?.memberType || currentUser?.MEMBER_TYPE;
  61. // memberType이 없으면 URL로 판단
  62. if (!memberType) {
  63. const currentPath = route.path;
  64. const companyNumber = currentUser?.COMPANY_NUMBER;
  65. // 벤더 대시보드 경로이거나 COMPANY_NUMBER가 있으면 벤더사로 판단
  66. if (currentPath.includes("/vendor/dashboard") || companyNumber) {
  67. memberType = "VENDOR";
  68. } else {
  69. memberType = "INFLUENCER";
  70. }
  71. }
  72. console.log("=== 헤더 메뉴 디버깅 ===");
  73. console.log("SNS 사용자:", snsUser);
  74. console.log("Auth 사용자:", authUser);
  75. console.log("현재 사용자:", currentUser);
  76. console.log("원본 memberType:", currentUser?.memberType);
  77. console.log("원본 MEMBER_TYPE:", currentUser?.MEMBER_TYPE);
  78. console.log("최종 memberType:", memberType);
  79. console.log("현재 경로:", route.path);
  80. console.log("COMPANY_NUMBER:", currentUser?.COMPANY_NUMBER);
  81. if (memberType === "VENDOR") {
  82. // 벤더사 메뉴
  83. memberTypeText.value = "벤더사";
  84. info.push(
  85. {
  86. menuId: "menu00",
  87. parentMenuId: "menu00",
  88. menuName: "주문 관리",
  89. linkType: "/view/vendor/dashboard",
  90. },
  91. {
  92. menuId: "menu01",
  93. parentMenuId: "menu01",
  94. menuName: "제품 관리",
  95. linkType: "/view/common/item",
  96. },
  97. {
  98. menuId: "menu02",
  99. parentMenuId: "menu02",
  100. menuName: "배송 관리",
  101. linkType: "/view/common/deli",
  102. },
  103. {
  104. menuId: "menu03",
  105. parentMenuId: "menu03",
  106. menuName: "인플루언서 관리",
  107. linkType: "/view/vendor/dashboard/influencer-requests",
  108. },
  109. {
  110. menuId: "menu04",
  111. parentMenuId: "menu04",
  112. menuName: "정산 관리",
  113. linkType: "/view/common/settle",
  114. },
  115. {
  116. menuId: "menu05",
  117. parentMenuId: "menu05",
  118. menuName: "고객센터",
  119. linkType: "/view/common/cs",
  120. }
  121. );
  122. } else {
  123. // 인플루언서 메뉴
  124. memberTypeText.value = "인플루언서";
  125. info.push(
  126. {
  127. menuId: "menu00",
  128. parentMenuId: "menu00",
  129. menuName: "주문 관리",
  130. linkType: "/view/vendor/dashboard",
  131. },
  132. {
  133. menuId: "menu01",
  134. parentMenuId: "menu01",
  135. menuName: "제품 관리",
  136. linkType: "/view/common/item",
  137. },
  138. {
  139. menuId: "menu02",
  140. parentMenuId: "menu02",
  141. menuName: "배송 관리",
  142. linkType: "/view/common/deli",
  143. },
  144. {
  145. menuId: "menu03",
  146. parentMenuId: "menu03",
  147. menuName: "벤더 관리",
  148. linkType: "/view/influencer/search",
  149. },
  150. {
  151. menuId: "menu04",
  152. parentMenuId: "menu04",
  153. menuName: "정산 관리",
  154. linkType: "/view/common/settle",
  155. },
  156. {
  157. menuId: "menu05",
  158. parentMenuId: "menu05",
  159. menuName: "고객센터",
  160. linkType: "/view/common/cs",
  161. }
  162. );
  163. }
  164. arrMenuInfo.value = info;
  165. $log.debug("[header][fnSetMenu][success] - MEMBER_TYPE:", memberType);
  166. };
  167. const menuAction = (__MENUID, _MENUROOTNAME, __URL) => {
  168. useStore.menuInfo.menuIndex = "0";
  169. useStore.menuInfo.menuId = __MENUID;
  170. useStore.menuInfo.pageRtName = _MENUROOTNAME;
  171. useStore.menuInfo.pageStatus = null;
  172. useUtil.setPageMove(__URL);
  173. };
  174. const fnLoguOut = () => {
  175. const { logout } = useLogout();
  176. logout();
  177. };
  178. const myPage = (userId) => {
  179. router.push({
  180. path: "/view/mng/mngAdd",
  181. });
  182. useDtStore.adminInfo.adminId = userId;
  183. useDtStore.adminInfo.pageType = "U";
  184. };
  185. const withdrawal = () => {
  186. let _req = {
  187. SEQ: useStoreAuth.getSnsTempData.user.SEQ,
  188. GOOGLE_REFRESH_TOKEN: useStoreAuth.getSnsTempData.user.GOOGLE_REFRESH_TOKEN,
  189. KAKAO_REFRESH_TOKEN: useStoreAuth.getSnsTempData.user.KAKAO_REFRESH_TOKEN,
  190. NAVER_REFRESH_TOKEN: useStoreAuth.getSnsTempData.user.NAVER_REFRESH_TOKEN,
  191. };
  192. let _uri = useStoreAuth.getSnsTempData.user.GOOGLE_REFRESH_TOKEN
  193. ? "/auth/withdrawal"
  194. : useStoreAuth.getSnsTempData.user.KAKAO_REFRESH_TOKEN
  195. ? "/auth/kakaowithdrawal"
  196. : useStoreAuth.getSnsTempData.user.NAVER_REFRESH_TOKEN
  197. ? "/auth/naverwithdrawal"
  198. : "/auth/withdrawal";
  199. useAxios()
  200. .post(_uri, _req)
  201. .then((res) => {
  202. localStorage.removeItem("tempAccess");
  203. useStore.getSnsTempData = "";
  204. useAuthStore().setLogout();
  205. router.push({
  206. path: "/",
  207. });
  208. })
  209. .catch((error) => {
  210. if (error.response) {
  211. console.log("status:", error.response.status, "data:", error.response.data);
  212. // 안전하게 errCode, message 접근
  213. const errData = error.response.data || {};
  214. const errCode = errData.errCode || errData.errorCode || errData.code || "";
  215. const errMsg = errData.message || "알 수 없는 오류가 발생했습니다.";
  216. console.log("errCode:", errCode, "message:", errMsg);
  217. } else {
  218. console.log("error:", error.message, error.code);
  219. }
  220. if (error.response?.status) {
  221. fnLoginSet(error.response.data.messages.message);
  222. }
  223. $log.debug("[withdrawal][fnIdPwCheck][error]");
  224. })
  225. .finally(() => {
  226. $log.debug("[withdrawal][fnIdPwCheck][finished]");
  227. });
  228. };
  229. /************************************************************************
  230. | 라이프사이클 : onMounted
  231. ************************************************************************/
  232. onMounted(() => {
  233. console.log(useStoreAuth.getSnsTempData.user);
  234. userId.value = localStorage.getItem("tempAccess");
  235. userName.value = JSON.parse(localStorage.getItem("authStore"))?.auth.name;
  236. userCompanyName.value = JSON.parse(
  237. localStorage.getItem("authStore")
  238. )?.auth.companyName;
  239. fnSetMenu();
  240. });
  241. </script>
  242. <style scoped>
  243. .new--header {
  244. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  245. box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  246. border-radius: 0 0 12px 12px;
  247. overflow: hidden;
  248. }
  249. .pro--wrap {
  250. display: flex;
  251. align-items: center;
  252. padding: 16px 24px;
  253. background: rgba(255, 255, 255, 0.95);
  254. backdrop-filter: blur(10px);
  255. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  256. }
  257. .pro--img {
  258. width: 40px;
  259. height: 40px;
  260. border-radius: 50%;
  261. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  262. display: flex;
  263. align-items: center;
  264. justify-content: center;
  265. margin-right: 12px;
  266. box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
  267. }
  268. /* .pro--img::before {
  269. content: "👤";
  270. color: white;
  271. font-size: 18px;
  272. } */
  273. .pro--id {
  274. position: relative;
  275. color: #374151;
  276. font-weight: 500;
  277. font-size: 16px;
  278. cursor: pointer;
  279. padding: 8px 12px;
  280. border-radius: 8px;
  281. transition: all 0.2s ease;
  282. }
  283. .pro--id:hover {
  284. background: rgba(102, 126, 234, 0.1);
  285. color: #667eea;
  286. }
  287. .ico {
  288. margin-left: 8px;
  289. transition: transform 0.2s ease;
  290. color: #9ca3af;
  291. }
  292. .ico.on {
  293. transform: rotate(90deg);
  294. color: #667eea;
  295. }
  296. .id--box {
  297. position: absolute;
  298. top: 100%;
  299. left: 0;
  300. margin-top: 8px;
  301. background: white;
  302. border: 1px solid #e5e7eb;
  303. border-radius: 12px;
  304. box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  305. z-index: 1000;
  306. overflow: hidden;
  307. min-width: 160px;
  308. }
  309. .btn-profile,
  310. .btn-logout {
  311. width: 100%;
  312. padding: 16px 20px;
  313. border: none;
  314. background: none;
  315. text-align: left;
  316. cursor: pointer;
  317. transition: all 0.2s ease;
  318. font-size: 14px;
  319. color: #374151;
  320. }
  321. .btn-profile:hover {
  322. background: #f3f4f6;
  323. color: #667eea;
  324. }
  325. .btn-logout:hover {
  326. background: #fef2f2;
  327. color: #dc2626;
  328. }
  329. .pro--info {
  330. margin-left: auto;
  331. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  332. color: white;
  333. padding: 6px 16px;
  334. border-radius: 20px;
  335. font-size: 14px;
  336. font-weight: 500;
  337. box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
  338. }
  339. .gnb {
  340. background: rgba(255, 255, 255, 0.98);
  341. backdrop-filter: blur(10px);
  342. }
  343. .depth1 {
  344. display: flex;
  345. width: 100%;
  346. list-style: none;
  347. margin: 0;
  348. padding: 0;
  349. align-items: center;
  350. }
  351. .depth1 button {
  352. width: 100%;
  353. padding: 16px 24px;
  354. border: none;
  355. background: none;
  356. font-size: 15px;
  357. font-weight: 500;
  358. color: #6b7280;
  359. cursor: pointer;
  360. transition: all 0.3s ease;
  361. position: relative;
  362. border-bottom: 3px solid transparent;
  363. text-align: left;
  364. }
  365. .depth1 button:hover {
  366. color: #667eea;
  367. transform: translateY(-1px);
  368. }
  369. .depth1 button.actv {
  370. color: #667eea;
  371. border-bottom-color: #667eea;
  372. font-weight: 600;
  373. }
  374. .depth1 button.actv::before {
  375. content: "";
  376. position: absolute;
  377. bottom: -3px;
  378. left: 50%;
  379. transform: translateX(-50%);
  380. width: 60%;
  381. height: 3px;
  382. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  383. border-radius: 2px;
  384. }
  385. </style>