index.js 14.5 KB
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 180 181 182 183 184 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
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: '/basic1',
                name: 'basic1',
                component: () => import('@/views/basic/Basic1.vue'),
                meta: {
                    breadcrumb: [{ parent: 'Basic', label: 'Basic1' }],
                },
            },
            {
                path: '/basic2',
                name: 'basic2',
                component: () => import('@/views/basic/Basic2.vue'),
                meta: {
                    breadcrumb: [{ parent: 'Basic', label: 'Basic2' }],
                },
            },
            {
                path: '/basic3',
                name: 'basic3',
                component: () => import('@/views/basic/Basic3.vue'),
                meta: {
                    breadcrumb: [{ parent: 'Basic', label: 'Basic3' }],
                },
            },
            {
                path: '/basic4',
                name: 'basic4',
                component: () => import('@/views/basic/Basic4.vue'),
                meta: {
                    breadcrumb: [{ parent: 'Basic', label: 'Basic4' }],
                },
            },
            {
                path: '/basic5',
                name: 'basic5',
                component: () => import('@/views/basic/Basic5.vue'),
                meta: {
                    breadcrumb: [{ parent: 'Basic', label: 'Basic5' }],
                },
            },

            {
                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: '/authority',
                name: 'authority',
                component: () => import('@/views/system/Authority.vue'),
                meta: {
                    breadcrumb: [{ parent: 'System', label: 'Authority' }],
                },
            },
            {
                path: '/messages',
                name: 'messages',
                component: () => import('@/views/system/Messages.vue'),
                meta: {
                    breadcrumb: [{ parent: 'System', label: 'Messages' }],
                },
            },
        ],
    },
    {
        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: {
                            breadcrumb: [{ parent: 'UI Kit(Samples)', label: 'PaymentDemo' }],
                        },
                    },
                    {
                        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/tuiGrid',
                name: 'samplestuiGrid',
                component: () => import('@/views/samples/pages/TuiGrid.vue'),
                meta: {
                    breadcrumb: [{ parent: 'Pages(Samples)', label: 'TuiGrid 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;