befly-admin 3.13.19 → 3.13.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/plugins/http.js +6 -91
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly-admin",
|
|
3
|
-
"version": "3.13.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "3.13.20",
|
|
4
|
+
"gitHead": "cb5f3fe922985a84d5abd02a27e50cade25ad135",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly Admin - 基于 Vue3 + TDesign Vue Next 的后台管理系统",
|
|
7
7
|
"files": [
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"axios": "^1.13.5",
|
|
32
32
|
"befly-admin-ui": "1.8.24",
|
|
33
|
+
"befly-shared": "1.0.1",
|
|
33
34
|
"befly-vite": "^1.5.7",
|
|
34
35
|
"pinia": "^3.0.4",
|
|
35
36
|
"tdesign-icons-vue-next": "^0.4.0",
|
package/src/plugins/http.js
CHANGED
|
@@ -1,91 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const shouldDrop = (key, value) => {
|
|
8
|
-
for (const dropValue of dropList) {
|
|
9
|
-
if (Object.is(value, dropValue)) {
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
if (Array.isArray(dropKeyMap[key])) {
|
|
14
|
-
for (const dropValue of dropKeyMap[key]) {
|
|
15
|
-
if (Object.is(value, dropValue)) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return false;
|
|
21
|
-
};
|
|
22
|
-
let payloadData = data ?? {};
|
|
23
|
-
if (isForm) {
|
|
24
|
-
const nextForm = new FormData();
|
|
25
|
-
for (const entry of payloadData.entries()) {
|
|
26
|
-
const key = entry[0];
|
|
27
|
-
const value = entry[1];
|
|
28
|
-
if (!shouldDrop(key, value)) {
|
|
29
|
-
nextForm.append(key, value);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
payloadData = nextForm;
|
|
33
|
-
} else if (payloadData && typeof payloadData === "object") {
|
|
34
|
-
const nextData = {};
|
|
35
|
-
for (const key of Object.keys(payloadData)) {
|
|
36
|
-
const value = payloadData[key];
|
|
37
|
-
if (!shouldDrop(key, value)) {
|
|
38
|
-
nextData[key] = value;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
payloadData = nextData;
|
|
42
|
-
}
|
|
43
|
-
const headers = new Headers();
|
|
44
|
-
if (!isForm) {
|
|
45
|
-
headers.set("Content-Type", "application/json");
|
|
46
|
-
}
|
|
47
|
-
const tokenValue = typeof tokenGetter === "function" ? tokenGetter() : "";
|
|
48
|
-
if (tokenValue) {
|
|
49
|
-
headers.set("Authorization", "Bearer " + tokenValue);
|
|
50
|
-
}
|
|
51
|
-
const init = {
|
|
52
|
-
method: "POST",
|
|
53
|
-
headers: headers,
|
|
54
|
-
body: isForm ? payloadData : JSON.stringify(payloadData ?? {})
|
|
55
|
-
};
|
|
56
|
-
const res = await fetch(fullUrl, init);
|
|
57
|
-
let payload;
|
|
58
|
-
try {
|
|
59
|
-
payload = await res.json();
|
|
60
|
-
} catch {
|
|
61
|
-
if (res.ok) {
|
|
62
|
-
return Promise.reject({ msg: "响应解析失败" });
|
|
63
|
-
}
|
|
64
|
-
payload = {
|
|
65
|
-
code: res.status,
|
|
66
|
-
msg: `请求失败:HTTP ${res.status}`
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
if (payload.code !== 0) {
|
|
70
|
-
return Promise.reject({
|
|
71
|
-
msg: payload.msg ?? "请求失败",
|
|
72
|
-
code: payload.code,
|
|
73
|
-
detail: payload.detail
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
return Promise.resolve(payload);
|
|
77
|
-
} catch (error) {
|
|
78
|
-
if (error && typeof error === "object") {
|
|
79
|
-
return Promise.reject(error);
|
|
80
|
-
}
|
|
81
|
-
return Promise.reject({ msg: "网络连接失败" });
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
export const $Http = {
|
|
85
|
-
json: async (url, data, dropValues, dropKeyValue) => {
|
|
86
|
-
return requestPost(() => localStorage.getItem($Config.tokenName) ?? "", url, data ?? {}, dropValues, dropKeyValue);
|
|
87
|
-
},
|
|
88
|
-
form: async (url, formData, dropValues, dropKeyValue) => {
|
|
89
|
-
return requestPost(() => localStorage.getItem($Config.tokenName) ?? "", url, formData, dropValues, dropKeyValue);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
1
|
+
import { createHttp } from "befly-shared/createHttp";
|
|
2
|
+
|
|
3
|
+
export const $Http = createHttp({
|
|
4
|
+
apiPath: $Config.apiPath,
|
|
5
|
+
getToken: () => localStorage.getItem($Config.tokenName) ?? ""
|
|
6
|
+
});
|