yjryu / KERIS star
윤주 2023-10-30
231030 류윤주 login 커밋
@bf3367e22a27325750186533e83c4d9c08b9a5db
client/views/layout/AdminFooter.vue
--- client/views/layout/AdminFooter.vue
+++ client/views/layout/AdminFooter.vue
@@ -14,7 +14,7 @@
   computed: {},
   components: {},
   mounted() {
-    console.log("Header mounted");
+    console.log("admin footer mounted");
   },
 };
 </script>
client/views/layout/AdminHeader.vue
--- client/views/layout/AdminHeader.vue
+++ client/views/layout/AdminHeader.vue
@@ -51,7 +51,7 @@
     computed: {},
     components: {},
     mounted() {
-        console.log("Header mounted");
+        console.log("adminHeader mounted");
         console.log("Header route: ", this.route);
     },
 };
client/views/layout/AdminMenu.vue
--- client/views/layout/AdminMenu.vue
+++ client/views/layout/AdminMenu.vue
@@ -1,7 +1,7 @@
 <template>
   <nav class="main-menu">
     <div class="logo-wrap">
-      <h1 class="logo"><router-link to="/">AI 디지털교과서 통합지원센터</router-link></h1>
+      <h1 class="logo"><router-link to="/adm/main">AI 디지털교과서 통합지원센터</router-link></h1>
     </div>
     <ul>
       <li v-for="(menu, index) in menuList" :key="index" @click="toggleMenu(menu)">
