|
@@ -1,7 +1,7 @@
|
|
|
import * as db from "./db.js";
|
|
|
import { baseUrl } from "./config.js";
|
|
|
import { User } from "@/config/api.js";
|
|
|
-import { modal } from "@/config/util.js";
|
|
|
+import store from "../store/index.js";
|
|
|
const showError = (error) => {
|
|
|
let errorMsg = "";
|
|
|
switch (error.status) {
|
|
@@ -53,15 +53,14 @@ const showError = (error) => {
|
|
|
},
|
|
|
});
|
|
|
};
|
|
|
+
|
|
|
// get请求
|
|
|
export const getHttp = (url, data, status = 1) => {
|
|
|
// 获取用户token和用户信息
|
|
|
let token = db.get("access_token");
|
|
|
let authHeader = token || "";
|
|
|
if (status) {
|
|
|
- uni.showLoading({
|
|
|
- title: "加载中",
|
|
|
- });
|
|
|
+ store.commit("requestShowLoading");
|
|
|
}
|
|
|
return new Promise((resolve, reject) => {
|
|
|
uni.request({
|
|
@@ -74,7 +73,7 @@ export const getHttp = (url, data, status = 1) => {
|
|
|
},
|
|
|
method: "GET",
|
|
|
success: (res) => {
|
|
|
- status && uni.hideLoading();
|
|
|
+ status && store.commit("requestHideLoading");
|
|
|
// 408 token失效
|
|
|
if (res.data.Ret === 408) {
|
|
|
refreshToken(getHttp, url, data, resolve);
|
|
@@ -90,14 +89,14 @@ export const getHttp = (url, data, status = 1) => {
|
|
|
resolve(res.data);
|
|
|
},
|
|
|
fail: (error) => {
|
|
|
- status && uni.hideLoading();
|
|
|
+ status && store.commit("requestHideLoading");
|
|
|
if (error && error.response) {
|
|
|
showError(error.response);
|
|
|
}
|
|
|
},
|
|
|
complete: () => {
|
|
|
setTimeout(() => {
|
|
|
- status && uni.hideLoading();
|
|
|
+ status && store.commit("requestHideLoading");
|
|
|
}, 250);
|
|
|
},
|
|
|
});
|
|
@@ -108,24 +107,20 @@ export const postHttp = (url, data, status = 1) => {
|
|
|
// 获取用户token和用户信息
|
|
|
let token = db.get("access_token");
|
|
|
let authHeader = token || "";
|
|
|
-
|
|
|
if (status) {
|
|
|
- uni.showLoading({
|
|
|
- title: "加载中",
|
|
|
- });
|
|
|
+ store.commit("requestShowLoading");
|
|
|
}
|
|
|
return new Promise((resolve, reject) => {
|
|
|
uni.request({
|
|
|
url: baseUrl + url,
|
|
|
data: data,
|
|
|
header: {
|
|
|
- // 'Accept': 'application/json',
|
|
|
"Content-Type": "application/json",
|
|
|
Authorization: authHeader,
|
|
|
},
|
|
|
method: "POST",
|
|
|
success: (res) => {
|
|
|
- status && uni.hideLoading();
|
|
|
+ status && store.commit("requestHideLoading");
|
|
|
// 408 token失效
|
|
|
if (res.data.Ret === 408) {
|
|
|
refreshToken(postHttp, url, data, resolve);
|
|
@@ -141,14 +136,14 @@ export const postHttp = (url, data, status = 1) => {
|
|
|
resolve(res.data);
|
|
|
},
|
|
|
fail: (error) => {
|
|
|
- status && uni.hideLoading();
|
|
|
+ status && store.commit("requestHideLoading");
|
|
|
if (error && error.response) {
|
|
|
showError(error.response);
|
|
|
}
|
|
|
},
|
|
|
complete: () => {
|
|
|
setTimeout(() => {
|
|
|
- status && uni.hideLoading();
|
|
|
+ status && store.commit("requestHideLoading");
|
|
|
}, 250);
|
|
|
},
|
|
|
});
|