<!DOCTYPE html>
<html lang="zh">

<head>
  <meta charset="UTF-8"/>
  <title>Access</title>
  <meta name="viewport" content="width=device-width, minimum-scale=0.1">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="/cdn-cgi/access/static_resources/bootstrap-icons/1.8.1/font/bootstrap-icons.css">
  <link rel="stylesheet" href="/cdn-cgi/access/static_resources/bootstrap/5.3.6/css/bootstrap.min.css">
  <script src="/cdn-cgi/access/static_resources/jquery/3.7.1/jquery.min.js"></script>
  <script src="/cdn-cgi/access/static_resources/bootstrap/5.3.6/js/bootstrap.bundle.min.js"></script>
  <script src="/cdn-cgi/access/static_resources/t/font_1991031_a241no7pxi.js"></script>

  <script src="/cdn-cgi/access/static_resources/static/i18n.js"></script>
  <script src="/cdn-cgi/access/static_resources/static/loading.js"></script>
  <link rel="stylesheet" href="/cdn-cgi/access/static_resources/static/loading.css">
  <link rel="icon" id="page-icon" href="">
  <style>
    * {
     margin: 0px;
     padding: 0px;
     box-sizing: border-box;
     font-family: sans-serif;
   }

::-webkit-scrollbar {
	width: 3px;
}
::-webkit-scrollbar-track {
	border-radius: 3px;
}
::-webkit-scrollbar-thumb {
	border-radius: 3px;
	height: 3px;
	background-color: #ccc;
}
html{
  width: 100%;
  height: 100%;
}

   body {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
     /* height: 100vh; */
     /* overflow: hidden; */
   }

   .alert-danger {
    position: absolute;
    top: 0;
    left: 0;
    padding: 8px 0;
    font-size: 12px;
    border: none;
    background: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(255, 75, 76, 1), rgba(0, 0, 0, 0));
    width: 100%;
    height: 36px;
    z-index: 6;
   }

   .alert-danger.login {
    position: relative;
    padding: 8px 0;
    font-size: 14px;
    border: none;
    background: transparent;
    color: rgba(255, 75, 76, 1);
    width: 100%;
    height: 36px;
    z-index: 6;
   }

   .alert-ok {
     padding: 8px 0;
     font-size: 12px;
     border: none;
     background: linear-gradient(to right, rgba(0, 0, 0, 0), #5FC97C, rgba(0, 0, 0, 0));
   }

   .BtnSend {
     position: absolute;
     right: 8px;
     top: 8px;
     font-size: 14px;
     color: #bbb;
     z-index: 999;
   }

   .navbar {
     display: block;
     position: absolute;
     top: 12px;
     left: 24px;
     right: 24px;
   }

   .logo {
     /* width: 110px; */
     height: 110px;
   }

   @media (max-width: 768px) {
     .navbar {
       text-align: center;
     }
   }

   .bgimg {
     position: fixed;
     top: 0;
     left: 0;
     width: 100%;
     height: 100%;
     z-index: -10;
     zoom: 1;
     background-color: #fff;
     /* background: url("YUNDUN_ACCESS_HOLDER_BG") no-repeat; */
     background-repeat: no-repeat;
     background-size: cover;
     -webkit-background-size: cover;
     -o-background-size: cover;
     background-position: center 0;
   }

   body {
     /* position: relative; */
     background-color: #fff;
     background-size: cover;
     -webkit-background-size: cover;
     -o-background-size: cover;
     background-position: center 0;
   }

   .main {
    position: relative;
    border-radius: 8px;
    border-top: 4px solid rgba(0, 120, 255, 1);
    background-color: rgba(255, 255, 255, .94);
    backdrop-filter: blur(5px);
    min-height: 320px;
    margin: 0 auto;
    margin-top: 160px;
    z-index: 4;
    padding: 0 24px 36px;
    overflow: auto;
    width: 640px;
    height: calc(100vh - 260px);;
    /* max-height: 600px; */
    background-color: linear-gradient( 90deg, rgba(255,255,255,.94) 0%, rgba(237,240,245,.94) 100%);
    box-shadow: 0px 6px 18px 0px rgba(41,113,222,0.2);
    background-image: url('/cdn-cgi/access/static_resources/images/ztna_bl.png');
    background-size: 346px 320px;
    background-repeat: no-repeat;
    background-position: right top;
   }
   .main#YunAdLoginCard {
    height: auto;
    max-height: 600px;
   }

   .main#AppListCard{
    max-height: 600px;
   }
   @media (max-width: 768px) {
     .main {
       margin-top: 140px;
       position: relative;
     }
   }

   .input-group-append {
     height: 32px;
     line-height: 32px;
   }

   .input-group-append .btn {
     line-height: 20px;
     outline: none;
     border: 1px solid #ced4da;
     border-left: none;
   }

   .btn-outline-secondary {
     color: #333;
     outline: none;
   }

   .btn-outline-secondary:hover {
     background: none;
     color: #333;
     outline: none;
     border: none;
   }

   .main-error {
     position: relative;
     display: flex;
     justify-content: center;
     align-items: center;
     flex-direction: column;
   }

   .BackBtn {
     display: block;
     margin-top: 30px;
   }

   .main-error .BackBtn {
     position: absolute;
     bottom: 16px;
   }

   .main-error .icon {
     width: 32px;
     margin-right: 12px;
   }

   .main-error .title {
     font-size: 20px;
     margin-top: -16px;
   }

   .main-form {
     max-width: 290px;
     margin: 0 auto;
   }

   .main-first {
     text-align: center;
     display: flex;
     flex-direction: column;
     align-items: center;
     justify-content: center;
   }

   .main-first {
     border: none;
     background: none;
     backdrop-filter: none;
     box-shadow: none;
   }


   @media (min-width: 768px) {}

   .main h1 {
     margin-bottom: 35px;
     font-size: 28px;
     font-weight: 300;
   }

   @media (max-width: 768px) {
     .main h1 {
       font-size: 22px;
       font-weight: 400;
     }
   }

   .el-divider--horizontal {
     display: flex;
     height: 1px;
     width: 100%;
     margin: 0px 0 42px 0;
   }

   .el-divider {
     position: relative;
     margin-left: auto;
     margin-right: auto;
     max-width: 480px;
   }

   .el-divider .line {
     flex: 1;
     height: 1px;
     background-color: #dcdfe6;
   }

   .el-divider__text {
     /* position: absolute; */
     margin: 0 20px;
     margin-top: -10px;
     font-weight: 400;
     color: #333;
     font-size: 14px;
   }

   .el-divider__text .loginType {
     margin-top: -12px;
   }

   .card {
     background: rgba(255, 255, 255, .9);
     width: 100%;
     padding: 0px;
     border-radius: 5px;
     border-top: 1px solid #0078FF;
     padding: 12px;
     flex-direction: row !important;
     text-align: center;
     justify-content: center !important;
     margin-bottom: 12px;
   }

   .loginType {
     display: flex;
     align-items: center;
     justify-content: center;
     color: #333;
     font-weight: 400;
   }
   .loginType:hover {
    color: #333;
    text-decoration: none;
   }

   .loginType-icon {
     margin-right: 8px;
     width: 45px;
     height: 45px;
   }

   .loginType-item {
     max-width: 420px;
     margin-left: auto;
     margin-right: auto;
     background: #fff;
     display: flex;
     align-items: center;
     justify-content: center;
     border: 1px solid #eee;
     border-radius: 6px;
     padding: 10px;
     margin-bottom: 6px;
     cursor: pointer;
     transition: .4s;
   }

   .loginType-item:hover{
    border: 1px solid #007bff;
   }

   .loginType-item img {
     width: 42px;
     height: 42px;
   }

   .loginType-item:hover a {
     text-decoration: none;
   }

   .loginType-item-title {
     text-decoration: none;
     color: #333;
     line-height: 38px;
     margin-left: 12px;
     /* width: 160px; */
     text-align: left;
     overflow: hidden;
     text-overflow: ellipsis;
     white-space: nowrap;
     font-size: 14px;
   }

   .loginType-item-icon{
    width: 32px;
    height: 32px;
   }

   .inner_hold {
     width: 100%;
     height: 100%;
     float: left;
     display: block;
   }

   .inner_block {
     border-width: 1px;
     border-color: rgb(233, 237, 241);
     border-style: solid;
     border-radius: 2px;
     background-color: rgb(255, 255, 255);
     float: left;
     width: 206px;
     height: 72px;
     z-index: 11;
     margin-right: 8px;
     margin-left: 8px;
     margin-bottom: 16px;
     line-height: 72px;
     font-size: 16px;
     font-weight: 300;
     transition: all .3s ease;
   }

   .solgon {
     position: absolute;
     left: 0px;
     top: 260px;
     width: 100%;
     height: 120px;
     text-align: center;
     padding-top: 28px;
   }

   .solgon span {
     font-size: 44px;
     background: linear-gradient(to right, #353536, #666666, #353536);
     -webkit-background-clip: text;
     color: transparent;
     font-weight: 500;
     letter-spacing: 2px;
     width: 100%;
     display: block;
   }

   .btn_m {
     position: absolute;
     left: 0px;
     top: 340px;
     width: 100%;
     height: 120px;
     text-align: center;
     padding-top: 28px;
   }

   .footer {
     position: absolute;
     bottom: 0px;
     width: 100%;
     padding: 18px 0;
     font-size: 12px;
     text-align: center;
   }

   .login_bt {
     padding: 100px;
     width: 400px;
   }

   @media (max-width: 768px) {
     .main {
       width: 100%;
       max-height: 600px;
       position: relative;
     }

     .main#YunAdLoginCard, .main#AppListCard{
      /* height: auto; */
      max-height: 600px;
    }
   }

   .btn {
    width: 290px;
    height: 50px;
    background: #0078E6;
    border-radius: 6px;
    position: relative;
    color: #fff;
    font-size: 16px;
    background-color: rgb(0, 120, 230);
    overflow:hidden;
    text-align:center;
    font-family: sans-serif;
    transition: 0.2s;
  }
  .mask {
    position: absolute;
    height: 100%;
    background-color: #fff;
    opacity: 1;
  }
  .mask-1 {
    left: 50%;
    top: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
  }
  .btn:hover{
    background-color: rgb(0, 132, 246);
    box-shadow: 0px 8px 24px 0px rgba(46, 126, 236, 0.6);
    cursor:pointer;
    border: none;
  }
  .btn:active{
    box-shadow:none;
    background-color: rgb(0, 116, 222);
  }
  .btn.disabled{
    background: #EFEFEF;
    border-radius: 6px;
    font-size: 16px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #BBBBBB;
    border: none;
  }
  .btn.disabled:hover{
    background-color: none;
    box-shadow: none;
    cursor:pointer;
    border: none;
  }
  .btn.disabled:focus{
    background-color: none;
    box-shadow: none;
    cursor:pointer;
  }
  .btn.disabled:active{
    background-color: none;
    box-shadow: none;
    cursor:pointer;
  }
  .btn:active .mask-1 {
    animation-name: btn-on;
    animation-duration: 1.6s;
  }
  @keyframes btn-on {
    from {
      width: 1px;
      height: 1px;
      transform: scale(0);
      opacity: .3;
    }
    to {
      width: 290px;
      height: 290px;
      transform: scale(100);
      opacity: 0;
    }
  }

  /* 覆盖 bootstrap */
  .form-group input{
    width: 290px;
    height: 50px;
    /* padding: 0 73px; */
    background: #FFFFFF;
    border: 1px solid #D2D9E3;
    border-radius: 6px;
    font-size: 14px;
    text-align: left;
  }
  .form-group input:focus{
    background: #FFFFFF;
    border: 1px solid #2971DE;
    box-shadow: none;
    border-radius: 6px;
  }

  .applist-disabled {
    pointer-events: none;
  }
  .applist-cursor {
    cursor: not-allowed;
  }
