81 lines
1.8 KiB
JavaScript
81 lines
1.8 KiB
JavaScript
class UrlBuilder {
|
|
constructor(url) {
|
|
this.orginurl = url;
|
|
this.baseurl = url;
|
|
this.checked = false;
|
|
}
|
|
addKV(key, value){
|
|
if(typeof(value) == 'undefined'){
|
|
return this;
|
|
}
|
|
this._checkurl();
|
|
let str = encodeURIComponent(key) + '=' + encodeURIComponent(value);
|
|
this.baseurl += str;
|
|
return this;
|
|
}
|
|
|
|
clear(){
|
|
this.baseurl = this.orginurl;
|
|
this.checked = false;
|
|
}
|
|
|
|
_checkurl(){
|
|
if(!this.checked){
|
|
if(this.baseurl.indexOf("?") === -1){
|
|
this.baseurl += "?";
|
|
}else{
|
|
this.baseurl += "&";
|
|
}
|
|
this.checked = true;
|
|
}else{
|
|
this.baseurl += "&";
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
module.exports = UrlBuilder;
|
|
// module.exports = cc.Class({
|
|
// // LIFE-CYCLE CALLBACKS:
|
|
//
|
|
// // onLoad () {},
|
|
//
|
|
// // start () {},
|
|
//
|
|
// // update (dt) {},
|
|
// __ctor__ (url){
|
|
// this.orginurl = url;
|
|
// this.baseurl = url;
|
|
// this.checked = false;
|
|
// },
|
|
//
|
|
// addKV(key, value){
|
|
// if(typeof(value) == 'undefined'){
|
|
// return this;
|
|
// }
|
|
// this._checkurl();
|
|
// var str = encodeURIComponent(key) + '=' + encodeURIComponent(value);
|
|
// this.baseurl += str;
|
|
// return this;
|
|
// },
|
|
//
|
|
// clear(){
|
|
// this.baseurl = this.orginurl;
|
|
// this.checked = false;
|
|
// },
|
|
//
|
|
// _checkurl(){
|
|
// if(!this.checked){
|
|
// if(this.baseurl.indexOf("?") == -1){
|
|
// this.baseurl += "?";
|
|
// }else{
|
|
// this.baseurl += "&";
|
|
// }
|
|
// this.checked = true;
|
|
// }else{
|
|
// this.baseurl += "&";
|
|
// }
|
|
//
|
|
// }
|
|
// });
|