Load configuration file
var instance = axios.create ({
BaseURL: ' http://zy-shop.tincent.me/Wechat/',
Headers: {
' Content-type ': ' application/x-www-form-urlencoded '
}
Withcredentials:true
});
Public functions
function public () {
This.get=function () {
Console.log (1)
},
This.post=function () {
Console.log (2)
},
Bullet box method for top tip
This.remind=function (That,remind) {
That.remindshow=true;
That.remind=remind;
SetTimeout (function () {
That.remindshow=false
},1000)
},
60 Seconds Countdown,
This.countdown=function (that) {
var time=60;
That.downtime=time+ "acquired after seconds";
var timer=setinterval (function () {
time--;
When the time is reduced to 0 o'clock
if (time==0) {
That.downtime= "Get It Again";
Clearinterval (timer);
}else{
That.downtime=time+ "acquired after seconds";
}
},1000)
}
Analysis of data transfer between front and rear tables
This.json2form=function (JSON) {
var str = "";
For (Var p in JSON) {
Determines whether an object is an array
if (typeof json[p]== "Object") {
var m=string (P)
for (Var i=0;i<json[p].length;i++) {
for (Var x in json[p][i]) {
str+=m+ "[" +i+ "]" + "[" +x+ "]" + "=" +json[p][i][x]+ "&";
}
}
}else{
Str+=p + "=" + json[p]+ "&";
}
}
Intercept string The last one &
var length=str.length-1;
Str=str.substring (0,length);
return string str
return str;
},
Lock handling when submitting forms
This.getcsrftoken=function () {
Instance.get (' Service/getcsrftoken '). Then (function (res) {
Sessionstorage.setitem (' Submitkey ', json.stringify ({' Submitkey ': Res.data.data.submitKey}))
})
},
Session Store
This.savesession=function (Key,data) {
Sessionstorage.setitem (key,json.stringify (data));
},
Session Extraction
This.getsession=function (KEY,STR) {
How to determine the value
var user = Json.parse (Sessionstorage.getitem (key));
if (user) {
if (str) {
return USER[STR];
}
return user;
}
},
Session Clear
This.removesession=function (key) {
Sessionstorage.removeitem (Key)
}
Local storage
This.savelocal=function (Key,data) {
Localstorage.setitem (key,json.stringify (data));
},
Local extract
This.getlocal=function (KEY,STR) {
How to determine the value
var user = Json.parse (Localstorage.getitem (key));
if (user) {
if (str) {
return USER[STR];
}
return user;
}
},
Clear Local
This.removelocal=function (key) {
Localstorage.removeitem (Key)
},
Gets the parameters passed by the URL
This.geturlparam=function (name) {
var reg = new RegExp ("(^|&)" + name + "= ([^&]*) (&|$)");
var r = window.location.search.substr (1). Match (REG);
if (r!=null) return unescape (r[2]); return null;
},
Page lodding function
This.loadding=function (type) {
Determine if it is a startup loadding
if (type== ' load ') {
Toast.loading ({
Title: "Loading in",
duration:2000
},function (ret) {
});
} else if (type= ' hide ') {
SetTimeout (function () {
Toast.hide ();
},500)
}
},
Define the text display when loading
This.pageword=function (That,pageflag,title) {
if (pageflag==1) {
That.pageword=title;
}else{
that.pageword= "No More"
}
}
}
var toast = new Auitoast ();
var public=new public ();
Self-occupied public JS file