import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../layout/index.vue'
import { Message } from 'element-ui';
import i18n from '../i18n/index'
Vue.use(VueRouter)


// 提取子路由配置
const childrenRoutes = [
  {
    path: '',
    name: 'Home',
    component: () => import('../views/home/index.vue'),
    meta: {
      title: '首页',
      description: i18n.t(`seo.Home`),
      allAuthority: [`all`],
      // keywords: 'M2Pool, cryptocurrency mining pool, bitcoin mining, DGB mining, mining pool service, 加密货币矿池, 比特币挖矿, DGB挖矿, 矿池服务'
      keywords: {
        en: 'M2Pool, cryptocurrency mining pool, bitcoin mining, DGB mining, mining pool service, 加密货币矿池, 比特币挖矿, DGB挖矿, 矿池服务',
        zh: 'M2Pool, 加密货币矿池, 比特币挖矿, DGB挖矿, 矿池服务'
      }



    }
  },
  {//只读页面挖矿账户页
    path: 'miningAccount',
    name: 'MiningAccount',
    component: () => import('../views/miningAccount/index.vue'),
    meta: {
      title: '挖矿账户页面',
      description: i18n.t(`seo.miningAccount`),
      allAuthority: [`admin`, `registered`, `customer_service`, `back_admin`],
      // keywords: 'M2Pool mining account, crypto mining stats, mining rewards, hashrate monitor, 矿池账户, 挖矿收益, 算力监控'
      keywords: {
        en: 'M2Pool mining account, crypto mining stats, mining rewards, hashrate monitor, 矿池账户, 挖矿收益, 算力监控',
        zh: 'M2Pool 挖矿账户, 加密挖矿统计, 挖矿奖励, 算力监控, 矿池账户, 挖矿收益, 算力监控'
      }
    }
  },
  {//只读页面展示页
    path: 'readOnlyDisplay',
    name: 'ReadOnlyDisplay',
    component: () => import('../views/readOnlyDisplay/index.vue'),
    meta: {
      title: '只读页面展示页',
      description: i18n.t(`seo.readOnlyDisplay`),
      allAuthority: [`all`],
      // keywords: 'M2Pool 矿池,只读页面,收益状况,矿工信息,Read only page,Revenue situation,Mining Pool,Miner information'
      keywords: {
        en: 'Read only page,Revenue situation,Mining Pool,Miner information',
        zh: 'M2Pool 矿池,只读页面,收益状况,矿工信息'
      }



    }
  },
  {//报块页面
    path: 'reportBlock',
    name: 'ReportBlock',
    component: () => import('../views/reportBlock/index.vue'),
    meta: {
      title: '报块页面',
      description: i18n.t(`seo.reportBlock`),
      allAuthority: [`admin`, `registered`, `customer_service`, `back_admin`],
      // keywords: 'M2Pool 矿池,报块页面,幸运值,区块高度,Block page,Lucky Value,block height,Mining Pool'
      keywords: {
        en: 'Block page,Lucky Value,block height,Mining Pool',
        zh: 'M2Pool 矿池,报块页面,幸运值,区块高度'
      }


    }
  },
  {//帮助中心
    path: 'helpCenter',
    name: 'HelpCenter',
    component: () => import('../views/helpCenter/index.vue'),
    meta: {
      title: '帮助中心',
      description: i18n.t(`seo.helpCenter`),
      allAuthority: [`all`],
      keywords: {
        en: 'Help Center,Beginner Guide,Mining Data,Frequently Asked Questions,Announcement Center,Other',
        zh: '帮助中心,新手入门,常见问题,公告中心'
      }


    }
  },
   {//编辑器测试
    path: 'editorDocument',
    name: 'EditorDocument',
    component: () => import('../views/editorDocument.vue'),
    meta: {
      title: '编辑器测试',
      description: i18n.t(`seo.helpCenter`),
      allAuthority: [`all`],
      keywords: {
        en: 'Help Center,Beginner Guide,Mining Data,Frequently Asked Questions,Announcement Center,Other',
        zh: '帮助中心,新手入门,常见问题,公告中心'
      }


    }
  },

  {//广播页面
    path: 'broadcast',
    name: 'Broadcast',
    component: () => import('../views/broadcast/index.vue'),
    meta: {
      title: '广播页面',
      description: i18n.t(`seo.broadcast`),
      allAuthority: [`back_admin`],
      keywords: {
        en: 'broadcast',
        zh: '广播'
      }
    }
  },
  {//用户管理
    path: 'userManagement',
    name: 'UserManagement',
    component: () => import('../views/userManagement/index.vue'),
    meta: {
      title: '用户管理',
      description: i18n.t(`seo.userManagement`),
      allAuthority: [`back_admin`],
      keywords: {
        en: 'userManagement',
        zh: '用户管理'
      }
    },

  },
  {//用户详情
    path: 'userDetails',
    name: 'UserDetails',
    component: () => import('../views/userDetails/index.vue'),
    meta: {
      title: '用户详情',
      description: i18n.t(`seo.userManagement`),
      allAuthority: [`back_admin`],
      keywords: {
        en: 'userDetails',
        zh: '用户详情'
      }
    }
  },
    {//待支付汇总
      path: 'pendingPaymentSummary',
      name: 'PendingPaymentSummary',
      component: () => import('../views/pendingPaymentSummary/index.vue'),
      meta: {
        title: '待支付汇总',
        description: i18n.t(`seo.pendingPaymentSummary`),
        allAuthority: [`back_admin`],
        keywords: {
          en: 'pendingPaymentSummary',
          zh: '待支付汇总'
        }
      },
  
    },
    {//文档管理
      path: 'documentManagement',
      name: 'DocumentManagement',
      component: () => import('../views/documentManagement/index.vue'),
      meta: {
        title: '文档管理',
        description: i18n.t(`seo.documentManagement`),
        allAuthority: [`back_admin`],
        keywords: {
            en: 'documentManagement',
            zh: '文档管理'
        }
      }
    },
   {//新增文档  modifyDocument
    path: 'addDocument',
    name: 'AddDocument',
    component: () => import('../views/documentManagement/addDocument/index.vue'),
    meta: {
      title: '新增文档',
      description: i18n.t(`seo.documentManagement`),
      allAuthority: [`back_admin`],
      keywords: {
          en: 'documentManagement',
          zh: '文档管理'
      }
    }
  },
    {//修改文档  
      path: 'modifyDocument',
      name: 'ModifyDocument',
      component: () => import('../views/documentManagement/modifyDocument/index.vue'),
      meta: {
        title: '修改文档',
        description: i18n.t(`seo.documentManagement`),
        allAuthority: [`back_admin`],
        keywords: {
            en: 'documentManagement',
            zh: '文档管理'
        }
      }
    },


  {//费率
    path: 'rate',
    name: 'Rate',
    component: () => import('../views/rate/index.vue'),
    meta: {
      title: '费率页面',
      description: i18n.t(`seo.rate`),
      allAuthority: [`all`],
      // keywords: 'M2Pool 矿池,费率页面,挖矿费率,收益计算,Mining Pool,Rate,Mining fee rate,Profit calculation'
      keywords: {
        en: 'Mining Pool,Rate,Mining fee rate,Profit calculation',
        zh: 'M2Pool 矿池,费率页面,挖矿费率,收益计算'
      }


    }
  },
  {//分配说明
    path: 'allocationExplanation',
    name: 'AllocationExplanation',
    component: () => import('../views/allocationExplanation/index.vue'),
    meta: {
      title: '分配说明页面',
      description: i18n.t(`seo.rate`),
      allAuthority: [`all`],
      // keywords: '分配、转账说明,矿池分配,转账说明,Allocation,Transfer,Mining Pool,Pool allocation,Transfer instructions'
      keywords: {
        en: 'Allocation,Transfer,Mining Pool,Pool allocation,Transfer instructions',
        zh: '分配、转账说明,矿池分配,转账说明'
      }
    }
  },
  {//API文档
    path: 'apiFile',
    name: 'ApiFile',
    component: () => import('../views/apiFile/index.vue'),
    meta: {
      title: 'API文档页面',
      description: i18n.t(`seo.apiFile`),
      allAuthority: [`all`],
      // keywords: 'M2Pool 矿池,API 文档,认证 token,接口调用,API file,authentication token,Interface call'
      keywords: {
        en: 'API file,authentication token,Interface call',
        zh: 'M2Pool 矿池,API 文档,认证 token,接口调用'
      }

    }
  },
  {//在线客服
    path: 'customerService',
    name: 'CustomerService',
    component: () => import('../views/customerService/index.vue'),
    meta: {
      title: '在线客服',
      description: i18n.t(`seo.apiFile`),
      allAuthority: [`customer_service`, `admin`,],//客服权限
      // keywords: 'M2Pool 矿池,API 文档,认证 token,接口调用,API file,authentication token,Interface call'
      keywords: {
        en: 'API file,authentication token,Interface call',
        zh: 'M2Pool 矿池,API 文档,认证 token,接口调用'
      }

    }
  },

  {//接入矿池页面
    path: '/:lang/AccessMiningPool',
    name: 'AccessMiningPool',
    component: () => import('../views/AccessMiningPool/index.vue'),
    meta: {
      title: '接入矿池页面',
      description: i18n.t(`seo.allocationExplanation`),
      allAuthority: [`all`],
      // keywords: 'M2Pool 矿池,接入矿池,币种接入,挖矿指南,Access to Mining Pools,Coin Access,Mining Guide'
      keywords: {
        en: 'Access to Mining Pools,Coin Access,Mining Guide',
        zh: 'M2Pool 矿池,接入矿池,币种接入,挖矿指南'
      }

    },
    children: [
      {//nexa 挖矿页面
        path: 'nexaAccess',
        name: 'NexaAccess',
        component: () => import('../views/AccessMiningPool/nexaAccess/index.vue'),
        meta: {
          title: 'nexa 挖矿页面',
          description: i18n.t(`seo.nexaAccess`),
          allAuthority: [`all`],
          keepAlive: true,
          requiresAuth: false,
          // keywords: 'nexa,挖矿教程,Nexa接入,Nexa Access,Mining Tutorial'
          keywords: {
            en: 'Nexa Access,Mining Tutorial',
            zh: 'nexa,挖矿教程,Nexa接入,Nexa Access,Mining Tutorial'
          }
        }
      },
      {//rxd 挖矿页面
        path: 'rxdAccess',
        name: 'RxdAccess',
        component: () => import('../views/AccessMiningPool/rxdAccess/index.vue'),
        meta: {
          title: 'rxd 挖矿页面',
          description: i18n.t(`seo.rxdAccess`),
          allAuthority: [`all`],
          // keywords: 'rxd,挖矿教程,Radiant接入,rxd Access,Radiant Access,Mining Tutorial,radiant'
          keywords: {
            en: 'rxd Access,Radiant Access,Mining Tutorial,radiant',
            zh: 'rxd,矿池挖矿教程,Radiant接入,'
          }
        }
      },
      {//mona 挖矿页面
        path: 'monaAccess',
        name: 'MonaAccess',
        component: () => import('../views/AccessMiningPool/monaAccess/index.vue'),
        meta: {
          title: 'mona 挖矿页面',
          description: i18n.t(`seo.monaAccess`),
          allAuthority: [`all`],
          // keywords: 'mona,挖矿教程,mona接入,Mona Access,MONA Access,Mining Tutorial'
          keywords: {
            en: 'Mona Access,MONA Access,Mining Tutorial',
            zh: 'mona,挖矿教程,mona接入,'
          }
        },

      },
      {//grs 挖矿页面 
        path: 'grsAccess',
        name: 'GrsAccess',
        component: () => import('../views/AccessMiningPool/grsAccess/index.vue'),
        meta: {
          title: 'grs 挖矿页面',
          description: i18n.t(`seo.grsAccess`),
          allAuthority: [`all`],
          // keywords: 'GRS,Grs接入,GRS Access,grs Access,Mining Tutorial'
          keywords: {
            en: 'GRS Access,grs Access,Mining Tutorial',
            zh: 'GRS,Grs接入,GRS挖矿教程'
          }
        },

      },
      {//dgbqA挖矿页面  dgboAccess
        path: 'dgbqAccess',
        name: 'DgbqAccess',
        component: () => import('../views/AccessMiningPool/dgbqAccess/index.vue'),
        meta: {
          title: 'Dgbq 挖矿页面',
          description: i18n.t(`seo.dgbAccess`),
          allAuthority: [`all`],
          // keywords: 'Dgbq,dgb(qubit)接入,Dgb(qubit) Access,DGB(qubit) Access,Mining Tutorial,DGB'
          keywords: {
            en: 'Dgb(qubit) Access,DGB(qubit) Access,Mining Tutorial,DGB',
            zh: 'Dgbq,dgb(qubit)接入,dgb(qubit)挖矿教程'
          }
        },

      },
      {//dgboAccess 挖矿页面   
        path: 'dgboAccess',
        name: 'DgboAccess',
        component: () => import('../views/AccessMiningPool/dgboAccess/index.vue'),
        meta: {
          title: 'Dgbo 挖矿页面',
          description: i18n.t(`seo.dgbAccess`),
          allAuthority: [`all`],
          // keywords: 'dgbo,dgb(odocrypt)接入,Dgb(odocrypt) Access,DGB(odocrypt) Access,Mining Tutorial,DGB'
          keywords: {
            en: 'Dgb(odocrypt) Access,DGB(odocrypt) Access,Mining Tutorial,DGB',
            zh: 'dgbo,dgb(odocrypt)接入,dgb(odocrypt)挖矿教程'
          }
        },

      },
      {//dgbsAccess 挖矿页面   
        path: 'dgbsAccess',
        name: 'DgbsAccess',
        component: () => import('../views/AccessMiningPool/dgbsAccess/index.vue'),
        meta: {
          title: 'Dgbs 挖矿页面',
          description: i18n.t(`seo.dgbAccess`),
          allAuthority: [`all`],
          // keywords: 'dgbs,dgb(skein)接入,Dgb(skein) Access,DGB(skein) Access,Mining Tutorial,DGB'
          keywords: {
            en: 'Dgb(skein) Access,DGB(skein) Access,Mining Tutorial,DGB',
            zh: 'dgbs,dgb(skein)接入,dgb(skein)挖矿教程'
          }
        },

      },
      {//enxAccess 挖矿页面   
        path: 'enxAccess',
        name: 'EnxAccess',
        component: () => import('../views/AccessMiningPool/enxAccess/index.vue'),
        meta: {
          title: ' Entropyx(enx) 挖矿页面',
          description: i18n.t(`seo.enxAccess`),
          allAuthority: [`all`],
          // keywords: 'Entropyx(Enx), Entropyx(enx)接入,enx,ENX,Mining Tutorial'
          keywords: {
            en: 'Entropyx(Enx), enx,ENX,Mining Tutorial',
            zh: 'Entropyx(enx)接入,Entropyx挖矿教程'
          }
        },

      },
      {//alphminingPool 挖矿页面   
        path: 'alphminingPool',
        name: 'AlphminingPool',
        component: () => import('../views/AccessMiningPool/alphminingPool/index.vue'),
        meta: {
          title: ' alephium 挖矿页面',
          description: i18n.t(`seo.alphAccess`),
          allAuthority: [`all`],
          // keywords: 'Entropyx(Enx), Entropyx(enx)接入,enx,ENX,Mining Tutorial'
          keywords: {
            en: 'alephium(alph), Alephium,Mining Tutorial',
            zh: 'alephium(alph)接入,alephium挖矿教程'
          }
        },

      },


    ]
  },
  {//服务条款
    path: 'ServiceTerms',
    name: 'ServiceTerms',
    component: () => import('../views/ServiceTerms/index.vue'),
    meta: {
      title: '服务条款页面',
      description: i18n.t(`seo.ServiceTerms`),
      allAuthority: [`all`],
      // keywords: 'M2Pool 矿池,服务条款,用户权益,权利义务,Terms of Service, User Rights, Rights and Obligations'
      keywords: {
        en: 'Terms of Service, User Rights, Rights and Obligations',
        zh: 'M2Pool 矿池,服务条款,用户权益,权利义务'
      }
    }
  },
  {//提交工单
    path: 'submitWorkOrder',
    name: 'SubmitWorkOrder',
    component: () => import('../views/submitWorkOrder/index.vue'),
    meta: {
      title: '提交工单页面',
      description: i18n.t(`seo.submitWorkOrder`),
      allAuthority: [`admin`, `registered`, `customer_service`, `back_admin`],
      // keywords: 'M2Pool 矿池,提交工单,技术支持,问题处理,Mining Pool,Work Order Submission, Technical Support, Troubleshooting'
      keywords: {
        en: 'Mining Pool,Work Order Submission, Technical Support, Troubleshooting',
        zh: 'M2Pool 矿池,提交工单,技术支持,问题处理'
      }
    }
  },
  {//用户查看工单记录
    path: 'workOrderRecords',
    name: 'WorkOrderRecords',
    component: () => import('../views/workOrderRecords/index.vue'),
    meta: {
      title: '工单记录页面(用户)',
      description: i18n.t(`seo.workOrderRecords`),
      allAuthority: [`admin`, `registered`, `customer_service`, `back_admin`],
      // keywords: 'M2Pool 矿池,用户工单记录,处理状态,问题进度,User Work Order Records, Processing Status, Issue Progress'
      keywords: {
        en: 'User Work Order Records, Processing Status, Issue Progress',
        zh: 'M2Pool 矿池,用户工单记录,处理状态,问题进度'
      }
    }
  },
  {//用户查看工单详情
    path: 'userWorkDetails',
    name: 'UserWorkDetails',
    component: () => import('../views/userWorkDetails/index.vue'),
    meta: {
      title: '工单详情页面(用户)',
      description: i18n.t(`seo.userWorkDetails`),
      allAuthority: [`admin`, `registered`, `customer_service`, `back_admin`],
      // keywords: 'M2Pool 矿池,用户工单详情,问题描述,补充提交,User Work Order Details, Problem Description, Additional Submissions'
      keywords: {
        en: 'User Work Order Details, Problem Description, Additional Submissions',
        zh: 'M2Pool 矿池,用户工单详情,问题描述,补充提交'
      }
    }
  },
  {//后台工单管理
    path: 'workOrderBackend',
    name: 'WorkOrderBackend',
    component: () => import('../views/workOrderBackend/index.vue'),
    meta: {
      title: '工单管理页面(后台)',
      description: "M2Pool 矿池后台工单管理页面，供 M2Pool 管理员查看和管理用户提交的工单记录，确保问题及时处理，提升用户体验。",
      allAuthority: [`back_admin`],
      // keywords: 'M2Pool 矿池,后台工单管理,用户工单,及时处理,Back-office work order management, user work orders, timely processing'
      keywords: {
        en: 'Back-office work order management, user work orders, timely processing',
        zh: 'M2Pool 矿池,后台工单管理,用户工单,及时处理'
      }
    }
  },
  {//后台工单详情页面
    path: 'BKWorkDetails',
    name: 'BKWorkDetails',
    component: () => import('../views/BKWorkDetails/index.vue'),
    meta: {
      title: '工单详情页面(后台)',
      description: "M2Pool 矿池后台工单详情页面，管理员可在此查看提交工单的详细情况，包括提交时间、详细问题描述以及处理过程，并通过本页面对该工单进行回复处理。",
      allAuthority: [`back_admin`],
      // keywords: 'M2Pool 矿池,后台工单详情,问题处理,回复工单,Backend Work Order Details, Problem Handling, Responding to Work Orders'
      keywords: {
        en: 'Backend Work Order Details, Problem Handling, Responding to Work Orders',
        zh: 'M2Pool 矿池,后台工单详情,问题处理,回复工单'
      }
    }
  },
  {//数据展示
    path: 'dataDisplay',
    name: 'DataDisplay',
    component: () => import('../views/dataDisplay/index.vue'),
    meta: {
      title: '数据展示页面',
      description: "M2Pool 矿池数据展示页面",
      allAuthority: [`all`],
      // keywords: 'M2Pool 矿池,数据展示,Mining Pool,Data Display'
      keywords: {
        en: 'Mining Pool,Data Display',
        zh: 'M2Pool 矿池,数据展示'
      }
    }
  },
  {//公告中心
    path: 'announcements',
    name: 'Announcements',
    component: () => import('../views/announcements/index.vue'),
    meta: {
      title: '公告中心',
      description: i18n.t(`seo.announcements`) || 'M2Pool 矿池公告中心，提供最新的公告、通知和重要信息，让用户及时了解矿池的最新动态和服务变更。',
      allAuthority: [`all`],
      keywords: {
        en: 'Announcement Center,Latest Announcements,Mining Pool News,Service Updates,Important Notices',
        zh: 'M2Pool 矿池,公告中心,最新公告,矿池动态,服务更新,重要通知'
      }
    }
  },
    {//公告详情
      path: 'announcementDetails',
      name: 'AnnouncementDetails',
      component: () => import('../views/announcementDetails/index.vue'),
      meta: {
        title: '公告详情',
        // description: i18n.t(`seo.announcements`) || 'M2Pool 矿池公告中心，提供最新的公告、通知和重要信息，让用户及时了解矿池的最新动态和服务变更。',
        allAuthority: [`all`],
        // keywords: {
        //   en: 'Announcement Center,Latest Announcements,Mining Pool News,Service Updates,Important Notices',
        //   zh: 'M2Pool 矿池,公告中心,最新公告,矿池动态,服务更新,重要通知'
        // }
      }
    },
    {//常见问题
      path: 'commonProblem',
      name: 'CommonProblem',
      component: () => import('../views/commonProblem/index.vue'),
      meta: {
        title: '常见问题',
        // description: i18n.t(`seo.announcements`) || 'M2Pool 矿池公告中心，提供最新的公告、通知和重要信息，让用户及时了解矿池的最新动态和服务变更。',
        allAuthority: [`all`],
        // keywords: {
        //   en: 'Announcement Center,Latest Announcements,Mining Pool News,Service Updates,Important Notices',
        //   zh: 'M2Pool 矿池,公告中心,最新公告,矿池动态,服务更新,重要通知'
        // }
      }
    },
    {//搜索结果页面
      path: 'searchResult',
      name: 'SearchResult',
      component: () => import('../views/searchResult/index.vue'),
      meta: {
        title: '搜索结果',
        // description: i18n.t(`seo.announcements`) || 'M2Pool 矿池公告中心，提供最新的公告、通知和重要信息，让用户及时了解矿池的最新动态和服务变更。',
        allAuthority: [`all`],
        // keywords: {
        //   en: 'Announcement Center,Latest Announcements,Mining Pool News,Service Updates,Important Notices',
        //   zh: 'M2Pool 矿池,公告中心,最新公告,矿池动态,服务更新,重要通知'
        // }
      }
    },

  {//警报通知
    path: 'alerts',
    name: 'Alerts',
    component: () => import('../views/alerts/index.vue'),
    meta: {
      title: '警报通知',
      description: i18n.t(`seo.alerts`),
      allAuthority: [`admin`, `registered`, `back_admin`],
      // keywords: 'M2Pool, 矿池,离线告警设置,矿机离线,Mining Pool,Offline Alarm Setting,Mining Machine Offline'
      keywords: {
        en: 'Mining Pool,Offline Alarm Setting,Mining Machine Offline',
        zh: 'M2Pool 矿池,离线告警设置,矿机离线'
      }
    }
  },

  {//个人中心
    path: 'personalCenter',
    name: 'PersonalCenter',
    // redirect: "/personalCenter/personalMining",
    component: () => import('../views/personalCenter/index.vue'),
    meta: {
      title: '个人中心页面',
      description: i18n.t(`seo.personalCenter`),
      allAuthority: [`admin`, `registered`, `customer_service`, `back_admin`],
      // keywords: 'M2Pool 矿池,个人中心,挖矿账户,只读页面设置，安全设置，API密钥生成,Personal Center,Mining Account,Read-Only Page Setup,Security Settings,API Key Generation'
      keywords: {
        en: 'Personal Center,Mining Account,Read-Only Page Setup,Security Settings,API Key Generation',
        zh: 'M2Pool 矿池,个人中心,挖矿账户,只读页面设置，安全设置，API密钥生成'
      }
    },
    children: [
      {//个人中心挖矿账户
        path: 'personalMining',
        name: 'PersonalMining',
        component: () => import('../views/personalCenter/personalMining/index.vue'),
        meta: {
          title: '挖矿账户设置页面',
          description: i18n.t(`seo.personalMining`),
          allAuthority: [`admin`, `registered`, `customer_service`, `back_admin`],
          // keywords: 'M2Pool 矿池,个人中心,挖矿账户设置,币种账户,Personal Center,Mining Account Settings,Coin Accounts'
          keywords: {
            en: 'Personal Center,Mining Account Settings,Coin Accounts',
            zh: 'M2Pool 矿池,个人中心,挖矿账户设置,币种账户'
          }
        }
      },
      {//个人中心只读页面 securitySetting
        path: 'readOnly',
        name: 'ReadOnly',
        component: () => import('../views/personalCenter/readOnly/index.vue'),
        meta: {
          title: '只读页面设置',
          description: i18n.t(`seo.readOnly`),
          allAuthority: [`admin`, `registered`, `customer_service`, `back_admin`],
          // keywords: 'M2Pool 矿池,个人中心,只读页面设置,矿池分享,Personal Center,Read-Only Page Setting,Mining Pool Sharing'
          keywords: {
            en: 'Personal Center,Read-Only Page Setting,Mining Pool Sharing',
            zh: 'M2Pool 矿池,个人中心,只读页面设置,矿池分享'
          }
        }
      },
      {//个人中心安全设置personal
        path: 'securitySetting',
        name: 'SecuritySetting',
        component: () => import('../views/personalCenter/securitySetting/index.vue'),
        meta: {
          title: '安全设置页面',
          description: i18n.t(`seo.securitySetting`),
          allAuthority: [`admin`, `registered`, `customer_service`, `back_admin`],
          // keywords: 'M2Pool 矿池,安全设置,密码修改,Security settings, password change'
          keywords: {
            en: 'Security settings, password change',
            zh: 'M2Pool 矿池,安全设置,密码修改'
          }
        }
      },
      {//个人中心 
        path: 'personal',
        name: 'personal',
        component: () => import('../views/personalCenter/personal/index.vue'),
        meta: {
          title: '个人信息页面',
          description: i18n.t(`seo.personal`),
          allAuthority: [`admin`, `registered`, `customer_service`, `back_admin`],
          // keywords: 'M2Pool 矿池,个人信息,登录历史,Personal Information, Login History'
          keywords: {
            en: 'Personal Information, Login History',
            zh: 'M2Pool 矿池,个人信息,登录历史'
          }
        }
      },
      {//个人中心 挖矿报告 (隐藏)
        path: 'miningReport',
        name: 'MiningReport',
        component: () => import('../views/personalCenter/miningReport/index.vue'),
        meta: {
          title: '挖矿报告页面',
          description: i18n.t(`seo.miningReport`),
          allAuthority: [`admin`, `registered`, `customer_service`, `back_admin`],
          // keywords: 'M2Pool 矿池,个人中心,挖矿报告,订阅服务,Mining Report, Subscription Service'
          keywords: {
            en: 'Mining Report, Subscription Service',
            zh: 'M2Pool 矿池,个人中心,挖矿报告,订阅服务'
          }
        }
      },

      {//个人中心 API
        path: 'personalAPI',
        name: 'PersonalAPI',
        component: () => import('../views/personalCenter/personalAPI/index.vue'),
        meta: {
          title: 'API页面',
          description: i18n.t(`seo.personalAPI`),
          allAuthority: [`admin`, `registered`, `customer_service`, `back_admin`],
          // keywords: 'M2Pool 矿池,个人中心,API 页面,API密钥生成,API Page,API Key Generation'
          keywords: {
            en: 'API Page,API Key Generation',
            zh: 'M2Pool 矿池,个人中心,API 页面,API密钥生成'
          }
        }
      },

    ]
  },


]

