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/5",
          component: () => import("@/pages/service_shop/shop"),
          children: [
            {
              path: "/shop/data_service_list/:id", // 数据服务列表页
              name: "shopDataList",
              component: () => import("@/pages/service_shop/shop_list"),
            },
            {
              path: "/shop/space_time_service_list/:id", // 时空服务列表页
              name: "shopSpaceTimeList",
              component: () => import("@/pages/service_shop/shop_list"),
            },
            {
              path: "/shop/video_service_list/:id", // 视频服务列表页
              name: "shopVideoList",
              component: () => import("@/pages/service_shop/shop_list"),
            },
            {
              path: "/shop/perception_service_list/:id", // 感知服务列表页
              name: "shopPerceptionList",
              component: () => import("@/pages/service_shop/shop_list"),
            },
            {
              path: "/shop/comprehensive_app_list/:id", // 综合应用列表页
              name: "shopComAppList",
              component: () => import("@/pages/service_shop/shop_list"),
            },
            {
              path: "/shop/cloud", // 云资源服务
              name: "shopCloud",
              component: () => import("@/pages/service_shop/shop_cloud"),
            },
            {
              path: "/shop/service_application_successfully", // 云资源服务
              name: "shopSuccess",
              component: () =>
                import("@/pages/service_shop/service_application_successfully"),
            },
            {
              path: "/shop/app_store_list/:id", // 应用商店列表页
              name: "shopAppStoreList",
              component: () => import("@/pages/service_shop/shop_list"),
            },
            {
              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/order_list"),
            },
            {
              path: "/user/order_detail/:id", // 订单管理页
              name: "orderDetail",
              component: () => import("@/pages/user/order/order_detail"),
            },
          ],
        }, // 个人中心
        {
          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/organization/detail/:id", // 组织管理详情
              name: "organizationdetail",
              component: () => import("@/pages/authority/organizationdetail"),
            },
            {
              path: "/authority/organization/add", // 组织管理组织新增
              name: "organizationadd",
              component: () => import("@/pages/authority/organizationedit"),
            },
            {
              path: "/authority/organization/edit/:id", // 组织管理组织编辑
              name: "organizationedit",
              component: () => import("@/pages/authority/organizationedit"),
            },
            {
              path: "/authority/organization/user/:id", // 组织管理组织用户
              name: "organizationuser",
              component: () => import("@/pages/authority/organizationuser"),
            },
            {
              path: "/authority/users", // 用户管理页
              name: "users",
              component: () => import("@/pages/authority/users"),
            },
            {
              path: "/authority/users/roles/:id", // 分配角色
              name: "userRoles",
              component: () => import("@/pages/authority/userRoles"),
            },
            {
              path: "/authority/users/add", // 用户管理-新增
              name: "usersadd",
              component: () => import("@/pages/authority/organizationuser"),
            },
            {
              path: "/authority/users/detail/:id", // 用户管理-详情
              name: "usersdetail",
              component: () => import("@/pages/authority/organizationuser"),
            },
            {
              path: "/authority/users/permission", // 用户管理页 - 权限审批
              name: "users",
              component: () => import("@/pages/authority/permission"),
            },
            {
              path: "/authority/menu", // 菜单管理页
              name: "menu",
              component: () => import("@/pages/authority/menus"),
            },
            {
              path: "/authority/roles", // 角色管理页
              name: "roles",
              component: () => import("@/pages/authority/roles"),
            },
            {
              path: "/authority/roles/add", // 新建角色
              name: "addroles",
              component: () => import("@/pages/authority/addroles"),
            },
            {
              path: "/authority/roles/edit/:id", // 编辑角色
              name: "editroles",
              component: () => import("@/pages/authority/addroles"),
            },
            {
              path: "/authority/roles/allot/:id", // 分配角色
              name: "allotroles",
              component: () => import("@/pages/authority/addroles"),
            },
          ],
        }, // 权限管理
        {
          path: "/data_analysis", // 数据分析中心
          name: "dataAnalysis",
          redirect: "/data_analysis/my_service",
          component: () => import("@/pages/data-analysis/data-analysis"),
          children: [
            {
              path: "/data_analysis/my_service", // 数据分析中心
              name: "myServiceDataAnalysis",
              component: () => import("@/pages/data-analysis/my-service"),
            },
            {
              path: "/data_analysis/my_application", // 数据分析中心
              name: "myApplicationDataAnalysis",
              component: () => import("@/pages/data-analysis/my-application"),
            }
          ]
        }
      ],
    },
    {
      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"),
    },
  ],
});
