import Vue from 'vue'
import Router from 'vue-router'
import store from '../vuex'
import axios from 'axios'

Vue.use(Router);

const router = new Router({
    routes: [
        {
            path: '/',
            component: () => import('../pages/App'),
            children: [
                {
                    path: '/',
                    redirect: 'dashboard'
                },
                {
                    path: '/404',
                    name: '404',
                    component: () => import('../pages/404')
                },
                {
                    path: '/dashboard',
                    name: 'dashboard',
                    component: () => import('../pages/Dashboard')
                },
                {
                    path: '/users',
                    name: 'users',
                    component: () => import('../pages/Users')
                },
                {
                    path: '/user',
                    name: 'user',
                    component: () => import('../pages/User')
                },
                {
                    path: '/menus',
                    name: 'menus',
                    component: () => import('../pages/Menus')
                },
                {
                    path: '/roles',
                    name: 'roles',
                    component: () => import('../pages/Roles')
                },
                {
                    path: '/role',
                    name: 'role',
                    component: () => import('../pages/Role')
                },
                {
                    path: '/api',
                    name: 'api',
                    component: () => import('../pages/Api')
                },
                {
                    path: '/genCodes',
                    name: 'genCodes',
                    component: () => import('../pages/GenCodes')
                },
                {
                    path: '/genCode',
                    name: 'genCode',
                    component: () => import('../pages/GenCode')
                },
                {
                    path: '/permissions',
                    name: 'permissions',
                    component: () => import('../pages/Permissions')
                },
                {
                    path: '/permission',
                    name: 'permission',
                    component: () => import('../pages/Permission')
                },
                {
                    path: '/departs',
                    name: 'departs',
                    component: () => import('../pages/Departs')
                },
                {
                    path: '/lineChart',
                    name: 'lineChart',
                    component: () => import('../pages/LineChart')
                },
                {
                    path: '/barChart',
                    name: 'barChart',
                    component: () => import('../pages/BarChart')
                },
                {
                    path: '/polarAreaChart',
                    name: 'polarAreaChart',
                    component: () => import('../pages/PolarAreaChart')
                },
                {
                    path: '/pieChart',
                    name: 'pieChart',
                    component: () => import('../pages/PieChart')
                },
                {
                    path: '/radarChart',
                    name: 'radarChart',
                    component: () => import('../pages/RadarChart')
                },
                {
                    path: '/bubbleChart',
                    name: 'bubbleChart',
                    component: () => import('../pages/BubbleChart')
                },
                {
                    path: '/processModels',
                    name: 'processModels',
                    component: () => import('../pages/ProcessModels')
                },
                {
                    path: '/processDefinitions',
                    name: 'processDefinitions',
                    component: () => import('../pages/ProcessDefinitions')
                },
                {
                    path: '/myProcesses',
                    name: 'myProcesses',
                    component: () => import('../pages/MyProcesses')
                },
                {
                    path: '/myTasks',
                    name: 'myTasks',
                    component: () => import('../pages/MyTasks')
                },
                {
                    path: '/completeTaskDynamic',
                    name: 'CompleteTaskDynamic',
                    component: () => import('../pages/CompleteTaskDynamic')
                },
                {
                    path: '/commonQuerys',
                    name: 'commonQuerys',
                    component: () => import('../pages/CommonQuerys')
                },
                {
                    path: '/commonQuery',
                    name: 'commonQuery',
                    component: () => import('../pages/CommonQuery')
                },
                {
                    path: '/commonIframe',
                    name: 'commonIframe',
                    component: () => import('../pages/CommonIframe')
                },
                {
                    path: '/queryConfigs',
                    name: 'queryConfigs',
                    component: () => import('../pages/QueryConfigs')
                },
                {
                    path: '/queryConfig',
                    name: 'queryConfig',
                    component: () => import('../pages/QueryConfig')
                },
                {
                    path: '/dataSourceInfos',
                    name: 'dataSourceInfos',
                    component: () => import('../pages/DataSourceInfos')
                },
                {
                    path: '/dataSourceInfo',
                    name: 'dataSourceInfo',
                    component: () => import('../pages/DataSourceInfo')
                },
                {
                    path: '/deploySystem',
                    name: 'DeploySystem',
                    component: () => import('../pages/DeploySystem')
                },
                {
                    path: '/serviceType',
                    name: 'ServiceType',
                    component: () => import('../pages/ServiceType')
                },
                {
                    path: '/serviceTypes',
                    name: 'ServiceTypes',
                    component: () => import('../pages/ServiceTypes')
                },
                {
                    path: '/serviceTypeDetail',
                    name: 'ServiceTypeDetail',
                    component: () => import('../pages/ServiceTypeDetail')
                },
                {
                    path: '/serviceTypeDetails',
                    name: 'ServiceTypeDetails',
                    component: () => import('../pages/ServiceTypeDetails')
                },
                {
                    path: '/bannerInfo',
                    name: 'BannerInfo',
                    component: () => import('../pages/BannerInfo')
                },
                {
                    path: '/bannerInfos',
                    name: 'BannerInfos',
                    component: () => import('../pages/BannerInfos')
                },
                {
                    path: '/quickLinks',
                    name: 'QuickLinks',
                    component: () => import('../pages/QuickLinks')
                },
                {
                    path: '/quickLinkss',
                    name: 'QuickLinkss',
                    component: () => import('../pages/QuickLinkss')
                },
                {
                    path: '/districtInfo',
                    name: 'DistrictInfo',
                    component: () => import('../pages/DistrictInfo')
                },
                {
                    path: '/districtInfos',
                    name: 'DistrictInfos',
                    component: () => import('../pages/DistrictInfos')
                },
                {
                    path: '/aboutUs',
                    name: 'AboutUs',
                    component: () => import('../pages/AboutUs')
                },
                {
                    path: '/aboutUss',
                    name: 'AboutUss',
                    component: () => import('../pages/AboutUss')
                },
                {
                    path: '/contactUs',
                    name: 'ContactUs',
                    component: () => import('../pages/ContactUs')
                },
                {
                    path: '/contactUss',
                    name: 'ContactUss',
                    component: () => import('../pages/ContactUss')
                },
                {
                    path: '/joinUs',
                    name: 'JoinUs',
                    component: () => import('../pages/JoinUs')
                },
                {
                    path: '/joinUss',
                    name: 'JoinUss',
                    component: () => import('../pages/JoinUss')
                },
                {
                    path: '/personalAuthentication',
                    name: 'PersonalAuthentication',
                    component: () => import('../pages/PersonalAuthentication')
                },
                {
                    path: '/personalAuthentications',
                    name: 'PersonalAuthentications',
                    component: () => import('../pages/PersonalAuthentications')
                },
                {
                    path: '/companyAuthentication',
                    name: 'CompanyAuthentication',
                    component: () => import('../pages/CompanyAuthentication')
                },
                {
                    path: '/companyAuthentications',
                    name: 'CompanyAuthentications',
                    component: () => import('../pages/CompanyAuthentications')
                },
                {
                    path: '/storeInfo',
                    name: 'StoreInfo',
                    component: () => import('../pages/StoreInfo')
                },
                {
                    path: '/storeInfos',
                    name: 'StoreInfos',
                    component: () => import('../pages/StoreInfos')
                },
                {
                    path: '/shopAgreement',
                    name: 'ShopAgreement',
                    component: () => import('../pages/ShopAgreement')
                },
                {
                    path: '/shopAgreements',
                    name: 'ShopAgreements',
                    component: () => import('../pages/ShopAgreements')
                },
                {
                    path: '/userAddress',
                    name: 'UserAddress',
                    component: () => import('../pages/UserAddress')
                },
                {
                    path: '/userAddresss',
                    name: 'UserAddresss',
                    component: () => import('../pages/UserAddresss')
                },
                {
                    path: '/orderAddress',
                    name: 'OrderAddress',
                    component: () => import('../pages/OrderAddress')
                },
                {
                    path: '/orderAddresss',
                    name: 'OrderAddresss',
                    component: () => import('../pages/OrderAddresss')
                },
                {
                    path: '/orderMessage',
                    name: 'OrderMessage',
                    component: () => import('../pages/OrderMessage')
                },
                {
                    path: '/orderMessages',
                    name: 'OrderMessages',
                    component: () => import('../pages/OrderMessages')
                },
                {
                    path: '/orderLogistics',
                    name: 'OrderLogistics',
                    component: () => import('../pages/OrderLogistics')
                },
                {
                    path: '/orderLogisticss',
                    name: 'OrderLogisticss',
                    component: () => import('../pages/OrderLogisticss')
                },
                {
                    path: '/productCollection',
                    name: 'ProductCollection',
                    component: () => import('../pages/ProductCollection')
                },
                {
                    path: '/productCollections',
                    name: 'ProductCollections',
                    component: () => import('../pages/ProductCollections')
                },
                {
                    path: '/storeCollection',
                    name: 'StoreCollection',
                    component: () => import('../pages/StoreCollection')
                },
                {
                    path: '/storeCollections',
                    name: 'StoreCollections',
                    component: () => import('../pages/StoreCollections')
                },
                {
                    path: '/productComment',
                    name: 'ProductComment',
                    component: () => import('../pages/ProductComment')
                },
                {
                    path: '/productComments',
                    name: 'ProductComments',
                    component: () => import('../pages/ProductComments')
                },
                {
                    path: '/productCommentImage',
                    name: 'ProductCommentImage',
                    component: () => import('../pages/ProductCommentImage')
                },
                {
                    path: '/productCommentImages',
                    name: 'ProductCommentImages',
                    component: () => import('../pages/ProductCommentImages')
                },
                {
                    path: '/couponInfo',
                    name: 'CouponInfo',
                    component: () => import('../pages/CouponInfo')
                },
                {
                    path: '/couponInfos',
                    name: 'CouponInfos',
                    component: () => import('../pages/CouponInfos')
                },
                {
                    path: '/userCoupon',
                    name: 'UserCoupon',
                    component: () => import('../pages/UserCoupon')
                },
                {
                    path: '/userCoupons',
                    name: 'UserCoupons',
                    component: () => import('../pages/UserCoupons')
                },
                {
                    path: '/memberCoin',
                    name: 'MemberCoin',
                    component: () => import('../pages/MemberCoin')
                },
                {
                    path: '/memberCoins',
                    name: 'MemberCoins',
                    component: () => import('../pages/MemberCoins')
                },
                {
                    path: '/memberCoinSong',
                    name: 'MemberCoinSong',
                    component: () => import('../pages/MemberCoinSong')
                },
                {
                    path: '/memberCoinTixian',
                    name: 'MemberCoinTixian',
                    component: () => import('../pages/MemberCoinTixian')
                },
                {
                    path: '/memberCoinTixians',
                    name: 'MemberCoinTixians',
                    component: () => import('../pages/MemberCoinTixians')
                },
                {
                    path: '/memberPoint',
                    name: 'MemberPoint',
                    component: () => import('../pages/MemberPoint')
                },
                {
                    path: '/memberPoints',
                    name: 'MemberPoints',
                    component: () => import('../pages/MemberPoints')
                },
                {
                    path: '/customerService',
                    name: 'CustomerService',
                    component: () => import('../pages/CustomerService')
                },
                {
                    path: '/customerServices',
                    name: 'CustomerServices',
                    component: () => import('../pages/CustomerServices')
                },
                {
                    path: '/productInfo',
                    name: 'ProductInfo',
                    component: () => import('../pages/ProductInfo')
                },
                {
                    path: '/productInfos',
                    name: 'ProductInfos',
                    component: () => import('../pages/ProductInfos')
                },
                {
                    path: '/productPrice',
                    name: 'ProductPrice',
                    component: () => import('../pages/ProductPrice')
                },
                {
                    path: '/productPrices',
                    name: 'ProductPrices',
                    component: () => import('../pages/ProductPrices')
                },
                {
                    path: '/productImage',
                    name: 'ProductImage',
                    component: () => import('../pages/ProductImage')
                },
                {
                    path: '/productImages',
                    name: 'ProductImages',
                    component: () => import('../pages/ProductImages')
                },
                {
                    path: '/feedback',
                    name: 'Feedback',
                    component: () => import('../pages/Feedback')
                },
                {
                    path: '/feedbacks',
                    name: 'Feedbacks',
                    component: () => import('../pages/Feedbacks')
                },
                {
                    path: '/orderImage',
                    name: 'OrderImage',
                    component: () => import('../pages/OrderImage')
                },
                {
                    path: '/orderImages',
                    name: 'OrderImages',
                    component: () => import('../pages/OrderImages')
                },
                {
                    path: '/orderRepair',
                    name: 'OrderRepair',
                    component: () => import('../pages/OrderRepair')
                },
                {
                    path: '/orderRepairs',
                    name: 'OrderRepairs',
                    component: () => import('../pages/OrderRepairs')
                },
                {
                    path: '/orderRepairDetail',
                    name: 'OrderRepairDetail',
                    component: () => import('../pages/OrderRepairDetail')
                },
                {
                    path: '/orderRepairDetails',
                    name: 'OrderRepairDetails',
                    component: () => import('../pages/OrderRepairDetails')
                },
                {
                    path: '/orderInvoice',
                    name: 'OrderInvoice',
                    component: () => import('../pages/OrderInvoice')
                },
                {
                    path: '/orderInvoices',
                    name: 'OrderInvoices',
                    component: () => import('../pages/OrderInvoices')
                },
                {
                    path: '/helpText',
                    name: 'HelpText',
                    component: () => import('../pages/HelpText')
                },
                {
                    path: '/helpTexts',
                    name: 'HelpTexts',
                    component: () => import('../pages/HelpTexts')
                },
                {
                    path: '/systemConfig',
                    name: 'SystemConfig',
                    component: () => import('../pages/SystemConfig')
                },
                {
                    path: '/systemConfigs',
                    name: 'SystemConfigs',
                    component: () => import('../pages/SystemConfigs')
                },
                {
                    path: '/userOrder',
                    name: 'UserOrder',
                    component: () => import('../pages/UserOrder')
                },
                {
                    path: '/userOrders',
                    name: 'UserOrders',
                    component: () => import('../pages/UserOrders')
                },
                {
                    path: '/storeLabel',
                    name: 'StoreLabel',
                    component: () => import('../pages/StoreLabel')
                },
                {
                    path: '/storeLabels',
                    name: 'StoreLabels',
                    component: () => import('../pages/StoreLabels')
                },
                {
                    path: '/alipayTemp',
                    name: 'AlipayTemp',
                    component: () => import('../pages/AlipayTemp')
                },
                {
                    path: '/alipayTemps',
                    name: 'AlipayTemps',
                    component: () => import('../pages/AlipayTemps')
                },
                {
                    path: '/wxpayTemp',
                    name: 'WxpayTemp',
                    component: () => import('../pages/WxpayTemp')
                },
                {
                    path: '/wxpayTemps',
                    name: 'WxpayTemps',
                    component: () => import('../pages/WxpayTemps')
                },
                {
                    path: '/companyType',
                    name: 'CompanyType',
                    component: () => import('../pages/CompanyType')
                },
                {
                    path: '/companyTypes',
                    name: 'CompanyTypes',
                    component: () => import('../pages/CompanyTypes')
                },
                {
                    path: '/logisticsInfo',
                    name: 'LogisticsInfo',
                    component: () => import('../pages/LogisticsInfo')
                },
                {
                    path: '/logisticsInfos',
                    name: 'LogisticsInfos',
                    component: () => import('../pages/LogisticsInfos')
                },
                {
                    path: '/imageUploadLog',
                    name: 'ImageUploadLog',
                    component: () => import('../pages/ImageUploadLog')
                },
                {
                    path: '/imageUploadLogs',
                    name: 'ImageUploadLogs',
                    component: () => import('../pages/ImageUploadLogs')
                },
                {
                    path: '/imageDownLog',
                    name: 'ImageDownLog',
                    component: () => import('../pages/ImageDownLog')
                },
                {
                    path: '/imageDownLogs',
                    name: 'ImageDownLogs',
                    component: () => import('../pages/ImageDownLogs')
                },
                {
                    path: '/userAgreement',
                    name: 'UserAgreement',
                    component: () => import('../pages/UserAgreement')
                },
                {
                    path: '/userAgreements',
                    name: 'UserAgreements',
                    component: () => import('../pages/UserAgreements')
                },
                {
                    path: '/creditRating',
                    name: 'CreditRating',
                    component: () => import('../pages/CreditRating')
                },
                {
                    path: '/creditRatings',
                    name: 'CreditRatings',
                    component: () => import('../pages/CreditRatings')
                }
                /**INSERT_LOCATION**/
            ]
        },
        {
            path: '/login',
            name: 'login',
            component: () => import('../pages/Login')
        }
    ]
});
router.beforeEach((to, from, next) => {
    //console.log(to);
    if (/^\/http/.test(to.path)) {
        console.log(Vue.$baseUrl);
        let url = to.path.replace('/', '');
        let params = [];
        if (to.query) {
            for (let key in to.query) {
                if (to.query.hasOwnProperty(key)) {
                    params.push(`${key}=${to.query[key]}`);
                }
            }
        }
        if (params.length > 0) {
            url += `?${params.join('&')}`;
        }
        window.open(url);
        return;
    }
    if (!store.state.userInfo && to.path !== '/login') {
        axios.get('/userInfo/getUserInfo').then(res => {
            if (res.status === 200) {
                if (res.data.success && res.data.data) {
                    store.commit('updateUserInfo', res.data.data);
                    next();
                    return;
                }
            }
            next('/login');
        }).catch(() => {
            next('/login');
        })
    } else if (!to.matched.length) {
        next('/404');
    } else {
        next();
    }
});
router.afterEach((to, from) => {
    window.onresize();
});

export default router;