@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 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、DELETE:`params` 转为 URL Query。
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
  完整示例:
@@ -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,
@@ -26,6 +26,7 @@ interface GzRequestConfig<TRequestParams = unknown> {
26
26
  url: string;
27
27
  method: GzRequestMethod;
28
28
  params?: TRequestParams;
29
+ paramsInUrl?: boolean;
29
30
  headers?: Record<string, string>;
30
31
  timeout?: number;
31
32
  showErrorMessage?: boolean;
@@ -26,6 +26,7 @@ interface GzRequestConfig<TRequestParams = unknown> {
26
26
  url: string;
27
27
  method: GzRequestMethod;
28
28
  params?: TRequestParams;
29
+ paramsInUrl?: boolean;
29
30
  headers?: Record<string, string>;
30
31
  timeout?: number;
31
32
  showErrorMessage?: boolean;
@@ -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.1-beta.4",
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
- "dependencies": {
46
- "ahooks": "^3.9.7",
47
- "axios": "^1.13.6"
48
- },
49
- "peerDependencies": {
50
- "@chenhui996/gg-ui": "^0.1.1",
51
- "react": "^18.0.0 || ^19.0.0"
52
- },
53
- "devDependencies": {
54
- "@chenhui996/gg-ui": "0.1.1",
55
- "@commitlint/cli": "21.2.1",
56
- "@commitlint/config-conventional": "21.2.0",
57
- "@eslint/js": "9.39.4",
58
- "@types/node": "24.10.0",
59
- "@types/react": "19.2.14",
60
- "@types/react-dom": "19.2.3",
61
- "eslint": "9.39.4",
62
- "globals": "16.5.0",
63
- "husky": "9.1.7",
64
- "lint-staged": "17.2.0",
65
- "msw": "2.12.7",
66
- "prettier": "3.9.6",
67
- "react": "19.2.4",
68
- "react-dom": "19.2.4",
69
- "tsup": "8.5.1",
70
- "typescript": "5.9.3",
71
- "typescript-eslint": "8.56.1",
72
- "vitest": "4.1.4"
73
- },
74
- "engines": {
75
- "node": ">=20"
76
- },
77
- "publishConfig": {
78
- "access": "public"
79
- },
80
- "lint-staged": {
81
- "*.{js,jsx,ts,tsx}": [
82
- "eslint --fix",
83
- "prettier --write"
84
- ],
85
- "*.{json,md,yml,yaml,css,less}": [
86
- "prettier --write"
87
- ]
88
- },
89
- "scripts": {
90
- "build": "node scripts/build.mjs",
91
- "lint": "eslint .",
92
- "typecheck": "tsc --noEmit",
93
- "test": "vitest run",
94
- "test:watch": "vitest",
95
- "verify:exports": "node tests/exports/smoke.mjs"
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
+ }