Blame view

babylon-vue-4.0.0/src/router/index.js 12.8 KB
0f94839d   함상기   babylon client fo...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
  import { createRouter, createWebHashHistory } from 'vue-router';
  import VueCookies from 'vue-cookies';
  import { refreshToken } from '../service/login';
  import AppLayout from '@/layout/AppLayout.vue';
  const routes = [
      {
          path: '/',
          component: AppLayout,
          children: [
              {
                  path: '/',
                  name: 'main',
                  exact: true,
                  component: () => import('@/views/Main.vue'),
                  meta: {
                      breadcrumb: [   
                          { parent: 'Home', label: 'Main' },
                      ],
                  },
              },
              {
                  path: '/systemCode',
                  name: 'systemCode',
                  component: () => import('@/views/system/SystemCode.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'System', label: 'System Code' }],
                  },
              },
              {
                  path: '/user',
                  name: 'user',
                  component: () => import('@/views/system/User.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'System', label: 'User' }],
                  },
              },
              {
                  path: '/userAuthority',
                  name: 'userAuthority',
                  component: () => import('@/views/system/UserAuthority.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'System', label: 'User Authority' }],
                  },
              },
          ],
      },
      {
          path: '/samples',
          component: () => import('@/layout/AppLayout.vue'),
          children: [
              {
                  path: '/samples',
                  name: 'samplesdashboard',
                  exact: true,
                  component: () => import('@/views/samples/Dashboard.vue'),
                  meta: {
                      breadcrumb: [   
                          { parent: 'Dashboard(Samples)', label: 'Sales Dashboard' },
                      ],
                  },
              },
              {
                  path: '/samples/formlayout',
                  name: 'samplesformlayout',
                  component: () => import('@/views/samples/uikit/FormLayoutDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'Form Layout' }],
                  },
              },
              {
                  path: '/samples/invalidstate',
                  name: 'samplesinvalidstate',
                  component: () => import('@/views/samples/uikit/InvalidStateDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'Invalid State' }],
                  },
              },
              {
                  path: '/samples/input',
                  name: 'samplesinput',
                  component: () => import('@/views/samples/uikit/InputDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'Input' }],
                  },
              },
              {
                  path: '/samples/floatlabel',
                  name: 'samplesfloatlabel',
                  component: () => import('@/views/samples/uikit/FloatLabelDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'Float Label' }],
                  },
              },
              {
                  path: '/samples/button',
                  name: 'samplesbutton',
                  component: () => import('@/views/samples/uikit/ButtonDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'Button' }],
                  },
              },
              {
                  path: '/samples/table',
                  name: 'samplestable',
                  component: () => import('@/views/samples/uikit/TableDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'Table' }],
                  },
              },
              {
                  path: '/samples/list',
                  name: 'sampleslist',
                  component: () => import('@/views/samples/uikit/ListDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'List' }],
                  },
              },
              {
                  path: '/samples/timeline',
                  name: 'samplestimeline',
                  component: () => import('@/views/samples/pages/TimelineDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'Pages(Samples)', label: 'Timeline' }],
                  },
              },
              {
                  path: '/samples/tree',
                  name: 'samplestree',
                  component: () => import('@/views/samples/uikit/TreeDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'Tree' }],
                  },
              },
              {
                  path: '/samples/panel',
                  name: 'samplespanel',
                  component: () => import('@/views/samples/uikit/PanelsDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'Panel' }],
                  },
              },
              {
                  path: '/samples/overlay',
                  name: 'samplesoverlay',
                  component: () => import('@/views/samples/uikit/OverlayDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'Overlay' }],
                  },
              },
              {
                  path: '/samples/media',
                  name: 'samplesmedia',
                  component: () => import('@/views/samples/uikit/MediaDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'Media' }],
                  },
              },
              {
                  path: '/samples/menu',
                  component: () => import('@/views/samples/uikit/MenuDemo.vue'),
                  children: [
                      {
                          path: '',
                          component: () => import('@/views/samples/uikit/menu/PersonalDemo.vue'),
                          meta: {
                              breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'Menu' }],
                          },
                      },
                      {
                          path: '/samples/menu/seat',
                          component: () => import('@/views/samples/uikit/menu/SeatDemo.vue'),
                          meta: {
                              breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'Menu' }],
                          },
                      },
                      {
                          path: '/samples/menu/payment',
                          component: () => import('@/views/samples/uikit/menu/PaymentDemo.vue'),
                          meta: {
22b5101a   함상기   2024.04.18
180
181
182
183
184
                              breadcrumb: [
                                  { parent: 'UI Kit(Samples)1', label: 'UI Kit(Samples)2' },
                                  { label: 'UI Kit(Samples)3' },
                                  { label: 'PaymentDemo' }
                              ],
0f94839d   함상기   babylon client fo...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
                          },
                      },
                      {
                          path: '/samples/menu/confirmation',
                          component: () => import('@/views/samples/uikit/menu/ConfirmationDemo.vue'),
                          meta: {
                              breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'Menu' }],
                          },
                      },
                  ],
              },
              {
                  path: '/samples/messages',
                  name: 'samplesmessages',
                  component: () => import('@/views/samples/uikit/MessagesDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'Messages' }],
                  },
              },
              {
                  path: '/samples/file',
                  name: 'samplesfile',
                  component: () => import('@/views/samples/uikit/FileDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'File' }],
                  },
              },
              {
                  path: '/samples/chart',
                  name: 'sampleschart',
                  component: () => import('@/views/samples/uikit/ChartDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'Charts' }],
                  },
              },
              {
                  path: '/samples/misc',
                  name: 'samplesmisc',
                  component: () => import('@/views/samples/uikit/MiscDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'Misc' }],
                  },
              },
              {
                  path: '/samples/icons',
                  name: 'samplesicons',
                  component: () => import('@/views/samples/utilities/Icons.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'Utilities(Samples)', label: 'Icons' }],
                  },
              },
              {
                  path: '/samples/crud',
                  name: 'samplescrud',
                  component: () => import('@/views/samples/pages/CrudDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'Pages(Samples)', label: 'Crud' }],
                  },
              },
              {
                  path: '/samples/calendar',
                  name: 'samplescalendar',
                  component: () => import('@/views/samples/pages/CalendarDemo.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'Pages(Samples)', label: 'Calendar' }],
                  },
              },
              {
                  path: '/samples/invoice',
                  name: 'samplesinvoice',
                  component: () => import('@/views/samples/pages/Invoice.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'Pages(Samples)', label: 'Invoice' }],
                  },
              },
              {
                  path: '/samples/help',
                  name: 'sampleshelp',
                  component: () => import('@/views/samples/pages/Help.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'Pages(Samples)', label: 'Help' }],
                  },
              },
              {
                  path: '/samples/empty',
                  name: 'samplesempty',
                  component: () => import('@/views/samples/pages/EmptyPage.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'Pages(Samples)', label: 'Empty Page' }],
                  },
              },
              {
                  path: '/samples/documentation',
                  name: 'samplesdocumentation',
                  component: () => import('@/views/samples/utilities/Documentation.vue'),
                  meta: {
                      breadcrumb: [{ parent: 'Start(Samples)', label: 'Documentation' }],
                  },
              },
          ],
      },
      {
          path: '/login',
          name: 'login',
          component: () => import('@/views/common/Login.vue'),
          meta: { unauthorized : true },
      },
      {
          path: '/logout',
          name: 'logout',
          component: () => import('@/views/common/Logout.vue'),
          meta: { unauthorized : true },
      },
      {
          path: '/error',
          name: 'error',
          component: () => import('@/views/common/Error.vue'),
      },
      {
          path: '/notfound',
          name: 'notfound',
          component: () => import('@/views/common/NotFound.vue'),
      },
      {
          path: '/access',
          name: 'access',
          component: () => import('@/views/common/Access.vue'),
      },
  ];
  
  const router = createRouter({
      history: createWebHashHistory(),
      routes,
      scrollBehavior() {
          return { left: 0, top: 0 };
      },
  });
  
  router.beforeEach( async(to, from, next) => {
  
      console.log('token=' + JSON.stringify(VueCookies.get('token')));
      console.log('refresh_token=' + JSON.stringify(VueCookies.get('refresh_token')));
      if (to.name === 'login') {
        VueCookies.remove('token');
        VueCookies.remove('refresh_token');
      }
    
      if(VueCookies.get('token')===null && VueCookies.get('refresh_token') !== null){
        console.log('refreshToken');
        await refreshToken();
      }
    
      console.log('token after refresh=' + JSON.stringify(VueCookies.get('token')));
      console.log(
        'if = ' +
          (
          to.matched.some(record => record.meta.unauthorized) 
          || (!to.matched.some(record => record.meta.unauthorized) && from.name === 'login')
          || VueCookies.get('token')
          )
      );
    
      if (
          to.matched.some(record => record.meta.unauthorized) 
          || (!to.matched.some(record => record.meta.unauthorized) && from.name === 'login')
          || VueCookies.get('token')
      ){
        console.log('next');
        return next();
      }
    
      alert('로그인 해주세요');
      return next('/login');
    })
    
  export default router;