You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
/**
|
|
|
|
|
* Cookie类,用于网络中cookie的各类操作
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
export class Cookie{
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* example: "autologin_trustie=8acaa2b09d5056c0e9d82519052276b9d4a524e9; domain=.educoder.net ; path=/; expires=Fri, 29 Nov 2019 15:32:53 -0000; HttpOnly"
|
|
|
|
|
*/
|
|
|
|
|
constructor(str){
|
|
|
|
|
this.origin_str = str;
|
|
|
|
|
this.analyse_cookie(str);
|
|
|
|
|
}
|
|
|
|
|
analyse_cookie(str){
|
|
|
|
|
this.string = str.slice(0, str.indexOf(";"));
|
|
|
|
|
//console.log(this.string);
|
|
|
|
|
let idx = this.string.indexOf("=");
|
|
|
|
|
this.key = this.string.slice(0, idx);
|
|
|
|
|
this.value = this.string.slice(idx+1);
|
|
|
|
|
//console.log(this);
|
|
|
|
|
}
|
|
|
|
|
toString(){
|
|
|
|
|
return this.string;
|
|
|
|
|
//return this.key + "=" + this.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
save(){
|
|
|
|
|
if(!this.key){
|
|
|
|
|
throw new Error("没有键值");
|
|
|
|
|
}
|
|
|
|
|
wx.setStorageSync(this.key, this.origin_str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static load(key){
|
|
|
|
|
return new Cookie(wx.getStorageSync(key));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
|
//used to test the class Cookie
|
|
|
|
|
cookie_str = "autologin_trustie=8acaa2b09d5056c0e9d82519052276b9d4a524e9; domain=.educoder.net ; path=/; expires=Fri, 29 Nov 2019 15:32:53 -0000; HttpOnly";
|
|
|
|
|
cookie = new Cookie(cookie_str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//test();
|