import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

const originalPush = Router.prototype.push;
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch((err) => err);
};

export default new Router({
  routes: [
    {
      path: "/",
      redirect: "/index",
    },
    {
      path: "/index",
      name: "index",
      component: () => import("@/pages/index"),
      redirect: "/services_shop",
      children: [
        {
          path: "/fwzc", // 服务注册
          name: "fwzc",
          redirect: "/fwzc/fwcs",
          component: () => import("@/pages/workbench/fwzc_fwcs"),
          children: [
            {
              path: "/fwzc/fwcs", // 服务注册/服务测试
              name: "fwcs",
              component: () => import("@/pages/workbench/fwzc_fwcs"),
            },
          ],
        }, // 工作台 - 服务注册模块
        {
          path: "/fwgl/:level", // 服务管理 level：用户等级
          name: "fwgl",
          redirect: "/fwgl/:level/0",
          component: () => import("@/pages/workbench/fwgl/fwgl"),
          children: [
            {
              path: "/fwgl/:level/:type", // 服务管理列表页
              name: "fwglList",
              component: () => import("@/pages/workbench/fwgl/fwglList"),
            },
            {
              path: "/fwgl/:level/:type/servicedetail/:id",
              name: "servicedetail",
              component: () => import("@/pages/workbench/fwgl/serviceDetail"),
            }, // 注册发布的服务 - 详情
            {
              path: "/fwgl/:level/:type/serviceedit/:id",
              name: "serviceedit",
              component: () => import("@/pages/workbench/fwgl/serviceEdit"),
            }, // 注册发布的服务 - 编辑
            {
              path: "/fwgl/:level/:type/applyserviceedit/:id",
              name: "applyserviceedit",
              component: () => import("@/pages/workbench/fwgl/apply_service_detail"),
            }, // 申请的服务 - 详情
            {
              path: "/fwgl/:level/:type/approvalserviceedit/:id",
              name: "approvalserviceedit",
              component: () => import("@/pages/workbench/fwgl/approval_service_detail"),
            }, // 审批的服务 - 详情
          ],
        }, // 工作台 - 服务管理模块
        {
          path: "/yygl/:level", // 应用管理 level：用户等级
          name: "yygl",
          redirect: "/yygl/:level/0",
          component: () => import("@/pages/workbench/yygl/yygl"),
          children: [
            {
              path: "/yygl/:level/:type", // 应用管理列表页
              name: "yyglList",
              component: () => import("@/pages/workbench/yygl/yyglList"),
            },
            {
              path: "/yygl/:level/:type/detail/:id", // 应用仓库详情
              name: "appdetail",
              component: () => import("@/pages/workbench/yygl/app_detail"),
            },
            {
              path: "/yygl/:level/:type/edit/:id", // 应用仓库编辑
              name: "appedit",
              component: () => import("@/pages/workbench/yygl/app_edit"),
            },
            {
              path: "/yygl/:level/:type/deploydetail/:id", // 我部署的应用详情
              name: "deploy_app_detail",
              component: () => import("@/pages/workbench/yygl/deploy_app_detail"),
            },
            {
              path: "/yygl/:level/:type/applydetail/:id", // 我申请的应用详情
              name: "apply_app_detail",
              component: () => import("@/pages/workbench/yygl/apply_app_detail"),
            },
            {
              path: "/yygl/:level/:type/approvaldetail/:id", // 我申请的应用详情
              name: "approval_app_detail",
              component: () => import("@/pages/workbench/yygl/approval_app_detail"),
            },
          ],
        }, // 工作台 - 应用管理模块
        {
          path: "/shop", // 服务超市
          name: "shop",
          redirect: "/shop/data_service_list",
          component: () => import("@/pages/service_shop/shop"),
          children: [
            {
              path: "/shop/data_service_list", // 数据服务列表页
              name: "shopDataList",
              component: () => import("@/pages/service_shop/shop_list_data"),
            },
            {
              path: "/shop/space_time_service_list", // 时空服务列表页
              name: "shopSpaceTimeList",
              component: () => import("@/pages/service_shop/shop_list_space_time"),
            },
            {
              path: "/shop/video_service_list", // 视频服务列表页
              name: "shopVideoList",
              component: () => import("@/pages/service_shop/shop_list_video"),
            },
            {
              path: "/shop/perception_service_list", // 感知服务列表页
              name: "shopPerceptionList",
              component: () => import("@/pages/service_shop/shop_list_perception"),
            },
            {
              path: "/shop/comprehensive_app_list", // 综合应用列表页
              name: "shopComAppList",
              component: () => import("@/pages/service_shop/shop_list_comprehensive_app"),
            },
            {
              path: "/shop/cloud", // 云资源服务
              name: "shopCloud",
              component: () => import("@/pages/service_shop/shop_cloud"),
            },
            {
              path: "/shop/app_store_list", // 应用商店列表页
              name: "shopAppStoreList",
              component: () => import("@/pages/service_shop/shop_list_app_store"),
            },
            {
              path: "/shop/shopping_cart", // 购物车页
              name: "shoppingCart",
              component: () => import("@/pages/service_shop/shopping_cart"),
            },
            {
              path: "/shop/shop_car_apply", // 购物车页
              name: "shopCarApply",
              component: () => import("@/pages/service_shop/shop_car_apply"),
            },
          ],
        }, // 服务超市 - 列表页
        {
          path: "/shop/sjfwDetail/:id",
          name: "sjfwDetail",
          component: () => import("@/pages/service_shop/sjfwDetail"),
        }, // 服务超市 - 数据服务详情
        {
          path: "/shop/skfwDetail/:id",
          name: "skfwDetail",
          component: () => import("@/pages/service_shop/skfwDetail"),
        }, // 服务超市 - 时空服务详情
        {
          path: "/shop/zhfwDetail/:id",
          name: "zhfwDetail",
          component: () => import("@/pages/service_shop/zhfwDetail"),
        }, // 服务超市 - 综合服务详情
        {
          path: "/shop/yysdDetail/:id",
          name: "yysdDetail",
          component: () => import("@/pages/service_shop/yysdDetail"),
        }, // 服务超市 - 应用详情
        {
          path: "/workplace",
          name: "workPlace",
          component: () => import("@/pages/workbench/workPlace"),
        }, // 主页 - 工作台
        {
          path: "/services_shop",
          name: "services_shop",
          component: () => import("@/pages/service_shop/services_shop"),
        }, // 主页 - 服务超市
        {
          path: "/app_build",
          name: "app_build",
          component: () => import("@/pages/workbench/app_build"),
        }, // 应用构建（镜像形式）
        {
          path: "/user", // 个人中心
          name: "user",
          redirect: "/user/user_info",
          component: () => import("@/pages/user/user"),
          children: [
            {
              path: "/user/user_info", // 个人信息页
              name: "userInfo",
              component: () => import("@/pages/user/user_info"),
            },
            {
              path: "/user/message", // 消息管理页
              name: "message",
              component: () => import("@/pages/user/message"),
            },
            {
              path: "/user/order_list", // 订单管理页
              name: "orderList",
              component: () => import("@/pages/user/order_list"),
            },
          ],
        },
        {
          path: "/authority", // 权限管理
          name: "authority",
          redirect: "/authority/organization",
          component: () => import("@/pages/authority/authority"),
          children: [
            {
              path: "/authority/organization", // 组织管理页
              name: "organization",
              component: () => import("@/pages/authority/organization"),
            },
            {
              path: "/authority/users", // 用户管理页
              name: "users",
              component: () => import("@/pages/authority/users"),
            },
            {
              path: "/authority/menu", // 菜单管理页
              name: "menu",
              component: () => import("@/pages/authority/menus"),
            },
            {
              path: "/authority/roles", // 角色管理页
              name: "roles",
              component: () => import("@/pages/authority/roles"),
            },
          ],
        },
      ],
    },
    {
      path: "/example_table", // 表格实例
      name: "example_table",
      component: () => import("@/pages/example/example_table"),
    },
    {
      path: "/example_upload", // 表格实例
      name: "example_upload",
      component: () => import("@/pages/example/example_upload"),
    },
    {
      path: "/example_code", // 编辑器实例
      name: "example_code",
      component: () => import("@/pages/example/example_code"),
    },
    {
      path: "/example_icon", // svg 实例
      name: "example_icon",
      component: () => import("@/pages/example/example_icon"),
    },
    {
      path: "/example_topology", // 拓扑图实例
      name: "example_topology",
      component: () => import("@/pages/example/example_topology"),
    },
    {
      path: "/example_commodity", // 商品详情实例
      name: "example_commodity",
      component: () => import("@/pages/example/example_commodity"),
    },
    {
      path: "/example_com_list", // 商品列表实例
      name: "example_com_list",
      component: () => import("@/pages/example/example_com_list"),
    },
  ],
});