</style>
</head>

<body id="bodyid">
  <navbar class="navbar">
    <img class="logo" id="page-logo" src="" alt="">
  </navbar>

  <div class="container">
    <div class="main main-error" style="display: none;" id="AppError">
      <div>
        <img class="icon" src="https://yundun-statics.yundun.com/lock.png" alt=""><span class="title" id="AppErrorText"></span>
      </div>
      <a id="BackBtn" class="BackBtn"><span id="i18n_return">返回</span></a>
    </div>

    <div class="main main-first" id="AppFirst" style="display: none;">
      <h1 class="title" id="page-title"></h1>
      <button id="StartBtn" style="width:230px; padding:10px;border-radius: 2px;" onclick="fetchAppList()" type="button"
        class="btn btn-primary login_bt"> <span id="i18n_login">登录</span> <i class="bi bi-arrow-right"></i></button>
    </div>

    <div class="main" style="text-align: center;height: 442px;" id="AppListCard">
      <h1 id="app-list-title" style="padding-top:36px;font-size: 20px;font-weight: 500;"></h1>
      <div class="el-divider el-divider--horizontal">
        <div class="line"></div>
        <div class="el-divider__text"><span id="i18n_login_method">请选择登录方式</span></div>
        <div class="line"></div>
      </div>
      <div class="card-login">
        <div class="" style="padding: 0px">
          <div id="app-list-alert" class="alert alert-small alert-danger" role="alert"></div>
          <form class="form-login">
            <div id="AppList" style="margin:0px;">
            </div>
          </form>
        </div>
      </div>
    </div>

    <div class="main" id="YunAdLoginCard" style="display:none; text-align: center">
      <!-- <div id="yun-ad-alert" class="alert alert-small alert-danger" role="alert" style="display: flex;justify-content: center; align-items: center;">
        <img src="/cdn-cgi/access/static_resources/images/icon_error.png" style="width: 14px;height:14px;margin-right: 8px" alt="icon_error">
        <div id="yun-ad-alert-text" style="color: white;"></div>
      </div> -->
      <h1 style="margin-bottom: 36px;padding-top:36px;font-size: 20px;font-weight: 500;" id="yun-ad-title" ></h1>
      <div class="el-divider el-divider--horizontal">
        <div class="line"></div>
        <div class="el-divider__text">
          <a class="loginType" style="margin-bottom: 12px">
            <img class="loginType-icon" id="idp-logo" src="" alt="">
            <span class="loginType-title" id="idp-title"></span>
          </a>
        </div>
        <div class="line"></div>
      </div>
      <div class="main-form">
        <div class="form-group">
          <input class="form-control" id="yun-ad-username" placeholder="用户名/邮箱/手机号">
        </div>
        <div class="form-group">
          <input class="form-control" type="password" id="yun-ad-password" placeholder="密码">
          <input style="display: none" id="action">
        </div>
        <div id="yun-ad-alert" class="alert alert-small alert-danger login" role="alert" style="display: flex;justify-content: center; align-items: center;">
          <!-- <img src="/cdn-cgi/access/static_resources/images/icon_error.png" style="width: 14px;height:14px;margin-right: 8px" alt="icon_error"> -->
          <div id="yun-ad-alert-text"></div>
        </div>
        <!-- <button id="YunAdSubmitBtn" type="submit" style="margin-top: 20px;"
          class="btn btn-primary btn-block">登录</button> -->
          <button style="margin: 30px 0 43px 0;" id="YunAdSubmitBtn" style="position:relative" type="submit" class="btn btn-primary btn-block"><img id="loading" style="width: 19px;height: 19px;margin-right: 8px" src="/cdn-cgi/access/static_resources/images/icon_loading.png" alt="icon_loading"><span id="YunAdSubmitBtnText">登录</span><span class="mask mask-1"></span></button>
          <div>
            <a id="resetPassword" href="" style="font-size: 14px;"><span id="i18n_forgot_password">忘记密码？</span></a>
          </div>
      </div>
      <!-- <a id="BackBtn" class="BackBtn"><i class="bi bi-arrow-left"></i> 返回</a> -->
    </div>

  </div>
  <div class="footer">
    <span id="copyright"></span>&nbsp;
    <span><a target="_blank" href="https://beian.miit.gov.cn/#/Integrated/index" id="icp_record"></a></span>&nbsp;
    <span id="police_record"></span>
  </div>
  <div class="bgimg" id="bgimg"></div>

  <script>
    var access_config = {"auto_style":"","page_title_color":"#333333","bgimg_url":"https:\/\/yundun-statics.yundun.com\/BaiShan_access_default_bg.png","login_mode":0,"icon":"https:\/\/yundun-statics.yundun.com\/1633948651616413ebd8b33-jpg","resetPasswordUrl":"https:\/\/sdwan-as.console.baishan.com\/zt-reset-password\/#\/captcha?realm_id=70f13972-d8d2-a8c2-d600-4d65dc820100","title":"Baishan Cloud Zero Trust Access","timestamp":0,"social_idp":{"da3cea85a5cd71a1fb4fab953d02eb29":{"name":"企业微信","redirectUrl":"https:\/\/baishan.yundun-access.com\/cdn-cgi\/access\/callback","meta":"8C4J5hXZifcZaNZA3Swrd4IkoTjYPakElIjZjJzod3Okbkfbf1Ru-4JmdEFz439sEn3mvK8LjtOVBU3K6PjwOP09qSjoWUHaw-BlD5i3Xra50HilM1Kn1AZMqQz9S4euWyQdUbdJu76LtsTFp2lfUANO1oaRi9kupany9lz-UEHKRSaeT-Bq-GRn188DHjp7M20iaVty31CGVzB9HxpQCx_jQmfA2lbm_ZLnbKjNb_F4gAb7h4LMm-sgtJSHHl-tMGy4ju9e1lXN6eKX7r0zNQJHIjbka0BeDIQ-MeUW33iOShVSgm68tsXJzdIxF2ZK8BgquTznQC1QBR-GoLDXaEoD14ayAjtdSwZHaa8haq6qDDhRZ5Lpvm5Xbig8BZJ4R83DRnKcRXHHGqfOtJjwvNLvQMpyGVj5BVYB9nd9tVHfJu2j61JkzTgAGn4Moni7ivXce4lzSTETVKheRCMumra5fPUK-Cq0VYBJTfWZ0-8","agentId":"1000027","idpId":"da3cea85a5cd71a1fb4fab953d02eb29","schema":"wwauthc9f52c6b045aebdb000027","type":"wechat-work","corpId":"wxc9f52c6b045aebdb"}},"icp_record":"Shanghai ICP No. 11032572-9","police_record":"Shanghai Public Network Security No. 31011202001043","ztconfig":true,"logo_type":0,"enable_notification":0,"login_url":"https:\/\/baishan.yundun-access.com\/cdn-cgi\/access\/login_canvas?redirect_uri=https%3A%2F%2Fdummy-app-launcher-uri&meta=8a7ExPUSguCpL94-MGbXaeLkQXbAsHl9dG-uCXRizmTCcz-s4JI2ZnOs4wbMnLmmDiI_SGQWF6hwQpNIrDDwkmzuRIJkLIThFeYmYjRvsIGa31xDFrURYTxS30v3vCTeZJ8aoFiB88JPWnGVdd-0R5F3-gEUA8KZ_EkNqaio4YE&nonce=722c36868228607dbf390eed197211de","idp_logo":"https:\/\/yundunarticle.yundun.com\/zerotrust_yun_ad.png","logo":"https:\/\/yundun-statics.yundun.com\/1633948651616413ebd8b33-jpg","copyright":"Copyright@2022 YUNDUN,All Rights Reserved Shanghai Yundun Information Technology Co., Ltd. All rights reserved","lang":"en","idp_title":"Cloud AD"};
    //设置内容
    $("title").text(access_config.title);
    $("#page-icon").attr("href",access_config.icon);
    $("#page-logo").attr("src",access_config.logo);
    $("#bodyid").attr('style',access_config.auto_style);
    $("#page-title").text(access_config.title);
    $("#page-title").css({color:access_config.page_title_color});
    $("#app-list-title").text(access_config.title);
    $("#app-list-title").css({color:access_config.page_title_color});
    $("#yun-ad-title").text(access_config.title);
    $("#yun-ad-title").css({color:access_config.page_title_color});
    $("#copyright").text(access_config.copyright);
    $("#icp_record").text(access_config.icp_record);
    $("#police_record").text(access_config.police_record);
    $("#bgimg").css('background-image', 'url('+access_config.bgimg_url+')');
    $("#idp-logo").attr("src",access_config.idp_logo);
    $("#idp-title").text(access_config.idp_title);
    $("#resetPassword").attr("href",access_config.resetPasswordUrl+"&bcc_lang="+window.get_i18n());


    //i18n
    $("#i18n_return").text(window.access_geti18n("Return"));
    $("#i18n_login").text(window.access_geti18n("Log in"));
    $("#i18n_login_method").text(window.access_geti18n("Log in method"));
    $("#i18n_forgot_password").text(window.access_geti18n("Forgot your password?"));
    $("#YunAdSubmitBtnText").text(window.access_geti18n("Log in"));
    $("#yun-ad-username").attr("placeholder",window.access_geti18n("Username/Email/Mobile"));
    $("#yun-ad-password").attr("placeholder",window.access_geti18n("Password"));


    $('#AppListCard').hide()
    $('#YunAdLoginCard').hide()
    $('#YunAdCodeCard').hide()
    $('#loading').hide()


    $('#BackBtn').click(function () {
      $('#SelectMethods').show()
      $('#LoginForm').hide()
      $('#AppError').hide()
    })

    $('#yun-ad-alert').hide()
    $('#app-list-alert').hide()


    function showAppError(text) {
      $('#AppErrorText').text(text)
      $('#AppError').show()
      $('#YunAdLoginCard').hide()
      $('#YunAdCodeCard').hide()
      $('#AppListCard').hide()
      $('#AppFirst').hide()

    }

    function hideAppListAlert() {
      $('#app-list-alert').hide()
    }

    function showYunAdAlert(text) {
      $('#yun-ad-alert-text').text(text)
      $('#yun-ad-alert').removeClass("alert-ok");
      $('#yun-ad-alert').addClass("alert-danger");
      $('#yun-ad-alert').show()
    }

    function showYunAdAlertOk(text) {
      $('#yun-ad-alert-text').text(text)
      $('#yun-ad-alert').removeClass("alert-danger");
      $('#yun-ad-alert').addClass("alert-ok");
      $('#yun-ad-alert').show()
    }

    function hideYunAdAlert() {
      $('#yun-ad-alert').hide()
    }

      var social_idp =access_config.social_idp
      var login_mode = access_config.login_mode; // 1 bcc
      if(login_mode==1){
        /**
         *iOS 专用方法
         */
         function setupWebViewJavascriptBridge(callback) {
            if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
            if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
            window.WVJBCallbacks = [callback];
            var WVJBIframe = document.createElement('iframe');
            WVJBIframe.style.display = 'none';
            WVJBIframe.src = 'https://__bridge_loaded__';
            document.documentElement.appendChild(WVJBIframe);
            setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
        }
        setupWebViewJavascriptBridge(function(bridge) {
              //给iOS 注册方法
              bridge.registerHandler('appLoginCallback', function(callbackData, responseCallback) {
              //console.log('appLoginCallback responding with : '+ callbackData)
              var callbackDataObj = JSON.parse(callbackData);
              //处理回调
              appLoginCallback(callbackDataObj.type, callbackData)
              //给iOS 的响应
              responseCallback(callbackData.errCode)
            })

            window.iOSIsInstall = function(idpType, divId, auto_redirect,link) {
              bridge.callHandler('isInstallV2', {'type': idpType }, function(response) {
                var responseObj = JSON.parse(response);
                var installStatus = responseObj.errCode == 0;
                if(auto_redirect && installStatus) {
                  launchAppLogin(divId);
                }else if(auto_redirect && !installStatus && "" != link){
                  //未安装则跳转
                  window.location.href=link
                }
                if(installStatus){
                  $("#"+divId).attr("data-link","javascript:launchAppLogin(\""+divId+"\")");
                }
              })
              return true;
            }

            window.iOSLaunchAppLogin = function(idpConf) {
              bridge.callHandler('launchAppLoginV2', idpConf, function(response) {
                console.log('launchAppLogin got response: ', response)
              })
            }

            window.iOSLoginPrepare = function() {
              bridge.callHandler('loginPrepare', {'loginVersion': 2}, function(response) {
                console.log('loginPrepare got response: ', response)
              })
            }

        })

      }




    $(document).ready(function () {
      isHideFooter()
      fetchAppList()
    });
    function onEnter(e) {
      if(e.keyCode === 13) {
          fetchYunAdLogin()
        }
    }

    // 移动端隐藏footer
    function isHideFooter(){
        if(window.navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)) {
          $('.footer').hide()
        }
    }

    function fetchAppList() {
      $('#StartBtn').hide()
      $('#YunAdLoginCard').hide()
      $('#YunAdCodeCard').hide()
      $('#AppListCard').show()

      $.ajax({
        type: "GET",
        url: access_config.login_url,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (res) {

            if(res.auto_redirect){
              //移动端直接拉起
              if (login_mode==1 && (res.type=="wechat-work" || res.type=="dingtalk" || res.type=="feishu") && res.id != undefined ){
                $('#YunAdLoginCard').hide()
                $('#YunAdCodeCard').hide()
                $('#AppListCard').hide()
                //显示loading
                loading.showLoading()
                isInstallApp(res.type,res.id,true,res.auto_redirect)
              }else{
                //PC 跳转
                window.location.href=res.auto_redirect
              }
            }else if(res.redirect_uri){
                window.location.href=res.redirect_uri
            }else{
              handleInit(res)
            }

        },
        error: function (res) {
          if(res.responseJSON != undefined) {
              if(res.responseJSON.hideback) {
                $('#BackBtn').hide()
              }
              showAppError(res.responseJSON.msg)
          }
        }
      });
    }

    var isAndroid =  window.bccJsBridge != undefined
    var isIOS =  window.WebViewJavascriptBridge != undefined || window.WVJBCallbacks != undefined
