单页面登录——编码传参(oa会对#号会进行截断)

/**
 * querystring有四种方法:注意queryString与query-string不是同一个依赖包
 *  querystring.stringify 序列化;
 *  querystring.parse 反序列化;
 *  querystring.escape 编码;//encodeURIComponent(),不使用escape()只编译汉字,encodeURI()不编译特殊符号
 *  querystring.unescape 解码;//decodeURIComponent,对应:unescape()、decodeURI()
 *query-string:字符串与对象互转(简写qs)
 *  qs.stringify:{foo: false}//=> 'foo=false'
 *  qs.parse:'likes=cake&name=bob&likes=icecream'//=> {likes: ['cake', 'icecream'], name: 'bob'}
 */

【清除本地缓存】:

let keys = document.cookie.match(/[^ =;]+(?==)/g);//清除当前域名下cookie
if (keys) {
  for (let i = keys.length; i--;) {
    document.cookie = keys[i] + '=0;path=/;expires=' + new Date(0).toUTCString();//清除当前域名下的cookie,例如:kp.oa.com
    document.cookie = keys[i] + '=0;path=/;domain=' + document.domain + ';expires=' + new Date(0).toUTCString();//清除当前域名下的,例如 .kp.oa.com
    document.cookie = keys[i] + '=0;path=/;domain=kevis.com;expires=' + new Date(0).toUTCString();//清除一级域名下的或指定的,例如 .oa.com
  }
}
localStorage.removeItem("usern"); //清除本地用户信息
this.$store.dispatch("setUserCurinfo", null);//清除

let authObj = {
protocol: 'http:',
host: 'passport.oa.com',
pathname: '/modules/passport/signin.ashx',
query: {
url:`${location.href}`
}
};
console.log(`http://passport.oa.com/modules/passport/signout.ashx?url=${location.href}&title=HADES`,"模板字符串")
import _url from "url";
console.log(_url.format(authObj),"模板字符串")
注意点:oa系统不识别#后面的值,需要改变路由模式。
原文地址:https://www.cnblogs.com/wheatCatcher/p/10496558.html