import Vue from 'vue'
import { $addStorageEvent } from '../util/processingData'
import VueRouter from 'vue-router'
import noPage from '../views/noPage.vue'
import Web from '../views/web.vue'
import i18n from '../lang/index'
Vue.use(VueRouter)

const routes = [
  {
    // path: '/Web',
    path: '/',
    name: 'Web',
    component: Web,
    meta:{
      title:"首页",
      description:i18n.t(`seo.Web`),
      keywords:"区块链分析、加密货币数据、Coinbus、链上数据指标、市场洞察,Blockchain Analytics, Cryptocurrency Data, Coinbus, On-Chain Data Metrics, Market Insights",
    },
    children: [
    //   {
    //   path: '/NDAQ',
    //   name: 'NDAQ',
    //   component: () => import('../views/NDAQ.vue'),
     
    // },
    // {
    //   path: 'ETH',
    //   name: 'ETH',
    //   component: () => import('../views/ETH.vue'),
    //   meta:{
    //     title:"",
    //     description:"",
    //     keywords:"",
    //   }
    // }
  ]
  },
  // {
  //   path: '/Home',
  //   name: 'Home',
  //   component: () => import('../views/Home/index.vue'),
  //   meta:{
  //     title:"",
  //     description:"",
  //     keywords:"",
  //   }
  // },
  {
    path: '/privilegeLevel',
    name: 'PrivilegeLevel',
    component: () => import('../views/privilegeLevel/index.vue'),
    meta:{
      roleKey: [`registered`, `advance`, `vip`, `support`, "verifier", `admin`] ,//可以访问人员
      title:"账户权限等级详情",
      description:i18n.t(`seo.privilegeLevel`),
      keywords:"Coinbus, 权限等级,账号权限,会员等级资费, Privilege Levels, Account Privileges, Membership Level Rates",
    }
  },
  // {
  //   path: '/Bian',
  //   name: 'Bian',
  //   component: () => import('../views/BiAnController.vue'),
  //   meta:{
  //     title:"",
  //     description:"",
  //     keywords:"",
  //   }
  // },
  {//帮助中心
    path: '/help',
    name: 'help',
    component: () => import('../views/help/index.vue'),
    meta: {//财会人员和匿名人员不能访问
      inaccessible: "accounting",
      roleKey: [`registered`, `advance`, `vip`, `support`, "verifier", `admin`] ,//可以访问人员
      title:"帮助中心",
      description:i18n.t(`seo.help`),
      keywords:"coinbus 帮助中心,工单提交,问题处理,Work order submission, problem handling",
    },
  },
  {//帮助中心历史工单点击跳出详情
    path: '/WorkOrderDetails',
    name: 'WorkOrderDetails',
    meta: {//财会人员和匿名人员不能访问
      inaccessible: "accounting",
      roleKey: [`registered`, `advance`, `vip`, `support`, "verifier", `admin`], //可以访问人员
      title:"工单详情",
      description:i18n.t(`seo.WorkOrderDetails`),
      keywords:"Coinbus 工单详情、用户工单、问题跟进,User work orders, problem follow-up",
    },
    component: () => import('../views/WorkOrderDetails/index.vue'),
  },
  {//帮助中心后台管理页面 
    path: '/HelpBackstage',
    name: 'HelpBackstage',
    meta: {
      roleKey: [`support`, `verifier`, `admin`], //可以访问人员
      // title:"后台管理",
      // description:"Coinbus 帮助中心后台管理页面，供管理员查看工单提交情况分析，包括工单历史图表、超时工单列表、待处理及已处理工单等，高效管理用户问题。",
      // keywords:"Coinbus 后台管理、工单分析、工单处理",
    },
    component: () => import('../views/helpBackstage/index.vue'),
  },
  {//帮助中心后台管理页面的详情页面
    path: '/HelpDetails',
    name: 'HelpDetails',
    meta: {
      roleKey: [`support`, `verifier`, `admin`], //可以访问人员
      // title:"工单详情",
      // description:"后台管理人员在此查看工单详情及处理历史记录，以便对用户回复处理情况，确保问题妥善解决。",
      // keywords:"Coinbus 后台工单详情、管理回复、问题处理历史",
    },
    component: () => import('../views/helpDetails/index.vue'),
  },
  {//个人中心
    path: '/personal',
    name: 'personal',
    alias: '/',
    meta: {
      roleKey: [`registered`, `advance`, `vip`, `support`, `verifier`, `accounting`, `admin`], //可以访问人员
      title:"个人中心",
      description:i18n.t(`seo.personal`),
      keywords:"Coinbus 个人中心、账号管理、余额查询,Personal center, account management, balance inquiry",
    },

    // component: Web,
    component: () => import('../views/personal/index.vue'),
  },
  {//留言板后台 WorkOrderDetails
    path: '/messageBoard',
    name: 'messageBoard',
    meta: {
      roleKey: [`support`, `verifier`, `admin`],
      // title:"留言板后台",
      // description:"Coinbus 留言板后台供管理人员监控用户留言情况，包含留言历史图表、未处理留言列表、已处理留言列表，及时回应用户反馈。",
      // keywords:"Coinbus 留言板管理、用户反馈、后台监控",
    },
    component: () => import('../views/MessageBoard/index.vue'),
  },
  {//自定义订阅 subscribe
    path: '/subscribe',
    name: 'subscribe',
    meta: {
      roleKey: [`advance`, `vip`, `support`, `verifier`, `admin`], //可以访问人员
      title:"自定义订阅",
      description:i18n.t(`seo.subscribe`),
      keywords:"Coinbus 自定义订阅、消息订阅、通知方式,Custom subscriptions, message subscriptions, notification methods",
    },
    component: () => import('../views/subscribe/index.vue'),
  },
  // {//自定义订阅 、订阅详情页面subscribeDetails 
  //   path: '/subscribeDetails',
  //   name: 'subscribeDetails',
  //   meta: {
  //     roleKey: [`advance`, `vip`, `support`, `verifier`, `admin`], //可以访问人员
  //     title:"",
  //     description:"",
  //     keywords:"",
  //   },
  //   component: () => import('../views/subscribeDetails/index.vue'),
  // },
  {//订阅管理后台 subscribeBoard  
    path: '/subscribeBoard',
    name: 'subscribeBoard',
    meta: {
      roleKey: [`verifier`, `admin`], //可以访问人员
      // title:"订阅管理后台",
      // description:"Coinbus 订阅管理后台供管理人员统计查看订阅报告数量，管理报告发布及待审核、已拒绝、已发布报告历史和自定义消息历史的相关信息分析统计。",
      // keywords:"Coinbus 订阅管理、报告统计、后台分析",
    },
    component: () => import('../views/subscribeBoard/index.vue'),
  },
  {//订阅发布 报告发布 subscribeRelease 
    path: '/subscribeRelease',
    name: 'subscribeRelease',
    meta: {
      roleKey: [`admin`], //可以访问人员
      // title:"报告发布",
      // description:"Coinbus 报告发布页面，仅供后台管理员使用。包含报告类型、预计发出时间、标题及内容，确保高质量的订阅报告发布",
      // keywords:"Coinbus 报告发布、管理员操作、订阅报告",
    },
    component: () => import('../views/subscribeRelease/index.vue'),
  },
  {//订阅 审核页面 subscribAaudit
    path: '/subscribAaudit',
    name: 'subscribAaudit',
    meta: {
      roleKey: [`verifier`, `admin`], //可以访问人员
      // title:"订阅审核",
      // description:"Coinbus 的发布报告审核页面，展示报告相关详情信息。审核人员可依据这些信息回复审核意见，决定通过或拒绝审核报告。",
      // keywords:"Coinbus 订阅审核、报告审核、审核意见",
    },
    component: () => import('../views/subscribAaudit/index.vue'),
  },
  {//支付管理后台 payManagement payHistories
    path: '/payManagement',
    name: 'payManagement',
    meta: {
      roleKey: [`accounting`, `admin`], //可以访问人员
      // title:"支付管理后台",
      // description:"Coinbus 支付管理后台，供管理人员管理用户信息。包括新增用户数量、日新增数量、转账、提现相关信息及消费金额，还有每日历史分析图。",
      // keywords:"Coinbus 支付管理、用户信息管理、历史分析",
    },
    component: () => import('../views/payManagement/index.vue'),
  },
  {//支付历史 payHistories AccountUpgrade
    path: '/payHistories',
    name: 'payHistories',
    meta: {
      roleKey: [`registered`, `advance`, `vip`, `support`, `verifier`, `accounting`, `admin`], //可以访问人员
      title:"支付历史",
      description:i18n.t(`seo.payHistories`),
      keywords:"Coinbus 支付历史、转账记录查询,Payment history, transfer history inquiry",
    },
    component: () => import('../views/payHistories/index.vue'),
  },
  {//账户升级页面  AccountUpgrade
    path: '/AccountUpgrade',
    name: 'AccountUpgrade',
    meta: {
      roleKey: [`registered`, `advance`, `vip`, `support`, `verifier`, `accounting`, `admin`], //可以访问人员
      title:"账户升级",
      description:i18n.t(`seo.AccountUpgrade`),
      keywords:"Coinbus 账户升级,权限提升、支付升级,Account Upgrade, Privilege Upgrade, Payment Upgrade",
    },
    component: () => import('../views/AccountUpgrade/index.vue'),
  },
  {//后台地址管理页面  管理员 财务可看  
    path: '/BackgroundAddress',
    name: 'BackgroundAddress',
    meta: {
      roleKey: [`accounting`, `admin`], //可以访问人员
      // title:"新增收款地址",
      // description:"Coinbus 后台地址管理页面，供后台财务和管理人员添加收款地址。",
      // keywords:"Coinbus 后台地址管理、收款地址添加",
    },
    component: () => import('../views/backgroundAddress/index.vue'),
  },
  {//后台确认支付  管理员 财务可看 
    path: '/BackendPayment',
    name: 'BackendPayment',
    meta: {
      roleKey: [`accounting`, `admin`], //可以访问人员
      // title:"转账确认",
      // description:"Coinbus 后台确认支付页面，供后台财务和管理人员确认处理用户提交的转账申请。",
      // keywords:"Coinbus 后台支付确认、转账处理",
    },
    component: () => import('../views/backendPayment/index.vue'),
  },
  {//后台退款确认  管理员 财务可看  
    path: '/BackendRefund',
    name: 'BackendRefund',
    meta: {
      roleKey: [`accounting`, `admin`], //可以访问人员
      // title:"退款确认",
      // description:"Coinbus 后台退款确认页面，供后台财务和管理人员及时处理用户的退款申请。",
      // keywords:"Coinbus 后台退款确认、退款处理",
    },
    component: () => import('../views/backendRefund/index.vue'),
  },
  {//后台提现 管理员 财务可看  
    path: '/BackendWithdrawal',
    name: 'BackendWithdrawal',
    meta: {
      roleKey: [`accounting`, `admin`], //可以访问人员
      // title:"提现订单",
      // description:"Coinbus 后台提现页面，供后台财务和管理人员处理用户提交的提现订单，并查询提现成功及失败的相关订单记录。",
      // keywords:"Coinbus 后台提现管理、提现订单处理",
    },
    component: () => import('../views/backendWithdrawal/index.vue'),
  },
  // {//数据监控  支持及维护人员, 审核者可看 admin后期取消
  //   path: '/DataMonitoring',
  //   name: 'DataMonitoring',
  //   meta: {
  //     roleKey: [`support`, `admin`] ,//可以访问人员
  //     title:"",
  //     description:"",
  //     keywords:"",
  //   },
  //   component: () => import('../views/dataMonitoring/index.vue'),
  // },
  {//指标解释页面
    path: '/IndexIntroduce',
    name: 'IndexIntroduce',
    meta: {
      roleKey: [`registered`, `advance`, `vip`, `support`, `verifier`, `accounting`, `admin`], //可以访问人员
      title:"指标文档介绍",
      description:i18n.t(`seo.IndexIntroduce`),
      keywords:"Coinbus 指标解释、链上指标含义,Interpretation of indicators, meaning of chained indicators",
    },
    component: () => import('../views/indexIntroduce/index.vue'),
  },
  {//充值页面
    path: '/Recharge',
    name: 'Recharge',
    meta: {
      roleKey: [`registered`, `advance`, `vip`, `support`, `verifier`, `accounting`, `admin`], //可以访问人员
      title:"充值",
      description:i18n.t(`seo.Recharge`),
      keywords:"Coinbus 充值、币种选择、支付网络,Top-ups, currency selection, payment networks",
    },
    component: () => import('../views/Recharge/index.vue'),
  },
  {//提交txid页面
    path: '/TXID',
    name: 'TXID',
    meta: {
      roleKey: [`registered`, `advance`, `vip`, `support`, `verifier`, `accounting`, `admin`], //可以访问人员
      title:"交易Hash",
      description:i18n.t(`seo.TXID`),
      keywords:"Coinbus 提交 txid、充值审核,Submit txid, recharge audit",
    },
    component: () => import('../views/TXID/index.vue'),
  },
  {//申请提现
    path: '/Withdrawal',
    name: 'Withdrawal',
    meta: {
      roleKey: [`registered`, `advance`, `vip`, `support`, `verifier`, `accounting`, `admin`], //可以访问人员
      title:"申请提现",
      description:i18n.t(`seo.Withdrawal`),
      keywords:"Coinbus 申请提现、提现设置,Application for withdrawal, withdrawal settings",
    },
    component: () => import('../views/Withdrawal/index.vue'),
  },
  {//申请提现历史记录
    path: '/withdrawalRecords',
    name: 'withdrawalRecords',
    meta: {
      roleKey: [`registered`, `advance`, `vip`, `support`, `verifier`, `accounting`, `admin`], //可以访问人员
      title:"申请提现历史记录",
      description:i18n.t(`seo.withdrawalRecords`),
      keywords:"Coinbus 提现历史、记录查询,Withdrawal history, record search",
    },
    component: () => import('../views/withdrawalRecords/index.vue'),
  },
  {//提现订单详情
    path: '/withdrawalDetails',
    name: 'withdrawalDetails',
    meta: {
      roleKey: [`registered`, `advance`, `vip`, `support`, `verifier`, `accounting`, `admin`], //可以访问人员
      title:"提现订单详情",
      description:i18n.t(`seo.withdrawalDetails`),
      keywords:"Coinbus 提现详情、订单信息,Withdrawal details, order information",
    },
    component: () => import('../views/withdrawalDetails/index.vue'),
  },
  {//充值记录  
    path: '/RechargeRecord',
    name: 'RechargeRecord',
    meta: {
      roleKey: [`accounting`, `admin`], //可以访问人员
      // title:"充值记录管理",
      // description:"Coinbus 充值记录管理页面，供后台管理人员和财务查看充值订单的详细信息，包括待处理订单、成功订单及失败订单。",
      // keywords:"Coinbus 充值记录管理、订单详情",
    },
    component: () => import('../views/rechargeRecord/index.vue'),
  },
  {//消费记录  subscriptionLetter
    path: '/ConsumptionRecords',
    name: 'ConsumptionRecords',
    meta: {
      roleKey: [`registered`, `advance`, `vip`, `support`, `verifier`, `accounting`, `admin`], //可以访问人员
      title:"消费记录",
      description:i18n.t(`seo.ConsumptionRecords`),
      keywords:"Coinbus 消费记录、消费查询,Consumption records, consumption inquiry",
    },
    component: () => import('../views/consumptionRecords/index.vue'),
  },
  // {//站内信  
  //   path: '/subscriptionLetter',
  //   name: 'SubscriptionLetter',
  //   meta: {
  //     roleKey: [`registered`, `advance`, `vip`, `support`, `verifier`, `accounting`, `admin`], //可以访问人员
  //     title:"",
  //     description:"",
  //     keywords:"",
  //   },
  //   component: () => import('../views/subscriptionLetter/index.vue'),
  // },
  {//订阅与告警 
    path: '/Alarm',
    name: 'Alarm',
    meta: {
      roleKey: [`registered`, `advance`, `vip`, `support`, `verifier`, `accounting`, `admin`], //可以访问人员
      title:"订阅与告警",
      description:i18n.t(`seo.Alarm`),
      keywords:"Coinbus 订阅告警、指标变化,Subscribe to alerts, indicator changes",
    },
    component: () => import('../views/Alarm/index.vue'),
  },
  {//发布观察报告 
    path: '/publishObservations',
    name: 'PublishObservations',
    meta: {
      roleKey: [`registered`, `advance`, `vip`, `support`, `verifier`, `accounting`, `admin`], //可以访问人员
      title:"发布观察报告 ",
      description:i18n.t(`seo.publishObservations`),
      keywords:"Coinbus 观察报告、发布历史,Observation reports, release history",
    },
    component: () => import('../views/publishObservations/index.vue'),
  },
   {//seo 数据展示
    path: '/dataDisplay',
    name: 'DataDisplay',
    meta: {
      roleKey: [`registered`, `advance`, `vip`, `support`, `verifier`, `accounting`, `admin`], //可以访问人员
      title:"coinbus 区块链数据分析平台介绍",
      description:i18n.t(`seo.dataDisplay`),
      keywords:"Coinbus、区块链数据分析、加密货币、交易数据、市场指标、大额交易监控、精准数据、可视化展示、订阅服务、专业团队、客户服务、投资决策、风险管理,Blockchain data analytics, cryptocurrencies, trading data, market metrics, large transaction monitoring, accurate data, visualization, subscription services, professional team, customer service, investment decisions, risk management",
    },
    component: () => import('../views/dataDisplay/index.vue'),
  },  

  {
    path: '*',//404  
    name: 'noPage',
    component: noPage
  },

]
 


