header.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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>