import { createRouter, createWebHashHistory } from "vue-router"; import { getLocal } from "@/common/js/utils"; const router = createRouter({ // hash模式:createWebHashHistory,history模式:createWebHistory history: createWebHashHistory(), routes: [ // 首页 { path: "/", redirect: "/home" }, // Home 页面 { path: "/home", name: "home", component: () => import("@/views/home/index.vue"), meta: { index: 1 }, }, // 录入维护记录 { path: "/addMaintenance", name: "addMaintenance", component: () => import("@/views/device/maintenance/add.vue"), meta: { index: 1, noLogin: true }, }, // 录入成功页面 { path: "/addMaintenanceSuccess", name: "addMaintenanceSuccess", component: () => import("@/views/device/maintenance/success.vue"), meta: { index: 1, noLogin: true }, }, // 登录页面 { path: "/login", name: "login", component: () => import("@/views/login.vue"), meta: { index: 1, noLogin: true }, }, // 微信登录跳板 { path: "/wxLogin", name: "wxLogin", component: () => import("@/views/wxLogin.vue"), meta: { index: 1, noLogin: true }, }, // 注册页面 { path: "/register", name: "register", component: () => import("@/views/register.vue"), meta: { index: 1, noLogin: true }, }, // 忘记密码页面 { path: "/forgetpassword", name: "forgetPassword", component: () => import("@/views/forgetPassword"), meta: { index: 1, noLogin: true }, }, // 绑定微信 { path: "/bindWechat", name: "bindWechat", component: () => import("@/views/bindWechat.vue"), meta: { index: 1, noLogin: true }, }, // 修改密码页面 { path: "/changepassword", name: "changePassword", component: () => import("@/views/changePassword"), meta: { index: 1, noLogin: true }, }, // 意见反馈 { path: "/feedback", name: "feedback", component: () => import("@/views/feedback"), meta: { index: 1 }, }, // 设备页面 { path: "/device", name: "device", component: () => import("@/views/device/index"), meta: { index: 1, keepAlive: true }, }, // 设备详情 { path: "/deviceSet", name: "deviceSet", component: () => import("@/views/device/deviceSet"), meta: { index: 1 }, }, // 编辑标签 { path: "/editTag", name: "editTag", component: () => import("@/views/device/tagSet/index.vue"), meta: { index: 1 }, }, // { path: '/deviceOpr', name: 'deviceOpr', component: () => import('@/views/device/deviceOper2.vue'), meta: { index: 1 } }, // 音量调节 { path: "/modulation", name: "modulation", component: () => import("@/views/device/modulation.vue"), meta: { index: 1 }, }, // 远程开门 { path: "/openDoor", name: "openDoor", component: () => import("@/views/device/openDoor.vue"), meta: { index: 1 }, }, // 远程做糖 { path: "/doSugar", name: "doSugar", component: () => import("@/views/device/doSugar.vue"), meta: { index: 1 }, }, // 今日做糖列表 { path: "/toDaySugarList", name: "toDaySugarList", component: () => import("@/views/device/toDaySugarList.vue"), meta: { index: 1 }, }, // 定时开关 { path: "/alarmClock", name: "alarmClock", component: () => import("@/views/device/alarmClock.vue"), meta: { index: 1 }, }, // 设置闹钟 { path: "/alarmClockAdd", name: "alarmClockAdd", component: () => import("@/views/device/alarmClockSet/index.vue"), meta: { index: 1 }, }, { path: "/alarmClockSet", name: "alarmClockSet", component: () => import("@/views/device/alarmClockSet/index.vue"), meta: { index: 1 }, }, // 参数设置 { path: "/paramsSet", name: "paramsSet", component: () => import("@/views/device/paramsSet/index.vue"), meta: { index: 1 }, }, { path: "/paramsSetInfo", name: "paramsSetInfo", component: () => import("@/views/device/paramsSet/paramsSetInfo.vue"), meta: { index: 1 }, }, // 设备充值 { path: "/recharge", name: "recharge", component: () => import("@/views/device/recharge.vue"), meta: { index: 1 }, }, // 机器排行 { path: "/robotranking", name: "robotranking", component: () => import("@/views/robotRanking.vue"), meta: { index: 1 }, }, // 个人中心 { path: "/user", name: "user", component: () => import("@/views/user.vue"), meta: { index: 1 }, }, // 结算账号 { path: "/joinPayBind", name: "joinPayBind", component: () => import("@/views/bindBankCard/joinPayBind.vue"), meta: { index: 1 }, }, // 结算账号 { path: "/huifuBind", name: "huifuBind", component: () => import("@/views/bindBankCard/huifuBind.vue"), meta: { index: 1 }, }, // 自充值 { path: "/uniPay", name: "uniPay", component: () => import("@/views/uniPay/index"), meta: { index: 1 }, }, // 优惠码 { path: "/discountCode", name: "discountCode", component: () => import("@/views/discountCode/index"), meta: { index: 1 }, }, // Airwallex 钱包 { path: "/airwallex", name: "airwallex", component: () => import("@/views/airwallex/index.vue"), meta: { index: 1 }, }, // Airwallex 创建付款人 { path: "/airwallexBeneficiary", name: "airwallexBeneficiary", component: () => import("@/views/airwallex/beneficiary.vue"), meta: { index: 1 }, }, // Airwallex 付款单 { path: "/airwallexPayout", name: "airwallexPayout", component: () => import("@/views/airwallex/payout.vue"), meta: { index: 1 }, }, // Airwallex 去付款 { path: "/caPayment", name: "caPayment", component: () => import("@/views/airwallex/caPayment.vue"), meta: { index: 1 }, }, // Airwallex 付款结果详情 { path: "/paymentDetail", name: "paymentDetail", component: () => import("@/views/airwallex/paymentDetail.vue"), meta: { index: 1 }, }, { path: "/payCode", name: "payCode", component: () => import("@/views/discountCode/payCode"), meta: { index: 1 }, }, // 分销设置 { path: "/distributionSet", name: "distributionSet", component: () => import("@/views/distributionSet/index"), meta: { index: 1 }, }, { path: "/distributionDetail", name: "distributionDetail", component: () => import("@/views/distributionSet/detail"), meta: { index: 1 }, }, // 账号权限 { path: "/accountPer", name: "accountPer", component: () => import("@/views/accountPer/index"), meta: { index: 1 }, }, // 添加账号 { path: "/accountPerAdd", name: "accountPerAdd", component: () => import("@/views/accountPer/add"), meta: { index: 1 }, }, // 角色权限 { path: "/role", name: "role", component: () => import("@/views/role/index"), meta: { index: 1 }, }, { path: "/roleSet", name: "roleSet", component: () => import("@/views/role/add"), meta: { index: 1 }, }, // 商户管理 { path: "/merchantManage", name: "merchantManage", component: () => import("@/views/merchantManage/index"), meta: { index: 1, keepAlive: true }, }, { path: "/merchantSet", name: "merchantSet", component: () => import("@/views/merchantManage/set"), meta: { index: 1 }, }, // 广告管理 { path: "/advertManage", name: "advertManage", component: () => import("@/views/advertManage/index"), meta: { index: 1 }, }, { path: "/advertSet", name: "advertSet", component: () => import("@/views/advertManage/adSet.vue"), meta: { index: 1 }, }, // 广告规则 { path: "/advertRule", name: "advertRule", component: () => import("@/views/advertManage/advertRule/index.vue"), meta: { index: 1 }, }, // 广告规则新增 { path: "/advertRuleAdd", name: "advertRuleAdd", component: () => import("@/views/advertManage/advertRule/add.vue"), meta: { index: 1 }, }, { path: "/advertRuleAddScreen", name: "advertRuleAddScreen", component: () => import("@/views/advertManage/advertRule/screen.vue"), meta: { index: 1 }, }, // apk管理 { path: "/apkManage", name: "apkManage", component: () => import("@/views/apkManage/index"), meta: { index: 1 }, }, // apk管理-新增 { path: "/apkManageAdd", name: "apkManageAdd", component: () => import("@/views/apkManage/add"), meta: { index: 1 }, }, // 报警历史 { path: "/alarmHistory", name: "alarmHistory", component: () => import("@/views/alarmHistory/index"), meta: { index: 1 }, }, // 订单导出 { path: "/orderExport", name: "orderExport", component: () => import("@/views/orderExport/index"), meta: { index: 1 }, }, // 任务消息 { path: "/taskMessage", name: "taskMessage", component: () => import("@/views/taskMessage/index"), meta: { index: 1 }, }, // 设备审批 { path: "/taskEquipment", name: "taskEquipment", component: () => import("@/views/taskMessage/equipment"), meta: { index: 1 }, }, // 分销审批 { path: "/taskProportion", name: "taskProportion", component: () => import("@/views/taskMessage/proportion"), meta: { index: 1 }, }, // 订单中心 { path: "/orderCenter", name: "orderCenter", component: () => import("@/views/orderCenter/index"), meta: { index: 1 }, }, // 测试 { path: "/test", name: "test", component: () => import("@/views/test"), meta: { index: 1 }, }, // 标签管理 { path: "/labelMan", name: "labelMan", component: () => import("@/views/labelMan/index"), meta: { index: 1 }, }, // 标签管理-新增 { path: "/labelManAdd", name: "labelManAdd", component: () => import("@/views/labelMan/add"), meta: { index: 1 }, }, // 修改价格 { path: "/modifyPrice", name: "modifyPrice", component: () => import("@/views/device/modifyPrice/index"), meta: { index: 1 }, }, // 屏蔽/展示商品 { path: "/showGoods", name: "showGoods", component: () => import("@/views/device/showGoods/index"), meta: { index: 1 }, }, // DIY花型 { path: "/diyFlower", name: "diyFlower", component: () => import("@/views/device/diyFlower/index"), meta: { index: 1 }, }, // 设备清洗提醒 { path: "/alarmClean", name: "alarmClean", component: () => import("@/views/device/alarmClean/index"), meta: { index: 1 }, }, // 远程退币 { path: "/returnCoin", name: "returnCoin", component: () => import("@/views/device/returnCoin/index"), meta: { index: 1 }, }, // 支付配置 { path: "/payInfo", name: "payInfo", component: () => import("@/views/device/payInfo/index"), meta: { index: 1 }, }, // 修改机器密码 { path: "/devicePassword", name: "devicePassword", component: () => import("@/views/device/devicePassword/index"), meta: { index: 1 }, }, // 查看定位 { path: "/viewPosition", name: "viewPosition", component: () => import("@/views/device/viewPosition/index"), meta: { index: 1 }, }, // 设备编辑-编辑规则 { path: "/editAdRule", name: "editAdRule", component: () => import("@/views/device/editAdRule/index"), meta: { index: 1 }, }, // 跳转空中云汇收单-消费者付款 { path: "/hpp", name: "Hpp", component: () => import("@/views/Hpp.vue"), meta: { index: 1, noLogin: true }, }, // 定制logo { path: "/customLogo", name: "customLogo", component: () => import("@/views/device/customLogo.vue"), meta: { index: 1 }, }, // 查看日志 { path: "/viewLogs", name: "viewLogs", component: () => import("@/views/device/viewLogs/index"), meta: { index: 1 }, }, // 账户操作 { path: "/accountOperation", name: "accountOperation", component: () => import("@/views/accountOperation/index"), meta: { index: 1 }, }, // 汇付支付获取openid { path: "/weChatPay", name: "weChatPay", component: () => import("@/views/weChatPay"), meta: { index: 1, noLogin: true }, }, // 汇付支付获取openid { path: "/popPayment", name: "popPayment", component: () => import("@/views/popPayment"), meta: { index: 1, noLogin: true }, }, // 钱包 { path: "/purse", name: "purse", component: () => import("@/views/purse/index"), meta: { index: 1 }, }, // 商品管理 { path: "/goodsMan", name: "goodsMan", component: () => import("@/views/device/goodsMan/index"), meta: { index: 1 }, }, // 修改支付方式 { path: "/payment", name: "payment", component: () => import("@/views/device/payment/index"), meta: { index: 1 }, }, // 税收管理 { path: "/tax", name: "tax", component: () => import("@/views/device/tax/index"), meta: { index: 1 }, }, // 维护记录 { path: "/maintenance", name: "maintenance", component: () => import("@/views/device/maintenance/index"), meta: { index: 1 }, }, // 果酱抽取 { path: "/jam", name: "jam", component: () => import("@/views/device/jam/index"), meta: { index: 1 }, }, // 提现列表 { path: "/withdrawList", name: "withdrawList", component: () => import("@/views/purse/withdrawList"), meta: { index: 1 }, }, // apk管理,广告管理,订单导出 不是所有的帐号能看到 ], }); let isVersionChecked = false; const MAX_RETRY_COUNT = 3; let retryCount = 0; router.beforeEach(async (to, from, next) => { // 只在首次路由跳转时检查版本(生产环境) if (!isVersionChecked && process.env.NODE_ENV === "production") { isVersionChecked = true; try { const response = await fetch(`/sc/version.json?t=${Date.now()}`, { cache: "no-store", }); const serverVersion = await response.json(); const localVersion = localStorage.getItem("appVersion") || ""; if (serverVersion.version !== localVersion) { // 版本不一致,提示用户刷新 if (retryCount < MAX_RETRY_COUNT) { retryCount++; console.log( `检测到新版本(${serverVersion.version}),第${retryCount}次尝试刷新...` ); localStorage.setItem("appVersion", serverVersion.version); window.location.reload(); return; // 中断当前路由导航 } else { console.log("已达到最大重试次数,继续使用旧版本"); retryCount = 0; // 重置计数器 } } else if (!localVersion) { localStorage.setItem("appVersion", serverVersion.version); } } catch (error) { console.error("版本检测失败:", error); // 继续路由导航,即使版本检测失败 } } // 页面带有不需要识别登录状态的跳过登录验证 if (to.meta.noLogin) { next(); } else { const user = getLocal("loginUser"); if (!user || user === "") { // 没有登录信息跳转登录页面 router.push("/login"); } else { const userObject = JSON.parse(user); // 登录信息异常跳转登录页面 if (!userObject) { router.push("/login"); } if (typeof userObject.id !== "number") { router.push("/login"); } } next(); } }); export default router;