// 独立页面路由
const staticRoutes = [
  {
    path: '/:lang/login',
    name: 'Login',
    component: () => import('../views/login/login.vue'),
    meta: {
      title: '登录页面',
      description: "M2Pool 矿池登录页面",
      allAuthority: [`all`],
      // keywords: 'M2Pool 矿池,登录页面,账号密码,安全登录'
      keywords: {
        en: 'M2Pool Mining Pool,login page,account password',
        zh: 'M2Pool 矿池,登录页面,账号密码,安全登录'
      }
    }
  },
  {
    path: '/:lang/register',
    name: 'Register',
    component: () => import('../views/register/register.vue'),
    meta: {
      title: '注册页面', description: "M2Pool 矿池注册页面，新用户可在此便捷注册账号，加入 M2Pool 矿池大家庭。", allAuthority: [`all`],
      // keywords: 'M2Pool 矿池,注册页面,新用户注册,账号创建'
      keywords: {
        en: 'M2Pool Mining Pool,register page,new user registration,account creation',
        zh: 'M2Pool 矿池,注册页面,新用户注册,账号创建'
      }
    }
  },
  {
    path: '/:lang/simulation',
    name: 'simulation',
    component: () => import('../views/simulation.vue'),
    meta: {
      title: '测试页面', description: "M2Pool 矿池测试页面，用于进行系统功能的模拟和测试，确保矿池稳定运行", allAuthority: [`all`],
      // keywords: 'M2Pool 矿池,测试页面,系统测试,稳定运行'
      keywords: {
        en: 'M2Pool Mining Pool,test page,system test,stable operation',
        zh: 'M2Pool 矿池,测试页面,系统测试,稳定运行'
      }
    }
  },
  {
    path: '/:lang/splitEditorDemo',
    name: 'splitEditorDemo',
    component: () => import('../views/splitEditorDemo/index.vue'),
    meta: {
      title: '分屏编辑器演示', 
      description: "M2Pool 分屏编辑器演示页面，支持编辑、预览、分屏三种模式的富文本编辑器", 
      allAuthority: [`all`],
      keywords: {
        en: 'split screen editor,rich text editor,real-time preview,WYSIWYG editor',
        zh: '分屏编辑器,富文本编辑器,实时预览,所见即所得编辑器'
      }
    }
  },



  {
    path: '/:lang/resetPassword',
    name: 'ResetPassword',
    component: () => import('../views/resetPassword/index.vue'),
    meta: {
      title: '重置密码页面', description: "M2Pool 矿池重置密码页面，用户可在此修改矿池网站账号密码，保障账户安全。", allAuthority: [`all`],
      // keywords: 'M2Pool 矿池,重置密码,修改密码,账户安全'
      keywords: {
        en: 'M2Pool Mining Pool,reset password,modify password,account security',
        zh: 'M2Pool 矿池,重置密码,修改密码,账户安全'
      }
    }
  },
  {//404
    path: '/:lang/404',
    component: () => import('../views/page404.vue'),
    meta: {
      title: '404页面', description: "M2Pool 矿池 404 页面，当 URL 错误时将跳转至此页面，提示用户页面不存在。", allAuthority: [`all`],
      // keywords: 'M2Pool 矿池,404 页面,页面不存在,错误跳转'
      keywords: {
        en: 'M2Pool Mining Pool,404 page,page not found,error redirect',
        zh: 'M2Pool 矿池,404 页面,页面不存在,错误跳转'
      }
    }
  },

]


