header.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. <button type="button" class="btn-profile" @click="withdrawal">회원탈퇴</button>
  13. <button type="button" class="btn-logout" @click="fnLoguOut">로그아웃</button>
  14. </div>
  15. </div>
  16. <div class="pro--info inf">{{ memberTypeText }}</div>
  17. </div>
  18. <nav class="gnb">
  19. <ul class="depth1">
  20. <li v-for="(menu, index) in arrMenuInfo" :key="index">
  21. <button
  22. @click="menuAction(menu.menuId, menu.menuName, menu.linkType)"
  23. :class="{ actv: menu.linkType === $route.path }"
  24. >
  25. {{ menu.menuName }}
  26. </button>
  27. </li>
  28. </ul>
  29. </nav>
  30. </header>
  31. </template>
  32. <script setup>
  33. /************************************************************************
  34. | 전역
  35. ************************************************************************/
  36. const { $log } = useNuxtApp();
  37. const proOn = ref(false);
  38. const pageId = "header";
  39. const arrMenuInfo = ref([]); // 메뉴정보
  40. const useStore = useDetailStore();
  41. const useStoreAuth = useAuthStore();
  42. const userName = ref("");
  43. const userCompanyName = ref("");
  44. const userId = ref("");
  45. const memberTypeText = ref("사용자");
  46. const route = useRoute();
  47. const router = useRouter();
  48. /************************************************************************
  49. | 함수 : 세팅
  50. ************************************************************************/
  51. const fnSetMenu = () => {
  52. let info = [];
  53. arrMenuInfo.value = [];
  54. // 사용자 타입 확인 (memberType으로 구분)
  55. const snsUser = useStoreAuth.getSnsTempData?.user;
  56. const authUser = JSON.parse(localStorage.getItem("authStore"))?.auth;
  57. const currentUser = snsUser || authUser;
  58. let memberType = currentUser?.memberType || currentUser?.MEMBER_TYPE;
  59. // memberType이 없으면 URL로 판단
  60. if (!memberType) {
  61. const currentPath = route.path;
  62. const companyNumber = currentUser?.COMPANY_NUMBER;
  63. // 벤더 대시보드 경로이거나 COMPANY_NUMBER가 있으면 벤더사로 판단
  64. if (currentPath.includes("/vendor/dashboard") || companyNumber) {
  65. memberType = "VENDOR";
  66. } else {
  67. memberType = "INFLUENCER";
  68. }
  69. }
  70. console.log("=== 헤더 메뉴 디버깅 ===");
  71. console.log("SNS 사용자:", snsUser);
  72. console.log("Auth 사용자:", authUser);
  73. console.log("현재 사용자:", currentUser);
  74. console.log("원본 memberType:", currentUser?.memberType);
  75. console.log("원본 MEMBER_TYPE:", currentUser?.MEMBER_TYPE);
  76. console.log("최종 memberType:", memberType);
  77. console.log("현재 경로:", route.path);
  78. console.log("COMPANY_NUMBER:", currentUser?.COMPANY_NUMBER);
  79. if (memberType === "VENDOR") {
  80. // 벤더사 메뉴
  81. memberTypeText.value = "벤더사";
  82. info.push(
  83. {
  84. menuId: "menu00",
  85. parentMenuId: "menu00",
  86. menuName: "주문 관리",
  87. linkType: "/view/vendor/dashboard",
  88. },
  89. {
  90. menuId: "menu01",
  91. parentMenuId: "menu01",
  92. menuName: "제품 관리",
  93. linkType: "/view/common/item",
  94. },
  95. {
  96. menuId: "menu02",
  97. parentMenuId: "menu02",
  98. menuName: "배송 관리",
  99. linkType: "/view/common/deli",
  100. },
  101. {
  102. menuId: "menu03",
  103. parentMenuId: "menu03",
  104. menuName: "인플루언서 관리",
  105. linkType: "/view/vendor/dashboard/influencer-requests",
  106. },
  107. {
  108. menuId: "menu04",
  109. parentMenuId: "menu04",
  110. menuName: "정산 관리",
  111. linkType: "/view/common/settle",
  112. },
  113. {
  114. menuId: "menu05",
  115. parentMenuId: "menu05",
  116. menuName: "고객센터",
  117. linkType: "/view/common/cs",
  118. }
  119. );
  120. } else {
  121. // 인플루언서 메뉴
  122. memberTypeText.value = "인플루언서";
  123. info.push(
  124. {
  125. menuId: "menu00",
  126. parentMenuId: "menu00",
  127. menuName: "주문 관리",
  128. linkType: "/view/vendor/dashboard",
  129. },
  130. {
  131. menuId: "menu01",
  132. parentMenuId: "menu01",
  133. menuName: "제품 관리",
  134. linkType: "/view/common/item",
  135. },
  136. {
  137. menuId: "menu02",
  138. parentMenuId: "menu02",
  139. menuName: "배송 관리",
  140. linkType: "/view/common/deli",
  141. },
  142. {
  143. menuId: "menu03",
  144. parentMenuId: "menu03",
  145. menuName: "벤더 관리",
  146. linkType: "/view/influencer/search",
  147. },
  148. {
  149. menuId: "menu04",
  150. parentMenuId: "menu04",
  151. menuName: "정산 관리",
  152. linkType: "/view/common/settle",
  153. },
  154. {
  155. menuId: "menu05",
  156. parentMenuId: "menu05",
  157. menuName: "고객센터",
  158. linkType: "/view/common/cs",
  159. }
  160. );
  161. }
  162. arrMenuInfo.value = info;
  163. $log.debug("[header][fnSetMenu][success] - MEMBER_TYPE:", memberType);
  164. };
  165. const menuAction = (__MENUID, _MENUROOTNAME, __URL) => {
  166. useStore.menuInfo.menuIndex = "0";
  167. useStore.menuInfo.menuId = __MENUID;
  168. useStore.menuInfo.pageRtName = _MENUROOTNAME;
  169. useStore.menuInfo.pageStatus = null;
  170. useUtil.setPageMove(__URL);
  171. };
  172. const fnLoguOut = () => {
  173. const { logout } = useLogout();
  174. logout();
  175. };
  176. const myPage = (userId) => {
  177. router.push({
  178. path: "/view/mng/mngAdd",
  179. });
  180. useDtStore.adminInfo.adminId = userId;
  181. useDtStore.adminInfo.pageType = "U";
  182. };
  183. const withdrawal = () => {
  184. let _req = {
  185. SEQ: useStoreAuth.getSnsTempData.user.SEQ,
  186. GOOGLE_REFRESH_TOKEN: useStoreAuth.getSnsTempData.user.GOOGLE_REFRESH_TOKEN,
  187. KAKAO_REFRESH_TOKEN: useStoreAuth.getSnsTempData.user.KAKAO_REFRESH_TOKEN,
  188. NAVER_REFRESH_TOKEN: useStoreAuth.getSnsTempData.user.NAVER_REFRESH_TOKEN,
  189. };
  190. let _uri = useStoreAuth.getSnsTempData.user.GOOGLE_REFRESH_TOKEN
  191. ? "/auth/withdrawal"
  192. : useStoreAuth.getSnsTempData.user.KAKAO_REFRESH_TOKEN
  193. ? "/auth/kakaowithdrawal"
  194. : useStoreAuth.getSnsTempData.user.NAVER_REFRESH_TOKEN
  195. ? "/auth/naverwithdrawal"
  196. : "/auth/withdrawal";
  197. useAxios()
  198. .post(_uri, _req)
  199. .then((res) => {
  200. localStorage.removeItem("tempAccess");
  201. useStore.getSnsTempData = "";
  202. useAuthStore().setLogout();
  203. router.push({
  204. path: "/",
  205. });
  206. })
  207. .catch((error) => {
  208. if (error.response) {
  209. console.log("status:", error.response.status, "data:", error.response.data);
  210. // 안전하게 errCode, message 접근
  211. const errData = error.response.data || {};
  212. const errCode = errData.errCode || errData.errorCode || errData.code || "";
  213. const errMsg = errData.message || "알 수 없는 오류가 발생했습니다.";
  214. console.log("errCode:", errCode, "message:", errMsg);
  215. } else {
  216. console.log("error:", error.message, error.code);
  217. }
  218. if (error.response?.status) {
  219. fnLoginSet(error.response.data.messages.message);
  220. }
  221. $log.debug("[withdrawal][fnIdPwCheck][error]");
  222. })
  223. .finally(() => {
  224. $log.debug("[withdrawal][fnIdPwCheck][finished]");
  225. });
  226. };
  227. /************************************************************************
  228. | 라이프사이클 : onMounted
  229. ************************************************************************/
  230. onMounted(() => {
  231. console.log(useStoreAuth.getSnsTempData.user);
  232. userId.value = localStorage.getItem("tempAccess");
  233. userName.value = JSON.parse(localStorage.getItem("authStore"))?.auth.name;
  234. userCompanyName.value = JSON.parse(
  235. localStorage.getItem("authStore")
  236. )?.auth.companyName;
  237. fnSetMenu();
  238. });
  239. </script>