import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/login'
import Page404 from '@/views/404'
import Layout from '@/views/layout/index'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home/index',
    meta: {
      title: '主页',
      roles: ['master', 'admin', 'editor'],
      hidden: true
    }
  },
  {
    path: '/mapstyle',
    component: Layout,
    redirect: '/mapstyle/index',
    meta: {
      title: '地图类型',
      icon: 'el-icon-map-location',
      roles: ['master'],
      hidden: true
    },
    children: [
      {
        path: '/mapstyle/index',
        component: () => import('@/views/layout/components/main/mapstyle/index'),
        meta: {
          title: '地图列表',
          icon: 'el-icon-tickets',
          roles: ['master'],
          hidden: true
        }
      },
      {
        path: '/mapstyle/add',
        component: () => import('@/views/layout/components/main/mapstyle/add'),
        meta: {
          title: '地图添加',
          icon: 'el-icon-plus',
          roles: ['master'],
          tapName: 'plane',
          hidden: true
        }
      },
      {
        path: '/mapstyle/edit/:id',
        component: () => import('@/views/layout/components/main/mapstyle/add'),
        meta: {
          title: '地图更新',
          icon: 'el-icon-edit',
          roles: ['master'],
          tapName: 'plane',
          hidden: true
        }
      }
    ]
  },
  {
    path: '/home',
    component: Layout,
    meta: {
      title: '概况',
      icon: 'iconfont icon-fuwudiqiu',
      roles: ['master', 'admin', 'editor'],
      tapName: 'plane'
    },
    redirect: '/home/index',
    children: [
      {
        path: '/home/index',
        component: () => import('@/views/layout/components/main/home/index'),
        meta: {
          title: '概况',
          icon: 'iconfont icon-fuwudiqiu',
          roles: ['master', 'admin', 'editor'],
          tapName: 'plane'
        }
      },
      {
        path: '/home/set',
        component: () => import('@/views/layout/components/main/home/set'),
        meta: {
          title: '设置',
          icon: 'iconfont icon-shezhi',
          roles: ['master', 'admin', 'editor'],
          tapName: 'plane',
          hidden: true
        }
      }
    ]
  },
  {
    path: '/login',
    component: Login,
    meta: {
      title: '登录',
      roles: ['master', 'admin', 'editor'],
      hidden: true
    }
  },
  {
    path: '/model',
    component: Layout,
    redirect: '/model/index',
    meta: {
      title: '机型管理',
      icon: 'iconfont icon-chuiqigudingyi',
      roles: ['master', 'admin'],
      tapName: 'plane'
    },
    children: [
      {
        path: '/model/index',
        component: () => import('@/views/layout/components/main/model/index'),
        meta: {
          title: '机型列表',
          icon: 'el-icon-tickets',
          roles: ['master', 'admin'],
          tapName: 'plane'
        }
      },
      {
        path: '/model/add',
        component: () => import('@/views/layout/components/main/model/add'),
        meta: {
          title: '机型添加',
          icon: 'el-icon-plus',
          roles: ['master', 'admin'],
          tapName: 'plane',
          hidden: true
        }
      },
      {
        path: '/model/edit/:id',
        component: () => import('@/views/layout/components/main/model/add'),
        meta: {
          title: '机型更新',
          icon: 'el-icon-edit',
          roles: ['master', 'admin'],
          tapName: 'plane',
          hidden: true
        }
      }
    ]
  },
  {
    path: '/register',
    component: Layout,
    redirect: '/register/index',
    meta: {
      title: '飞机管理',
      icon: 'el-icon-edit-outline',
      roles: ['master', 'admin'],
      tapName: 'plane'
    },
    children: [
      {
        path: '/register/index',
        component: () => import('@/views/layout/components/main/register/index'),
        meta: {
          title: '飞机列表',
          icon: 'el-icon-tickets',
          roles: ['master', 'admin'],
          tapName: 'plane'
        }
      },
      {
        path: '/register/add',
        component: () => import('@/views/layout/components/main/register/add'),
        meta: {
          title: '飞机添加',
          icon: 'el-icon-plus',
          roles: ['master', 'admin'],
          tapName: 'plane',
          hidden: true
        }
      },
      {
        path: '/register/edit/:id',
        component: () => import('@/views/layout/components/main/register/add'),
        meta: {
          title: '飞机更新',
          icon: 'el-icon-edit',
          roles: ['master', 'admin'],
          tapName: 'plane',
          hidden: true
        }
      },
      {
        path: '/register/crosFrequency/:shop_id/:plane_id',
        component: () => import('@/views/layout/components/main/register/crosFrequency'),
        meta: {
          title: '飞机对频',
          icon: 'el-icon-link',
          roles: ['master', 'admin'],
          tapName: 'plane',
          hidden: true
        }
      },
      {
        path: '/register/flyData',
        component: () => import('@/views/layout/components/main/register/flyData'),
        meta: {
          title: '飞行数据统计',
          icon: 'el-icon-data-line',
          roles: ['master', 'admin'],
          tapName: 'plane',
          hidden: true
        }
      }
    ]
  },
  {
    path: '/nofly',
    component: Layout,
    redirect: '/nofly/setNofly',
    meta: {
      title: '飞行限制',
      icon: 'iconfont icon-jinfeiqu',
      roles: ['master', 'admin'],
      tapName: 'plane'
    },
    children: [
      {
        path: '/nofly/setNofly',
        component: () => import('@/views/layout/components/main/nofly/setNofly'),
        meta: {
          title: '禁飞区设置',
          icon: 'iconfont icon-huizhi',
          roles: ['master', 'admin'],
          tapName: 'plane'
        }
      },
      {
        path: '/nofly/setRestrictfly',
        component: () => import('@/views/layout/components/main/nofly/setRestrictfly'),
        meta: {
          title: '限飞区设置',
          icon: 'iconfont icon-huizhi',
          roles: ['master', 'admin'],
          tapName: 'plane'
        }
      }
    ]
  },
  {
    path: '/route',
    component: Layout,
    redirect: '/route/index',
    meta: {
      title: '航线管理',
      icon: 'iconfont icon-feihangluxian',
      roles: ['master', 'admin'],
      tapName: 'plane'
    },
    children: [
      {
        path: '/route/index',
        component: () => import('@/views/layout/components/main/route/index'),
        meta: {
          title: '航线列表',
          icon: 'iconfont icon-a-05-1-1jihuazhihanggenzong',
          roles: ['master', 'admin'],
          tapName: 'plane'
        }
      },
      {
        path: '/route/add',
        component: () => import('@/views/layout/components/main/route/add'),
        meta: {
          title: '航线设计',
          icon: 'iconfont icon-huizhi',
          roles: ['master', 'admin'],
          tapName: 'plane'
        }
      },
      {
        path: '/route/edit/:id',
        component: () => import('@/views/layout/components/main/route/add'),
        meta: {
          title: '航线编辑',
          icon: 'iconfont icon-huizhi',
          roles: ['master', 'admin'],
          tapName: 'plane',
          hidden: true
        }
      }
    ]
  },
  {
    path: '/site',
    component: Layout,
    redirect: '/site/index',
    meta: {
      title: '站点管理',
      icon: 'iconfont icon-zhandianguanli',
      roles: ['master', 'admin'],
      tapName: 'plane'
    },
    children: [
      {
        path: '/site/index',
        component: () => import('@/views/layout/components/main/site/index'),
        meta: {
          title: '站点列表',
          icon: 'el-icon-tickets',
          roles: ['master', 'admin'],
          tapName: 'plane'
        }
      },
      {
        path: '/site/add',
        component: () => import('@/views/layout/components/main/site/add'),
        meta: {
          title: '站点添加',
          icon: 'el-icon-plus',
          roles: ['master', 'admin'],
          tapName: 'plane',
          hidden: true
        }
      },
      {
        path: '/site/edit/:id',
        component: () => import('@/views/layout/components/main/site/add'),
        meta: {
          title: '站点更新',
          icon: 'el-icon-edit',
          roles: ['master', 'admin'],
          tapName: 'plane',
          hidden: true
        }
      }
    ]
  },
  {
    path: '/planes',
    component: Layout,
    redirect: '/planes/index',
    meta: {
      title: '无人机',
      icon: 'iconfont icon-wurenji',
      roles: ['master', 'admin'],
      tapName: 'plane'
    },
    children: [
      {
        path: '/planes/swarm',
        component: () => import('@/views/layout/components/main/planes/swarm'),
        meta: {
          title: '集群控制',
          icon: 'iconfont icon-a-jiqunkongzhianniu_huaban1',
          roles: ['master', 'admin'],
          tapName: 'plane'
        }
      },
      {
        path: '/planes/index/:id/:name', // 动态加载路由时加ID参数
        component: () => import('@/views/layout/components/main/planes/index'),
        meta: {
          title: '飞机加载中',
          icon: 'el-icon-loading',
          roles: ['master', 'admin'],
          tapName: 'plane'
        }
      }
    ]
  },
  {
    path: '/shop',
    component: Layout,
    redirect: '/shop/edit',
    meta: {
      title: '商铺管理',
      icon: 'iconfont icon-a-shanghu_choose2x1',
      roles: ['master', 'admin', 'editor'],
      tapName: 'admin'
    },
    children: [
      {
        path: '/shop/edit',
        component: () => import('@/views/layout/components/main/shop/add'),
        meta: {
          title: '商铺设置',
          icon: 'iconfont icon-dianpuguanli',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin'
        }
      },
      {
        path: '/shop/add',
        component: () => import('@/views/layout/components/main/shop/add'),
        meta: {
          title: '商铺添加',
          icon: 'iconfont icon-check',
          roles: ['master'],
          tapName: 'admin'
        }
      }
    ]
  },
  {
    path: '/admin',
    component: Layout,
    redirect: '/admin/index',
    meta: {
      title: '管理员管理',
      icon: 'iconfont icon-guanliyuan',
      roles: ['master', 'admin'],
      tapName: 'admin'
    },
    children: [
      {
        path: '/admin/index',
        component: () => import('@/views/layout/components/main/admin/index'),
        meta: {
          title: '账户列表',
          icon: 'iconfont icon-yonghuguanli',
          roles: ['master', 'admin'],
          tapName: 'admin'
        }
      },
      {
        path: '/admin/add',
        component: () => import('@/views/layout/components/main/admin/add'),
        meta: {
          title: '账户添加',
          icon: 'iconfont icon-xinzengguanliyuan',
          roles: ['master', 'admin'],
          tapName: 'admin',
          hidden: true
        }
      },
      {
        path: '/admin/edit/:id',
        component: () => import('@/views/layout/components/main/admin/add'),
        meta: {
          title: '账户编辑',
          icon: 'iconfont icon-huizhi',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin',
          hidden: true
        }
      }
    ]
  },
  {
    path: '/message',
    component: Layout,
    redirect: '/message/index',
    meta: {
      title: '公告管理',
      icon: 'el-icon-microphone',
      roles: ['master', 'admin', 'editor'],
      tapName: 'admin'
    },
    children: [
      {
        path: '/message/index',
        component: () => import('@/views/layout/components/main/message/index'),
        meta: {
          title: '公告列表',
          icon: 'el-icon-chat-line-square',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin'
        }
      },
      {
        path: '/message/pub',
        component: () => import('@/views/layout/components/main/message/pub'),
        meta: {
          title: '发布公告',
          icon: 'el-icon-microphone',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin'
        }
      }
    ]
  },
  {
    path: '/category',
    component: Layout,
    redirect: '/category/index',
    meta: {
      title: '分类管理',
      icon: 'iconfont icon-a-ziliaocaozuoxianshifenleishu',
      roles: ['master', 'admin', 'editor'],
      tapName: 'admin'
    },
    children: [
      {
        path: '/category/index',
        component: () => import('@/views/layout/components/main/category/index'),
        meta: {
          title: '分类管理',
          icon: 'iconfont icon-a-ziliaocaozuoxianshifenleishu',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin'
        }
      }
    ]
  },
  {
    path: '/product',
    component: Layout,
    redirect: '/spu/index',
    meta: {
      title: '商品管理',
      icon: 'iconfont icon-chanpin',
      roles: ['master', 'admin', 'editor'],
      tapName: 'admin'
    },
    children: [
      {
        path: '/spu/index',
        component: () => import('@/views/layout/components/main/product/spu/index'),
        meta: {
          title: 'SPU列表',
          icon: 'iconfont icon-chanpinliebiao-02',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin'
        }
      },
      {
        path: '/spu/add',
        component: () => import('@/views/layout/components/main/product/spu/add'),
        meta: {
          title: 'SPU添加',
          icon: 'iconfont icon-huoquchanpin',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin',
          hidden: true
        }
      },
      {
        path: '/spu/edit/:id',
        component: () => import('@/views/layout/components/main/product/spu/add'),
        meta: {
          title: 'SPU编辑',
          icon: 'iconfont icon-huoquchanpin',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin',
          hidden: true
        }
      },
      {
        path: '/sku/index',
        component: () => import('@/views/layout/components/main/product/sku/index'),
        meta: {
          title: 'SKU列表',
          icon: 'iconfont icon-sku',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin'
        }
      },
      {
        path: '/sku/add',
        component: () => import('@/views/layout/components/main/product/sku/add'),
        meta: {
          title: 'SKU添加',
          icon: 'iconfont icon-sku1',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin',
          hidden: true
        }
      },
      {
        path: '/sku/edit/:id',
        component: () => import('@/views/layout/components/main/product/sku/add'),
        meta: {
          title: 'SKU编辑',
          icon: 'iconfont icon-sku1',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin',
          hidden: true
        }
      }
    ]
  },
  {
    path: '/broadcast',
    component: Layout,
    redirect: '/broadcast/banner',
    meta: {
      title: '广告管理',
      icon: 'iconfont icon-guanggao',
      roles: ['master', 'admin', 'editor'],
      tapName: 'admin'
    },
    children: [
      {
        path: '/broadcast/banner',
        component: () => import('@/views/layout/components/main/broadcast/banner'),
        meta: {
          title: 'banner设置',
          icon: 'iconfont icon-banner',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin'
        }
      },
      {
        path: '/broadcast/notice',
        component: () => import('@/views/layout/components/main/broadcast/notice'),
        meta: {
          title: '滚动通知设置',
          icon: 'iconfont icon-m-gundongwenzi',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin'
        }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/index',
    meta: {
      title: '订单与统计',
      icon: 'iconfont icon-dingdantongji',
      roles: ['master', 'admin', 'editor'],
      tapName: 'admin'
    },
    children: [
      {
        path: '/order/index',
        component: () => import('@/views/layout/components/main/order/index'),
        meta: {
          title: '订单管理',
          icon: 'iconfont icon-a-SalesOrderManagement',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin'
        }
      },
      {
        path: '/order/show/:id',
        component: () => import('@/views/layout/components/main/order/show'),
        meta: {
          title: '订单详情',
          icon: 'iconfont icon-a-SalesOrderManagement',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin',
          hidden: true
        }
      },
      {
        path: '/order/stat',
        component: () => import('@/views/layout/components/main/order/stat'),
        meta: {
          title: '销售统计',
          icon: 'iconfont icon-data-view',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin'
        }
      }
    ]
  },
  {
    path: '/download',
    component: Layout,
    redirect: '/download/index',
    meta: {
      title: '软件下载',
      icon: 'iconfont icon-dingdantongji',
      roles: ['master', 'admin', 'editor'],
      tapName: 'admin'
    },
    children: [
      {
        path: '/download/index',
        component: () => import('@/views/layout/components/main/download/index'),
        meta: {
          title: '软件下载',
          icon: 'iconfont icon-a-SalesOrderManagement',
          roles: ['master', 'admin', 'editor'],
          tapName: 'admin'
        }
      }
    ]
  },
  {
    path: '/404',
    component: Page404,
    meta: {
      title: '404',
      roles: ['master', 'admin', 'editor'],
      hidden: true
    }
  },
  {
    path: '*',
    redirect: '/',
    meta: {
      title: '主页',
      roles: ['master', 'admin', 'editor'],
      hidden: true
    }
  }
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

export default router
