|
@@ -28,67 +28,31 @@ function showErrToast(e) {
|
|
|
|
|
|
|
|
function getPromise(url, data, method) {
|
|
function getPromise(url, data, method) {
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
- const accessToken = wx.getStorageSync("accessToken");
|
|
|
|
|
-
|
|
|
|
|
- if (!accessToken) {
|
|
|
|
|
- // Cache the current API call
|
|
|
|
|
- const cachedCall = () => {
|
|
|
|
|
|
|
+ let quest = ()=>{
|
|
|
wx.request({
|
|
wx.request({
|
|
|
- url: `${baseUrl}${url}`,
|
|
|
|
|
- header: getHeader(),
|
|
|
|
|
- method: method,
|
|
|
|
|
- data: data,
|
|
|
|
|
- success: function (res) {
|
|
|
|
|
- if (res.data.code === 200) {
|
|
|
|
|
- resolve(res.data.data);
|
|
|
|
|
- } else {
|
|
|
|
|
- if (res.statusCode === 401) {
|
|
|
|
|
- reject(401);
|
|
|
|
|
- } else {
|
|
|
|
|
- reject(res.data.message);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- fail: function (err) {
|
|
|
|
|
- reject(err);
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- // Call App.getMUser to fetch accessToken
|
|
|
|
|
- App.getMUser()
|
|
|
|
|
- .then(() => {
|
|
|
|
|
- // Retry the cached API call after getting the token
|
|
|
|
|
- cachedCall();
|
|
|
|
|
- })
|
|
|
|
|
- .catch((err) => {
|
|
|
|
|
- console.error("Failed to fetch accessToken", err);
|
|
|
|
|
- showErrToast("Failed to fetch accessToken");
|
|
|
|
|
- reject(err);
|
|
|
|
|
|
|
+ url: `${baseUrl}${url}`,
|
|
|
|
|
+ header: getHeader(),
|
|
|
|
|
+ method: method,
|
|
|
|
|
+ data: data,
|
|
|
|
|
+ success: function (res) {
|
|
|
|
|
+ if (res.statusCode === 200) {
|
|
|
|
|
+ resolve(res.data);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (res.statusCode === 401) {
|
|
|
|
|
+ reject(401);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ reject(res.data.message);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: function (err) {
|
|
|
|
|
+ reject(err);
|
|
|
|
|
+ },
|
|
|
});
|
|
});
|
|
|
- } else {
|
|
|
|
|
- // Proceed with the API call if accessToken exists
|
|
|
|
|
- wx.request({
|
|
|
|
|
- url: `${baseUrl}${url}`,
|
|
|
|
|
- header: getHeader(),
|
|
|
|
|
- method: method,
|
|
|
|
|
- data: data,
|
|
|
|
|
- success: function (res) {
|
|
|
|
|
- if (res.statusCode === 200) {
|
|
|
|
|
- resolve(res.data);
|
|
|
|
|
- } else {
|
|
|
|
|
- if (res.statusCode === 401) {
|
|
|
|
|
- reject(401);
|
|
|
|
|
- } else {
|
|
|
|
|
- reject(res.data.message);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- fail: function (err) {
|
|
|
|
|
- reject(err);
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ App.checkLoginStatus().then(()=>{
|
|
|
|
|
+ quest();
|
|
|
|
|
+ })
|
|
|
}).catch((e) => {
|
|
}).catch((e) => {
|
|
|
console.error(`in promise error, url: ${baseUrl}${url}`);
|
|
console.error(`in promise error, url: ${baseUrl}${url}`);
|
|
|
console.error(e);
|
|
console.error(e);
|