index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <template>
  2. <div class="login-wrap">
  3. <!-- header -->
  4. <div class="login--header">
  5. <div class="login--header--l">
  6. <div class="logo">
  7. <!-- prettier-ignore -->
  8. SHOPDELI
  9. </div>
  10. </div>
  11. <div class="login--header--r"></div>
  12. </div>
  13. <!-- login -->
  14. <div class="login-box">
  15. <div class="login-l">
  16. <div class="login-l-center">
  17. <span class="logo">
  18. <!-- prettier-ignore -->
  19. SHOPDELI
  20. </span>
  21. <!-- <p>We Make Scalable Mobility Life</p> -->
  22. </div>
  23. </div>
  24. <div class="login-r">
  25. <div class="tit-login">
  26. <strong>로그인</strong>
  27. </div>
  28. <div class="login-input-wrap">
  29. <div
  30. class="txt-field-box"
  31. :class="!loginForm.validCheck.input.userId ? 'error' : ''"
  32. >
  33. <v-text-field
  34. v-model="loginForm.userId"
  35. placeholder="아이디를 입력해주세요"
  36. class="custom-input"
  37. @keyup.enter="loginAction(loginForm.userId, loginForm.passwd)"
  38. @input="setInputField('main_userId')"
  39. ></v-text-field>
  40. <i class="ico"></i>
  41. </div>
  42. <div
  43. class="txt-field-box"
  44. :class="!loginForm.validCheck.input.passwd ? 'error' : ''"
  45. >
  46. <v-text-field
  47. v-model="loginForm.passwd"
  48. :type="visible ? 'text' : 'password'"
  49. placeholder="비밀번호를 입력해주세요"
  50. class="custom-input"
  51. id="password"
  52. @keyup.enter="loginAction(loginForm.userId, loginForm.passwd)"
  53. @input="setInputField('main_passwd')"
  54. ></v-text-field>
  55. <i
  56. class="ico-eye"
  57. @click.stop="toggleVisibility"
  58. :class="visible ? 'eye-on' : 'eye-off'"
  59. ></i>
  60. <i class="ico"></i>
  61. </div>
  62. <!-- <p class="error-txt" v-if="!loginForm.validCheck.inputErrorCheck">
  63. {{ loginForm.validCheck.passwd }}
  64. </p> -->
  65. </div>
  66. <div class="login-btn-wrap">
  67. <v-btn
  68. class="custom-btn btn-blue"
  69. @keyup.enter="loginAction(loginForm.userId, loginForm.passwd)"
  70. @click="loginAction(loginForm.userId, loginForm.passwd)"
  71. >로그인</v-btn
  72. >
  73. </div>
  74. <div class="join--btn--wrap">
  75. <v-btn class="custom-btn text--btn">아이디 찾기</v-btn>
  76. <v-btn class="custom-btn text--btn">비밀번호 찾기</v-btn>
  77. <v-btn class="custom-btn text--btn" @click="location('join')">회원가입</v-btn>
  78. </div>
  79. <div class="short--login--wrap">
  80. <v-btn class="btn--google" @click="onGoogleLogin"></v-btn>
  81. <v-btn class="btn--kakao"></v-btn>
  82. <v-btn class="btn--naver"></v-btn>
  83. </div>
  84. </div>
  85. </div>
  86. <!-- footer -->
  87. <div class="login-footer">
  88. <div class="login--footer--l">
  89. <p>COPYRIGHT@2025 SHOPDELI INC. ALL RIGHTS RESERVED.</p>
  90. <p>마포구 합정동</p>
  91. </div>
  92. </div>
  93. </div>
  94. </template>
  95. <script setup>
  96. /************************
  97. * import
  98. ************************/
  99. //import PrivacyPop from "@/components/login/privacyPop.vue";
  100. //import AgrNPop from "@/components/terms/agreeNListPop.vue";
  101. import apiUrl from "@/composables/useApi";
  102. import QRCode from "qrcode";
  103. import { useI18n } from "vue-i18n";
  104. /************************
  105. * layout setting
  106. ************************/
  107. definePageMeta({
  108. layout: "loginlayout",
  109. });
  110. /************************
  111. * plugins inject
  112. ************************/
  113. const { $dayjs, $log, $eventBus, $toast, $userAgent } = useNuxtApp();
  114. const useStore = useDetailStore();
  115. /************************
  116. * data & created
  117. ************************/
  118. // 현재 입력 중인 필드를 설정하는 함수
  119. const setInputField = (name) => {
  120. fnValidCheck(name);
  121. };
  122. const pageId = "login";
  123. const i18n = useI18n();
  124. // 다국어
  125. let listObj = ref({
  126. langTypeList: {},
  127. });
  128. // 로그인 정보
  129. const loginForm = ref({
  130. userId: "",
  131. passwd: "",
  132. otpNum: "",
  133. username: "",
  134. authType: "GOOGLE",
  135. userAgent: "",
  136. validCheck: {
  137. input: {
  138. userId: true,
  139. passwd: true,
  140. },
  141. otp: {
  142. otpNum: true,
  143. },
  144. inputErrorCheck: true,
  145. inputValidTxt: "",
  146. otpValidTxt: "",
  147. loginValidCheck: false,
  148. btnTxt: "",
  149. btnTxtType: "",
  150. },
  151. });
  152. // 구글 OTP 1차 팝업
  153. const authPop1 = ref({
  154. popYn: false,
  155. certifyYN: false,
  156. userId: "",
  157. passwd: "",
  158. otpNum: "",
  159. validOtpKey: true,
  160. validOtpTxt: "",
  161. btnTxt: "",
  162. btnTxtType: "",
  163. applyBtn: false,
  164. succOtpYn: false,
  165. businessName: "",
  166. agreeChk1: false,
  167. agreeChk2: false,
  168. validCheck: {
  169. userId: true,
  170. passwd: true,
  171. },
  172. validTxt: "",
  173. errorCheck: false,
  174. });
  175. // 구글 OTP 2차 팝업
  176. const authPop2 = ref({
  177. popYn: false,
  178. otpNum: "",
  179. validOtpKey: true,
  180. validOtpTxt: "",
  181. errorCheck: false,
  182. });
  183. // 아이디 찾기
  184. const findId = ref({
  185. popYn: false,
  186. //tenantName: '',
  187. email: "",
  188. otpNum: "",
  189. validCheck: {
  190. input: {
  191. //tenantName: true,
  192. email: true,
  193. },
  194. otp: {
  195. otpNum: true,
  196. },
  197. inputErrorCheck: true,
  198. inputValidTxt: "",
  199. otpValidTxt: "",
  200. findIdValidCheck: false,
  201. },
  202. btnTxt: "",
  203. });
  204. // 비밀번호 초기화
  205. const resetPw = ref({
  206. popYn: false,
  207. userId: "",
  208. email: "",
  209. otpNum: "",
  210. validCheck: {
  211. input: {
  212. userId: true,
  213. email: true,
  214. },
  215. otp: {
  216. otpNum: true,
  217. },
  218. inputErrorCheck: true,
  219. inputValidTxt: "",
  220. otpValidTxt: "",
  221. resetPwValidCheck: false,
  222. },
  223. btnTxt: "",
  224. });
  225. // 초기 패스워드 변경
  226. const initPw = ref({
  227. popYn: false,
  228. passwd: "",
  229. passwd2: "",
  230. validCheck: {
  231. passwd: true,
  232. passwd2: true,
  233. },
  234. passwdCheck: false,
  235. errorTxt: "",
  236. });
  237. const selectPlaceholder = ref("");
  238. const initAuthPop1 = ref({});
  239. const initAuthPop2 = ref({});
  240. const initFindId = ref({});
  241. const initResetPw = ref({});
  242. const initInitPw = ref({});
  243. const googleOtpQrCode = ref("");
  244. const googleOtpSecretKey = ref("");
  245. const loginInfo = ref({});
  246. const checkbox = ref(false);
  247. const langType = ref("");
  248. const toggleVisibility = () => {
  249. visible.value = !visible.value;
  250. };
  251. const visible = ref(false);
  252. const isAgrNPop = ref(false);
  253. const isShowAgrNPop = ref(false);
  254. let saveId = localStorage.getItem("saveId");
  255. if (saveId) {
  256. checkbox.value = true;
  257. loginForm.value.userId = saveId;
  258. }
  259. // 개인정보처리방침 이용약관 팝업
  260. //const privacyPop = ref(false);
  261. const privacyDetail = ref({
  262. kr: {
  263. title: "",
  264. contents: "",
  265. },
  266. en: {
  267. title: "",
  268. contents: "",
  269. },
  270. });
  271. const systemInfo = ref({
  272. mode: "",
  273. });
  274. const loginAction = (__ID, __PASS) => {
  275. let _req = {
  276. id: __ID,
  277. password: __PASS,
  278. };
  279. useAxios()
  280. .post("/roulette/login", _req)
  281. .then((res) => {
  282. if (res.data) {
  283. // console.log(res.data);
  284. useAuthStore().setAuth(res.data);
  285. useAuthStore().setAccessToken(res.data.accessToken);
  286. useAuthStore().setRefreshToken(res.data.refreshToken);
  287. localStorage.setItem("tempAccess", __ID);
  288. useUtil.setPageMove("/view/item");
  289. useStore.menuInfo.menuIndex = "0";
  290. useStore.menuInfo.menuId = "menu01";
  291. useStore.menuInfo.pageRtName = "제품 관리";
  292. useStore.menuInfo.pageStatus = null;
  293. }
  294. })
  295. .catch((error) => {
  296. if (error.response) {
  297. console.log("status:", error.response.status, "data:", error.response.data);
  298. // 안전하게 errCode, message 접근
  299. const errData = error.response.data || {};
  300. const errCode = errData.errCode || errData.errorCode || errData.code || "";
  301. const errMsg = errData.message || "알 수 없는 오류가 발생했습니다.";
  302. console.log("errCode:", errCode, "message:", errMsg);
  303. } else {
  304. console.log("error:", error.message, error.code);
  305. }
  306. if (error.response?.status) {
  307. fnLoginSet(error.response.data.messages.message);
  308. }
  309. $log.debug("[login][fnIdPwCheck][error]");
  310. })
  311. .finally(() => {
  312. $log.debug("[login][fnIdPwCheck][finished]");
  313. });
  314. };
  315. const location = (__id) => {
  316. switch (__id) {
  317. case "join":
  318. useUtil.setPageMove("/auth/join");
  319. break;
  320. case "findId":
  321. findId.value.popYn = true;
  322. break;
  323. case "resetPw":
  324. resetPw.value.popYn = true;
  325. break;
  326. default:
  327. break;
  328. }
  329. };
  330. // onMounted
  331. onMounted(() => {
  332. function handleMessage(event) {
  333. // 개발환경이면 아래처럼 확인
  334. if (
  335. event.origin === "http://0.0.0.0:3000" || //배포시 도메인 변경
  336. event.origin === "http://localhost:3000" //배포시 도메인 변경
  337. ) {
  338. const { accessToken, refreshToken, user } = event.data;
  339. if (user?.JOIN === "1") {
  340. useAuthStore().setTempData(user);
  341. useUtil.setPageMove("/auth/join");
  342. } else {
  343. //useAuthStore().setAuth(res.data);
  344. const result = {
  345. refreshToken: refreshToken,
  346. user: user,
  347. };
  348. //console.log(result);
  349. //return;
  350. useAuthStore().setTempData(result);
  351. useAuthStore().setAccessToken(accessToken);
  352. useAuthStore().setRefreshToken(refreshToken);
  353. localStorage.setItem("tempAccess", result.user.NICK_NAME);
  354. useUtil.setPageMove("/view/item");
  355. useStore.menuInfo.menuIndex = "0";
  356. useStore.menuInfo.menuId = "menu02";
  357. useStore.menuInfo.pageRtName = "이벤트 관리";
  358. useStore.menuInfo.pageStatus = null;
  359. }
  360. }
  361. }
  362. window.addEventListener("message", handleMessage);
  363. onBeforeUnmount(() => window.removeEventListener("message", handleMessage));
  364. });
  365. watchEffect(() => {
  366. // 감시하고자 하는 데이터를 해당 블럭내에서 사용하면 호출된다.
  367. // getLang.value를 감시하는 상태
  368. //QfnGetEnumCode(useLangStore().getLang);
  369. });
  370. // $eventBus.off("SET_SUCCESS_POPUP");
  371. // $eventBus.on("SET_SUCCESS_POPUP", () => {
  372. // // 안내 팝업 확인 클릭 팝업 초기화처리
  373. // fnOtpPopClose("findId");
  374. // fnOtpPopClose("resetPw");
  375. // });
  376. // $eventBus.off("PASSWD_CHANGE");
  377. // $eventBus.on("PASSWD_CHANGE", () => {
  378. // fnPasswdChange();
  379. // });
  380. // $eventBus.off("INIT_PASSWORD");
  381. // $eventBus.on("INIT_PASSWORD", () => {
  382. // initPw.value.popYn = true;
  383. // });
  384. // $eventBus.off("SET_LOGIN");
  385. // $eventBus.on("SET_LOGIN", () => {
  386. // fnLogin();
  387. // });
  388. /************************
  389. * Methods
  390. ************************/
  391. const fnLoginSet = (__MSG) => {
  392. let param = {
  393. id: pageId,
  394. title: "로그인",
  395. content: __MSG,
  396. yes: {
  397. text: "확인",
  398. isProc: true,
  399. event: "FN_LOGIN",
  400. param: "",
  401. },
  402. no: {
  403. text: "취소",
  404. isProc: false,
  405. },
  406. };
  407. $eventBus.emit("OPEN_CONFIRM_POP_UP", param);
  408. };
  409. // 구글 로그인 버튼 클릭 시 호출
  410. function onGoogleLogin() {
  411. const clientId =
  412. "373780605211-diojebh7mug45urv9rnqdil6n0b1ogge.apps.googleusercontent.com"; // 실제 클라이언트 ID로 교체
  413. const redirectUri = "https://shopdeli.mycafe24.com/auth/callback"; // 실제 리디렉션 URI로 교체
  414. const scope = "openid email profile";
  415. const responseType = "code"; // 또는 'code' (백엔드 연동 시)
  416. const state = Math.random().toString(36).substring(2);
  417. const googleAuthUrl = `https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&client_id=${clientId}&redirect_uri=${encodeURIComponent(
  418. redirectUri
  419. )}&response_type=${responseType}&scope=${encodeURIComponent(scope)}&state=${state}`;
  420. const width = 500;
  421. const height = 600;
  422. const dualScreenLeft =
  423. window.screenLeft !== undefined ? window.screenLeft : window.screenX;
  424. const dualScreenTop =
  425. window.screenTop !== undefined ? window.screenTop : window.screenY;
  426. const currentWidth = window.innerWidth
  427. ? window.innerWidth
  428. : document.documentElement.clientWidth
  429. ? document.documentElement.clientWidth
  430. : screen.width;
  431. const currentHeight = window.innerHeight
  432. ? window.innerHeight
  433. : document.documentElement.clientHeight
  434. ? document.documentElement.clientHeight
  435. : screen.height;
  436. const left = dualScreenLeft + (currentWidth - width) / 2;
  437. const top = dualScreenTop + (currentHeight - height) / 2;
  438. window.open(
  439. googleAuthUrl,
  440. "googleLogin",
  441. `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`
  442. );
  443. }
  444. /**
  445. * @API
  446. * 최종 로그인 버튼 클릭 시 API
  447. */
  448. function fnLogin(__USERID, __USERPASS) {
  449. // 파라미터 전달 값 [아이디, 비밀번호, otpNum, 브라우저정보]
  450. //userId: loginForm.value.userId,
  451. // let _req = {
  452. // username: loginForm.value.userId,
  453. // password: btoa(loginForm.value.passwd),
  454. // };
  455. localStorage.setItem("tempAccess", __USERID);
  456. if (__USERID == "admin" && __USERPASS == "1234") {
  457. useUtil.setPageMove("/view/media/newsList");
  458. } else {
  459. fnLoginSet("비밀번호가 맞지 않습니다. 확인해주세요.");
  460. }
  461. // useAxios()
  462. // .post(apiUrl.otpCheck, _req)
  463. // .then((res) => {
  464. // loginInfo.value = res.data.data;
  465. // useAuthStore().setAccessToken(loginInfo.value.accessToken);
  466. // useAuthStore().setRefreshToken(loginInfo.value.refreshToken);
  467. // // OTP key체크 성공 후 개인정보에 대한 API를 호출 한다.
  468. // fnServiceModeCheck();
  469. // $log.debug("[login][fnLogin][success]");
  470. // })
  471. // .catch((error) => {
  472. // $log.debug("[login][fnLogin][error]");
  473. // let errorData = error.response.data;
  474. // errorData.type = "fnLogin";
  475. // fnLoginFail(errorData);
  476. // })
  477. // .finally(() => {
  478. // $log.debug("[login][fnLogin][finished]");
  479. // });
  480. }
  481. </script>