import {createRouter,createWebHashHistory} from "vue-router";
import FormHome from "../views/c-views/formPart/FormHome.vue";
import VisualizationHome from "../views/c-views/visualizationPart/VisualizationHome.vue";
import HouseBuilding from "@/views/c-views/visualizationPart/houseBuilding/HouseBuilding.vue";
import MainPage from "@/views/c-views/visualizationPart/mainPage/MainPage.vue";
import MunicipalFacilities from "@/views/c-views/visualizationPart/municipalFacilities/MunicipalFacilities.vue";
import {ElMessageBox} from "element-plus";
import {useUserStore} from "@/store/userStore.js";

const router = createRouter({
    history:createWebHashHistory(import.meta.env.BASE_URL),
    routes:[
        {
            path:'/',
            redirect:'/visualizationHome/mainPage'
        },
        {
            path:'/visualizationHome',
            name:'visualizationHome',
            component:VisualizationHome,
            children:[
                {
                    path:'houseBuilding',
                    name:'houseBuilding',
                    component:HouseBuilding,
                },
                {
                    path:'municipalFacilities',
                    name:'municipalFacilities',
                    component:MunicipalFacilities,
                },
                {
                    path:'mainPage',
                    name:'mainPage',
                    component:MainPage,
                },
            ]
        },
        {
            path:'/formHome',
            name:'formHome',
            component:FormHome
        }
    ]
})
router.beforeEach((to,from) =>{
    let userStore = useUserStore();
    let userInfo =  localStorage.getItem('exchangeUserInfo');
    userStore.userInfo = JSON.parse(userInfo);
    if(!userInfo ||userInfo == "null"||userInfo == null||userInfo == ""){
        ElMessageBox.alert("请登录后操作",name,{
            type:"warning",
            confirmButtonText: "确定",
        })
        window.location.href='https://cimweb.zjw.sh.cegn.cn:2007/cim-home/#/login';
    }
})
export default router