/*
*解析登陆渠道列表
*/
    var currentXLink = "";
    var verifyYunADUrl = "";
    function handleInit(appList) {
      //判断云AD是否唯一认证源
      if(appList.length==1 && appList[0].type=="yun_ad"){
        if (appList[0].platform != "lite") {
            $('#YunAdLoginCard').show()
            $('#YunAdCodeCard').hide()
            $('#AppListCard').hide()
            window.addEventListener('keydown',onEnter)
        } else {
            window.location.href=appList[0].link
        }
      }

      var tpl = ''
      appList.forEach(function (item) {
        item.xlink = item.link;
        if (item.type=="yun_ad" && item.platform != "lite"){
          $("#bodyid").attr('style',"display: block;");
          verifyYunADUrl = item.link
        }
        else if (login_mode==1 && (item.type=="wechat-work" || item.type=="dingtalk" || item.type=="feishu")){
          var status = isInstallApp(item.type,item.id,false,"")
          if(status && isAndroid){
            item.link = "javascript:launchAppLogin(\""+item.id+"\")";
          }
        }
        tpl += " \
        <div class='col-12'> \
          <div onclick='handleClickLoginType(this)' class='loginType-item' id ='"+item.id+"'  data-type='"+item.type+"'  data-platform='"+item.platform+"' data-link='"+item.link+"' data-xlink='"+item.xlink+" '> \
            <img class='loginType-item-icon' src='"+item.src+"' alt=''> \
            <span class='loginType-item-title'> \
              "+item.title+" \
              </span> \
              </div> \
              </div> \
              ";

      });
      $("#AppList").html(tpl);



    }



    /*
    *云AD 登陆相关
    */
    $("#YunAdSubmitBtn").on('click', fetchYunAdLogin)
    function handleClickLoginType(item) {
      $('.col-12').addClass("applist-cursor")
      $('.loginType-item').addClass("applist-disabled")

      var type = $(item).attr('data-type')
      var link = $(item).attr('data-link')
      var platform = $(item).attr('data-platform')
      currentXLink = $(item).attr('data-xlink')
      if (type === 'yun_ad' && platform != "lite") {
        $('#YunAdLoginCard').show()
        $('#YunAdCodeCard').hide()
        $('#AppListCard').hide()
        window.addEventListener('keydown',onEnter)
      } else {
        window.location.href=link
      }

      setTimeout(function() {
        $('.col-12').removeClass("applist-cursor")
        $('.loginType-item').removeClass("applist-disabled")
      }, 5000)
    }

    $('#BackBtn').on('click', function () {
      $('#YunAdLoginCard').hide()
      $('#YunAdCodeCard').hide()
      $('#AppListCard').show()
    })

    function fetchYunAdLogin() {
      $('#yun-ad-alert').hide()
      var username = $('#yun-ad-username').val();
      var password = $('#yun-ad-password').val();
      if (!password) {
        showYunAdAlert(window.access_geti18n("The password cannot be empty"))
        return;
      }
      if (!username) {
        showYunAdAlert(window.access_geti18n("The username cannot be empty"))
        return;
      }
      // $('#YunAdSubmitBtnText').text('正在登录')
      $('#YunAdSubmitBtnText').text(window.access_geti18n("Logging in"))
      $('#YunAdSubmitBtn').addClass("disabled");
      $('#loading').show();
      $.ajax({
        type: "POST",
        url: verifyYunADUrl,
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify({ username: username.trim(), password: password.trim(), action: action }),
        dataType: "json",
        success: function (resp) {
          if (resp.status == 0) {
            showYunAdAlertOk(resp.msg)
            window.location.href = resp.redirect_uri
          } else if (resp.status == 1) {
            showYunAdAlert(resp.msg)
            $('#action').val(resp.action)
          } else {
            showYunAdAlert(resp.msg)
          }
        // $('#YunAdSubmitBtnText').text('登录')
        $('#YunAdSubmitBtnText').text(window.access_geti18n("Log in"))
        $('#YunAdSubmitBtn').removeClass("disabled");
        $('#loading').hide();
        },
        error: function (resp) {
          // showYunAdAlert('后台服务器错误')
          showYunAdAlert(window.access_geti18n("Server error"))
          // $('#YunAdSubmitBtnText').text('登录')
          $('#YunAdSubmitBtnText').text(window.access_geti18n("Log in"))
          $('#YunAdSubmitBtn').removeClass("disabled");
          $('#loading').hide();
          return;
        }
      })
    }

    /**
     * 判断客户端是否安装
     */
    var isAndroid =  window.bccJsBridge != undefined
    var isIOS =  window.WebViewJavascriptBridge != undefined || window.WVJBCallbacks != undefined
    function isInstallApp(idpType,idpId,auto_redirect,link) {
      if(isAndroid){
        window.bccJsBridge.loginPrepare(JSON.stringify({'loginVersion': 2}))
        var status =  window.bccJsBridge.isInstallV2(JSON.stringify({'type': idpType }))
        if(auto_redirect && status) {
          launchAppLogin(idpId);
        }else if(auto_redirect && !status && "" != link){
            //未安装则跳转
            window.location.href=link
        }
        return status
      }
      else if(isIOS && window.iOSIsInstall != undefined ){
        window.iOSLoginPrepare()
        return window.iOSIsInstall(idpType,idpId,auto_redirect,link)
      }
      else if(auto_redirect ){
            //pc 客户端拉起
            window.location.href=link
      }
      return false
    }
    /**
     * 拉起客户端
     */
    function launchAppLogin(idpId) {
      var idpConf = social_idp[idpId]
      if(isAndroid){
        window.bccJsBridge.launchAppLoginV2(JSON.stringify(idpConf))
      }
      else if(isIOS){
        window.iOSLaunchAppLogin(idpConf)
      }
    }

    /**
     * 客户端回调方法
     */
    function appLoginCallback(idpType, callbackData) {
      //显示loading
      loading.showLoading()
      var callbackDataObj = JSON.parse(callbackData);
      if(callbackDataObj.errCode != 0){
        // window.location.href = '/cdn-cgi/access/error?txt='+encodeURIComponent('客户端拉起第三方登录异常，请稍后重试')
        window.location.href = '/cdn-cgi/access/error?txt='+encodeURIComponent(window.access_geti18n("Failure to launch the third party login, please retry later"))
        //隐藏loading
        loading.hideLoading()
        return;
      }
      $.ajax({
        type: "POST",
        url: "/sase/client/social_login",
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify({ type: idpType, code: callbackDataObj.data.code, meta: callbackDataObj.data.meta, idpId: callbackDataObj.data.idpId, deviceType: (isAndroid?"android":"ios") }),
        dataType: "json",
        success: function (resp) {
          if (resp.status == 0) {
            window.location.href = resp.redirect_uri
            //隐藏loading
            loading.hideLoading()
          } else {
            if(resp.msg != undefined ){
              var error_txt = resp.msg
              window.location.href = '/cdn-cgi/access/error?txt='+encodeURIComponent(error_txt)
            }
            //隐藏loading
            loading.hideLoading()
          }
        },
        error: function (resp) {
            // window.location.href = '/cdn-cgi/access/error?txt='+encodeURIComponent('第三方登录异常，请稍后重试')
            window.location.href = '/cdn-cgi/access/error?txt='+encodeURIComponent(window.access_geti18n("Third party login error, please retry later"))
          //隐藏loading
          loading.hideLoading()
          return;
        }
      })

    }

    // 检测登录超时
    if(access_config.timestamp != undefined && access_config.timestamp > 0){
      var overtime = access_config.timestamp + 600 * 1000 - new Date().getTime();
      setTimeout("login_timeout()",overtime>0?overtime:100);
    }
    function login_timeout(){
      window.location.href = "/sase/client/login_timeout";
    }

    // 禁止输入空格
    $('input').on('keydown', function(event) {
      if (event.which === 32) {
        event.preventDefault();
      }
    });

  </script>
</body>

</html>
