

/*
 * 鑾峰彇缁堢鐨勫叿浣撲俊鎭瓨鍦ㄥ叏灞€鍙橀噺mobileOS涓紝闄勪欢鐜妭闇€瑕佷娇鐢�
 */
var mobileOS="";
if(navigator.userAgent.indexOf("Android") >= 0){
    mobileOS="android";
}else if(navigator.userAgent.indexOf("Windows") >= 0){
    mobileOS="Windows";
}else{
    mobileOS="other";
}
/**
 * ajax
 * get sessiondata
 * edit url
 */
var moaBridge = {download:function(params){
        var sessionData;
        if(params.appid !=null && params.appid !=undefined){
            $.ajax({
                type: "get",
                url: "/smapsso/smapMoaSso.do?remoteAppId="+params.appid,
                dataType: "json",async: false ,cache:false,timeout:30000,
                contentType: "application/xml; charset=utf-8",
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    sessionData = "";
                    errorAlert(XMLHttpRequest, textStatus);
                },
                success:function(data){
                    if(data.result = true){
                        sessionData = data.sessionData;
                    }else{sessionData = "";}
                }
            });
        }

        /*
         * url澶勭悊
         * 1銆佹埅鍙�
         * 2銆佽浆鍖栦负澶栫綉瀹㈡埛绔笅杞藉湴鍧€
         */
        //cms-http://cmsuat.cce.hq.cmcc:8101/cms/cms/core/attachment/download//7611A1441F1E173BE0533312180A7A48
        if(params.url.indexOf("/cms/cms/") > -1){
            params.url = params.url.substring(params.url.indexOf("/cms/cms/"),params.url.length) +"&SMAP_SESSION_DATA=" + encodeURIComponent(sessionData);
        }
        //rbs-
        if(params.url.indexOf("/fssc/api/attach/") > -1){
            params.url = params.url.substring(params.url.indexOf("/fssc/api/attach/"),params.url.length) +"&SMAP_SESSION_DATA=" + encodeURIComponent(sessionData);
        }
        //pms
        if(params.url.indexOf("/cpms/file/api/") > -1){
            params.url = params.url.substring(params.url.indexOf("/cpms/file/api/"),params.url.length)+"&sessionData="+encodeURIComponent(sessionData);
        }
        //rms
        if(params.url.indexOf("/rms/file/ext/file/v1/5/v1/file/") > -1){
//		params.url = params.url.substring(params.url.indexOf("/rms/file/ext/file/v1/5/v1/file/"),params.url.length)+"?SMAP_SESSION_DATA="+encodeURIComponent(sessionData);
            //鍙朼ccessToken娣诲姞url鍙傛暟锛孫Auth2.0璁よ瘉
            var accessToken = window.sessionStorage.getItem("accessToken");
            params.url = params.url.substring(params.url.indexOf("/rms/file/ext/file/v1/5/v1/file/"),params.url.length) + "?access_token=" + accessToken;
        }
        //android-ios
        if (mobileOS == "android" || mobileOS == "Windows") {
            url = params.url;
            window.open(url);
        } else {
            url = "/attDetail?test=" + params.url;
            window.location.href = url;
        }
        //window.open(url);
        /*var downloadIframe = document.getElementById('downLoadIframe');
        if (downloadIframe) {
            downloadIframe.src = url;
        } else {
            downloadIframe = document.createElement('iframe');
            downloadIframe.id = 'downLoadIframe';
            downloadIframe.src = url;
            downloadIframe.style.display = "none";
            document.body.appendChild(downloadIframe);
        }*/
    },
    preview:function(){
        window._messageBox('涓嶆敮鎸侀瑙�', '鍏抽棴', {
            confirmButtonText: '纭畾',
            callback: action => {
                this.$message({
                    type: 'info',
                    message: 'action: ${ action }'
                });
            }
        });
    },
    backToHome:function (){
        window.location.href="/vwt_moa/page";
    },
    closeDoc:function(){
        window.location.href="/vwt_moa/page";
    }
}



window.moaBridge = moaBridge;
//moaBridge.download({url:'XXX',fileName:'XXX',uid:'XXX',appod:'ERP-CMS@HQ.CMCC'});