const router = new VueRouter({
  //  hash history
  mode: "history",
  routes
})



// 全局前置守卫  在每次路由跳转前执行一些逻辑
// router.beforeEach((to, from, next) => {
//   $addStorageEvent(1, "permissionMask", JSON.stringify(false))
//   // 想要进入个人中心页面 必须有token
//   let token = localStorage.getItem("token");
//   //当前用户等级
//   let identity = JSON.parse(localStorage.getItem("identity"));

//   // console.log(to.path,3333);
//   //返回首页关闭遮罩
//   if (to.path == "/" || to.path == "/web") {
//     //判断跳转的动态组件还是其他路由页面存不同的显示旗帜
//     $addStorageEvent(1, "routerPage", JSON.stringify("web"))
//     $addStorageEvent(1, "permissionMask", JSON.stringify(false))
//     next();
//   } else if (to.path == `/IndexIntroduce`) {

//     $addStorageEvent(1, "routerPage", JSON.stringify("IndexIntroduce"))

//   } else { //指标介绍和组件页面可以同时存在 
//     $addStorageEvent(1, "routerPage", JSON.stringify("noWeb"))

//   }



//   next();
// });




// const originalPush = VueRouter.prototype.push

// VueRouter.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch(err => err)
// }

// const VueRouterPush = VueRouter.prototype.push//处理重复跳转一个页面报错问题
// VueRouter.prototype.push = function push(to) {
//   return VueRouterPush.call(this, to).catch(err => err)
// }
// 处理重复路由导航
const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace

// 重写push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => {
    if (err.name !== 'NavigationDuplicated') {
      return Promise.reject(err)
    }
    return Promise.resolve(false)
  })
}

// 同样处理replace方法
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => {
    if (err.name !== 'NavigationDuplicated') {
      return Promise.reject(err)
    }
    return Promise.resolve(false)
  })
}

export default router