jichoi / lms_front star
woals 08-20
240820 권민수 대시보드 진입 시 쿼리 사용 방식에서 vuex state이용 방식으로 변경
@8240019eb82b481f6bd1c914d41ae6d8ad223552
client/views/index.js
--- client/views/index.js
+++ client/views/index.js
@@ -7,10 +7,12 @@
 
 import AppRouter from './pages/AppRouter.js';
 import App from './App.vue';
+import AppStore from './pages/AppStore.js';
 // import Login from './Login.vue';
 
 const vue = createApp(App).use(AppRouter)
 // .component('login-page', Login)
+.use(AppStore)
 .mount('#root');
 
 
client/views/pages/AppStore.js
--- client/views/pages/AppStore.js
+++ client/views/pages/AppStore.js
@@ -5,6 +5,10 @@
         token: null,
         userId: null,
         authcd: null,
+        stdId: null,
+        schdlId: null,
+        bookId: null,
+        unitId: null,
     },
     getters: {
         isLoggedIn(state) {
@@ -15,7 +19,19 @@
                 userId: state.userId,
                 authcd: state.authcd,
             }; 
-        }
+        },
+        getStdId(state) {
+            return state.stdId;
+        },
+        getSchdlId(state) {
+            return state.schdlId;
+        },
+        getBookId(state) {
+            return state.bookId;
+        },
+        getUnitId(state) {
+            return state.unitId;
+        },
     },
     mutations: {
         setToken(state, token) {
@@ -24,13 +40,29 @@
         clearToken(state) {
             state.token = null;
             state.userId = null; 
-            state.authcd = null; 
+            state.authcd = null;
+            state.stdId = null;
+            state.schdlId = null;
+            state.bookId = null;
+            state.unitId = null;
         },
         setUser(state, userId) {
             state.userId = userId; 
         },
         setAuthcd(state, authcd) {
             state.authcd = authcd; 
+        },
+        setStdId(state, stdId) {
+            state.stdId = stdId;
+        },
+        setSchdlId(state, schdlId) {
+            state.schdlId = schdlId;
+        },
+        setBookId(state, bookId) {
+            state.bookId = bookId;
+        },
+        setUnitId(state, unitId) {
+            state.unitId = unitId;
         }
     },
     actions: {
@@ -42,5 +74,29 @@
             commit('clearToken');
             localStorage.removeItem('token');
         },
+        updateStdId({ commit }, payload) {
+            return new Promise((resolve) => {
+                commit('setStdId', payload);
+                resolve();
+            });
+        },
+        updateSchdlId({ commit }, payload) {
+            return new Promise((resolve) => {
+                commit('setSchdlId', payload);
+                resolve();
+            });
+        },
+        updateBookId({ commit }, payload) {
+            return new Promise((resolve) => {
+                commit('setBookId', payload);
+                resolve();
+            });
+        },
+        updateUnitId({ commit }, payload) {
+            return new Promise((resolve) => {
+                commit('setUnitId', payload);
+                resolve();
+            });
+        }
     }
 });
client/views/pages/main/MyPlan.vue
--- client/views/pages/main/MyPlan.vue
+++ client/views/pages/main/MyPlan.vue
@@ -82,6 +82,8 @@
 import axios from "axios";
 import SvgIcon from '@jamescoyle/vue-icon';
 import { mdiMagnify, mdiWindowClose } from '@mdi/js';
+import { mapActions } from "vuex";
+import { mapGetters } from 'vuex';
 
 
 export default {
@@ -104,6 +106,9 @@
         }
     },
     methods: {
+
+        ...mapActions(['updateSchdlId', 'updateBookId', 'updateUnitId']),
+
         goToPage(page, scheduleId) {
         const startScheduleIndex = this.schedules.findIndex(schedule => schedule.schdl_id === scheduleId);
 
@@ -140,13 +145,26 @@
         Promise.all(updates)
             .then(() => {
                 const schedule = this.schedules[startScheduleIndex];
-                this.$router.push({ 
-                    name: page,
-                    query: {
-                        schdl_id: schedule.schdl_id,
-                        book_id: schedule.book_id,
-                        unit_id: schedule.unit_id
-                    }
+                // this.$router.push({ 
+                //     name: page,
+                //     query: {
+                //         schdl_id: schedule.schdl_id,
+                //         book_id: schedule.book_id,
+                //         unit_id: schedule.unit_id
+                //     }
+                // });
+                // 상태 업데이트가 완료된 후 라우팅
+                Promise.all([
+                    this.updateSchdlId(schedule.schdl_id),
+                    this.updateBookId(schedule.book_id),
+                    this.updateUnitId(schedule.unit_id)
+                ]).then(() => {
+                    console.log("Book ID:", this.getBookId);
+                    console.log("Unit ID:", this.getUnitId);
+
+                    this.$router.push({ name: page });
+                }).catch(error => {
+                    console.error("상태 업데이트 중 오류 발생:", error);
                 });
             })
             .catch(error => {
@@ -220,7 +238,7 @@
 
     },
     computed: {
-
+        ...mapGetters(['getBookId', 'getUnitId'])
     },
     components: {
         SvgIcon
Add a comment
List