123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706 |
- import { createRouter, createWebHistory } from "vue-router";
- import AppLayout from "@/components/layout/AppLayout.vue";
- import { useTokenStore } from "@/stores/mytoken"; // 确保正确导入 useTokenStore
- // 定义路由配置
- const routes = [
- { path: "/login", name: "login", component: () => import("@/views/login/loginView.vue") },
- {
- path: "/",
- component: AppLayout,
- meta: { requiresAuth: true },
- children: [
- {
- path: "/:catchAll(.*)",
- redirect: "/404", // 确保重定向到有效页面
- },
- {
- path: "select-city", // remove leading slash
- name: "selectCityAndCounty",
- component: () => import("@/views/User/selectCityAndCounty.vue"),
- meta: { title: "选择城市和县", fullScreen: true },
- },
- {
- path: "shuJuKanBan",
- name: "shuJuKanBan",
- component: () => import("@/views/User/shuJuKanBan/shuJuKanBan.vue"), // 修复路径
- meta: { title: "数据看板" },
- },
- {
- path: "SoilPro",
- name: "SoilPro",
- component: () => import("@/views/User/introduction/SoilPro.vue"), // 修复路径
- meta: { title: "软件简介" },
- },
- {
- path: "Overview",
- name: "Overview",
- component: () => import("@/views/User/introduction/Overview.vue"), // 修复路径
- meta: { title: "项目简介" },
- },
- {
- path: "ResearchFindings",
- name: "ResearchFindings",
- component: () =>
- import("@/views/User/introduction/ResearchFindings.vue"), // 修复路径
- meta: { title: "研究成果" },
- },
- {
- path: "Unit",
- name: "Unit",
- component: () => import("@/views/User/introduction/Unit.vue"), // 修复路径
- meta: { title: "团队信息" },
- },
- {
- path: "IntroductionUpdate",
- name: "IntroductionUpdate",
- component: () =>
- import("@/views/User/introduction/IntroductionUpdate.vue"), // 修复路径
- meta: { title: "更新介绍" },
- },
- //管理员
- // {
- // path: "HmOutFlux",
- // name: "HmOutFlux",
- // component: () => import("@/views/User/HmOutFlux"),
- // meta: { title: "重金属输出通量" },
- // },
- // {
- // path: "irrigationWater",
- // name: "irrigationWater",
- // component: () => import("@/views/User/HmOutFlux/irrigationWater"),
- // meta: { title: "灌溉水" },
- // },
- {
- path: "samplingMethodDevice1",
- name: "samplingMethodDevice1",
- component: () =>
- import(
- "@/views/User/HmOutFlux/irrigationWater/samplingMethodDevice1.vue"
- ),
- meta: { title: "采样方法和装置" },
- },
- {
- path: "irriSampleData",
- name: "irriSampleData",
- component: () =>
- import(
- "@/views/User/HmOutFlux/irrigationWater/irriWaterSampleData.vue"
- ),
- meta: { title: "灌溉水采样数据" },
- },
- {
- path: "csSampleData",
- name: "csSampleData",
- component: () =>
- import(
- "@/views/User/HmOutFlux/irrigationWater/crossSection.vue"
- ),
- meta: { title: "断面采样数据" },
- },
- {
- path: "irriInputFlux",
- name: "irriInputFlux",
- component: () =>
- import(
- "@/views/User/HmOutFlux/irrigationWater/irriWaterInputFlux.vue"
- ),
- meta: { title: "灌溉水输入通量" },
- },
- // {
- // path: "agriInput",
- // name: "agriInput",
- // component: () => import("@/views/User/HmOutFlux/agriInput"),
- // meta: { title: "农产品投入" },
- // },
- {
- path: "farmInputSamplingDesc",
- name: "farmInputSamplingDesc",
- component: () =>
- import("@/views/User/HmOutFlux/agriInput/farmInputSamplingDesc.vue"),
- meta: { title: "采样说明" },
- },
- {
- path: "prodInputFlux",
- name: "prodInputFlux",
- component: () =>
- import("@/views/User/HmOutFlux/agriInput/prodInputFlux.vue"),
- meta: { title: "农产品输入通量" },
- },
- // {
- // path: "atmosDeposition",
- // name: "atmosDeposition",
- // component: () => import("@/views/User/HmOutFlux/atmosDeposition"),
- // meta: { title: "大气干湿沉降" },
- // },
- {
- path: "AtmosDepositionSamplingDesc",
- name: "AtmosDepositionSamplingDesc",
- component: () =>
- import(
- "@/views/User/HmOutFlux/atmosDeposition/AtmosDepositionSamplingDesc.vue"
- ),
- meta: { title: "采样说明" },
- },
- {
- path: "heavyMetalEnterprise",
- name: "heavyMetalEnterprise",
- component: () =>
- import(
- "@/views/User/HmOutFlux/atmosDeposition/heavyMetalEnterprise.vue"
- ),
- meta: { title: "涉重企业" },
- },
- {
- path: "airSampleData",
- name: "airSampleData",
- component: () =>
- import("@/views/User/HmOutFlux/atmosDeposition/airSampleData.vue"),
- meta: { title: "大气采样数据" },
- },
- {
- path: "airInputFlux",
- name: "airInputFlux",
- component: () =>
- import("@/views/User/HmOutFlux/atmosDeposition/airInputFlux.vue"),
- meta: { title: "大气输入通量" },
- },
- // {
- // path: "hmInFlux",
- // name: "hmInFlux",
- // component: () => import("@/views/User/hmInFlux"),
- // meta: { title: "重金属输入通量" },
- // },
- // {
- // path: "grainRemoval",
- // name: "grainRemoval",
- // component: () => import("@/views/User/hmInFlux/grainRemoval"),
- // meta: { title: "籽粒移除" },
- // },
- {
- path: "samplingDesc1",
- name: "samplingDesc1",
- component: () =>
- import("@/views/User/hmInFlux/grainRemoval/samplingDesc1.vue"),
- meta: { title: "采样说明" },
- },
- {
- path: "grainRemovalInputFlux",
- name: "grainRemovalInputFlux",
- component: () =>
- import(
- "@/views/User/hmInFlux/grainRemoval/grainRemovalInputFlux.vue"
- ),
- meta: { title: "籽粒移除输入通量" },
- },
- // {
- // path: "strawRemoval",
- // name: "strawRemoval",
- // component: () => import("@/views/User/hmInFlux/strawRemoval"),
- // meta: { title: "秸秆移除" },
- // },
- {
- path: "samplingDesc2",
- name: "samplingDesc2",
- component: () =>
- import("@/views/User/hmInFlux/strawRemoval/samplingDesc2.vue"),
- meta: { title: "采样说明" },
- },
- {
- path: "strawRemovalInputFlux",
- name: "strawRemovalInputFlux",
- component: () =>
- import(
- "@/views/User/hmInFlux/strawRemoval/strawRemovalInputFlux.vue"
- ),
- meta: { title: "秸秆移除输入通量" },
- },
- // {
- // path: "subsurfaceLeakage",
- // name: "subsurfaceLeakage",
- // component: () => import("@/views/User/hmInFlux/subsurfaceLeakage"),
- // meta: { title: "地下渗漏" },
- // },
- {
- path: "samplingDesc3",
- name: "samplingDesc3",
- component: () =>
- import("@/views/User/hmInFlux/subsurfaceLeakage/samplingDesc3.vue"),
- meta: { title: "采样说明" },
- },
- {
- path: "subsurfaceLeakageInputFlux",
- name: "subsurfaceLeakageInputFlux",
- component: () =>
- import(
- "@/views/User/hmInFlux/subsurfaceLeakage/subsurfaceLeakageInputFlux.vue"
- ),
- meta: { title: "地下渗漏输入通量" },
- },
- // {
- // path: "surfaceRunoff",
- // name: "surfaceRunoff",
- // component: () => import("@/views/User/hmInFlux/surfaceRunoff"),
- // meta: { title: "地表径流" },
- // },
- {
- path: "samplingDesc4",
- name: "samplingDesc4",
- component: () =>
- import("@/views/User/hmInFlux/surfaceRunoff/samplingDesc4.vue"),
- meta: { title: "采样说明" },
- },
- {
- path: "surfaceRunoffInputFlux",
- name: "surfaceRunoffInputFlux",
- component: () =>
- import(
- "@/views/User/hmInFlux/surfaceRunoff/surfaceRunoffInputFlux.vue"
- ),
- meta: { title: "地表径流输入通量" },
- },
- {
- path: "Calculation",
- name: "Calculation",
- component: () => import("@/views/User/acidModel/Calculation.vue"), // 修复路径
- meta: { title: "反酸计算" },
- },
- {
- path: "AcidNeutralizationModel",
- name: "AcidNeutralizationModel",
- component: () =>
- import(
- "@/views/User/neutralizationModel/AcidNeutralizationModel.vue"
- ), // 修复路径
- meta: { title: "降酸计算" },
- },
- {
- path: "SoilAcidificationIterativeEvolution",
- name: "SoilAcidificationIterativeEvolution",
- component: () =>
- import(
- "@/views/User/neutralizationModel/SoilAcidificationIterativeEvolution.vue"
- ), // 修复路径
- meta: { title: "降酸模型显示" },
- },
- {
- path: "SoilAcidReductionIterativeEvolution",
- name: "SoilAcidReductionIterativeEvolution",
- component: () =>
- import(
- "@/views/User/acidModel/SoilAcidReductionIterativeEvolution.vue"
- ), // 修复路径
- meta: { title: "反酸模型显示" },
- },
- {
- path: "mapView",
- name: "mapView",
- component: () => import("@/views/User/mapView/leafletMapView.vue"), // 修复路径
- meta: { title: "地图展示" },
- },
- {
- path: "totalInputFlux",
- name: "totalInputFlux",
- component: () =>
- import("@/views/User/cadmiumPrediction/totalInputFlux.vue"),
- meta: { title: "输入总通量" },
- },
- {
- path: "totalOutputFlux",
- name: "totalOutputFlux",
- component: () =>
- import("@/views/User/cadmiumPrediction/totalOutputFlux.vue"), // 修复路径
- meta: { title: "输出总通量" },
- },
- {
- path: "netFlux",
- name: "netFlux",
- component: () => import("@/views/User/cadmiumPrediction/netFlux.vue"), // 修复路径
- meta: { title: "净通量" },
- },
- {
- path: "currentYearConcentration",
- name: "currentYearConcentration",
- component: () =>
- import("@/views/User/cadmiumPrediction/currentYearConcentration.vue"), // 修复路径
- meta: { title: "当年浓度" },
- },
- {
- path: "TotalCadmiumPrediction",
- name: "TotalCadmiumPrediction",
- component: () =>
- import("@/views/User/cadmiumPrediction/TotalCadmiumPrediction.vue"), // 修复路径
- meta: { title: "土壤镉的总含量预测" },
- },
- {
- path: "EffectiveCadmiumPrediction",
- name: "EffectiveCadmiumPrediction",
- component: () =>
- import(
- "@/views/User/cadmiumPrediction/EffectiveCadmiumPrediction.vue"
- ), // 修复路径
- meta: { title: "土壤镉有效态含量预测" },
- },
- {
- path: "CropCadmiumPrediction",
- name: "CropCadmiumPrediction",
- component: () =>
- import("@/views/User/cadmiumPrediction/CropCadmiumPrediction.vue"), // 修复路径
- meta: { title: "土壤镉作物态含量预测" },
- },
- {
- path: "cropRiskAssessment",
- name: "cropRiskAssessment",
- component: () =>
- import("@/views/User/cropRiskAssessment/cropRiskAssessment.vue"), // 修复路径
- meta: { title: "水稻镉污染风险" },
- },
- {
- path: "farmlandQualityAssessment",
- name: "farmlandQualityAssessment",
- component: () =>
- import(
- "@/views/User/farmlandQualityAssessment/farmlandQualityAssessment.vue"
- ), // 修复路径
- meta: { title: "韶关" },
- },
- {
- path: "SoilAcidReboundPrediction",
- name: "SoilAcidReboundPrediction",
- component: () =>
- import(
- "@/views/User/soilAcidificationPrediction/SoilAcidReboundPrediction.vue"
- ), // 修复路径
- meta: { title: "土壤反酸预测" },
- },
- {
- path: "SoilAcidReductionPrediction",
- name: "SoilAcidReductionPrediction",
- component: () =>
- import(
- "@/views/User/soilAcidificationPrediction/SoilAcidReductionPrediction.vue"
- ), // 修复路径
- meta: { title: "土壤降酸预测" },
- },
- {
- path: "TraditionalFarmingRisk",
- name: "TraditionalFarmingRisk",
- component: () =>
- import("@/views/User/scenarioSimulation/TraditionalFarmingRisk.vue"), // 修复路径
- meta: { title: "传统耕种习惯风险趋势" },
- },
- {
- path: "HeavyMetalCadmiumControl",
- name: "HeavyMetalCadmiumControl",
- component: () =>
- import(
- "@/views/User/scenarioSimulation/HeavyMetalCadmiumControl.vue"
- ), // 修复路径
- meta: { title: "重金属镉污染治理" },
- },
- {
- path: "SoilAcidificationControl",
- name: "SoilAcidificationControl",
- component: () =>
- import(
- "@/views/User/scenarioSimulation/SoilAcidificationControl.vue"
- ), // 修复路径
- meta: { title: "土壤酸化治理" },
- },
- {
- path: "DetectionStatistics",
- name: "DetectionStatistics",
- component: () =>
- import("@/views/User/dataStatistics/DetectionStatistics.vue"), // 修复路径
- meta: { title: "检测信息统计" },
- },
- {
- path: "FarmlandPollutionStatistics",
- name: "FarmlandPollutionStatistics",
- component: () =>
- import("@/views/User/dataStatistics/SoilCdStatistics.vue"), // 修复路径
- meta: { title: "土壤镉含量统计" },
- },
- {
- path: "LandClutivatesStatistics",
- name: "LandClutivatesStatistics",
- component: () =>
- import("@/views/User/dataStatistics/LandCultivatedStatistics.vue"), // 修复路径
- meta: { title: "作物风险评估系统" },
- },
- {
- path: "SoilacidificationStatistics",
- name: "SoilacidificationStatistics",
- component: () =>
- import("@/views/User/dataStatistics/SoilacidificationStatistics.vue"), // 修复路径
- meta: { title: "作物风险评估系统" },
- },
- {
- path: "AdminRegionData",
- name: "AdminRegionData",
- component: () =>
- import("@/views/Admin/dataManagement/AdminRegionData.vue"), // 修复路径
- meta: { title: "行政区域数据" },
- },
- {
- path: "irrigationWaterSampleData",
- name: "irrigationWaterSampleData",
- component: () =>
- import(
- "@/views/Admin/dataManagement/HeavyMetalInputFluxManager/irrigationWaterSampleData.vue"
- ),
- meta: { title: "灌溉水采样数据" },
- },
- {
- path: "crossSectionSampleData",
- name: "crossSectionSampleData",
- component: () =>
- import(
- "@/views/Admin/dataManagement/HeavyMetalInputFluxManager/crossSectionSampleData.vue"
- ),
- meta: { title: "断面采样数据" },
- },
- {
- path: "irrigationWaterInputFluxData",
- name: "irrigationWaterInputFluxData",
- component: () =>
- import(
- "@/views/Admin/dataManagement/HeavyMetalInputFluxManager/irrigationWaterInputFluxData.vue"
- ),
- meta: { title: "灌溉水输入通量数据" },
- },
- {
- path: "agriProductInputFluxData",
- name: "agriProductInputFluxData",
- component: () =>
- import(
- "@/views/Admin/dataManagement/HeavyMetalInputFluxManager/agriProductInputFluxData.vue"
- ),
- meta: { title: "农产品输入通量数据" },
- },
- {
- path: "heavyMetalEnterpriseData",
- name: "heavyMetalEnterpriseData",
- component: () =>
- import(
- "@/views/Admin/dataManagement/HeavyMetalInputFluxManager/heavyMetalEnterpriseData.vue"
- ),
- meta: { title: "涉重企业数据" },
- },
- {
- path: "atmosphericSampleData",
- name: "atmosphericSampleData",
- component: () =>
- import(
- "@/views/Admin/dataManagement/HeavyMetalInputFluxManager/atmosphericSampleData.vue"
- ),
- meta: { title: "大气采样数据" },
- },
- {
- path: "atmosphericInputFluxData",
- name: "atmosphericInputFluxData",
- component: () =>
- import(
- "@/views/Admin/dataManagement/HeavyMetalInputFluxManager/atmosphericInputFluxData.vue"
- ),
- meta: { title: "大气输入通量数据" },
- },
- {
- path: "SoilAssessmentUnitData",
- name: "SoilAssessmentUnitData",
- component: () =>
- import("@/views/Admin/dataManagement/SoilAssessmentUnitData.vue"),
- meta: { title: "土壤评估单元格数据" },
- },
- {
- path: "SoilHeavyMetalData",
- name: "SoilHeavyMetalData",
- component: () =>
- import("@/views/Admin/dataManagement/SoilHeavyMetalData.vue"),
- meta: { title: "土壤重金属采集数据" },
- },
- {
- path: "CropHeavyMetalData",
- name: "CropHeavyMetalData",
- component: () =>
- import("@/views/Admin/dataManagement/CropHeavyMetalData.vue"),
- meta: { title: "农作物重金属采集样数据" },
- },
- {
- path: "LandUseTypeData",
- name: "LandUseTypeData",
- component: () =>
- import("@/views/Admin/dataManagement/LandUseTypeData.vue"),
- meta: { title: "用地类型数据" },
- },
- {
- path: "SoilAcidificationData",
- name: "SoilAcidificationData",
- component: () =>
- import(
- "@/views/Admin/dataManagement/Soil Acidification and Acid Reduction Data Management/soilAcidificationData.vue"
- ),
- meta: { title: "土壤酸化采样数据" },
- },
- {
- path: "soilAcidReductionData",
- name: "soilAcidReductionData",
- component: () =>
- import(
- "@/views/Admin/dataManagement/Soil Acidification and Acid Reduction Data Management/soilAcidReductionData.vue"
- ),
- meta: { title: "土壤酸化采样数据" },
- },
- {
- path: "ClimateInfoData",
- name: "ClimateInfoData",
- component: () =>
- import("@/views/Admin/dataManagement/ClimateInfoData.vue"),
- meta: { title: "气候信息数据" },
- },
- {
- path: "GeographicEnvInfoData",
- name: "GeographicEnvInfoData",
- component: () =>
- import("@/views/Admin/dataManagement/GeographicEnvInfoData.vue"),
- meta: { title: "地理环境信息" },
- },
- {
- path: "ModelSelection",
- name: "ModelSelection",
- component: () =>
- import("@/views/Admin/parameterConfig/ModelSelection.vue"),
- meta: { title: "模型选择" },
- },
- {
- path: "thres",
- name: "thres",
- component: () => import("@/views/Admin/parameterConfig/thres.vue"),
- meta: { title: "阈值选择" },
- },
- {
- path: "ModelTrain",
- name: "ModelTrain",
- component: () => import("@/views/Admin/parameterConfig/ModelTrain.vue"),
- meta: { title: "模型训练" },
- },
- {
- path: "UserRegistration",
- name: "UserRegistration",
- component: () =>
- import("@/views/Admin/userManagement/UserRegistration.vue"),
- meta: { title: "普通用户" },
- },
- {
- path: "UserManagement",
- name: "UserManagement",
- component: () =>
- import("@/views/Admin/userManagement/UserManagement.vue"),
- meta: { title: "用户信息管理" },
- },
- {
- path: "CadmiumPredictionModel",
- name: "CadmiumPredictionModel",
- component: () =>
- import("@/views/Admin/modelManagement/CadmiumPredictionModel.vue"),
- meta: { title: "土壤镉含量预测模型" },
- },
- {
- path: "EffectiveCadmiumModel",
- name: "EffectiveCadmiumModel",
- component: () =>
- import("@/views/Admin/modelManagement/EffectiveCadmiumModel.vue"),
- meta: { title: "土壤有效态镉预测模型" },
- },
- {
- path: "RiceRiskModel",
- name: "RiceRiskModel",
- component: () =>
- import("@/views/Admin/modelManagement/RiceRiskModel.vue"),
- meta: { title: "水稻镉污染风险模型" },
- },
- {
- path: "AcidReductionModel",
- name: "AcidReductionModel",
- component: () =>
- import("@/views/Admin/modelManagement/AcidReductionModel.vue"),
- meta: { title: "反酸及降酸模型" },
- },
- {
- path: "WheatRiskModel",
- name: "WheatRiskModel",
- component: () =>
- import("@/views/Admin/modelManagement/WheatRiskModel.vue"),
- meta: { title: "小麦镉污染风险模型" },
- },
- {
- path: "VegetableRiskModel",
- name: "VegetableRiskModel",
- component: () =>
- import("@/views/Admin/modelManagement/VegetableRiskModel.vue"),
- meta: { title: "蔬菜镉污染风险模型" },
- },
- {
- path: "about",
- name: "about",
- component: () => import("@/views/AboutView.vue"),
- },
- {
- path: "/:pathMatch(.*)*",
- name: "ErrorPage",
- component: () => import("@/views/ErrorPage.vue"),
- },
- ],
- },
- ];
- const router = createRouter({
- history: createWebHistory(),
- routes,
- });
- router.beforeEach((to, from, next) => {
- const tokenStore = useTokenStore();
- const user = tokenStore.userInfo;
- const isSameRoute = (path: string) => to.fullPath === path;
- // 已登录用户访问 login 页面
- if (to.name === "login" && user?.userId) {
- return next("/select-city");
- }
- // 需要登录才能访问的页面
- if (to.matched.some(r => r.meta.requiresAuth)) {
- if (!user?.userId) {
- return next({ name: "login" });
- }
- // 管理员权限页面
- if (to.matched.some(r => r.meta.requiresAdmin)) {
- if (user.loginType !== "admin") {
- // 普通用户访问管理员页面,提示并重定向
- // Replace with your notification library, e.g. for naive-ui:
- // import { useMessage } from 'naive-ui' at the top of the file if not already imported
- // const message = useMessage();
- // message.error("登录失败:用户类型不匹配");
- // If using Element Plus:
- // import { ElMessage } from 'element-plus' at the top of the file
- // ElMessage.error("登录失败:用户类型不匹配");
- // Example using Element Plus:
- // ElMessage.error("登录失败:用户类型不匹配");
- if (!isSameRoute("/select-city")) return next({ name: "selectCityAndCounty" });
- return next();
- }
- }
- }
- next();
- });
- export default router;
|