<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Title</title>
</head>
<script src="https://uedcdn.zto.com/static/zcat/release/zcat.browser.min.js"></script>
<script>
    (function(){
        // debugger
        if(window.zcat) window.zcat.init({ appKey: "portal-web-error", isProd:true});
        //后端生成参数
        var domain = decodeURIComponent("https%3A%2F%2Fwww.zt-express.com%2F");
        var originalMenus = 'e-original-menus'
        var microMenus = ["device-data\/deviceMapping","welcome","user\/consumption-record","system\/appointment-record","system\/realTime-booking","system\/shuttle-bus","system\/venue","user\/list","system\/advertising-space","main-data\/device","main-data\/advert","main-data\/authority","main-data\/management","system\/analysis","meeting-system\/meeting-edition","master\/floor","master\/park","master\/building","master\/room","appointment","blacklist","visit","setup","data-statistics\/booking-record","home","template","data-statistics\/subscriber-use","gate-sentry","data-statistics\/meeting-use","system\/waterElectricity","device-data\/manage","system\/busBookingRecord","business\/platform","master\/area","\/videoManage","\/platform-manage\/search","platform-manage\/time-setting","platform-manage\/use-rate","platform-manage\/record","\/ticket-trace\/traces-query","\/ticket-trace\/center-trace-setting","data-statistics\/repair-record","\/ticket-trace\/center-trace-setting","\/ticket-trace\/traces-query","\/ticket-trace\/traces-query","\/ticket-trace\/trace-setting-visual","\/ticket-trace\/trace-setting-visual","device-data\/event","\/monitor-group","master\/board","\/transition-park-visual","parkVisualization\/readering-config","parkVisualization\/chart-editor","\/parkVisualization\/visualization-2d","\/video-center","\/video-site","\/video-log","\/VideoSiteBoard","\/business\/lineBody","\/master\/locationInventory"]
        var ebizId = "a_788"
        var aliasId = "zto-physical-web"
        var microAppId = "zto-physical-web"
        //白名单。优先使用业务自身的exx 参数，没有的使用白名单exx参数补
        // var whiteList = [{
        //     microAppId:'qt-front',
        //     path:'/taskManage/taskDetail/',   //菜单静态路径。注意，不包括path里的动态参数
        //     elabel:'菜单标题', //菜单默认标题
        //     eshareable:'y',//是否共享一个tab。共享 y ,不共享 n
        //     epathcount:'0',//path上的参数个数
        //     eaddroutes:'n',//是否使用到 mHelp.addPageDetail 方法。有 y ,无 n
        //     eiframe:'0' //门户是否用iframe打开这个详情页。是 1，否 0
        // }]
        var whiteList = [{"path":"\/live-new-out","eaddroutes":"n","elabel":"\u89C6\u9891\u8BE6\u60C5","eshareable":"n","microAppId":"zto-physical-web","epathcount":"1","eiframe":"1"},{"path":"\/h5-plugin-live-video-out","eaddroutes":"n","elabel":"\u89C6\u9891\u8BE6\u60C5","eshareable":"n","microAppId":"zto-physical-web","epathcount":"1","eiframe":"1"},{"path":"\/player","eaddroutes":"n","elabel":"\u89C6\u9891\u8BE6\u60C5","eshareable":"n","microAppId":"zto-physical-web","epathcount":"1","eiframe":"1"},{"path":"\/player-time-range","eaddroutes":"n","elabel":"\u89C6\u9891\u8BE6\u60C5","eshareable":"n","microAppId":"zto-physical-web","epathcount":"1","eiframe":"1"}]

        var isMobileModel = false // 是否移动设备（false：不是  true：是）
        var newTargetDomain = decodeURIComponent("") //新加载域名（用于移动接入时跳转）
        var hasMobileUpgrade = false //是否接入移动并且升级，用于移动访问中转静态资源访问（false：未接入  true：已接入）

        //页面参数
        var originalMenusPath = domain + originalMenus + '?ebizId=' + ebizId
        var hash = window.location.hash
        // 如果是95需要特殊处理因新老路径不一样
        var hash95 = is95Hash()
        if(hash95) hash = hash95

        var hashOnline = isOnlineHash()
        if(hashOnline) {
            hash = hashOnline
            microAppId = 'online-web'
            aliasId = 'online-web'
        }
        var hasSmsWeb = isSmsWebHash()
        if(hasSmsWeb) {
            hash = hasSmsWeb === '/' ? hash : hasSmsWeb
            microAppId = 'smsManageWeb'
            aliasId = 'ztIkVM3daLVp22GXpjzf-MDw'
        }
        var hasWorkFolwWeb = isWorkFolwWeb()
        if (hasWorkFolwWeb) {
            microAppId = 'task-center-web'
            aliasId = 'task-center-web'
        }

        var hashGhWeb  = isGhWeb()
        if(hashGhWeb){
            hash = hashGhWeb
        }

        var hashProblemWeb = isProblemWeb()
        if(hashProblemWeb){
            hash = hashProblemWeb
        }

        var hashWelcomeWeb = isWelcomeWeb()
        if(hashWelcomeWeb){
            hash = ''
        }

        var hashZtraceWeb = isZtraceWeb()
        if(hashZtraceWeb){
            aliasId = 'zt2o1y_ydKVoqZVkJJv6bhaQ'
        }

        var hashPath = hash.replace('#','').split('?')[0]
        var pathname = window.location.pathname
        var search = window.location.search
        var isIframe = window.top !== window.self
        var originDomain = window.location.host
        var originFullPath = window.location.href
        var href=''
        var match=false

        var isMobileJump = isMobileModel && hasMobileUpgrade && newTargetDomain

        //被iframe引入时，重定向e-static资源路径。如果为history路由，自动转为hash
        if(isIframe || isMobileJump){
            var _domain = isMobileJump ? newTargetDomain : domain
            href = _domain + 'e-static/'+ microAppId + '/default'
            href += hash ? ('/' + hash) : ('/#'+ pathname + search)
            //慧眼huiyan-manage-static 与 huiyan-online-static 特殊处理
            if(microAppId==='huiyan-manage-static'&& href.includes('/online/')){
                href = href.replace('/huiyan-manage-static/','/huiyan-online-static/')
            }
            if (microAppId === 'billtracing-web') {
                if (href.includes('/#/prod/index.html')) {
                    href = href.replace('/#/prod/index.html', '/prod/index.html')
                } else if (href.includes('/#/prod/indexView.html')) {
                    href = href.replace('/#/prod/indexView.html', '/indexView/index.html')
                }
                href = search ? href + '&dataSource=bill-tracing-web' : href + '?dataSource=bill-tracing-web'
            }
            try{
                zcat.report({appKey: "portal-web-error", url: originDomain})
                zcat.trackEvent('Portal.Proxy', originDomain, originFullPath, href)
            }catch (e) {}
            window.location.href = href
            return
        }
        if(hash){
            //hash路由
            match = isMatchMenu(hashPath, microMenus)
            //匹配菜单成功，跳转门户路径。
            href = (domain + 'e/' + aliasId + hash).replace('#','')
            //慧眼huiyan-manage-static 与 huiyan-online-static 特殊处理
            if(microAppId==='huiyan-manage-static'&& href.includes('/online/')){
                href = href.replace('/huiyan-manage-static/','/huiyan-online-static/')
            }
            if(!match){
                //匹配失败，填充详情参数跳转或跳转门户全部菜单导航
                href = whiteHref(hashPath, microAppId, whiteList, href) || originalMenusPath
            }
        }else{
            //history路由
            match = isMatchMenu(pathname, microMenus)
            if(microAppId = "billtracing-web"){
                if(pathname.includes('prod/indexView.html')){
                    pathname = pathname.replace('prod/indexView.html','indexView/index.html')
                }
                search = search + (search ? '&' : '?') + 'esingle=y&esinglefull=y&eiframe=1'
            }
            //匹配菜单成功，跳转门户路径。
            href = (domain + 'e/'+ aliasId + pathname + search)
            if(!match){
                //匹配失败，填充详情参数跳转或跳转门户全部菜单导航
                href = whiteHref(pathname, microAppId, whiteList, href) || originalMenusPath
            }
        }
        try{
            console.log('Portal.Proxy')
            zcat.report({appKey: "portal-web-error", url: originDomain})
            zcat.trackEvent('Portal.Proxy', originDomain, originFullPath, href)
        }catch (e) {}
        window.location.href = href

        function fillSlash(path) {
            return path && path[0] === '/' ? path : ('/'+path)
        }
        function isMatchMenu(path, microMenus){
            //微应用菜单列表匹配
            var match = microMenus.some((item)=>{
                return path === fillSlash(item)
            })
            return match
        }
        //功能详情页路由处理
        function whiteHref(path, microAppId, whiteList, href){
            var obj = whiteList.find((item)=>{
                return microAppId===item.microAppId && path.startsWith(item.path)
            })
            //填query参数
            if(obj){
                var url = new URL(href);
                var searchParams = new URLSearchParams(url.search);
                var result= []

                if(!searchParams.has("edetail")) result.push('edetail=y')
                if(!searchParams.has("elabel")) result.push('elabel='+encodeURIComponent(obj.elabel))
                if(!searchParams.has("eshareable")) result.push('eshareable='+obj.eshareable)
                if(!searchParams.has("epathcount")) result.push('epathcount='+obj.epathcount)
                if(!searchParams.has("eaddroutes")) result.push('eaddroutes='+obj.eaddroutes)
                if(!searchParams.has("eiframe")) result.push('eiframe='+obj.eiframe)

                href+= result.length>0&&href.includes('?') ? '&':'?'
                href+= result.join('&')
                return href
            }
            return ''
        }
        //95工作台特殊处理
        function is95Hash(){
            if(microAppId !== 'web-95') return ''
            var newHash = ''
            var automap = [{
                oldHash:'#/serviceWorkbench/reception',
                newHash:'#/workbench-reception'
            },{
                oldHash:'#/serviceWorkbench/wiringTable',
                newHash:'#/workbench-wiring'
            },{
                oldHash:'#/serviceWorkbench/callRecords',
                newHash:'#/call-record'
            },{
                oldHash:'#/serviceWorkbench/notification',
                newHash:'#/notice-manage'
            }]

            automap.forEach((item,index)=>{
                if(hash.indexOf(item.oldHash) !== -1){
                    newHash = hash.replace(item.oldHash,item.newHash)
                }
            })

            if(newHash){
                return newHash
            }
        }
        //在线工作台特殊处理
        function isOnlineHash(){
            if(microAppId !== 'cs-web-sdk') return ''
            if(hash.indexOf('charsJs') !== -1){
                return '#/workbench'
            }
        }
        function isSmsWebHash(){
            if(microAppId !== 'sms-web') return ''
            var newHash = '/'
            var automap = [{
                oldHash:'#/mobileSms/sendMsm',
                newHash:'#/send/send-sms'
            },{
                oldHash:'#/mobileSms/sendBulk',
                newHash:'#/send/send-batch'
            },{
                oldHash:'#/sendMessageRecord/smsSendRecord',
                newHash:'#/records/records-message'
            },{
                oldHash:'#/sendMessageRecord/voiceMessageRecord',
                newHash:'#/records/records-voice'
            },{
                oldHash:'#/sendMessageRecord/phoneMessageRecord',
                newHash:'#/records/records-telephone'
            },{
                oldHash:'#/balancePackageManage/buyRecharge',
                newHash:'#/balance/balance-recharge'
            },{
                oldHash:'#/balancePackageManage/myOrder',
                newHash:'#/balance/balance-order'
            },{
                oldHash:'#/balancePackageManage/rechargeRecord',
                newHash:'#/balance/balance-record'
            },{
                oldHash:'#/smsManage/siteSmsBalance',
                newHash:'#/sms/sms-left'
            },{
                oldHash:'#/smsManage/smsNumber',
                newHash:'#/sms/sms-recycle'
            },{
                oldHash:'#/smsManage/exportRecord',
                newHash:'#/records/records-message'
            },{
                oldHash:'#/smsManage/recycleRecord',
                newHash:'#/sms/sms-modify'
            },{
                oldHash:'#/voiceManage/myAccount',
                newHash:'#/voice/voice-myAccount'
            },{
                oldHash:'#/voiceManage/accountAudit',
                newHash:'#/voice/voice-accountAudit'
            },{
                oldHash:'#/voiceManage/accountRecharge',
                newHash:'#/voice/voice-accountRecharge'
            },{
                oldHash:'#/voiceManage/siteVoiceAccount',
                newHash:'#/voice/voice-left'
            },{
                oldHash:'#/voiceManage/distributeRecycle',
                newHash:'#/voice/voice-distribute'
            },{
                oldHash:'#/voiceManage/accountFinancial',
                newHash:'#/voice/voice-accountFlow'
            },{
                oldHash:'#/serviceWorkbench/notification',
                newHash:'#/notice-manage'
            },{
                oldHash:'#/downloadCenter/index',
                newHash:'#/download/download-center'
            },{
                oldHash:'#/callbackBinding/binding',
                newHash:'#/voice/callbackBinding'
            }]

            automap.forEach((item,index)=>{
                if(hash.indexOf(item.oldHash) !== -1){
                    newHash = hash.replace(item.oldHash,item.newHash)
                }
            })

            return newHash
        }
        function isWorkFolwWeb(){
            if(microAppId !== 'workflow-web') return ''
            var replacehashData = [{
                path:'#/task-center',
            },
                {
                    path:'#/approve',
                }]
            var newHash = ''
            replacehashData.forEach((item,index)=> {
                if(hash.indexOf(item.path) !== -1){
                    newHash = true
                }
            })
            return newHash
        }
        function isGhWeb(){
            if(microAppId !== 'work-order-front-gray') return ''
            var newHash = ''
            if(hash === ''){
                newHash = '#/welcome'
            }
            return newHash
        }
        function isProblemWeb(){
            if(microAppId !== 'problem-front') return ''
            var newHash = ''
            if(hash === '' || hash === '#/index') {
                newHash = '#/expressCourier/expressNotFound'
            }
            return newHash
        }

        function isWelcomeWeb(){
            if(microAppId !== 'billing-mangement-system-vue' && microAppId !== 'zto_material_web') return ''
            return hash === '#/welcome' ? '/' : ''
        }
        function isZtraceWeb(){
            if(microAppId !== 'ztrace-web') return ''
            var newHash = ''
            if(hash === '#/home/ztoBillServiceApply') {
                newHash = '/'
            }
            return newHash
        }

    })();
</script>
<body></body>
</html>