index.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. import { createRouter, createWebHashHistory } from "vue-router";
  2. import { getLocal } from "@/common/js/utils";
  3. const router = createRouter({
  4. // hash模式:createWebHashHistory,history模式:createWebHistory
  5. history: createWebHashHistory(),
  6. routes: [
  7. // 首页
  8. { path: "/", redirect: "/home" },
  9. // Home 页面
  10. {
  11. path: "/home",
  12. name: "home",
  13. component: () => import("@/views/home/index.vue"),
  14. meta: { index: 1 },
  15. },
  16. // 录入维护记录
  17. {
  18. path: "/addMaintenance",
  19. name: "addMaintenance",
  20. component: () => import("@/views/device/maintenance/add.vue"),
  21. meta: { index: 1, noLogin: true },
  22. },
  23. // 录入成功页面
  24. {
  25. path: "/addMaintenanceSuccess",
  26. name: "addMaintenanceSuccess",
  27. component: () => import("@/views/device/maintenance/success.vue"),
  28. meta: { index: 1, noLogin: true },
  29. },
  30. // 登录页面
  31. {
  32. path: "/login",
  33. name: "login",
  34. component: () => import("@/views/login.vue"),
  35. meta: { index: 1, noLogin: true },
  36. },
  37. // 微信登录跳板
  38. {
  39. path: "/wxLogin",
  40. name: "wxLogin",
  41. component: () => import("@/views/wxLogin.vue"),
  42. meta: { index: 1, noLogin: true },
  43. },
  44. // 注册页面
  45. {
  46. path: "/register",
  47. name: "register",
  48. component: () => import("@/views/register.vue"),
  49. meta: { index: 1, noLogin: true },
  50. },
  51. // 忘记密码页面
  52. {
  53. path: "/forgetpassword",
  54. name: "forgetPassword",
  55. component: () => import("@/views/forgetPassword"),
  56. meta: { index: 1, noLogin: true },
  57. },
  58. // 绑定微信
  59. {
  60. path: "/bindWechat",
  61. name: "bindWechat",
  62. component: () => import("@/views/bindWechat.vue"),
  63. meta: { index: 1, noLogin: true },
  64. },
  65. // 修改密码页面
  66. {
  67. path: "/changepassword",
  68. name: "changePassword",
  69. component: () => import("@/views/changePassword"),
  70. meta: { index: 1, noLogin: true },
  71. },
  72. // 意见反馈
  73. {
  74. path: "/feedback",
  75. name: "feedback",
  76. component: () => import("@/views/feedback"),
  77. meta: { index: 1 },
  78. },
  79. // 设备页面
  80. {
  81. path: "/device",
  82. name: "device",
  83. component: () => import("@/views/device/index"),
  84. meta: { index: 1, keepAlive: true },
  85. },
  86. // 设备详情
  87. {
  88. path: "/deviceSet",
  89. name: "deviceSet",
  90. component: () => import("@/views/device/deviceSet"),
  91. meta: { index: 1 },
  92. },
  93. // 编辑标签
  94. {
  95. path: "/editTag",
  96. name: "editTag",
  97. component: () => import("@/views/device/tagSet/index.vue"),
  98. meta: { index: 1 },
  99. },
  100. // { path: '/deviceOpr', name: 'deviceOpr', component: () => import('@/views/device/deviceOper2.vue'), meta: { index: 1 } },
  101. // 音量调节
  102. {
  103. path: "/modulation",
  104. name: "modulation",
  105. component: () => import("@/views/device/modulation.vue"),
  106. meta: { index: 1 },
  107. },
  108. // 远程开门
  109. {
  110. path: "/openDoor",
  111. name: "openDoor",
  112. component: () => import("@/views/device/openDoor.vue"),
  113. meta: { index: 1 },
  114. },
  115. // 远程做糖
  116. {
  117. path: "/doSugar",
  118. name: "doSugar",
  119. component: () => import("@/views/device/doSugar.vue"),
  120. meta: { index: 1 },
  121. },
  122. // 今日做糖列表
  123. {
  124. path: "/toDaySugarList",
  125. name: "toDaySugarList",
  126. component: () => import("@/views/device/toDaySugarList.vue"),
  127. meta: { index: 1 },
  128. },
  129. // 定时开关
  130. {
  131. path: "/alarmClock",
  132. name: "alarmClock",
  133. component: () => import("@/views/device/alarmClock.vue"),
  134. meta: { index: 1 },
  135. },
  136. // 设置闹钟
  137. {
  138. path: "/alarmClockAdd",
  139. name: "alarmClockAdd",
  140. component: () => import("@/views/device/alarmClockSet/index.vue"),
  141. meta: { index: 1 },
  142. },
  143. {
  144. path: "/alarmClockSet",
  145. name: "alarmClockSet",
  146. component: () => import("@/views/device/alarmClockSet/index.vue"),
  147. meta: { index: 1 },
  148. },
  149. // 参数设置
  150. {
  151. path: "/paramsSet",
  152. name: "paramsSet",
  153. component: () => import("@/views/device/paramsSet/index.vue"),
  154. meta: { index: 1 },
  155. },
  156. {
  157. path: "/paramsSetInfo",
  158. name: "paramsSetInfo",
  159. component: () => import("@/views/device/paramsSet/paramsSetInfo.vue"),
  160. meta: { index: 1 },
  161. },
  162. // 设备充值
  163. {
  164. path: "/recharge",
  165. name: "recharge",
  166. component: () => import("@/views/device/recharge.vue"),
  167. meta: { index: 1 },
  168. },
  169. // 机器排行
  170. {
  171. path: "/robotranking",
  172. name: "robotranking",
  173. component: () => import("@/views/robotRanking.vue"),
  174. meta: { index: 1 },
  175. },
  176. // 个人中心
  177. {
  178. path: "/user",
  179. name: "user",
  180. component: () => import("@/views/user.vue"),
  181. meta: { index: 1 },
  182. },
  183. // 结算账号
  184. {
  185. path: "/joinPayBind",
  186. name: "joinPayBind",
  187. component: () => import("@/views/bindBankCard/joinPayBind.vue"),
  188. meta: { index: 1 },
  189. },
  190. // 结算账号
  191. {
  192. path: "/huifuBind",
  193. name: "huifuBind",
  194. component: () => import("@/views/bindBankCard/huifuBind.vue"),
  195. meta: { index: 1 },
  196. },
  197. // 自充值
  198. {
  199. path: "/uniPay",
  200. name: "uniPay",
  201. component: () => import("@/views/uniPay/index"),
  202. meta: { index: 1 },
  203. },
  204. // 优惠码
  205. {
  206. path: "/discountCode",
  207. name: "discountCode",
  208. component: () => import("@/views/discountCode/index"),
  209. meta: { index: 1 },
  210. },
  211. // Airwallex 钱包
  212. {
  213. path: "/airwallex",
  214. name: "airwallex",
  215. component: () => import("@/views/airwallex/index.vue"),
  216. meta: { index: 1 },
  217. },
  218. // Airwallex 创建付款人
  219. {
  220. path: "/airwallexBeneficiary",
  221. name: "airwallexBeneficiary",
  222. component: () => import("@/views/airwallex/beneficiary.vue"),
  223. meta: { index: 1 },
  224. },
  225. // Airwallex 付款单
  226. {
  227. path: "/airwallexPayout",
  228. name: "airwallexPayout",
  229. component: () => import("@/views/airwallex/payout.vue"),
  230. meta: { index: 1 },
  231. },
  232. // Airwallex 去付款
  233. {
  234. path: "/caPayment",
  235. name: "caPayment",
  236. component: () => import("@/views/airwallex/caPayment.vue"),
  237. meta: { index: 1 },
  238. },
  239. // Airwallex 付款结果详情
  240. {
  241. path: "/paymentDetail",
  242. name: "paymentDetail",
  243. component: () => import("@/views/airwallex/paymentDetail.vue"),
  244. meta: { index: 1 },
  245. },
  246. {
  247. path: "/payCode",
  248. name: "payCode",
  249. component: () => import("@/views/discountCode/payCode"),
  250. meta: { index: 1 },
  251. },
  252. // 分销设置
  253. {
  254. path: "/distributionSet",
  255. name: "distributionSet",
  256. component: () => import("@/views/distributionSet/index"),
  257. meta: { index: 1 },
  258. },
  259. {
  260. path: "/distributionDetail",
  261. name: "distributionDetail",
  262. component: () => import("@/views/distributionSet/detail"),
  263. meta: { index: 1 },
  264. },
  265. // 账号权限
  266. {
  267. path: "/accountPer",
  268. name: "accountPer",
  269. component: () => import("@/views/accountPer/index"),
  270. meta: { index: 1 },
  271. },
  272. // 添加账号
  273. {
  274. path: "/accountPerAdd",
  275. name: "accountPerAdd",
  276. component: () => import("@/views/accountPer/add"),
  277. meta: { index: 1 },
  278. },
  279. // 角色权限
  280. {
  281. path: "/role",
  282. name: "role",
  283. component: () => import("@/views/role/index"),
  284. meta: { index: 1 },
  285. },
  286. {
  287. path: "/roleSet",
  288. name: "roleSet",
  289. component: () => import("@/views/role/add"),
  290. meta: { index: 1 },
  291. },
  292. // 商户管理
  293. {
  294. path: "/merchantManage",
  295. name: "merchantManage",
  296. component: () => import("@/views/merchantManage/index"),
  297. meta: { index: 1, keepAlive: true },
  298. },
  299. {
  300. path: "/merchantSet",
  301. name: "merchantSet",
  302. component: () => import("@/views/merchantManage/set"),
  303. meta: { index: 1 },
  304. },
  305. // 广告管理
  306. {
  307. path: "/advertManage",
  308. name: "advertManage",
  309. component: () => import("@/views/advertManage/index"),
  310. meta: { index: 1 },
  311. },
  312. {
  313. path: "/advertSet",
  314. name: "advertSet",
  315. component: () => import("@/views/advertManage/adSet.vue"),
  316. meta: { index: 1 },
  317. },
  318. // 广告规则
  319. {
  320. path: "/advertRule",
  321. name: "advertRule",
  322. component: () => import("@/views/advertManage/advertRule/index.vue"),
  323. meta: { index: 1 },
  324. },
  325. // 广告规则新增
  326. {
  327. path: "/advertRuleAdd",
  328. name: "advertRuleAdd",
  329. component: () => import("@/views/advertManage/advertRule/add.vue"),
  330. meta: { index: 1 },
  331. },
  332. {
  333. path: "/advertRuleAddScreen",
  334. name: "advertRuleAddScreen",
  335. component: () => import("@/views/advertManage/advertRule/screen.vue"),
  336. meta: { index: 1 },
  337. },
  338. // apk管理
  339. {
  340. path: "/apkManage",
  341. name: "apkManage",
  342. component: () => import("@/views/apkManage/index"),
  343. meta: { index: 1 },
  344. },
  345. // apk管理-新增
  346. {
  347. path: "/apkManageAdd",
  348. name: "apkManageAdd",
  349. component: () => import("@/views/apkManage/add"),
  350. meta: { index: 1 },
  351. },
  352. // 报警历史
  353. {
  354. path: "/alarmHistory",
  355. name: "alarmHistory",
  356. component: () => import("@/views/alarmHistory/index"),
  357. meta: { index: 1 },
  358. },
  359. // 订单导出
  360. {
  361. path: "/orderExport",
  362. name: "orderExport",
  363. component: () => import("@/views/orderExport/index"),
  364. meta: { index: 1 },
  365. },
  366. // 任务消息
  367. {
  368. path: "/taskMessage",
  369. name: "taskMessage",
  370. component: () => import("@/views/taskMessage/index"),
  371. meta: { index: 1 },
  372. },
  373. // 设备审批
  374. {
  375. path: "/taskEquipment",
  376. name: "taskEquipment",
  377. component: () => import("@/views/taskMessage/equipment"),
  378. meta: { index: 1 },
  379. },
  380. // 分销审批
  381. {
  382. path: "/taskProportion",
  383. name: "taskProportion",
  384. component: () => import("@/views/taskMessage/proportion"),
  385. meta: { index: 1 },
  386. },
  387. // 订单中心
  388. {
  389. path: "/orderCenter",
  390. name: "orderCenter",
  391. component: () => import("@/views/orderCenter/index"),
  392. meta: { index: 1 },
  393. },
  394. // 测试
  395. {
  396. path: "/test",
  397. name: "test",
  398. component: () => import("@/views/test"),
  399. meta: { index: 1 },
  400. },
  401. // 标签管理
  402. {
  403. path: "/labelMan",
  404. name: "labelMan",
  405. component: () => import("@/views/labelMan/index"),
  406. meta: { index: 1 },
  407. },
  408. // 标签管理-新增
  409. {
  410. path: "/labelManAdd",
  411. name: "labelManAdd",
  412. component: () => import("@/views/labelMan/add"),
  413. meta: { index: 1 },
  414. },
  415. // 修改价格
  416. {
  417. path: "/modifyPrice",
  418. name: "modifyPrice",
  419. component: () => import("@/views/device/modifyPrice/index"),
  420. meta: { index: 1 },
  421. },
  422. // 屏蔽/展示商品
  423. {
  424. path: "/showGoods",
  425. name: "showGoods",
  426. component: () => import("@/views/device/showGoods/index"),
  427. meta: { index: 1 },
  428. },
  429. // DIY花型
  430. {
  431. path: "/diyFlower",
  432. name: "diyFlower",
  433. component: () => import("@/views/device/diyFlower/index"),
  434. meta: { index: 1 },
  435. },
  436. // 设备清洗提醒
  437. {
  438. path: "/alarmClean",
  439. name: "alarmClean",
  440. component: () => import("@/views/device/alarmClean/index"),
  441. meta: { index: 1 },
  442. },
  443. // 远程退币
  444. {
  445. path: "/returnCoin",
  446. name: "returnCoin",
  447. component: () => import("@/views/device/returnCoin/index"),
  448. meta: { index: 1 },
  449. },
  450. // 支付配置
  451. {
  452. path: "/payInfo",
  453. name: "payInfo",
  454. component: () => import("@/views/device/payInfo/index"),
  455. meta: { index: 1 },
  456. },
  457. // 修改机器密码
  458. {
  459. path: "/devicePassword",
  460. name: "devicePassword",
  461. component: () => import("@/views/device/devicePassword/index"),
  462. meta: { index: 1 },
  463. },
  464. // 查看定位
  465. {
  466. path: "/viewPosition",
  467. name: "viewPosition",
  468. component: () => import("@/views/device/viewPosition/index"),
  469. meta: { index: 1 },
  470. },
  471. // 设备编辑-编辑规则
  472. {
  473. path: "/editAdRule",
  474. name: "editAdRule",
  475. component: () => import("@/views/device/editAdRule/index"),
  476. meta: { index: 1 },
  477. },
  478. // 跳转空中云汇收单-消费者付款
  479. {
  480. path: "/hpp",
  481. name: "Hpp",
  482. component: () => import("@/views/Hpp.vue"),
  483. meta: { index: 1, noLogin: true },
  484. },
  485. // 定制logo
  486. {
  487. path: "/customLogo",
  488. name: "customLogo",
  489. component: () => import("@/views/device/customLogo.vue"),
  490. meta: { index: 1 },
  491. },
  492. // 查看日志
  493. {
  494. path: "/viewLogs",
  495. name: "viewLogs",
  496. component: () => import("@/views/device/viewLogs/index"),
  497. meta: { index: 1 },
  498. },
  499. // 账户操作
  500. {
  501. path: "/accountOperation",
  502. name: "accountOperation",
  503. component: () => import("@/views/accountOperation/index"),
  504. meta: { index: 1 },
  505. },
  506. // 汇付支付获取openid
  507. {
  508. path: "/weChatPay",
  509. name: "weChatPay",
  510. component: () => import("@/views/weChatPay"),
  511. meta: { index: 1, noLogin: true },
  512. },
  513. // 汇付支付获取openid
  514. {
  515. path: "/popPayment",
  516. name: "popPayment",
  517. component: () => import("@/views/popPayment"),
  518. meta: { index: 1, noLogin: true },
  519. },
  520. // 钱包
  521. {
  522. path: "/purse",
  523. name: "purse",
  524. component: () => import("@/views/purse/index"),
  525. meta: { index: 1 },
  526. },
  527. // 商品管理
  528. {
  529. path: "/goodsMan",
  530. name: "goodsMan",
  531. component: () => import("@/views/device/goodsMan/index"),
  532. meta: { index: 1 },
  533. },
  534. // 修改支付方式
  535. {
  536. path: "/payment",
  537. name: "payment",
  538. component: () => import("@/views/device/payment/index"),
  539. meta: { index: 1 },
  540. },
  541. // 税收管理
  542. {
  543. path: "/tax",
  544. name: "tax",
  545. component: () => import("@/views/device/tax/index"),
  546. meta: { index: 1 },
  547. },
  548. // 维护记录
  549. {
  550. path: "/maintenance",
  551. name: "maintenance",
  552. component: () => import("@/views/device/maintenance/index"),
  553. meta: { index: 1 },
  554. },
  555. // 果酱抽取
  556. {
  557. path: "/jam",
  558. name: "jam",
  559. component: () => import("@/views/device/jam/index"),
  560. meta: { index: 1 },
  561. },
  562. // 提现列表
  563. {
  564. path: "/withdrawList",
  565. name: "withdrawList",
  566. component: () => import("@/views/purse/withdrawList"),
  567. meta: { index: 1 },
  568. },
  569. // apk管理,广告管理,订单导出 不是所有的帐号能看到
  570. ],
  571. });
  572. let isVersionChecked = false;
  573. const MAX_RETRY_COUNT = 3;
  574. let retryCount = 0;
  575. router.beforeEach(async (to, from, next) => {
  576. // 只在首次路由跳转时检查版本(生产环境)
  577. if (!isVersionChecked && process.env.NODE_ENV === "production") {
  578. isVersionChecked = true;
  579. try {
  580. const response = await fetch(`/sc/version.json?t=${Date.now()}`, {
  581. cache: "no-store",
  582. });
  583. const serverVersion = await response.json();
  584. const localVersion = localStorage.getItem("appVersion") || "";
  585. if (serverVersion.version !== localVersion) {
  586. // 版本不一致,提示用户刷新
  587. if (retryCount < MAX_RETRY_COUNT) {
  588. retryCount++;
  589. console.log(
  590. `检测到新版本(${serverVersion.version}),第${retryCount}次尝试刷新...`
  591. );
  592. localStorage.setItem("appVersion", serverVersion.version);
  593. window.location.reload();
  594. return; // 中断当前路由导航
  595. } else {
  596. console.log("已达到最大重试次数,继续使用旧版本");
  597. retryCount = 0; // 重置计数器
  598. }
  599. } else if (!localVersion) {
  600. localStorage.setItem("appVersion", serverVersion.version);
  601. }
  602. } catch (error) {
  603. console.error("版本检测失败:", error);
  604. // 继续路由导航,即使版本检测失败
  605. }
  606. }
  607. // 页面带有不需要识别登录状态的跳过登录验证
  608. if (to.meta.noLogin) {
  609. next();
  610. } else {
  611. const user = getLocal("loginUser");
  612. if (!user || user === "") {
  613. // 没有登录信息跳转登录页面
  614. router.push("/login");
  615. } else {
  616. const userObject = JSON.parse(user);
  617. // 登录信息异常跳转登录页面
  618. if (!userObject) {
  619. router.push("/login");
  620. }
  621. if (typeof userObject.id !== "number") {
  622. router.push("/login");
  623. }
  624. }
  625. next();
  626. }
  627. });
  628. export default router;