index.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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. {
  7. path: "/login",
  8. name: "login",
  9. component: () => import("@/views/login/loginView.vue"), // 修复路径
  10. },
  11. {
  12. path: "/",
  13. name: "home",
  14. component: AppLayout,
  15. meta: { requiresAuth: true, title: "模型" },
  16. redirect: { name: "login" }, // 修改默认重定向为 login
  17. children: [
  18. {
  19. path: "/:catchAll(.*)",
  20. redirect: "/404", // 确保重定向到有效页面
  21. },
  22. {
  23. path: "select-city", // remove leading slash
  24. name: "selectCityAndCounty",
  25. component: () => import("@/views/User/selectCityAndCounty.vue"),
  26. meta: { title: "选择城市和县", fullScreen: true },
  27. },
  28. {
  29. path: "shuJuKanBan",
  30. name: "shuJuKanBan",
  31. component: () => import("@/views/User/shuJuKanBan/shuJuKanBan.vue"), // 修复路径
  32. meta: { title: "数据看板" },
  33. },
  34. {
  35. path: "SoilPro",
  36. name: "SoilPro",
  37. component: () => import("@/views/User/introduction/SoilPro.vue"), // 修复路径
  38. meta: { title: "软件简介" },
  39. },
  40. {
  41. path: "Overview",
  42. name: "Overview",
  43. component: () => import("@/views/User/introduction/Overview.vue"), // 修复路径
  44. meta: { title: "项目简介" },
  45. },
  46. {
  47. path: "ResearchFindings",
  48. name: "ResearchFindings",
  49. component: () =>
  50. import("@/views/User/introduction/ResearchFindings.vue"), // 修复路径
  51. meta: { title: "研究成果" },
  52. },
  53. {
  54. path: "Unit",
  55. name: "Unit",
  56. component: () => import("@/views/User/introduction/Unit.vue"), // 修复路径
  57. meta: { title: "团队信息" },
  58. },
  59. {
  60. path: "IntroductionUpdate",
  61. name: "IntroductionUpdate",
  62. component: () =>
  63. import("@/views/User/introduction/IntroductionUpdate.vue"), // 修复路径
  64. meta: { title: "更新介绍" },
  65. },
  66. {
  67. path: "Calculation",
  68. name: "Calculation",
  69. component: () => import("@/views/User/acidModel/Calculation.vue"), // 修复路径
  70. meta: { title: "反酸计算" },
  71. },
  72. {
  73. path: "AcidNeutralizationModel",
  74. name: "AcidNeutralizationModel",
  75. component: () =>
  76. import(
  77. "@/views/User/neutralizationModel/AcidNeutralizationModel.vue"
  78. ), // 修复路径
  79. meta: { title: "降酸计算" },
  80. },
  81. {
  82. path: "SoilAcidificationIterativeEvolution",
  83. name: "SoilAcidificationIterativeEvolution",
  84. component: () =>
  85. import(
  86. "@/views/User/neutralizationModel/SoilAcidificationIterativeEvolution.vue"
  87. ), // 修复路径
  88. meta: { title: "降酸模型显示" },
  89. },
  90. {
  91. path: "SoilAcidReductionIterativeEvolution",
  92. name: "SoilAcidReductionIterativeEvolution",
  93. component: () =>
  94. import(
  95. "@/views/User/acidModel/SoilAcidReductionIterativeEvolution.vue"
  96. ), // 修复路径
  97. meta: { title: "反酸模型显示" },
  98. },
  99. {
  100. path: "mapView",
  101. name: "mapView",
  102. component: () => import("@/views/User/mapView/leafletMapView.vue"), // 修复路径
  103. meta: { title: "地图展示" },
  104. },
  105. {
  106. path: "TotalCadmiumPrediction",
  107. name: "TotalCadmiumPrediction",
  108. component: () =>
  109. import("@/views/User/cadmiumPrediction/TotalCadmiumPrediction.vue"), // 修复路径
  110. meta: { title: "土壤镉的总含量预测" },
  111. },
  112. {
  113. path: "EffectiveCadmiumPrediction",
  114. name: "EffectiveCadmiumPrediction",
  115. component: () =>
  116. import(
  117. "@/views/User/cadmiumPrediction/EffectiveCadmiumPrediction.vue"
  118. ), // 修复路径
  119. meta: { title: "土壤镉有效态含量预测" },
  120. },
  121. {
  122. path: "cropRiskAssessment",
  123. name: "cropRiskAssessment",
  124. component: () =>
  125. import("@/views/User/cropRiskAssessment/cropRiskAssessment.vue"), // 修复路径
  126. meta: { title: "水稻镉污染风险" },
  127. },
  128. {
  129. path: "farmlandQualityAssessment",
  130. name: "farmlandQualityAssessment",
  131. component: () =>
  132. import(
  133. "@/views/User/farmlandQualityAssessment/farmlandQualityAssessment.vue"
  134. ), // 修复路径
  135. meta: { title: "韶关" },
  136. },
  137. {
  138. path: "SoilAcidReboundPrediction",
  139. name: "SoilAcidReboundPrediction",
  140. component: () =>
  141. import(
  142. "@/views/User/soilAcidificationPrediction/SoilAcidReboundPrediction.vue"
  143. ), // 修复路径
  144. meta: { title: "土壤反酸预测" },
  145. },
  146. {
  147. path: "SoilAcidReductionPrediction",
  148. name: "SoilAcidReductionPrediction",
  149. component: () =>
  150. import(
  151. "@/views/User/soilAcidificationPrediction/SoilAcidReductionPrediction.vue"
  152. ), // 修复路径
  153. meta: { title: "土壤降酸预测" },
  154. },
  155. {
  156. path: "TraditionalFarmingRisk",
  157. name: "TraditionalFarmingRisk",
  158. component: () =>
  159. import("@/views/User/scenarioSimulation/TraditionalFarmingRisk.vue"), // 修复路径
  160. meta: { title: "传统耕种习惯风险趋势" },
  161. },
  162. {
  163. path: "HeavyMetalCadmiumControl",
  164. name: "HeavyMetalCadmiumControl",
  165. component: () =>
  166. import(
  167. "@/views/User/scenarioSimulation/HeavyMetalCadmiumControl.vue"
  168. ), // 修复路径
  169. meta: { title: "重金属镉污染治理" },
  170. },
  171. {
  172. path: "SoilAcidificationControl",
  173. name: "SoilAcidificationControl",
  174. component: () =>
  175. import(
  176. "@/views/User/scenarioSimulation/SoilAcidificationControl.vue"
  177. ), // 修复路径
  178. meta: { title: "土壤酸化治理" },
  179. },
  180. {
  181. path: "DetectionStatistics",
  182. name: "DetectionStatistics",
  183. component: () =>
  184. import("@/views/User/dataStatistics/DetectionStatistics.vue"), // 修复路径
  185. meta: { title: "检测信息统计" },
  186. },
  187. {
  188. path: "FarmlandPollutionStatistics",
  189. name: "FarmlandPollutionStatistics",
  190. component: () =>
  191. import("@/views/User/dataStatistics/FarmlandPollutionStatistics.vue"), // 修复路径
  192. meta: { title: "耕地污染信息统计" },
  193. },
  194. {
  195. path: "PlantingRiskStatistics",
  196. name: "PlantingRiskStatistics",
  197. component: () =>
  198. import("@/views/User/dataStatistics/PlantingRiskStatistics.vue"), // 修复路径
  199. meta: { title: "种植风险信息统计" },
  200. },
  201. {
  202. path: "Visualizatio",
  203. name: "Visualizatio",
  204. component: () =>
  205. import("@/views/Admin/dataManagement/Visualizatio.vue"), // 修复路径
  206. meta: { title: "降酸数据管理" },
  207. },
  208. {
  209. path: "Visualization",
  210. name: "Visualization",
  211. component: () =>
  212. import("@/views/Admin/dataManagement/Visualization.vue"), // 修复路径
  213. meta: { title: "反酸数据管理" },
  214. },
  215. {
  216. path: "AdminRegionData",
  217. name: "AdminRegionData",
  218. component: () =>
  219. import("@/views/Admin/dataManagement/AdminRegionData.vue"), // 修复路径
  220. meta: { title: "行政区域数据" },
  221. },
  222. {
  223. path: "SoilAssessmentUnitData",
  224. name: "SoilAssessmentUnitData",
  225. component: () =>
  226. import("@/views/Admin/dataManagement/SoilAssessmentUnitData.vue"),
  227. meta: { title: "土壤评估单元格数据" },
  228. },
  229. {
  230. path: "SoilHeavyMetalData",
  231. name: "SoilHeavyMetalData",
  232. component: () =>
  233. import("@/views/Admin/dataManagement/SoilHeavyMetalData.vue"),
  234. meta: { title: "土壤重金属采集数据" },
  235. },
  236. {
  237. path: "CropHeavyMetalData",
  238. name: "CropHeavyMetalData",
  239. component: () =>
  240. import("@/views/Admin/dataManagement/CropHeavyMetalData.vue"),
  241. meta: { title: "农作物重金属采集样数据" },
  242. },
  243. {
  244. path: "LandUseTypeData",
  245. name: "LandUseTypeData",
  246. component: () =>
  247. import("@/views/Admin/dataManagement/LandUseTypeData.vue"),
  248. meta: { title: "用地类型数据" },
  249. },
  250. {
  251. path: "SoilAcidificationData",
  252. name: "SoilAcidificationData",
  253. component: () =>
  254. import("@/views/Admin/dataManagement/SoilAcidificationData.vue"),
  255. meta: { title: "土壤酸化采样数据" },
  256. },
  257. {
  258. path: "ClimateInfoData",
  259. name: "ClimateInfoData",
  260. component: () =>
  261. import("@/views/Admin/dataManagement/ClimateInfoData.vue"),
  262. meta: { title: "气候信息数据" },
  263. },
  264. {
  265. path: "GeographicEnvInfoData",
  266. name: "GeographicEnvInfoData",
  267. component: () =>
  268. import("@/views/Admin/dataManagement/GeographicEnvInfoData.vue"),
  269. meta: { title: "地理环境信息" },
  270. },
  271. {
  272. path: "ModelSelection",
  273. name: "ModelSelection",
  274. component: () =>
  275. import("@/views/Admin/modelManagement/AcidReductionModel/ModelSelection.vue"),
  276. meta: { title: "模型选择" },
  277. },
  278. {
  279. path: "thres",
  280. name: "thres",
  281. component: () => import("@/views/Admin/modelManagement/AcidReductionModel/thres.vue"),
  282. meta: { title: "阈值选择" },
  283. },
  284. {
  285. path: "ModelTrain",
  286. name: "ModelTrain",
  287. component: () => import("@/views/Admin/modelManagement/AcidReductionModel/ModelTrain.vue"),
  288. meta: { title: "模型训练" },
  289. },
  290. {
  291. path: "UserRegistration",
  292. name: "UserRegistration",
  293. component: () =>
  294. import("../views/Admin/userManagement/UserRegistration.vue"),
  295. meta: { title: "普通用户" },
  296. },
  297. {
  298. path: "UserManagement",
  299. name: "UserManagement",
  300. component: () =>
  301. import("@/views/Admin/userManagement/UserManagement.vue"),
  302. meta: { title: "用户信息管理" },
  303. },
  304. {
  305. path: "CadmiumPredictionModel",
  306. name: "CadmiumPredictionModel",
  307. component: () =>
  308. import("@/views/Admin/modelManagement/CadmiumPredictionModel.vue"),
  309. meta: { title: "土壤镉含量预测模型" },
  310. },
  311. {
  312. path: "EffectiveCadmiumModel",
  313. name: "EffectiveCadmiumModel",
  314. component: () =>
  315. import("@/views/Admin/modelManagement/EffectiveCadmiumModel.vue"),
  316. meta: { title: "土壤有效态镉预测模型" },
  317. },
  318. {
  319. path: "RiceRiskModel",
  320. name: "RiceRiskModel",
  321. component: () =>
  322. import("@/views/Admin/modelManagement/RiceRiskModel.vue"),
  323. meta: { title: "水稻镉污染风险模型" },
  324. },
  325. {
  326. path: "WheatRiskModel",
  327. name: "WheatRiskModel",
  328. component: () =>
  329. import("@/views/Admin/modelManagement/WheatRiskModel.vue"),
  330. meta: { title: "小麦镉污染风险模型" },
  331. },
  332. {
  333. path: "VegetableRiskModel",
  334. name: "VegetableRiskModel",
  335. component: () =>
  336. import("@/views/Admin/modelManagement/VegetableRiskModel.vue"),
  337. meta: { title: "蔬菜镉污染风险模型" },
  338. },
  339. {
  340. path: "irrigationWater",
  341. name: "irrigationWater",
  342. component: () =>
  343. import(
  344. "@/views/User/heavyMetalFluxCalculation/inputFluxCalculation/irrigationWater.vue"
  345. ),
  346. meta: { title: "灌溉水" },
  347. },
  348. {
  349. path: "agriculturalProductInput",
  350. name: "agriculturalProductInput",
  351. component: () =>
  352. import(
  353. "@/views/User/heavyMetalFluxCalculation/inputFluxCalculation/agriculturalProductInput.vue"
  354. ),
  355. meta: { title: "农产品投入" },
  356. },
  357. {
  358. path: "atmosphericDryWetDeposition",
  359. name: "atmosphericDryWetDeposition",
  360. component: () =>
  361. import(
  362. "@/views/User/heavyMetalFluxCalculation/inputFluxCalculation/atmosphericDryWetDeposition.vue"
  363. ),
  364. meta: { title: "大气干湿沉降" },
  365. },
  366. {
  367. path: "surfaceRunoff",
  368. name: "surfaceRunoff",
  369. component: () =>
  370. import(
  371. "@/views/User/heavyMetalFluxCalculation/outputFluxCalculation/surfaceRunoff.vue"
  372. ),
  373. meta: { title: "地表径流" },
  374. },
  375. {
  376. path: "cropRemoval",
  377. name: "cropRemoval",
  378. component: () =>
  379. import(
  380. "@/views/User/heavyMetalFluxCalculation/outputFluxCalculation/cropRemoval.vue"
  381. ),
  382. meta: { title: "农作物移除" },
  383. },
  384. {
  385. path: "subsurfaceFlow",
  386. name: "subsurfaceFlow",
  387. component: () =>
  388. import(
  389. "@/views/User/heavyMetalFluxCalculation/outputFluxCalculation/subsurfaceFlow.vue"
  390. ),
  391. meta: { title: "地下渗流" },
  392. },
  393. {
  394. path: "about",
  395. name: "about",
  396. component: () => import("@/views/AboutView.vue"),
  397. },
  398. {
  399. path: "/:pathMatch(.*)*",
  400. name: "ErrorPage",
  401. component: () => import("@/views/ErrorPage.vue"),
  402. },
  403. ],
  404. },
  405. ];
  406. const router = createRouter({
  407. history: createWebHistory(import.meta.env.BASE_URL),
  408. routes,
  409. });
  410. router.beforeEach((to, from, next) => {
  411. const tokenStore = useTokenStore();
  412. if (to.name === "login" && tokenStore.token.userid) {
  413. next({ name: "selectCityAndCounty" });
  414. } else if (to.matched.some((r) => r.meta.requiresAuth)) {
  415. tokenStore.token.userid ? next() : next({ name: "login" });
  416. } else {
  417. next();
  418. }
  419. });
  420. export default router;