@gz-fronted/gz-pc 0.1.1-beta.4 → 0.1.2-beta.0
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/README.md +16 -3
- package/dist/fetch/index.cjs +1 -1
- package/dist/fetch/index.d.cts +1 -0
- package/dist/fetch/index.d.ts +1 -0
- package/dist/fetch/index.js +1 -1
- package/package.json +99 -97
package/README.md
CHANGED
|
@@ -123,6 +123,7 @@ function gzFetch<TResponse, TRequestParams = unknown>(
|
|
|
123
123
|
| `url` | `string` | 是 | 请求地址;配置了 `baseURL` 时会与其组合 |
|
|
124
124
|
| `method` | `'GET' \| 'POST' \| 'PUT' \| 'DELETE'` | 是 | 请求方法,统一使用大写 |
|
|
125
125
|
| `params` | `TRequestParams` | 否 | 统一请求入参,由第二个泛型约束 |
|
|
126
|
+
| `paramsInUrl` | `boolean` | 否 | 仅 DELETE 生效;为 `true` 时参数放入 Query |
|
|
126
127
|
| `headers` | `Record<string, string>` | 否 | 本次请求附加的请求头 |
|
|
127
128
|
| `timeout` | `number` | 否 | 本次请求超时时间,单位毫秒;优先于实例配置 |
|
|
128
129
|
| `showErrorMessage` | `boolean` | 否 | 是否调用 gg-ui 的 `message.error` |
|
|
@@ -133,11 +134,23 @@ function gzFetch<TResponse, TRequestParams = unknown>(
|
|
|
133
134
|
|
|
134
135
|
请求入参字段统一使用 `params`,业务代码不需要区分 Axios 的 `params` 和 `data`:
|
|
135
136
|
|
|
136
|
-
- GET
|
|
137
|
-
- POST、PUT:`params` 转为 Request Body。
|
|
137
|
+
- GET:`params` 转为 URL Query。
|
|
138
|
+
- POST、PUT、DELETE:`params` 转为 Request Body。
|
|
139
|
+
|
|
140
|
+
DELETE 的 `paramsInUrl` 默认为 `false`。仅当兼容明确要求 Query 参数的 DELETE
|
|
141
|
+
接口时设置为 `true`,此时 `params` 只转为 URL Query,不再发送 Request Body:
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
await gzFetch<void, { id: number }>({
|
|
145
|
+
url: '/users',
|
|
146
|
+
method: 'DELETE',
|
|
147
|
+
params: { id: 1 },
|
|
148
|
+
paramsInUrl: true,
|
|
149
|
+
});
|
|
150
|
+
```
|
|
138
151
|
|
|
139
152
|
业务请求配置不支持 `data`,也不得混用 `params` 和 `data`。
|
|
140
|
-
POST、PUT 的 `params` 支持 JSON 对象、`FormData`、`URLSearchParams` 和 `Blob`;
|
|
153
|
+
POST、PUT、DELETE 的 `params` 支持 JSON 对象、`FormData`、`URLSearchParams` 和 `Blob`;
|
|
141
154
|
自定义请求头通过 `headers` 传入。
|
|
142
155
|
|
|
143
156
|
完整示例:
|
package/dist/fetch/index.cjs
CHANGED
|
@@ -257,7 +257,7 @@ function createGzFetch(options = {}) {
|
|
|
257
257
|
{ ...initialConfig, headers },
|
|
258
258
|
middlewares
|
|
259
259
|
);
|
|
260
|
-
const usesRequestBody = currentConfig.method === "POST" || currentConfig.method === "PUT";
|
|
260
|
+
const usesRequestBody = currentConfig.method === "POST" || currentConfig.method === "PUT" || currentConfig.method === "DELETE" && !currentConfig.paramsInUrl;
|
|
261
261
|
const axiosConfig = {
|
|
262
262
|
url: currentConfig.url,
|
|
263
263
|
method: currentConfig.method,
|
package/dist/fetch/index.d.cts
CHANGED
package/dist/fetch/index.d.ts
CHANGED
package/dist/fetch/index.js
CHANGED
|
@@ -251,7 +251,7 @@ function createGzFetch(options = {}) {
|
|
|
251
251
|
{ ...initialConfig, headers },
|
|
252
252
|
middlewares
|
|
253
253
|
);
|
|
254
|
-
const usesRequestBody = currentConfig.method === "POST" || currentConfig.method === "PUT";
|
|
254
|
+
const usesRequestBody = currentConfig.method === "POST" || currentConfig.method === "PUT" || currentConfig.method === "DELETE" && !currentConfig.paramsInUrl;
|
|
255
255
|
const axiosConfig = {
|
|
256
256
|
url: currentConfig.url,
|
|
257
257
|
method: currentConfig.method,
|
package/package.json
CHANGED
|
@@ -1,97 +1,99 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@gz-fronted/gz-pc",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Shared fetch, hooks and utility primitives for GZ frontend applications.",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"sideEffects": false,
|
|
8
|
-
"files": [
|
|
9
|
-
"dist",
|
|
10
|
-
"README.md"
|
|
11
|
-
],
|
|
12
|
-
"exports": {
|
|
13
|
-
"./fetch": {
|
|
14
|
-
"import": {
|
|
15
|
-
"types": "./dist/fetch/index.d.ts",
|
|
16
|
-
"default": "./dist/fetch/index.js"
|
|
17
|
-
},
|
|
18
|
-
"require": {
|
|
19
|
-
"types": "./dist/fetch/index.d.cts",
|
|
20
|
-
"default": "./dist/fetch/index.cjs"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"./hooks": {
|
|
24
|
-
"import": {
|
|
25
|
-
"types": "./dist/hooks/index.d.ts",
|
|
26
|
-
"default": "./dist/hooks/index.js"
|
|
27
|
-
},
|
|
28
|
-
"require": {
|
|
29
|
-
"types": "./dist/hooks/index.d.cts",
|
|
30
|
-
"default": "./dist/hooks/index.cjs"
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"./utils": {
|
|
34
|
-
"import": {
|
|
35
|
-
"types": "./dist/utils/index.d.ts",
|
|
36
|
-
"default": "./dist/utils/index.js"
|
|
37
|
-
},
|
|
38
|
-
"require": {
|
|
39
|
-
"types": "./dist/utils/index.d.cts",
|
|
40
|
-
"default": "./dist/utils/index.cjs"
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
"./package.json": "./package.json"
|
|
44
|
-
},
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"@
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
"
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
"
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
"
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
"
|
|
96
|
-
|
|
97
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@gz-fronted/gz-pc",
|
|
3
|
+
"version": "0.1.2-beta.0",
|
|
4
|
+
"description": "Shared fetch, hooks and utility primitives for GZ frontend applications.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
"./fetch": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/fetch/index.d.ts",
|
|
16
|
+
"default": "./dist/fetch/index.js"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/fetch/index.d.cts",
|
|
20
|
+
"default": "./dist/fetch/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"./hooks": {
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./dist/hooks/index.d.ts",
|
|
26
|
+
"default": "./dist/hooks/index.js"
|
|
27
|
+
},
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./dist/hooks/index.d.cts",
|
|
30
|
+
"default": "./dist/hooks/index.cjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"./utils": {
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/utils/index.d.ts",
|
|
36
|
+
"default": "./dist/utils/index.js"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/utils/index.d.cts",
|
|
40
|
+
"default": "./dist/utils/index.cjs"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "node scripts/build.mjs",
|
|
47
|
+
"lint": "eslint .",
|
|
48
|
+
"typecheck": "tsc --noEmit",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:watch": "vitest",
|
|
51
|
+
"verify:exports": "node tests/exports/smoke.mjs",
|
|
52
|
+
"prepublishOnly": "npm run build",
|
|
53
|
+
"prepare": "husky"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"ahooks": "^3.9.7",
|
|
57
|
+
"axios": "^1.13.6"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"@chenhui996/gg-ui": "^0.1.1",
|
|
61
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@chenhui996/gg-ui": "0.1.1",
|
|
65
|
+
"@commitlint/cli": "21.2.1",
|
|
66
|
+
"@commitlint/config-conventional": "21.2.0",
|
|
67
|
+
"@eslint/js": "9.39.4",
|
|
68
|
+
"@types/node": "24.10.0",
|
|
69
|
+
"@types/react": "19.2.14",
|
|
70
|
+
"@types/react-dom": "19.2.3",
|
|
71
|
+
"eslint": "9.39.4",
|
|
72
|
+
"globals": "16.5.0",
|
|
73
|
+
"husky": "9.1.7",
|
|
74
|
+
"lint-staged": "17.2.0",
|
|
75
|
+
"msw": "2.12.7",
|
|
76
|
+
"prettier": "3.9.6",
|
|
77
|
+
"react": "19.2.4",
|
|
78
|
+
"react-dom": "19.2.4",
|
|
79
|
+
"tsup": "8.5.1",
|
|
80
|
+
"typescript": "5.9.3",
|
|
81
|
+
"typescript-eslint": "8.56.1",
|
|
82
|
+
"vitest": "4.1.4"
|
|
83
|
+
},
|
|
84
|
+
"engines": {
|
|
85
|
+
"node": ">=20"
|
|
86
|
+
},
|
|
87
|
+
"publishConfig": {
|
|
88
|
+
"access": "public"
|
|
89
|
+
},
|
|
90
|
+
"lint-staged": {
|
|
91
|
+
"*.{js,jsx,ts,tsx}": [
|
|
92
|
+
"eslint --fix",
|
|
93
|
+
"prettier --write"
|
|
94
|
+
],
|
|
95
|
+
"*.{json,md,yml,yaml,css,less}": [
|
|
96
|
+
"prettier --write"
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
}
|