import Vue from 'vue'
import store from '@/store'
import VueRouter, { RouteConfig } from 'vue-router'
// 解决Vue-Router升级导致的Uncaught(in promise) navigation guard问题
const originalPush = VueRouter.prototype.push
// @ts-ignore
VueRouter.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
    // @ts-ignore
    return originalPush.call(this, location).catch((err) => err)
}
// @ts-ignore
import { getPvUv } from '@/api/public.js'
Vue.use(VueRouter)

const routes: Array<RouteConfig> = [
    // 项目概况
    {
        path: '/',
        name: 'Overview',
        // redirect: '/otherMatter',
        component: () => import(/* webpackChunkName: "overview" */ '../views/overview/index.vue'),
        meta: {
            keepAlive: true,
            showTabbar: true,
        },
    },
    // 项目概况
    {
        path: '/overview',
        name: 'Overview',
        component: () => import(/* webpackChunkName: "overview" */ '../views/overview/index.vue'),
        meta: {
            keepAlive: true,
            showTabbar: true,
        },
    },
    // 楼层功能
    {
        path: '/floorFunc',
        name: 'FloorFunc',
        component: () => import(/* webpackChunkName: "floorFunc" */ '../views/FloorFunc.vue'),
        meta: {
            keepAlive: true,
            showTabbar: true,
        },
    },
    // 设备设施
    {
        path: '/equipmentFacilities',
        name: 'EquipmentFacilities',
        component: () => import(/* webpackChunkName: "equipmentFacilities" */ '../views/equipmentFacilities/index.vue'),
        meta: {
            keepAlive: true,
            showTabbar: true,
        },
    },
    // 设备设施 --> 设备卡片跳转到的设备列表页面
    {
        path: '/equipmentList',
        name: 'EquipmentList',
        component: () => import(/* webpackChunkName: "equipmentFacilities" */ '../views/equipmentFacilities/EquipmentList.vue'),
        meta: {
            keepAlive: false,
            showTabbar: false,
            hideNarBar: true,
        },
    },
    // 设备设置 --> 机房平面布置图
    {
        path: '/engineRoomPicture',
        name: 'EngineRoomPicture',
        component: () => import(/* webpackChunkName: "equipmentFacilities" */ '../views/equipmentFacilities/EngineRoomPicture.vue'),
        meta: {
            keepAlive: true,
            showTabbar: false,
            hideNarBar: true,
        },
    },
    // 设备设置 --> 楼层分布
    {
        path: '/systemFloor',
        name: 'SystemFloor',
        component: () => import(/* webpackChunkName: "equipmentFacilities" */ '../views/equipmentFacilities/SystemFloor.vue'),
        meta: {
            keepAlive: false,
            showTabbar: true,
            hideNarBar: true,
        },
    },
    // 设备设置 --> 电井间控制商铺范围
    {
        path: '/electricWell',
        name: 'ElectricWell',
        component: () => import(/* webpackChunkName: "equipmentFacilities" */ '../views/equipmentFacilities/ElectricWell.vue'),
        meta: {
            keepAlive: false,
            showTabbar: false,
            hideNarBar: true,
        },
    },
    // 其他事项
    {
        path: '/otherMatter',
        name: 'OtherMatter',
        component: () => import(/* webpackChunkName: "otherMatter" */ '../views/otherMatter/index.vue'),
        meta: {
            keepAlive: true,
            showTabbar: true,
        },
    },
    // 其他事项 --> 综合事项
    {
        path: '/comprehensiveMatter',
        name: 'ComprehensiveMatter',
        component: () => import(/* webpackChunkName: "comprehensiveMatter" */ '../views/otherMatter/ComprehensiveMatter.vue'),
        meta: {
            keepAlive: true,
            showTabbar: true,
        },
    },
    // 其他事项 --> 综合事项 --> 政府/其他 事项列表页面
    {
        path: '/comprehensiveMatterList',
        name: 'ComprehensiveMatterList',
        component: () => import(/* webpackChunkName: "comprehensiveMatter" */ '../views/otherMatter/ComprehensiveMatterList.vue'),
        meta: {
            keepAlive: false,
            showTabbar: false,
            hideNarBar: true,
        },
    },
    //  其他事项 --> 辅助用房
    {
        path: '/auxiliaryRoom',
        name: 'AuxiliaryRoom',
        component: () => import(/* webpackChunkName: "comprehensiveMatter" */ '../views/otherMatter/AuxiliaryRoom.vue'),
        meta: {
            keepAlive: false,
            showTabbar: true,
        },
    },
    // 说明书更新记录
    {
        path: '/updateRecord',
        name: 'UpdateRecord',
        component: () => import(/* webpackChunkName: "updateRecord" */ '../views/overview/UpdateRecord.vue'),
        meta: {
            keepAlive: true,
            showTabbar: false,
            hideNarBar: true,
        },
    },
    // 说明书更新记录详情
    {
        path: '/updateRecordDetail',
        name: 'UpdateRecordDetail',
        component: () => import(/* webpackChunkName: "updateRecord" */ '../views/overview/UpdateRecordDetail.vue'),
        meta: {
            keepAlive: false,
            showTabbar: false,
            hideNarBar: true,
        },
    },
    // 平面图查看
    {
        path: '/mapView',
        name: 'MapView',
        component: () => import(/* webpackChunkName: "mapView" */ '../views/overview/MapView.vue'),
        meta: {
            keepAlive: false,
            showTabbar: false,
            hideNarBar: true,
        },
    },
    // 全局搜索
    {
        path: '/globalSearch',
        name: 'GlobalSearch',
        component: () => import(/* webpackChunkName: "globalSearch" */ '../views/GlobalSearch.vue'),
        meta: {
            keepAlive: false,
            showTabbar: false,
            hideNarBar: true,
        },
    },
    // 设备详情页
    {
        path: '/assetDetail',
        name: 'AssetDetail',
        component: () => import(/* webpackChunkName: "assetDetail" */ '../views/AssetDetail.vue'),
        meta: {
            keepAlive: false,
            showTabbar: false,
            hideNarBar: true,
        },
    },
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes,
})
// 跳入路由后要对发送pvuv
router.afterEach((to) => {
    // console.log(to)
    // 项目概览,楼层功能,设备设施,其他事项 记录pupv
    let pupvArr = ['Overview', 'FloorFunc', 'EquipmentFacilities', 'OtherMatter']
    // @ts-ignore
    if (!pupvArr.includes(to.name)) {
        return true
    }
    let postParams = {
        type: 'router',
        target: to.name,
        parameter: to.path,
        app: 'H5',
    }
    const data = {
        plazaId: store.getters['plazaId'],
    }
    getPvUv(data, postParams)
        .then((res: any) => {
            // console.log('pvuv', res)
        })
        .catch((res: any) => {
            // console.log('error', res)
        })
})
export default router
