Home > front end >  Js how to perform another function in the current function, and wait for the end of another function
Js how to perform another function in the current function, and wait for the end of another function

Time:12-10

 
Var baseURL=the require ("./API. Js');
Var sm2=the require ("./sm2. Js');
Var appJs;
//display the progress bar network request
The requested url//url: network
//params: request parameter
//the message: the progress bar's tooltip
//the methods: request way
//hideLoad: hidden wx showLoading
//hideToast: hidden wx showToast
//used to generate the uuid
The function S4 () {
Return (((1 + Math. The random ()) * 0 x10000) | 0). ToString (16). The substring (1);
}

The function guid () {
Return (S4 () + S4 () + "-" + S4 () + "-" + S4 () + "-" + S4 () + "-" + S4 S4 () () + + S4 ());
}

The function objKeySort (obj) {//sorting function
Var newkey=Object. Keys (obj). Sort ();
//with the Object of a built-in class first obtained keys to sort Object property names, using the Array sort method to obtain the property name on the prototype for sorting, newkey is an Array
Var newObj={};//create a new object, used to hold sorted key/value pair
For (var I=0; I & lt; The newkey. Length; I++) {//traverse the newkey array
NewObj [newkey [I]]=obj [newkey [I]].//to the newly created object, in turn, increase the key/value pair in row of good order
}
Return newObj;//returns the sorted new object
}

The function timest () {
Var TMP=Date. Parse (new Date ()). The toString ();
TMP=TMP. Substr (0, 10);
return tmp;
}

Var uuid;
Var token="";
Var _token_="";
Let superPrivateKey=sm2. SuperPrivateKey;
Let privateKey="";
Const rsa=the require ("../utils/cryptojs - master/cryptojs js');
Const Encrypt=the require ("../utils/jsencrypt. Min. Js');
Let the encryptor=new Encrypt. JSEncrypt ();
The encryptor. SetPrivateKey (superPrivateKey);//set the private key

//function getResult (callback, callback1) {
//if (! PrivateKey) {
//callback ()
//the debugger
//} else {
//callback1 ()
//}
//}
//getResult (getA, requestLoading);

The function getA () {
Wx. Request ({
Url: baseURL baseURL + 'API/services/app/Setting/GetCerPriKeyAsync',
Data: "'
Header: {},
Method: 'Get',
Success: the function (res) {
The console. The log (res)
Let array=res. Data. The Result. The data;
Let sourcePrivate=' ';
For (let a=0; A. & lt; Array. The length; {+)
SourcePrivate +=the encryptor. Decrypt (array) [a];
}
The console. The log (" original private key "+ sourcePrivate);
The encryptor. SetPrivateKey (sourcePrivate);
PrivateKey=sourcePrivate;
The debugger
//requestLoading ()
//getHomeSetting ()
},
Fail: function (res) {
The console. The log (res)
},
Complete: a function (res) {},
})
}

The function requestLoading (url, params, message, the methods, hideLoad, hideToast) {
if (! AppJs) {
AppJs=getApp ();
}
Return new Promise (function (resolve, reject) {
if (! PrivateKey) {
GetA ()
The debugger
Reject ()
}
Var method=the methods | | "GET";
Params=params | | {};
Params. MpContentType=1;
if (! HideLoad) {
{if (method=="POST")
If (the message! {
="")Wx. ShowLoading ({
Title: message,
Mask: true
})
} else {
Wx. ShowLoading ({
Title: 'data load,
Mask: true
});
}
}
}
If (url. The substring (0, 1)=='/') {
Url=url. Substr (1);
}
//token is used directly, there is no empty
If (appJs) {
Token=appJs. GlobalData. Token;
AppJs. GlobalData. PrivateKey=privateKey;
if (! Token) {
Token=wx. GetStorageSync (' token ') | | wx. GetStorageSync (" token ");
AppJs. GlobalData. Token=token;
}
_token_=token;
} else {
Token=wx. GetStorageSync (' token ') | | wx. GetStorageSync (" token ");
_token_=token;
}
//url splicing token and __shop__
Let __shop__=wx. GetStorageSync (" organizationid ") | | '.
If (url. LastIndexOf ("?" )==1) {
Url=url + '? _token_='+ _token_ + & amp; __shop__='+ __shop__
} else {
Url=url + '& amp; _token_='+ _token_ + & amp; __shop__='+ __shop__
}
{if (method=="GET")
Params. Timestamp=timest ();
Params=objKeySort (params);
Let the STR=Object. Keys (params). The map (function (key) {
Return "" concat (encodeURIComponent (key),"="). The concat (encodeURIComponent (params [key]));
}). Join (' & amp; ');
STR='_token_=' + _token_ + '& amp; __shop__='+ __shop__ + & amp; '+ STR;
Let sha256sign=the encryptor. Sign (STR, rsa. The Crypto. SHA256, "SHA256");
Sha256sign=encodeURIComponent (sha256sign);
Params. Sign=sha256sign;
}
If (method=="POST" | | method=="PUT") {
Var aa=JSON. Stringify (params);
Let the STR='_token_=' + _token_ + '& amp; __shop__='+ __shop__ + & amp; Timestamp='+ timest () + aa;
Let sha256sign=the encryptor. Sign (STR, rsa. The Crypto. SHA256, "SHA256")
Sha256sign=encodeURIComponent (sha256sign);
Url=url + '& amp; Timestamp='+ timest () +' & amp; Sign='+ sha256sign;
}
{if (method=="DELETE")
Let the index=url. LastIndexOf ("?" );
Let the STR=url. The substring (index + 1, url. Length) + '& amp; Timestamp='+ timest () + JSON. Stringify (params);
Let sha256sign=the encryptor. Sign (STR, rsa. The Crypto. SHA256, "SHA256")
Sha256sign=encodeURIComponent (sha256sign);
Url=url + '& amp; Timestamp='+ timest () +' & amp; Sign='+ sha256sign;
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related