const routes = [
  {
    path: '/:lang',
    component: Layout,
    beforeEnter: (to, from, next) => {
      const lang = to.params.lang
      const supportedLanguages = ['zh', 'en']

      // 检查语言参数
      if (!supportedLanguages.includes(lang)) {
        return next(`/en${to.path}`)
      }

      // 设置语言
      if (i18n.locale !== lang) {
        i18n.locale = lang
        localStorage.setItem('lang', lang)
      }
      return next()
    },
    children: childrenRoutes
  },
  // 根路径重定向
  {
    path: '/',
    redirect: () => {
      const defaultLang = localStorage.getItem('lang') || 'en'
      return `/${defaultLang}`
    }
  },
  // 添加所有静态路由
  ...staticRoutes,
  // 404页面
  {
    path: '*',
    redirect: to => {
      const lang = localStorage.getItem('lang') || 'en'
      return `/${lang}/404`
    }
  }
]



const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  strict: true, // 启用严格模式，不允许尾部斜杠
  scrollBehavior(to, from, savedPosition) { //每次路由跳转时，滚动到顶部
    // 如果有保存的滚动位置（比如浏览器前进后退），就用它
    if (savedPosition) {
      return savedPosition;
    } else {
      // 否则滚动到顶部，并使用平滑滚动
      return { x: 0, y: 0, behavior: 'smooth' };
    }
  }

})
router.afterEach(() => {
  Vue.nextTick(() => {
    // 滚动主内容区
    const contentMain = document.querySelector('.el-main');
    if (contentMain) {
      contentMain.scrollTo({ top: 0, left: 0, behavior: 'smooth' });
    }
    // 兼容其它页面（如登录页等）
    window.scrollTo({ top: 0, left: 0, behavior: 'smooth' });
  });
});

