
250404 하석형 관리자 menuList 조회 시 자식 메뉴에 context Path 추가, 게시판 내용 조회 시 bbsMngId에 context Path 제거
@e1e96b0651690a88d155babe20bb71a543ec128c
--- client/resources/js/queryParams.js
+++ client/resources/js/queryParams.js
... | ... | @@ -40,7 +40,9 @@ |
40 | 40 |
/** 게시판 pageId 추출 **/ |
41 | 41 |
fnBbsIdExtraction() { |
42 | 42 |
if(this.$route.path != null && this.$route.path != undefined && this.$route.path != '') { |
43 |
- let url = this.$route.path; |
|
43 |
+ console.log("this.$route.path", this.$route.path) |
|
44 |
+ let url = this.$filters.logicalPath(this.$route.path); |
|
45 |
+ console.log("url", url) |
|
44 | 46 |
const regex = /^\/[^\/]+\/([^\/]+)\//; // 두 번째 '/'와 세 번째 '/' 사이의 문자열 추출 |
45 | 47 |
const match = url.match(regex); // 라우터 경로와 정규식 매칭 |
46 | 48 |
if(match) { |
--- client/views/common/filters.js
+++ client/views/common/filters.js
... | ... | @@ -4,9 +4,15 @@ |
4 | 4 |
const filters = { |
5 | 5 |
|
6 | 6 |
// Context Path를 포함한 URL 생성 |
7 |
- ctxPath(value) { |
|
7 |
+ ctxPath(path) { |
|
8 | 8 |
const contextPath = store.state.contextPath || ''; |
9 |
- return contextPath + value; |
|
9 |
+ return contextPath + path; |
|
10 |
+ }, |
|
11 |
+ |
|
12 |
+ // Context Path를 제외한 URL 생성 |
|
13 |
+ logicalPath(path) { |
|
14 |
+ const contextPath = store.state.contextPath || ''; |
|
15 |
+ return (contextPath !== '/' && path.startsWith(contextPath)) ? path.slice(contextPath.length) : path; |
|
10 | 16 |
}, |
11 | 17 |
|
12 | 18 |
// 아이디 정규식(5~20자의 영문 소문자, 숫자와 특수기호(_),(-)만 사용) |
--- client/views/layout/AdminMenu.vue
+++ client/views/layout/AdminMenu.vue
... | ... | @@ -71,16 +71,18 @@ |
71 | 71 |
}; |
72 | 72 |
const res = await findBySysMenu(params); |
73 | 73 |
if (res.status === 200) { |
74 |
- // `isOpen` 속성을 추가하여 초기 상태 설정 |
|
75 |
- this.menuList = res.data.data.menuList.map(menu => ({ |
|
76 |
- ...menu, |
|
77 |
- isOpen: false, // 1뎁스 닫힘 |
|
78 |
- childList: menu.childList.map(sub => ({ |
|
79 |
- ...sub, |
|
80 |
- isOpen: false, // 2뎁스도 닫힘 |
|
81 |
- routerUrl: this.$filters.ctxPath(sub.routerUrl) |
|
82 |
- })) |
|
83 |
- })); |
|
74 |
+ this.menuList = this.formatMenuList(res.data.data.menuList); |
|
75 |
+ // // `isOpen` 속성을 추가하여 초기 상태 설정 |
|
76 |
+ // this.menuList = res.data.data.menuList.map(menu => ({ |
|
77 |
+ // ...menu, |
|
78 |
+ // isOpen: false, // 1뎁스 닫힘 |
|
79 |
+ // childList: menu.childList.map(sub => ({ |
|
80 |
+ // ...sub, |
|
81 |
+ // isOpen: false, // 2뎁스도 닫힘 |
|
82 |
+ // routerUrl: this.$filters.ctxPath(sub.routerUrl) |
|
83 |
+ // })) |
|
84 |
+ // })); |
|
85 |
+ |
|
84 | 86 |
// 전체 메뉴 트리 store에 저장 |
85 | 87 |
this.$store.commit('setMenuList', this.menuList); |
86 | 88 |
|
... | ... | @@ -141,7 +143,26 @@ |
141 | 143 |
} |
142 | 144 |
} |
143 | 145 |
return null; |
144 |
- } |
|
146 |
+ }, |
|
147 |
+ |
|
148 |
+ // 메뉴 리스트를 가공 |
|
149 |
+ formatMenuList(menuList) { |
|
150 |
+ // `isOpen` 속성을 추가하여 초기 상태 설정 |
|
151 |
+ return menuList.map(menu => { |
|
152 |
+ const formatted = { |
|
153 |
+ ...menu, |
|
154 |
+ isOpen: false, |
|
155 |
+ routerUrl: menu.routerUrl !== "" ? this.$filters.ctxPath(menu.routerUrl) : menu.routerUrl, // 최상위 메뉴가 아닐 때만 context path 가공 |
|
156 |
+ }; |
|
157 |
+ |
|
158 |
+ // 자식이 있으면 재귀 호출 |
|
159 |
+ if (menu.childList && menu.childList.length > 0) { |
|
160 |
+ formatted.childList = this.formatMenuList(menu.childList); |
|
161 |
+ } |
|
162 |
+ |
|
163 |
+ return formatted; |
|
164 |
+ }); |
|
165 |
+ }, |
|
145 | 166 |
}, |
146 | 167 |
watch: { |
147 | 168 |
// 나중에 네비게이션 가드에서 form 받을 수 있으면 form adm/main으로 갈때 sotre.state값0로 바꿔주기 |
--- client/views/pages/AppRouter.js
+++ client/views/pages/AppRouter.js
... | ... | @@ -162,6 +162,7 @@ |
162 | 162 |
}); |
163 | 163 |
|
164 | 164 |
AppRouter.beforeEach(async (to, from, next) => { |
165 |
+ const contextPath = store.state.contextPath; // Context Path 정보 |
|
165 | 166 |
const routeExists = AppRouter.getRoutes().some(route => route.path === to.path || (route.name && route.name === to.name)); |
166 | 167 |
if (!routeExists) { |
167 | 168 |
next({ name: 'notfound' }); |
... | ... | @@ -214,8 +215,13 @@ |
214 | 215 |
let path = to.path; |
215 | 216 |
// 게시판일 경우 .page로 끝나는 경로가 있으므로 마지막 '/' 이전 경로로 설정 |
216 | 217 |
if (to.path.includes('BBS_MNG')) { |
217 |
- const lastSlashIndex = to.path.lastIndexOf(filters.ctxPath('/')); // 마지막 '/' 인덱스 |
|
218 |
- path = to.path.substring(0, lastSlashIndex); // 마지막 '/' 이전 경로 |
|
218 |
+ let logicalPath = to.path; |
|
219 |
+ // context path 제거 |
|
220 |
+ if (contextPath !== '/' && logicalPath.startsWith(contextPath)) { |
|
221 |
+ logicalPath = logicalPath.substring(contextPath.length); |
|
222 |
+ } |
|
223 |
+ const lastSlashIndex = logicalPath.lastIndexOf('/'); // 마지막 '/' 인덱스 |
|
224 |
+ path = logicalPath.substring(0, lastSlashIndex); // 마지막 '/' 이전 경로 |
|
219 | 225 |
} |
220 | 226 |
store.commit('setPath', path); |
221 | 227 |
store.commit('setPageAuth', pageAuth); |
... | ... | @@ -248,8 +254,13 @@ |
248 | 254 |
// 권한이 있고 접근 가능한 경우 |
249 | 255 |
if (hasAcc) { |
250 | 256 |
if (to.path.includes('.page')) { |
251 |
- const lastSlashIndex = to.path.lastIndexOf(filters.ctxPath('/')); // 마지막 '/' 인덱스 |
|
252 |
- const path = to.path.substring(0, lastSlashIndex); // 마지막 '/' 이전 경로 |
|
257 |
+ let logicalPath = to.path; |
|
258 |
+ // context path 제거 |
|
259 |
+ if (contextPath !== '/' && logicalPath.startsWith(contextPath)) { |
|
260 |
+ logicalPath = logicalPath.substring(contextPath.length); |
|
261 |
+ } |
|
262 |
+ const lastSlashIndex = logicalPath.lastIndexOf('/'); // 마지막 '/' 인덱스 |
|
263 |
+ const path = logicalPath.substring(0, lastSlashIndex); // 마지막 '/' 이전 경로 |
|
253 | 264 |
store.commit('setPath', path); |
254 | 265 |
} |
255 | 266 |
// 접속 통계 |
--- client/views/pages/adm/system/LoginPolicy/LoginPolicy.vue
+++ client/views/pages/adm/system/LoginPolicy/LoginPolicy.vue
... | ... | @@ -167,15 +167,16 @@ |
167 | 167 |
if (!this.validation()) { |
168 | 168 |
return; |
169 | 169 |
} |
170 |
- const isCheck = confirm("Context Path를 변경하면 로그아웃됩니다.\n계속하시겠습니까?"); |
|
171 |
- if (isCheck) { |
|
170 |
+ // const isCheck = confirm("Context Path를 변경하면 로그아웃됩니다.\n계속하시겠습니까?"); |
|
171 |
+ const isCheck = confirm("Context Path를 변경하시겠습니까?"); |
|
172 |
+ if (isCheck) { |
|
172 | 173 |
try { |
173 |
- let ctx = {path: this.cntxtPth}; |
|
174 |
+ let ctx = { path: this.cntxtPth }; |
|
174 | 175 |
const res = await saveCntxtPth(ctx); |
175 | 176 |
alert(res.data.message); |
176 | 177 |
if (res.status == 200) { |
177 | 178 |
let storeCtx = this.cntxtPth; |
178 |
- if(storeCtx == '/') { |
|
179 |
+ if (storeCtx == '/') { |
|
179 | 180 |
storeCtx = ''; |
180 | 181 |
} |
181 | 182 |
store.commit("setContextPath", storeCtx); // 캐시 초기화 요청을 보내기 위한 Context Path 정보 저장 |
... | ... | @@ -201,17 +202,17 @@ |
201 | 202 |
this.$refs.cntxtPth.focus(); |
202 | 203 |
return false; |
203 | 204 |
} |
204 |
- if(this.cntxtPth.length > 50) { |
|
205 |
+ if (this.cntxtPth.length > 50) { |
|
205 | 206 |
alert("Context Path는 50자 이내로 입력해주세요."); |
206 | 207 |
this.$refs.cntxtPth.focus(); |
207 | 208 |
return false; |
208 | 209 |
} |
209 |
- if(this.cntxtPth == this.defaultCntxtPth) { |
|
210 |
+ if (this.cntxtPth == this.defaultCntxtPth) { |
|
210 | 211 |
alert("변경된 내용이 없습니다."); |
211 | 212 |
this.$refs.cntxtPth.focus(); |
212 | 213 |
return false; |
213 | 214 |
} |
214 |
- if(!regex.test(this.cntxtPth)) { |
|
215 |
+ if (!regex.test(this.cntxtPth)) { |
|
215 | 216 |
alert("Context Path는 '/'로 시작해야 하며, 알파벳, 숫자, '-' 또는 '_'만 포함할 수 있습니다."); |
216 | 217 |
this.$refs.cntxtPth.focus(); |
217 | 218 |
return false; |
--- client/views/pages/user/portal/search/Search.vue
+++ client/views/pages/user/portal/search/Search.vue
... | ... | @@ -328,7 +328,7 @@ |
328 | 328 |
fnView(item, subItem) { |
329 | 329 |
let menuPath = null; |
330 | 330 |
if(item.routerUrl.includes('.page')) { |
331 |
- const lastSlashIndex = item.routerUrl.lastIndexOf(this.$filters.ctxPath('/')); // 마지막 '/' 인덱스 |
|
331 |
+ const lastSlashIndex = item.routerUrl.lastIndexOf('/'); // 마지막 '/' 인덱스 |
|
332 | 332 |
menuPath = item.routerUrl.substring(0, lastSlashIndex) ; // 마지막 '/' 이전 경로 |
333 | 333 |
} |
334 | 334 |
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?