index.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. import { createRouter, createWebHistory } from "vue-router";
  2. import AppLayout from "@/components/layout/AppLayout.vue";
  3. import { useTokenStore } from "@/stores/mytoken"; // 确保正确导入 useTokenStore
  4. // 定义路由配置
  5. const routes = [
  6. { path: "/login", name: "login", component: () => import("@/views/login/loginView.vue") },
  7. {
  8. path: "/",
  9. component: AppLayout,
  10. meta: { requiresAuth: true },
  11. children: [
  12. {
  13. path: "/:catchAll(.*)",
  14. redirect: "/404", // 确保重定向到有效页面
  15. },
  16. {
  17. path: "select-city", // remove leading slash
  18. name: "selectCityAndCounty",
  19. component: () => import("@/views/User/selectCityAndCounty.vue"),
  20. meta: { title: "选择城市和县", fullScreen: true },
  21. },
  22. {
  23. path: "shuJuKanBan",
  24. name: "shuJuKanBan",
  25. component: () => import("@/views/User/shuJuKanBan/shuJuKanBan.vue"), // 修复路径
  26. meta: { title: "数据看板" },
  27. },
  28. {
  29. path: "SoilPro",
  30. name: "SoilPro",
  31. component: () => import("@/views/User/introduction/SoilPro.vue"), // 修复路径
  32. meta: { title: "软件简介" },
  33. },
  34. {
  35. path: "Overview",
  36. name: "Overview",
  37. component: () => import("@/views/User/introduction/Overview.vue"), // 修复路径
  38. meta: { title: "项目简介" },
  39. },
  40. {
  41. path: "ResearchFindings",
  42. name: "ResearchFindings",
  43. component: () =>
  44. import("@/views/User/introduction/ResearchFindings.vue"), // 修复路径
  45. meta: { title: "研究成果" },
  46. },
  47. {
  48. path: "Unit",
  49. name: "Unit",
  50. component: () => import("@/views/User/introduction/Unit.vue"), // 修复路径
  51. meta: { title: "团队信息" },
  52. },
  53. {
  54. path: "IntroductionUpdate",
  55. name: "IntroductionUpdate",
  56. component: () =>
  57. import("@/views/User/introduction/IntroductionUpdate.vue"), // 修复路径
  58. meta: { title: "更新介绍" },
  59. },
  60. //管理员
  61. // {
  62. // path: "HmOutFlux",
  63. // name: "HmOutFlux",
  64. // component: () => import("@/views/User/HmOutFlux"),
  65. // meta: { title: "重金属输出通量" },
  66. // },
  67. // {
  68. // path: "irrigationWater",
  69. // name: "irrigationWater",
  70. // component: () => import("@/views/User/HmOutFlux/irrigationWater"),
  71. // meta: { title: "灌溉水" },
  72. // },
  73. {
  74. path: "samplingMethodDevice1",
  75. name: "samplingMethodDevice1",
  76. component: () =>
  77. import(
  78. "@/views/User/HmOutFlux/irrigationWater/samplingMethodDevice1.vue"
  79. ),
  80. meta: { title: "采样方法和装置" },
  81. },
  82. {
  83. path: "irriSampleData",
  84. name: "irriSampleData",
  85. component: () =>
  86. import(
  87. "@/views/User/HmOutFlux/irrigationWater/irriWaterSampleData.vue"
  88. ),
  89. meta: { title: "灌溉水采样数据" },
  90. },
  91. {
  92. path: "csSampleData",
  93. name: "csSampleData",
  94. component: () =>
  95. import(
  96. "@/views/User/HmOutFlux/irrigationWater/crossSection.vue"
  97. ),
  98. meta: { title: "断面采样数据" },
  99. },
  100. {
  101. path: "irriInputFlux",
  102. name: "irriInputFlux",
  103. component: () =>
  104. import(
  105. "@/views/User/HmOutFlux/irrigationWater/irriWaterInputFlux.vue"
  106. ),
  107. meta: { title: "灌溉水输入通量" },
  108. },
  109. // {
  110. // path: "agriInput",
  111. // name: "agriInput",
  112. // component: () => import("@/views/User/HmOutFlux/agriInput"),
  113. // meta: { title: "农产品投入" },
  114. // },
  115. {
  116. path: "farmInputSamplingDesc",
  117. name: "farmInputSamplingDesc",
  118. component: () =>
  119. import("@/views/User/HmOutFlux/agriInput/farmInputSamplingDesc.vue"),
  120. meta: { title: "采样说明" },
  121. },
  122. {
  123. path: "prodInputFlux",
  124. name: "prodInputFlux",
  125. component: () =>
  126. import("@/views/User/HmOutFlux/agriInput/prodInputFlux.vue"),
  127. meta: { title: "农产品输入通量" },
  128. },
  129. // {
  130. // path: "atmosDeposition",
  131. // name: "atmosDeposition",
  132. // component: () => import("@/views/User/HmOutFlux/atmosDeposition"),
  133. // meta: { title: "大气干湿沉降" },
  134. // },
  135. {
  136. path: "AtmosDepositionSamplingDesc",
  137. name: "AtmosDepositionSamplingDesc",
  138. component: () =>
  139. import(
  140. "@/views/User/HmOutFlux/atmosDeposition/AtmosDepositionSamplingDesc.vue"
  141. ),
  142. meta: { title: "采样说明" },
  143. },
  144. {
  145. path: "heavyMetalEnterprise",
  146. name: "heavyMetalEnterprise",
  147. component: () =>
  148. import(
  149. "@/views/User/HmOutFlux/atmosDeposition/heavyMetalEnterprise.vue"
  150. ),
  151. meta: { title: "涉重企业" },
  152. },
  153. {
  154. path: "airSampleData",
  155. name: "airSampleData",
  156. component: () =>
  157. import("@/views/User/HmOutFlux/atmosDeposition/airSampleData.vue"),
  158. meta: { title: "大气采样数据" },
  159. },
  160. {
  161. path: "airInputFlux",
  162. name: "airInputFlux",
  163. component: () =>
  164. import("@/views/User/HmOutFlux/atmosDeposition/airInputFlux.vue"),
  165. meta: { title: "大气输入通量" },
  166. },
  167. // {
  168. // path: "hmInFlux",
  169. // name: "hmInFlux",
  170. // component: () => import("@/views/User/hmInFlux"),
  171. // meta: { title: "重金属输入通量" },
  172. // },
  173. // {
  174. // path: "grainRemoval",
  175. // name: "grainRemoval",
  176. // component: () => import("@/views/User/hmInFlux/grainRemoval"),
  177. // meta: { title: "籽粒移除" },
  178. // },
  179. {
  180. path: "samplingDesc1",
  181. name: "samplingDesc1",
  182. component: () =>
  183. import("@/views/User/hmInFlux/grainRemoval/samplingDesc1.vue"),
  184. meta: { title: "采样说明" },
  185. },
  186. {
  187. path: "grainRemovalInputFlux",
  188. name: "grainRemovalInputFlux",
  189. component: () =>
  190. import(
  191. "@/views/User/hmInFlux/grainRemoval/grainRemovalInputFlux.vue"
  192. ),
  193. meta: { title: "籽粒移除输入通量" },
  194. },
  195. // {
  196. // path: "strawRemoval",
  197. // name: "strawRemoval",
  198. // component: () => import("@/views/User/hmInFlux/strawRemoval"),
  199. // meta: { title: "秸秆移除" },
  200. // },
  201. {
  202. path: "samplingDesc2",
  203. name: "samplingDesc2",
  204. component: () =>
  205. import("@/views/User/hmInFlux/strawRemoval/samplingDesc2.vue"),
  206. meta: { title: "采样说明" },
  207. },
  208. {
  209. path: "strawRemovalInputFlux",
  210. name: "strawRemovalInputFlux",
  211. component: () =>
  212. import(
  213. "@/views/User/hmInFlux/strawRemoval/strawRemovalInputFlux.vue"
  214. ),
  215. meta: { title: "秸秆移除输入通量" },
  216. },
  217. // {
  218. // path: "subsurfaceLeakage",
  219. // name: "subsurfaceLeakage",
  220. // component: () => import("@/views/User/hmInFlux/subsurfaceLeakage"),
  221. // meta: { title: "地下渗漏" },
  222. // },
  223. {
  224. path: "samplingDesc3",
  225. name: "samplingDesc3",
  226. component: () =>
  227. import("@/views/User/hmInFlux/subsurfaceLeakage/samplingDesc3.vue"),
  228. meta: { title: "采样说明" },
  229. },
  230. {
  231. path: "subsurfaceLeakageInputFlux",
  232. name: "subsurfaceLeakageInputFlux",
  233. component: () =>
  234. import(
  235. "@/views/User/hmInFlux/subsurfaceLeakage/subsurfaceLeakageInputFlux.vue"
  236. ),
  237. meta: { title: "地下渗漏输入通量" },
  238. },
  239. // {
  240. // path: "surfaceRunoff",
  241. // name: "surfaceRunoff",
  242. // component: () => import("@/views/User/hmInFlux/surfaceRunoff"),
  243. // meta: { title: "地表径流" },
  244. // },
  245. {
  246. path: "samplingDesc4",
  247. name: "samplingDesc4",
  248. component: () =>
  249. import("@/views/User/hmInFlux/surfaceRunoff/samplingDesc4.vue"),
  250. meta: { title: "采样说明" },
  251. },
  252. {
  253. path: "surfaceRunoffInputFlux",
  254. name: "surfaceRunoffInputFlux",
  255. component: () =>
  256. import(
  257. "@/views/User/hmInFlux/surfaceRunoff/surfaceRunoffInputFlux.vue"
  258. ),
  259. meta: { title: "地表径流输入通量" },
  260. },
  261. {
  262. path: "Calculation",
  263. name: "Calculation",
  264. component: () => import("@/views/User/acidModel/Calculation.vue"), // 修复路径
  265. meta: { title: "反酸计算" },
  266. },
  267. {
  268. path: "AcidNeutralizationModel",
  269. name: "AcidNeutralizationModel",
  270. component: () =>
  271. import(
  272. "@/views/User/neutralizationModel/AcidNeutralizationModel.vue"
  273. ), // 修复路径
  274. meta: { title: "降酸计算" },
  275. },
  276. {
  277. path: "SoilAcidificationIterativeEvolution",
  278. name: "SoilAcidificationIterativeEvolution",
  279. component: () =>
  280. import(
  281. "@/views/User/neutralizationModel/SoilAcidificationIterativeEvolution.vue"
  282. ), // 修复路径
  283. meta: { title: "降酸模型显示" },
  284. },
  285. {
  286. path: "SoilAcidReductionIterativeEvolution",
  287. name: "SoilAcidReductionIterativeEvolution",
  288. component: () =>
  289. import(
  290. "@/views/User/acidModel/SoilAcidReductionIterativeEvolution.vue"
  291. ), // 修复路径
  292. meta: { title: "反酸模型显示" },
  293. },
  294. {
  295. path: "mapView",
  296. name: "mapView",
  297. component: () => import("@/views/User/mapView/leafletMapView.vue"), // 修复路径
  298. meta: { title: "地图展示" },
  299. },
  300. {
  301. path: "totalInputFlux",
  302. name: "totalInputFlux",
  303. component: () =>
  304. import("@/views/User/cadmiumPrediction/totalInputFlux.vue"),
  305. meta: { title: "输入总通量" },
  306. },
  307. {
  308. path: "totalOutputFlux",
  309. name: "totalOutputFlux",
  310. component: () =>
  311. import("@/views/User/cadmiumPrediction/totalOutputFlux.vue"), // 修复路径
  312. meta: { title: "输出总通量" },
  313. },
  314. {
  315. path: "netFlux",
  316. name: "netFlux",
  317. component: () => import("@/views/User/cadmiumPrediction/netFlux.vue"), // 修复路径
  318. meta: { title: "净通量" },
  319. },
  320. {
  321. path: "currentYearConcentration",
  322. name: "currentYearConcentration",
  323. component: () =>
  324. import("@/views/User/cadmiumPrediction/currentYearConcentration.vue"), // 修复路径
  325. meta: { title: "当年浓度" },
  326. },
  327. {
  328. path: "TotalCadmiumPrediction",
  329. name: "TotalCadmiumPrediction",
  330. component: () =>
  331. import("@/views/User/cadmiumPrediction/TotalCadmiumPrediction.vue"), // 修复路径
  332. meta: { title: "土壤镉的总含量预测" },
  333. },
  334. {
  335. path: "EffectiveCadmiumPrediction",
  336. name: "EffectiveCadmiumPrediction",
  337. component: () =>
  338. import(
  339. "@/views/User/cadmiumPrediction/EffectiveCadmiumPrediction.vue"
  340. ), // 修复路径
  341. meta: { title: "土壤镉有效态含量预测" },
  342. },
  343. {
  344. path: "CropCadmiumPrediction",
  345. name: "CropCadmiumPrediction",
  346. component: () =>
  347. import("@/views/User/cadmiumPrediction/CropCadmiumPrediction.vue"), // 修复路径
  348. meta: { title: "土壤镉作物态含量预测" },
  349. },
  350. {
  351. path: "cropRiskAssessment",
  352. name: "cropRiskAssessment",
  353. component: () =>
  354. import("@/views/User/cropRiskAssessment/cropRiskAssessment.vue"), // 修复路径
  355. meta: { title: "水稻镉污染风险" },
  356. },
  357. {
  358. path: "farmlandQualityAssessment",
  359. name: "farmlandQualityAssessment",
  360. component: () =>
  361. import(
  362. "@/views/User/farmlandQualityAssessment/farmlandQualityAssessment.vue"
  363. ), // 修复路径
  364. meta: { title: "韶关" },
  365. },
  366. {
  367. path: "SoilAcidReboundPrediction",
  368. name: "SoilAcidReboundPrediction",
  369. component: () =>
  370. import(
  371. "@/views/User/soilAcidificationPrediction/SoilAcidReboundPrediction.vue"
  372. ), // 修复路径
  373. meta: { title: "土壤反酸预测" },
  374. },
  375. {
  376. path: "SoilAcidReductionPrediction",
  377. name: "SoilAcidReductionPrediction",
  378. component: () =>
  379. import(
  380. "@/views/User/soilAcidificationPrediction/SoilAcidReductionPrediction.vue"
  381. ), // 修复路径
  382. meta: { title: "土壤降酸预测" },
  383. },
  384. {
  385. path: "TraditionalFarmingRisk",
  386. name: "TraditionalFarmingRisk",
  387. component: () =>
  388. import("@/views/User/scenarioSimulation/TraditionalFarmingRisk.vue"), // 修复路径
  389. meta: { title: "传统耕种习惯风险趋势" },
  390. },
  391. {
  392. path: "HeavyMetalCadmiumControl",
  393. name: "HeavyMetalCadmiumControl",
  394. component: () =>
  395. import(
  396. "@/views/User/scenarioSimulation/HeavyMetalCadmiumControl.vue"
  397. ), // 修复路径
  398. meta: { title: "重金属镉污染治理" },
  399. },
  400. {
  401. path: "SoilAcidificationControl",
  402. name: "SoilAcidificationControl",
  403. component: () =>
  404. import(
  405. "@/views/User/scenarioSimulation/SoilAcidificationControl.vue"
  406. ), // 修复路径
  407. meta: { title: "土壤酸化治理" },
  408. },
  409. {
  410. path: "DetectionStatistics",
  411. name: "DetectionStatistics",
  412. component: () =>
  413. import("@/views/User/dataStatistics/DetectionStatistics.vue"), // 修复路径
  414. meta: { title: "检测信息统计" },
  415. },
  416. {
  417. path: "FarmlandPollutionStatistics",
  418. name: "FarmlandPollutionStatistics",
  419. component: () =>
  420. import("@/views/User/dataStatistics/SoilCdStatistics.vue"), // 修复路径
  421. meta: { title: "土壤镉含量统计" },
  422. },
  423. {
  424. path: "LandClutivatesStatistics",
  425. name: "LandClutivatesStatistics",
  426. component: () =>
  427. import("@/views/User/dataStatistics/LandCultivatedStatistics.vue"), // 修复路径
  428. meta: { title: "作物风险评估系统" },
  429. },
  430. {
  431. path: "SoilacidificationStatistics",
  432. name: "SoilacidificationStatistics",
  433. component: () =>
  434. import("@/views/User/dataStatistics/SoilacidificationStatistics.vue"), // 修复路径
  435. meta: { title: "作物风险评估系统" },
  436. },
  437. {
  438. path: "AdminRegionData",
  439. name: "AdminRegionData",
  440. component: () =>
  441. import("@/views/Admin/dataManagement/AdminRegionData.vue"), // 修复路径
  442. meta: { title: "行政区域数据" },
  443. },
  444. {
  445. path: "irrigationWaterSampleData",
  446. name: "irrigationWaterSampleData",
  447. component: () =>
  448. import(
  449. "@/views/Admin/dataManagement/HeavyMetalInputFluxManager/irrigationWaterSampleData.vue"
  450. ),
  451. meta: { title: "灌溉水采样数据" },
  452. },
  453. {
  454. path: "crossSectionSampleData",
  455. name: "crossSectionSampleData",
  456. component: () =>
  457. import(
  458. "@/views/Admin/dataManagement/HeavyMetalInputFluxManager/crossSectionSampleData.vue"
  459. ),
  460. meta: { title: "断面采样数据" },
  461. },
  462. {
  463. path: "irrigationWaterInputFluxData",
  464. name: "irrigationWaterInputFluxData",
  465. component: () =>
  466. import(
  467. "@/views/Admin/dataManagement/HeavyMetalInputFluxManager/irrigationWaterInputFluxData.vue"
  468. ),
  469. meta: { title: "灌溉水输入通量数据" },
  470. },
  471. {
  472. path: "agriProductInputFluxData",
  473. name: "agriProductInputFluxData",
  474. component: () =>
  475. import(
  476. "@/views/Admin/dataManagement/HeavyMetalInputFluxManager/agriProductInputFluxData.vue"
  477. ),
  478. meta: { title: "农产品输入通量数据" },
  479. },
  480. {
  481. path: "heavyMetalEnterpriseData",
  482. name: "heavyMetalEnterpriseData",
  483. component: () =>
  484. import(
  485. "@/views/Admin/dataManagement/HeavyMetalInputFluxManager/heavyMetalEnterpriseData.vue"
  486. ),
  487. meta: { title: "涉重企业数据" },
  488. },
  489. {
  490. path: "atmosphericSampleData",
  491. name: "atmosphericSampleData",
  492. component: () =>
  493. import(
  494. "@/views/Admin/dataManagement/HeavyMetalInputFluxManager/atmosphericSampleData.vue"
  495. ),
  496. meta: { title: "大气采样数据" },
  497. },
  498. {
  499. path: "atmosphericInputFluxData",
  500. name: "atmosphericInputFluxData",
  501. component: () =>
  502. import(
  503. "@/views/Admin/dataManagement/HeavyMetalInputFluxManager/atmosphericInputFluxData.vue"
  504. ),
  505. meta: { title: "大气输入通量数据" },
  506. },
  507. {
  508. path: "SoilAssessmentUnitData",
  509. name: "SoilAssessmentUnitData",
  510. component: () =>
  511. import("@/views/Admin/dataManagement/SoilAssessmentUnitData.vue"),
  512. meta: { title: "土壤评估单元格数据" },
  513. },
  514. {
  515. path: "SoilHeavyMetalData",
  516. name: "SoilHeavyMetalData",
  517. component: () =>
  518. import("@/views/Admin/dataManagement/SoilHeavyMetalData.vue"),
  519. meta: { title: "土壤重金属采集数据" },
  520. },
  521. {
  522. path: "CropHeavyMetalData",
  523. name: "CropHeavyMetalData",
  524. component: () =>
  525. import("@/views/Admin/dataManagement/CropHeavyMetalData.vue"),
  526. meta: { title: "农作物重金属采集样数据" },
  527. },
  528. {
  529. path: "LandUseTypeData",
  530. name: "LandUseTypeData",
  531. component: () =>
  532. import("@/views/Admin/dataManagement/LandUseTypeData.vue"),
  533. meta: { title: "用地类型数据" },
  534. },
  535. {
  536. path: "SoilAcidificationData",
  537. name: "SoilAcidificationData",
  538. component: () =>
  539. import(
  540. "@/views/Admin/dataManagement/Soil Acidification and Acid Reduction Data Management/soilAcidificationData.vue"
  541. ),
  542. meta: { title: "土壤酸化采样数据" },
  543. },
  544. {
  545. path: "soilAcidReductionData",
  546. name: "soilAcidReductionData",
  547. component: () =>
  548. import(
  549. "@/views/Admin/dataManagement/Soil Acidification and Acid Reduction Data Management/soilAcidReductionData.vue"
  550. ),
  551. meta: { title: "土壤酸化采样数据" },
  552. },
  553. {
  554. path: "ClimateInfoData",
  555. name: "ClimateInfoData",
  556. component: () =>
  557. import("@/views/Admin/dataManagement/ClimateInfoData.vue"),
  558. meta: { title: "气候信息数据" },
  559. },
  560. {
  561. path: "GeographicEnvInfoData",
  562. name: "GeographicEnvInfoData",
  563. component: () =>
  564. import("@/views/Admin/dataManagement/GeographicEnvInfoData.vue"),
  565. meta: { title: "地理环境信息" },
  566. },
  567. {
  568. path: "ModelSelection",
  569. name: "ModelSelection",
  570. component: () =>
  571. import("@/views/Admin/parameterConfig/ModelSelection.vue"),
  572. meta: { title: "模型选择" },
  573. },
  574. {
  575. path: "thres",
  576. name: "thres",
  577. component: () => import("@/views/Admin/parameterConfig/thres.vue"),
  578. meta: { title: "阈值选择" },
  579. },
  580. {
  581. path: "ModelTrain",
  582. name: "ModelTrain",
  583. component: () => import("@/views/Admin/parameterConfig/ModelTrain.vue"),
  584. meta: { title: "模型训练" },
  585. },
  586. {
  587. path: "UserRegistration",
  588. name: "UserRegistration",
  589. component: () =>
  590. import("@/views/Admin/userManagement/UserRegistration.vue"),
  591. meta: { title: "普通用户" },
  592. },
  593. {
  594. path: "UserManagement",
  595. name: "UserManagement",
  596. component: () =>
  597. import("@/views/Admin/userManagement/UserManagement.vue"),
  598. meta: { title: "用户信息管理" },
  599. },
  600. {
  601. path: "CadmiumPredictionModel",
  602. name: "CadmiumPredictionModel",
  603. component: () =>
  604. import("@/views/Admin/modelManagement/CadmiumPredictionModel.vue"),
  605. meta: { title: "土壤镉含量预测模型" },
  606. },
  607. {
  608. path: "EffectiveCadmiumModel",
  609. name: "EffectiveCadmiumModel",
  610. component: () =>
  611. import("@/views/Admin/modelManagement/EffectiveCadmiumModel.vue"),
  612. meta: { title: "土壤有效态镉预测模型" },
  613. },
  614. {
  615. path: "RiceRiskModel",
  616. name: "RiceRiskModel",
  617. component: () =>
  618. import("@/views/Admin/modelManagement/RiceRiskModel.vue"),
  619. meta: { title: "水稻镉污染风险模型" },
  620. },
  621. {
  622. path: "AcidReductionModel",
  623. name: "AcidReductionModel",
  624. component: () =>
  625. import("@/views/Admin/modelManagement/AcidReductionModel.vue"),
  626. meta: { title: "反酸及降酸模型" },
  627. },
  628. {
  629. path: "WheatRiskModel",
  630. name: "WheatRiskModel",
  631. component: () =>
  632. import("@/views/Admin/modelManagement/WheatRiskModel.vue"),
  633. meta: { title: "小麦镉污染风险模型" },
  634. },
  635. {
  636. path: "VegetableRiskModel",
  637. name: "VegetableRiskModel",
  638. component: () =>
  639. import("@/views/Admin/modelManagement/VegetableRiskModel.vue"),
  640. meta: { title: "蔬菜镉污染风险模型" },
  641. },
  642. {
  643. path: "about",
  644. name: "about",
  645. component: () => import("@/views/AboutView.vue"),
  646. },
  647. {
  648. path: "/:pathMatch(.*)*",
  649. name: "ErrorPage",
  650. component: () => import("@/views/ErrorPage.vue"),
  651. },
  652. ],
  653. },
  654. ];
  655. const router = createRouter({
  656. history: createWebHistory(),
  657. routes,
  658. });
  659. router.beforeEach((to, from, next) => {
  660. const tokenStore = useTokenStore();
  661. const user = tokenStore.userInfo;
  662. const isSameRoute = (path: string) => to.fullPath === path;
  663. // 已登录用户访问 login 页面
  664. if (to.name === "login" && user?.userId) {
  665. return next("/select-city");
  666. }
  667. // 需要登录才能访问的页面
  668. if (to.matched.some(r => r.meta.requiresAuth)) {
  669. if (!user?.userId) {
  670. return next({ name: "login" });
  671. }
  672. // 管理员权限页面
  673. if (to.matched.some(r => r.meta.requiresAdmin)) {
  674. if (user.loginType !== "admin") {
  675. // 普通用户访问管理员页面,提示并重定向
  676. // Replace with your notification library, e.g. for naive-ui:
  677. // import { useMessage } from 'naive-ui' at the top of the file if not already imported
  678. // const message = useMessage();
  679. // message.error("登录失败:用户类型不匹配");
  680. // If using Element Plus:
  681. // import { ElMessage } from 'element-plus' at the top of the file
  682. // ElMessage.error("登录失败:用户类型不匹配");
  683. // Example using Element Plus:
  684. // ElMessage.error("登录失败:用户类型不匹配");
  685. if (!isSameRoute("/select-city")) return next({ name: "selectCityAndCounty" });
  686. return next();
  687. }
  688. }
  689. }
  690. next();
  691. });
  692. export default router;