<sctipt src='https://code.jquery.com/jquery-3.4.1.min.js'></script>
$(function(){
document.cookie="name-zp";//登录用户名保存 下面是后端提供给你的uuid、token、需要跳转的目标url、获取后端code数据的url
var appId = 'ICECLDAS-E9MQ-VEHV-OP47-71X59JA7TAJP',
client_secret = 'UePEO6o6Keou6jYmJHDw',
redirect_url = encodeURI('https://-data.colourlife.com/wp/dist/midea_report/html/home.html#/login?'),
baseUrl = 'https://oauth-.colourlife.com/web/auth/authorize?';
let url = window.localtion.href;//获取地址
let urlParams = GetReques(url);//调网址解析函数,获取相关数据
let isSode = urlParams.hasOwnProperty('code');
var name_token = ‘’ //获取cookie
if(! name_token){//进入说明没有登录
if(!urlParams.hasOwnProperty('code')){//进入说明不是扫码跳转回来的
let geturl = baseUrl+'source=cgj&scopes=[]';
geturl += '&app_id='+appId;
geturl += '&client_secret='+client_secret;
geturl += '&redirect_uri='+redirect_uri;
window.location.href = baseUrl + geturl;
}else{ //根据code获取name_token }
}
})
//网址解析函数:
function GetRequest(urlStr){
if(typeof urlStr == 'undefind'){
let url = decodeURI(location.search);//获取url中的“?” 后的查询串
}else{
let url = "?" + urlStr.split("?")[1];
}
let theRequest = new Object();
if(url.indexOf("?") != -1){
let str =url.substr(1);//截取一份
let strs = str.split('&');//转成数组
for(var i = 0;i <strs.length; i++){//遍历strs
theRequest[strs[i].split('=')[0]] = decodeURI(strs[i].split("=")[1]);
}
}
return theRequest;
}