@@ -22,10 +22,10 @@
     return {
       menuList: [
         { path: "/adm.page", pathName: "대시보드" },
-        { path: "/adm/notice.page", pathName: "커뮤니티", subMenu: [{ path: "/notice.page", pathName: "공지사항" }, { path: "/new.page", pathName: "홍보/뉴스" }], icon: "<i class='fa-solid fa-angle-right'></i>", isOpen: false },
-        { path: "/adm/document.page", pathName: "자료실", subMenu: [{ path: "/document.page", pathName: "기술문서" }, { path: "/reference.page", pathName: "자료집" }], icon: "<i class='fa-solid fa-angle-right'></i>", isOpen: false },
+        { path: "/adm/noticeSelectList.page", pathName: "커뮤니티", subMenu: [{ path: "/adm/noticeSelectList.page", pathName: "공지사항" }, { path: "/adm/new.page", pathName: "홍보/뉴스" }], icon: "<i class='fa-solid fa-angle-right'></i>", isOpen: false },
+        { path: "/adm/document.page", pathName: "자료실", subMenu: [{ path: "/adm/document.page", pathName: "기술문서" }, { path: "/adm/reference.page", pathName: "자료집" }], icon: "<i class='fa-solid fa-angle-right'></i>", isOpen: false },
         { path: "/adm/statistics.page", pathName: "통계서비스" },
-        { path: "/adm/corporatePR.page", pathName: "네트워킹", subMenu: [{ path: "/corporatePR.page", pathName: "기업홍보관" }], icon: "<i class='fa-solid fa-angle-right'></i>", isOpen: false },
+        { path: "/adm/corporatePR.page", pathName: "네트워킹", subMenu: [{ path: "/adm/corporatePR.page", pathName: "기업홍보관" }], icon: "<i class='fa-solid fa-angle-right'></i>", isOpen: false },
         { path: "/adm/modal.page", pathName: "팝업관리" },
         { path: "/adm/email.page", pathName: "메일발송" },
         { path: "/adm/userSelectList.page", pathName: "사용자관리" },
@@ -36,7 +36,7 @@
   methods: {
     //토글 메뉴
     toggleMenu(menu) {
-      console.log(menu);
+
       if (menu.hasOwnProperty('isOpen')) {
         menu.isOpen = !menu.isOpen;
         if (menu.isOpen) {
@@ -55,7 +55,7 @@
   computed: {},
   components: {},
   mounted() {
-    console.log("Header mounted");
+    console.log("admin menu mounted");
   },
 };
 </script>
client/views/pages/App.vue
--- client/views/pages/App.vue
+++ client/views/pages/App.vue
@@ -1,11 +1,16 @@
 <template>
-   <div v-if="isUserPage" :class="{ 'layout-wrap': true }">
-      <AdminHeader></AdminHeader>
-      <AdminMenu></AdminMenu>
-      <div class="main-warp">
-         <router-view />
+   <div v-if="isAdminPage" class="admin-wrap">
+      <div :class="{ 'layout-wrap': true }" v-show="isLogin">
+         <AdminHeader></AdminHeader>
+         <AdminMenu></AdminMenu>
+         <div class="main-warp">
+            <router-view />
+         </div>
+         <AdminFooter></AdminFooter>
       </div>
-      <AdminFooter></AdminFooter>
+      <div>
+         <AdminLogin @updateIsLogin="updateIsLogin"/>
+      </div>
    </div>
    <div v-else>
       <Header></Header>
@@ -26,6 +31,7 @@
 import AdminHeader from '../layout/AdminHeader.vue';
 import AdminMenu from '../layout/AdminMenu.vue';
 import AdminFooter from '../layout/AdminFooter.vue';
+import AdminLogin from '../pages/admin/login/Login.vue'
 
 const App = {
    data() {
@@ -39,6 +45,10 @@
       };
    },
    methods: {
+      // 로그인
+      updateIsLogin(newValue) {
+      this.isLogin = newValue;
+    },
       //로그인 사용자 조회
       loginUserSelectOne: function (callback) {
          let vm = this;
@@ -72,7 +82,7 @@
 
    },
    computed: {
-      isUserPage() {
+      isAdminPage() {
          // 현재 URL을 기반으로 사용자와 관리자 페이지 여부를 판단
          return this.$route.path.startsWith('/adm');
       }
@@ -84,6 +94,7 @@
       'AdminMenu': AdminMenu,
       'Footer': Footer,
       'AdminFooter': AdminFooter,
+      'AdminLogin': AdminLogin
    },
    mounted() {
       console.log('Vue mounted');
@@ -135,6 +146,11 @@
 </script>
 
 <style scoped>
+.admin-wrap {
+   width: 100%;
+   height: 100%;
+}
+
 .layout-wrap {
    width: 100%;
    height: 100%;
client/views/pages/AppRouter.js
--- client/views/pages/AppRouter.js
+++ client/views/pages/AppRouter.js
@@ -1,4 +1,5 @@
 import { createWebHistory, createRouter } from "vue-router";
+import { useStore } from "vuex";
 
 import Main from "../pages/user/main/Main.vue";
 import Matching from "../pages/user/networking/Matching.vue";
@@ -18,8 +19,9 @@
 
 /* 관리자 */
 import AdminLogin from "../pages/admin/login/Login.vue";
-import AdminMain from "../pages/admin/main/Main.vue";
+import AdminMain from "../pages/admin/main/Amain.vue";
 import AdminUser from "../pages/admin/user/UserSelectList.vue";
+import AdminNotice from "../pages/admin/notice/noticeSelectList.vue";
 
 const routes = [
   /* 메인화면 */
@@ -43,9 +45,10 @@
     component: TechnologyDtail,
   },
   /* 관리자 */
-  { path: "/adm.page", name: "AdminMain", component: AdminMain },
-  { path: "/adm/login.page", name: "AdminMain", component: AdminLogin },
+  { path: "/adm.page", name: "AdminMain", component: AdminMain,meta: { requiresAuth: true }},
+  { path: "/adm/login.page", name: "AdminLogin", component: AdminLogin },
   { path: "/adm/userSelectList.page", name: "AdminUser", component: AdminUser },
+  { path: "/adm/noticeSelectList.page", name: "AdminNotice", component: AdminNotice },
 ];
 
 const AppRouter = createRouter({
client/views/pages/AppStore.js
--- client/views/pages/AppStore.js
+++ client/views/pages/AppStore.js
@@ -4,7 +4,8 @@
 export default createStore ({
     state: {
         loginUser: null,
-        key:null
+        key:null,
+        isLogin: false,
 
     },
     getters: {
client/views/pages/admin/login/Login.vue
--- client/views/pages/admin/login/Login.vue
+++ client/views/pages/admin/login/Login.vue
@@ -1,34 +1,66 @@
 <template>
-
+    <div>
+        <label for="id">
+            <input type="text" name="" id="id" v-model="mngrLogin.mngr_id">
+        </label>
+        <label for="pw">
+            <input type="password" name="" id="pw" v-model="mngrLogin.mngr_pw">
+        </label>
+        <button class="blue-btn"  @click="login">
+            로그인
+        </button>
+    </div>
 </template>
   
 <script>
 import axios from 'axios';
-
+import crypto from "crypto-js";
+import { useStore } from 'vuex';
 
 export default {
     data() {
-        return {};
+        return {
+            mngrLogin: {
+                mngr_id: null,
+                mngr_pw: null
+            },
+            store: useStore(),
+        };
     },
     methods: {
-        async login() {
-            // TODO: store에서 키 불러오기
-            let response = await axios({
-                url: "/manager/login.json",
-                method: "post",
+        //로그인
+        login: function () {
+            let vm = this;
+            
+            axios({
+                url: '/manager/login.json',
+                method: 'post',
                 headers: {
-                    "Content-Type": "application/json; charset=UTF-8",
+                    'Content-Type': 'application/json; charset=UTF-8'
                 },
-                data: {
-                    mngr_id: 'asdf', mngr_pw: '1234'
+                data: vm.mngrLogin
+            }).then(function (response) {
+                // console.log("login - response : ", response);
+                if (response.data == true) {
+                    this.$emit("updateIsLogin", !this.isLogin);
+                    vm.$router.push({ path: '/adm.page', query: {} });
+                } else {
+                    alert('로그인 정보를 다시 확인해주세요.');
+                    vm.mngrLogin.mngr_id = null;
+                    vm.mngrLogin.mngr_pw = null;
                 }
+            }).catch(function (error) {
+                console.log("login - error : ", error);
+                vm.mngrLogin.mngr_id = null;
+                vm.mngrLogin.mngr_pw = null;
             });
-            console.log(response.data.key);
-        }},
+        },
+    },
     watch: {},
     computed: {},
     components: {},
     mounted() {
+        console.log("login::::::::::")
     },
 };
 </script>
 
client/views/pages/admin/main/Amain.vue (added)
+++ client/views/pages/admin/main/Amain.vue
@@ -0,0 +1,61 @@
+<template>
+    <div class="admin-wrap">
+        <div class="content-box">
+            <div class="title-wrap">
+                <h2 class="main-title">대시보드</h2>
+            </div>
+            <div class="content-wrap">
+
+            </div>
+        </div>
+    </div>
+</template>
+<script>
+import { useStore } from "vuex";
+
+export default {
+
+    data() {
+        return {
+            isLogin: false,
+            userInfo: {
+                user_id: null,
+            },
+            store: useStore(),
+        };
+    },
+    methods: {},
+    watch: {},
+    computed: {},
+    components: {},
+    mounted() {
+        this.$router.beforeEach((to, from, next) => {
+            const isLogin = this.store.state.loginUser != null;
+            // 로그인한 상태일 때
+            if (isLogin) {
+                // 로그인 페이지로 이동하려는 경우
+                if (to.path === '/adm/login.page') {
+                    next('/adm.page'); // 로그인 페이지로 이동하지 않고 admin main 페이지로 리다이렉트
+                } else {
+                    next(); // 다른 페이지로 이동을 허용
+                }
+            } else { // 로그인하지 않은 상태일 때
+                // 로그인 페이지로 이동하려는 경우
+                if (to.path === '/adm/login.page') {
+                    next(); // 로그인 페이지로 이동 허용
+                } else {
+                    next('/adm/login.page'); // 다른 페이지로 이동하지 않고 로그인 페이지로 리다이렉트
+                }
+            }
+        });
+    }
+};
+</script>
+<style scoped>
+.admin-wrap,
+.content-box {
+    width: 100%;
+    height: 100%;
+    font-size: 1.3rem;
+}
+</style>
 
client/views/pages/admin/main/Main.vue (deleted)
--- client/views/pages/admin/main/Main.vue
@@ -1,34 +0,0 @@
-<template>
-TEST2
-</template>
-
-<script>
-import axios from "axios";
-
-
-export default {
-    data() {
-        return {}
-    },
-    methods: {},
-    watch: {},
-    computed: {},
-    components: {},
-    mounted() {
-        // TODO: 로그인 체크
-        // axios({
-        //     url: "/user/loginUserSelectOne.json", // TODO: managerSelectOne
-        //     method: "post",
-        //     headers: {
-        //        "Content-Type": "application/json; charset=UTF-8",
-        //     },
-        //  }).then(function (response) {
-        //     console.log(response.data);
-        //     // TODO: check manager.mngr_id
-        //     let key = new common.AesKey(response.data.key);
-        //     // TODO: store에 key 저장
-        //     alert(key.encrypt('asdf'));
-        //  });
-    }
-}
-</script>
 
client/views/pages/admin/notice/NoticeSelectList.vue (added)
+++ client/views/pages/admin/notice/NoticeSelectList.vue
@@ -0,0 +1,37 @@
+<template>
+    <div class="admin-wrap">
+        <div class="content-box">
+            <div class="title-wrap">
+                <h2 class="main-title">공지사항</h2>
+            </div>
+            <div class="content-wrap">
+
+            </div>
+        </div>
+    </div>
+</template>
+<script>
+
+export default {
+
+    data() {
+        return {};
+    },
+    methods: {},
+    watch: {},
+    computed: {},
+    components: {},
+    mounted() {
+console.log("main mounted")
+    },
+};
+</script>
+<style scoped>
+.admin-wrap,
+.content-box {
+    width: 100%;
+    height: 100%;
+    font-size: 1.3rem;
+}
+
+</style>(No newline at end of file)
Add a comment
List