router.beforeEach((to, from, next) => {
  const lang = to.params.lang || (localStorage.getItem('lang') || 'en');
  let token = null;
  try {
    token = JSON.parse(localStorage.getItem('token'));
  } catch (e) {
    token = null;
  }
  // 权限判断
  let jurisdiction = null;
  try {
    jurisdiction = JSON.parse(localStorage.getItem("jurisdiction"));
  } catch (e) {
    jurisdiction = null;
  }
    
    

  
// --------------------------
// 未登录
if (!token) {
  console.log(`未登录`);
  if (
    to.meta.allAuthority &&
    (
      to.meta.allAuthority[0] === 'all' ||
      (jurisdiction && jurisdiction.roleKey && to.meta.allAuthority.includes(jurisdiction.roleKey))
    )
  ) {
    return next();
  } else {


    // 无权限
    Message({
      showClose: true,
      message: i18n.t(`mining.jurisdiction`),
      type: 'error'
    });
    return next({ path: `/${lang}/login` });
  }

} else {


  if (jurisdiction && jurisdiction.roleKey == `back_admin`) {
    if (to.name == 'Login' || to.name == 'Register'  || jurisdiction && jurisdiction.roleKey && to.meta.allAuthority.includes(jurisdiction.roleKey)) {
      return next();
    } else if(to.path == `/${lang}`) {
      return next({ path: `/${lang}/userManagement` });
    }else {
      // 无权限
      Message({
        showClose: true,
        message: `当前身份只能访问后台管理系统`,
        type: 'error'
      });
      localStorage.setItem("activeIndex", `1`);
      return next({ path: `/${lang}/broadcast` });

     
    }
    
  } else {

    if (to.name === 'Login' || to.name === 'Register') {
      return next({ path: `/${lang}` });
    } else if (to.meta.allAuthority &&
      (
        to.meta.allAuthority[0] === 'all' ||
        (jurisdiction && jurisdiction.roleKey && to.meta.allAuthority.includes(jurisdiction.roleKey))
      )
    ) {
      return next();
    } else {
      // 无权限
      Message({
        showClose: true,
        message: i18n.t(`mining.jurisdiction`),
        type: 'error'
      });
      return next({ path: `/${lang}/login` });
    }


  }






}





});




// 解决报错 此方法只针对VueRouter3.0以上
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
export default router
