vue2server7 2.3.8 → 2.3.9

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/test/111.txt +44 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue2server7",
3
- "version": "2.3.8",
3
+ "version": "2.3.9",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "nodemon --watch src --ext ts --exec \"ts-node src/app.ts\"",
package/test/111.txt ADDED
@@ -0,0 +1,44 @@
1
+ import axios from "axios";
2
+
3
+ const service = axios.create({
4
+ baseURL: import.meta.env.VITE_API_BASE,
5
+ timeout: 15000,
6
+ headers: {
7
+ "Content-Type": "application/json",
8
+ },
9
+ });
10
+
11
+ // 分页字段
12
+ const PAGE_KEYS = ["pageIndex", "pageSize"];
13
+
14
+ // 拆分函数
15
+ function splitHeadBody(params = {}, tranCode) {
16
+ const head = {
17
+ tranCode, // 关键:接口地址放进 head.tranCode
18
+ };
19
+ const body = {};
20
+
21
+ Object.keys(params).forEach((key) => {
22
+ if (PAGE_KEYS.includes(key)) {
23
+ head[key] = params[key];
24
+ } else {
25
+ body[key] = params[key];
26
+ }
27
+ });
28
+
29
+ return { head, body };
30
+ }
31
+
32
+ const request = {
33
+ post(tranCode, params = {}, config = {}) {
34
+ const { head, body } = splitHeadBody(params, tranCode);
35
+
36
+ return service.post(
37
+ "/gateway", // 实际统一请求地址
38
+ { head, body },
39
+ config
40
+ );
41
+ },
42
+ };
43
+
44
+ export default request;