import Vue from 'vue';
import Router from 'vue-router';
import Admin from '@/views/Admin';
import store from './store';
import http from './plugins/http';

Vue.use(Router);

const router = new Router({
    mode: 'history',
    base: process.env.BASE_URL,
    routes: [
        {
            path: '/',
            component: Admin,
            children: [
                {
                    path: '/',
                    redirect: 'dashboard'
                },
                {
                    path: '/404',
                    name: '404',
                    component: () => import(/* webpackChunkName: "404" */ '@/views/404.vue')
                },
                {
                    path: '/dashboard',
                    name: 'dashboard',
                    component: () => import(/* webpackChunkName: "404" */ '@/views/Dashboard.vue'),
                    meta: {
                        title: '首页'
                    }
                },
                // {
                //     path: '/dashboard',
                //     redirect: 'collectionList'
                // },
                {
                    path: '/api',
                    name: 'api',
                    component: () => import(/* webpackChunkName: "api" */ '@/views/Api.vue'),
                    meta: {
                        title: '接口调试'
                    }
                },
                {
                    path: '/genCodeEdit',
                    name: 'genCodeEdit',
                    component: () => import(/* webpackChunkName: "genCodeEdit" */ '@/views/GenCodeEdit.vue'),
                    meta: {
                        title: '代码生成编辑'
                    }
                },
                {
                    path: '/genCodeList',
                    name: 'genCodeList',
                    component: () => import(/* webpackChunkName: "genCodeList" */ '@/views/GenCodeList.vue'),
                    meta: {
                        title: '代码生成'
                    }
                },
                {
                    path: '/menus',
                    name: 'menus',
                    component: () => import(/* webpackChunkName: "menus" */ '@/views/Menus.vue'),
                    meta: {
                        title: '菜单配置'
                    }
                },
                {
                    path: '/menuAuthority',
                    name: 'menuAuthority',
                    component: () => import(/* webpackChunkName: "menuAuthority" */ '@/views/MenuAuthority.vue'),
                    meta: {
                        title: '菜单权限'
                    }
                },
                {
                    path: '/userEdit',
                    name: 'userEdit',
                    component: () => import(/* webpackChunkName: "userEdit" */ '@/views/UserEdit.vue'),
                    meta: {
                        title: '用户编辑'
                    }
                },
                {
                    path: '/userList',
                    name: 'userList',
                    component: () => import(/* webpackChunkName: "userList" */ '@/views/UserList.vue'),
                    meta: {
                        title: '用户管理'
                    }
                },
                {
                    path: '/sysConfigList',
                    name: 'sysConfigList',
                    component: () => import(/* webpackChunkName: "sysConfigList" */ '@/views/SysConfigList.vue'),
                    meta: {
                        title: '参数配置'
                    }
                },
                {
                    path: '/upload',
                    name: 'upload',
                    component: () => import(/* webpackChunkName: "upload" */ '@/views/Upload.vue'),
                    meta: {
                        title: '上传'
                    }
                },
                {
                    path: '/testClassEdit',
                    name: 'TestClassEdit',
                    component: () => import(/* webpackChunkName: "testClassEdit" */ '@/views/TestClassEdit.vue'),
                    meta: {
                        title: '测试编辑'
                    }
                },
                {
                    path: '/testClassList',
                    name: 'TestClassList',
                    component: () => import(/* webpackChunkName: "testClassList" */ '@/views/TestClassList.vue'),
                    meta: {
                        title: '测试'
                    }
                },
                {
                    path: '/operationLogList',
                    name: 'OperationLogList',
                    component: () => import(/* webpackChunkName: "operationLogList" */ '@/views/OperationLogList.vue'),
                    meta: {
                        title: '操作日志'
                    }
                },
                {
                    path: '/exceptionLogList',
                    name: 'ExceptionLogList',
                    component: () => import(/* webpackChunkName: "exceptionLogList" */ '@/views/ExceptionLogList.vue'),
                    meta: {
                        title: '异常日志'
                    }
                },
                {
                    path: '/collectionEdit',
                    name: 'CollectionEdit',
                    component: () => import(/* webpackChunkName: "collectionEdit" */ '@/views/CollectionEdit.vue'),
                    meta: {
                        title: '藏品管理编辑'
                    }
                },
                {
                    path: '/collectionList',
                    name: 'CollectionList',
                    component: () => import(/* webpackChunkName: "collectionList" */ '@/views/CollectionList.vue'),
                    meta: {
                        title: '藏品管理'
                    }
                },
                {
                    path: '/orderEdit',
                    name: 'OrderEdit',
                    component: () => import(/* webpackChunkName: "orderEdit" */ '@/views/OrderEdit.vue'),
                    meta: {
                        title: '订单编辑'
                    }
                },
                {
                    path: '/orderList',
                    name: 'OrderList',
                    component: () => import(/* webpackChunkName: "orderList" */ '@/views/OrderList.vue'),
                    meta: {
                        title: '订单'
                    }
                },
                {
                    path: '/orderUsedList',
                    name: 'OrderUsedList',
                    component: () => import(/* webpackChunkName: "orderUsedList" */ '@/views/OrderUsedList.vue'),
                    meta: {
                        title: '订单'
                    }
                },
                {
                    path: '/assetEdit',
                    name: 'AssetEdit',
                    component: () => import(/* webpackChunkName: "assetEdit" */ '@/views/AssetEdit.vue'),
                    meta: {
                        title: '资产编辑'
                    }
                },
                {
                    path: '/assetList',
                    name: 'AssetList',
                    component: () => import(/* webpackChunkName: "assetList" */ '@/views/AssetList.vue'),
                    meta: {
                        title: '资产'
                    }
                },
                {
                    path: '/likeEdit',
                    name: 'LikeEdit',
                    component: () => import(/* webpackChunkName: "likeEdit" */ '@/views/LikeEdit.vue'),
                    meta: {
                        title: '点赞编辑'
                    }
                },
                {
                    path: '/likeList',
                    name: 'LikeList',
                    component: () => import(/* webpackChunkName: "likeList" */ '@/views/LikeList.vue'),
                    meta: {
                        title: '点赞'
                    }
                },
                {
                    path: '/followEdit',
                    name: 'FollowEdit',
                    component: () => import(/* webpackChunkName: "followEdit" */ '@/views/FollowEdit.vue'),
                    meta: {
                        title: '关注编辑'
                    }
                },
                {
                    path: '/followList',
                    name: 'FollowList',
                    component: () => import(/* webpackChunkName: "followList" */ '@/views/FollowList.vue'),
                    meta: {
                        title: '关注'
                    }
                },
                {
                    path: '/minterEdit',
                    name: 'MinterEdit',
                    component: () => import(/* webpackChunkName: "minterEdit" */ '@/views/MinterEdit.vue'),
                    meta: {
                        title: '铸造者编辑'
                    }
                },
                {
                    path: '/minterList',
                    name: 'MinterList',
                    component: () => import(/* webpackChunkName: "minterList" */ '@/views/MinterList.vue'),
                    meta: {
                        title: '铸造者列表'
                    }
                },
                {
                    path: '/identityAuthEdit',
                    name: 'IdentityAuthEdit',
                    component: () => import(/* webpackChunkName: "identityAuthEdit" */ '@/views/IdentityAuthEdit.vue'),
                    meta: {
                        title: '身份认证编辑'
                    }
                },
                {
                    path: '/identityAuthList',
                    name: 'IdentityAuthList',
                    component: () => import(/* webpackChunkName: "identityAuthList" */ '@/views/IdentityAuthList.vue'),
                    meta: {
                        title: '身份认证'
                    }
                },
                {
                    path: '/bannerEdit',
                    name: 'BannerEdit',
                    component: () => import(/* webpackChunkName: "bannerEdit" */ '@/views/BannerEdit.vue'),
                    meta: {
                        title: 'Banner编辑'
                    }
                },
                {
                    path: '/bannerList',
                    name: 'BannerList',
                    component: () => import(/* webpackChunkName: "bannerList" */ '@/views/BannerList.vue'),
                    meta: {
                        title: 'Banner'
                    }
                },
                {
                    path: '/blindBoxEdit',
                    name: 'BlindBoxEdit',
                    component: () => import(/* webpackChunkName: "blindBoxEdit" */ '@/views/BlindBoxEdit.vue'),
                    meta: {
                        title: '盲盒编辑'
                    }
                },
                {
                    path: '/blindBoxList',
                    name: 'BlindBoxList',
                    component: () => import(/* webpackChunkName: "blindBoxList" */ '@/views/BlindBoxList.vue'),
                    meta: {
                        title: '盲盒'
                    }
                },
                {
                    path: '/adminEdit',
                    name: 'adminEdit',
                    component: () => import(/* webpackChunkName: "adminEdit" */ '@/views/AdminEdit.vue'),
                    meta: {
                        title: '账号编辑'
                    }
                },
                {
                    path: '/adminList',
                    name: 'AdminList',
                    component: () => import(/* webpackChunkName: "adminList" */ '@/views/AdminList.vue'),
                    meta: {
                        title: '账号管理'
                    }
                },
                {
                    path: '/privilegeOptionEdit',
                    name: 'PrivilegeOptionEdit',
                    component: () =>
                        import(/* webpackChunkName: "privilegeOptionEdit" */ '@/views/PrivilegeOptionEdit.vue'),
                    meta: {
                        title: '特权配置编辑'
                    }
                },
                {
                    path: '/privilegeOptionList',
                    name: 'PrivilegeOptionList',
                    component: () =>
                        import(/* webpackChunkName: "privilegeOptionList" */ '@/views/PrivilegeOptionList.vue'),
                    meta: {
                        title: '特权配置'
                    }
                },
                {
                    path: '/airDropEdit',
                    name: 'AirDropEdit',
                    component: () => import(/* webpackChunkName: "airDropEdit" */ '@/views/AirDropEdit.vue'),
                    meta: {
                        title: '空投编辑'
                    }
                },
                {
                    path: '/airDropList',
                    name: 'AirDropList',
                    component: () => import(/* webpackChunkName: "airDropList" */ '@/views/AirDropList.vue'),
                    meta: {
                        title: '空投'
                    }
                },
                {
                    path: '/couponEdit',
                    name: 'CouponEdit',
                    component: () => import(/* webpackChunkName: "couponEdit" */ '@/views/CouponEdit.vue'),
                    meta: {
                        title: '兑换券编辑'
                    }
                },
                {
                    path: '/couponList',
                    name: 'CouponList',
                    component: () => import(/* webpackChunkName: "couponList" */ '@/views/CouponList.vue'),
                    meta: {
                        title: '兑换券'
                    }
                },
                {
                    path: '/commissionRecordEdit',
                    name: 'CommissionRecordEdit',
                    component: () =>
                        import(/* webpackChunkName: "commissionRecordEdit" */ '@/views/CommissionRecordEdit.vue'),
                    meta: {
                        title: '分销记录编辑'
                    }
                },
                {
                    path: '/commissionRecordList',
                    name: 'CommissionRecordList',
                    component: () =>
                        import(/* webpackChunkName: "commissionRecordList" */ '@/views/CommissionRecordList.vue'),
                    meta: {
                        title: '分销记录'
                    }
                },
                {
                    path: '/recommendEdit',
                    name: 'RecommendEdit',
                    component: () => import(/* webpackChunkName: "recommendEdit" */ '@/views/RecommendEdit.vue'),
                    meta: {
                        title: '首页推荐编辑'
                    }
                },
                {
                    path: '/recommendList',
                    name: 'RecommendList',
                    component: () => import(/* webpackChunkName: "recommendList" */ '@/views/RecommendList.vue'),
                    meta: {
                        title: '首页推荐'
                    }
                },
                {
                    path: '/activityEdit',
                    name: 'ActivityEdit',
                    component: () => import(/* webpackChunkName: "activityEdit" */ '@/views/ActivityEdit.vue'),
                    meta: {
                        title: '活动编辑'
                    }
                },
                {
                    path: '/activityList',
                    name: 'ActivityList',
                    component: () => import(/* webpackChunkName: "activityList" */ '@/views/ActivityList.vue'),
                    meta: {
                        title: '活动'
                    }
                },
                {
                    path: '/inviteEdit',
                    name: 'InviteEdit',
                    component: () => import(/* webpackChunkName: "inviteEdit" */ '@/views/InviteEdit.vue'),
                    meta: {
                        title: '邀请码管理编辑'
                    }
                },
                {
                    path: '/inviteList',
                    name: 'InviteList',
                    component: () => import(/* webpackChunkName: "inviteList" */ '@/views/InviteList.vue'),
                    meta: {
                        title: '邀请码管理'
                    }
                },
                {
                    path: '/appVersionEdit',
                    name: 'AppVersionEdit',
                    component: () => import(/* webpackChunkName: "appVersionEdit" */ '@/views/AppVersionEdit.vue'),
                    meta: {
                        title: 'APP版本管理编辑'
                    }
                },
                {
                    path: '/appVersionList',
                    name: 'AppVersionList',
                    component: () => import(/* webpackChunkName: "appVersionList" */ '@/views/AppVersionList.vue'),
                    meta: {
                        title: 'APP版本管理'
                    }
                },
                {
                    path: '/mintActivityEdit',
                    name: 'MintActivityEdit',
                    component: () => import(/* webpackChunkName: "mintActivityEdit" */ '@/views/MintActivityEdit.vue'),
                    meta: {
                        title: '铸造活动编辑'
                    }
                },
                {
                    path: '/mintActivityList',
                    name: 'MintActivityList',
                    component: () => import(/* webpackChunkName: "mintActivityList" */ '@/views/MintActivityList.vue'),
                    meta: {
                        title: '铸造活动'
                    }
                },
                {
                    path: '/mintOrderEdit',
                    name: 'MintOrderEdit',
                    component: () => import(/* webpackChunkName: "mintOrderEdit" */ '@/views/MintOrderEdit.vue'),
                    meta: {
                        title: '铸造订单编辑'
                    }
                },
                {
                    path: '/mintOrderList',
                    name: 'MintOrderList',
                    component: () => import(/* webpackChunkName: "mintOrderList" */ '@/views/MintOrderList.vue'),
                    meta: {
                        title: '铸造订单'
                    }
                },
                {
                    path: '/mintOrderAuditList',
                    name: 'MintOrderAuditList',
                    component: () => import(/* webpackChunkName: "mintOrderList" */ '@/views/MintOrderAuditList.vue'),
                    meta: {
                        title: '铸造订单'
                    }
                },
                {
                    path: '/purchaseLevelEdit',
                    name: 'PurchaseLevelEdit',
                    component: () =>
                        import(/* webpackChunkName: "purchaseLevelEdit" */ '@/views/PurchaseLevelEdit.vue'),
                    meta: {
                        title: '会员等级编辑'
                    }
                },
                {
                    path: '/purchaseLevelList',
                    name: 'PurchaseLevelList',
                    component: () =>
                        import(/* webpackChunkName: "purchaseLevelList" */ '@/views/PurchaseLevelList.vue'),
                    meta: {
                        title: '会员等级'
                    }
                },
                {
                    path: '/newsEdit',
                    name: 'NewsEdit',
                    component: () => import(/* webpackChunkName: "newsEdit" */ '@/views/NewsEdit.vue'),
                    meta: {
                        title: '新闻管理编辑'
                    }
                },
                {
                    path: '/newsList',
                    name: 'NewsList',
                    component: () => import(/* webpackChunkName: "newsList" */ '@/views/NewsList.vue'),
                    meta: {
                        title: '新闻管理'
                    }
                },
                {
                    path: '/adapayMerchantEdit',
                    name: 'AdapayMerchantEdit',
                    component: () =>
                        import(/* webpackChunkName: "adapayMerchantEdit" */ '@/views/AdapayMerchantEdit.vue'),
                    meta: {
                        title: 'ada编辑'
                    }
                },
                {
                    path: '/adapayMerchantList',
                    name: 'AdapayMerchantList',
                    component: () =>
                        import(/* webpackChunkName: "adapayMerchantList" */ '@/views/AdapayMerchantList.vue'),
                    meta: {
                        title: 'ada'
                    }
                },
                {
                    path: '/collectionRoomEdit',
                    name: 'CollectionRoomEdit',
                    component: () => import(/* webpackChunkName: "showroomEdit" */ '@/views/CollectionRoomEdit.vue'),
                    meta: {
                        title: '展厅编辑'
                    }
                },
                {
                    path: '/collectionRoomList',
                    name: 'CollectionRoomList',
                    component: () => import(/* webpackChunkName: "showroomList" */ '@/views/CollectionRoomList.vue'),
                    meta: {
                        title: '展厅'
                    }
                },
                {
                    path: '/querySettle',
                    name: 'QuerySettle',
                    component: () => import(/* webpackChunkName: "querySettle" */ '@/views/QuerySettle.vue'),
                    meta: {
                        title: '结算查询'
                    }
                },
                {
                    path: '/settings',
                    name: 'Settings',
                    component: () => import(/* webpackChunkName: "settings" */ '@/views/Settings.vue'),
                    meta: {
                        title: '结算查询'
                    }
                },
                {
                    path: '/userBalance',
                    name: 'UserBalance',
                    component: () => import(/* webpackChunkName: "userBalance" */ '@/views/UserBalance.vue'),
                    meta: {
                        title: '用户余额'
                    }
                },
                {
                    path: '/companyCollectionShow',
                    name: 'CompanyCollectionShow',
                    component: () =>
                        import(/* webpackChunkName: "companyCollectionShow" */ '@/views/CompanyCollectionShow.vue'),
                    meta: {
                        title: '企业藏品详情'
                    }
                },
                {
                    path: '/companyCollectionList',
                    name: 'CompanyCollectionList',
                    component: () =>
                        import(/* webpackChunkName: "companyCollectionList" */ '@/views/CompanyCollectionList.vue'),
                    meta: {
                        title: '企业藏品'
                    }
                },
                {
                    path: '/companyCollFailList',
                    name: 'CompanyCollFailList',
                    component: () =>
                        import(/* webpackChunkName: "companyCollectionList" */ '@/views/CompanyCollFailList.vue'),
                    meta: {
                        title: '企业藏品'
                    }
                },
                {
                    path: '/companyEdit',
                    name: 'CompanyEdit',
                    component: () => import(/* webpackChunkName: "companyEdit" */ '@/views/CompanyEdit.vue'),
                    meta: {
                        title: '企业编辑'
                    }
                },
                {
                    path: '/companyList',
                    name: 'CompanyList',
                    component: () => import(/* webpackChunkName: "companyList" */ '@/views/CompanyList.vue'),
                    meta: {
                        title: '企业'
                    }
                },
                /**企业 */
                {
                    path: '/collectionPendingList',
                    name: 'CollectionPendingList',
                    component: () =>
                        import(
                            /* webpackChunkName: "collectionPendingList" */ '@/views/company/CollectionPendingList.vue'
                        ),
                    meta: {
                        title: '申请中藏品'
                    }
                },
                {
                    path: '/collectionPassList',
                    name: 'CollectionPassList',
                    component: () =>
                        import(/* webpackChunkName: "collectionPassList" */ '@/views/company/CollectionPassList.vue'),
                    meta: {
                        title: '已通过藏品'
                    }
                },
                {
                    path: '/collectionFailList',
                    name: 'CollectionFailList',
                    component: () =>
                        import(/* webpackChunkName: "collectionFailList" */ '@/views/company/CollectionFailList.vue'),
                    meta: {
                        title: '未通过藏品'
                    }
                },
                {
                    path: '/companyCollectionEdit',
                    name: 'CompanyCollectionEdit',
                    component: () =>
                        import(
                            /* webpackChunkName: "companyCollectionEdit" */ '@/views/company/CompanyCollectionEdit.vue'
                        ),
                    meta: {
                        title: '企业藏品编辑'
                    }
                },
                {
                    path: '/companyCollectionShelf',
                    name: 'CompanyCollectionShelf',
                    component: () =>
                        import(
                            /* webpackChunkName: "companyCollectionShelf" */ '@/views/company/CompanyCollectionShelf.vue'
                        ),
                    meta: {
                        title: '企业藏品查看'
                    }
                },
                {
                    path: '/showroomEdit',
                    name: 'ShowroomEdit',
                    component: () => import(/* webpackChunkName: "showroomEdit" */ '@/views/ShowroomEdit.vue'),
                    meta: {
                        title: '展厅编辑'
                    }
                },
                {
                    path: '/showroomList',
                    name: 'ShowroomList',
                    component: () => import(/* webpackChunkName: "showroomList" */ '@/views/ShowroomList.vue'),
                    meta: {
                        title: '展厅'
                    }
                },
                {
                    path: '/companyRoomEdit',
                    name: 'CompanyRoomEdit',
                    component: () =>
                        import(/* webpackChunkName: "companyRoomEdit" */ '@/views/company/CompanyRoomEdit.vue'),
                    meta: {
                        title: '展厅编辑'
                    }
                },
                {
                    path: '/companyRoomList',
                    name: 'CompanyRoomList',
                    component: () =>
                        import(/* webpackChunkName: "companyRoomList" */ '@/views/company/CompanyRoomList.vue'),
                    meta: {
                        title: '展厅'
                    }
                },
                {
                    path: '/captcha',
                    name: 'captcha',
                    component: () => import(/* webpackChunkName: "captcha" */ '@/views/Captcha.vue'),
                    meta: {
                        title: 'captcha'
                    }
                },
                {
                    path: '/tagEdit',
                    name: 'TagEdit',
                    component: () => import(/* webpackChunkName: "tagEdit" */ '@/views/TagEdit.vue'),
                    meta: {
                       title: '标签编辑',
                    },
                },
                {
                    path: '/tagList',
                    name: 'TagList',
                    component: () => import(/* webpackChunkName: "tagList" */ '@/views/TagList.vue'),
                    meta: {
                       title: '标签',
                    },
               },
                {
                    path: '/priceListEdit',
                    name: 'PriceListEdit',
                    component: () => import(/* webpackChunkName: "priceListEdit" */ '@/views/PriceListEdit.vue'),
                    meta: {
                       title: 'pricelist编辑',
                    },
                },
                {
                    path: '/priceListList',
                    name: 'PriceListList',
                    component: () => import(/* webpackChunkName: "priceListList" */ '@/views/PriceListList.vue'),
                    meta: {
                       title: 'pricelist',
                    },
               }
                /**INSERT_LOCATION**/
            ]
        },
        {
            path: '/login',
            name: 'login',
            component: () => import('@/views/Login'),
            meta: {
                title: '登录'
            }
        },
        {
            path: '/photoProcessing',
            name: 'photoProcessing',
            component: () => import('@/views/PhotoProcessing'),
            meta: {
                title: '图片处理'
            }
        }
    ]
});
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' && to.path!=='/photoProcessing') {
        http.axios
            .get('/user/my')
            .then(res => {
                store.commit('updateUserInfo', res.data);
                next();
                return;
            })
            .catch(() => {
                localStorage.removeItem('token');
                next('/login');
            });
    } else if (!to.matched.length) {
        next('/404');
    } else {
        next();
    }
});

export default router;