vue2-client 1.20.91 → 1.20.92

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.
@@ -34,7 +34,7 @@ const result = await post('/api/user/save', { name: '张三' })
34
34
  const result = await post('/api/user/save', { name: '张三' }, {
35
35
  globalLoading: '保存中...', // 显示全局 Loading
36
36
  dedupe: false, // 关闭请求去重(POST 默认开启)
37
- showErrorMessage: false // 关闭 code 500 的默认错误提示,由业务自行处理
37
+ showErrorMessage: false // 关闭 code 500 / 其他非 200 的默认错误提示,由业务自行处理
38
38
  })
39
39
  ```
40
40
 
@@ -43,7 +43,7 @@ const result = await post('/api/user/save', { name: '张三' }, {
43
43
  | 参数 | 类型 | 默认值 | 说明 |
44
44
  |------|------|--------|------|
45
45
  | `globalLoading` | `boolean \| string` | `false` | 是否显示全局 Loading,传字符串可自定义提示文字 |
46
- | `showErrorMessage` | `boolean` | `true` | 仅对业务 **code 500** 是否显示默认错误提示,设为 `false` 时由业务自行处理 |
46
+ | `showErrorMessage` | `boolean` | `true` | 对业务 **code 500** 及其他非 200(不含 601)是否显示默认错误提示,设为 `false` 时由业务自行处理 |
47
47
  | `dedupe` | `boolean` | `true` | 请求去重开关,POST 请求默认开启 |
48
48
 
49
49
  ### 2. get - GET 请求
@@ -152,13 +152,13 @@ import { runLogic } from '@vue2-client/services/api/common'
152
152
  // 基础用法(失败时自动弹出右上角错误提示)
153
153
  const result = await runLogic('getUserInfo', { userId: 1 }, 'af-system')
154
154
 
155
- // 关闭 code 500 的默认错误提示,自行处理失败
155
+ // 关闭默认错误提示,自行处理失败
156
156
  try {
157
157
  const result = await runLogic('getUserInfo', { userId: 1 }, 'af-system', false, {
158
158
  showErrorMessage: false
159
159
  })
160
160
  } catch (msg) {
161
- this.$message.warning(msg) // 仅对 500 生效;其他 code 仍会走拦截器默认提示
161
+ this.$message.warning(msg) // 500 及其他非 200 生效;601 等仍会走拦截器默认提示
162
162
  }
163
163
  ```
164
164
 
@@ -167,11 +167,11 @@ try {
167
167
  | 参数 | 类型 | 默认值 | 说明 |
168
168
  |------|------|--------|------|
169
169
  | `globalLoading` | `boolean \| string` | `false` | 是否显示全局 Loading |
170
- | `showErrorMessage` | `boolean` | `true` | 仅对业务 **code 500** 是否显示默认错误提示,设为 `false` 时由业务自行处理 |
170
+ | `showErrorMessage` | `boolean` | `true` | 对业务 **code 500** 及其他非 200(不含 601)是否显示默认错误提示,设为 `false` 时由业务自行处理 |
171
171
  | `dedupe` | `boolean` | `true` | 请求去重开关 |
172
172
  | `dedupeStrategy` | `string` | 见环境 | 去重策略:`reject` 或 `reuse` |
173
173
 
174
- > 说明:默认错误提示由 `request.js` 响应拦截器通过 Ant Design Vue 的 `notification` 展示(右上角)。`showErrorMessage: false` **仅对业务 code 500**(及 HTTP 500)关闭自动提示;601、其他非 200、401/403 等仍按原逻辑提示。请求仍会 `reject`,便于在 `.catch` 或 `try/catch` 中自定义处理。
174
+ > 说明:默认错误提示由 `request.js` 响应拦截器通过 Ant Design Vue 的 `notification` 展示(右上角)。`showErrorMessage: false` **code 500**、**其他非 200**(及 HTTP 500)关闭自动提示;**601**、401/403 等仍按原逻辑提示。请求仍会 `reject`,便于在 `.catch` 或 `try/catch` 中自定义处理。
175
175
 
176
176
  ### useRunLogic - 响应式 Hook
177
177
 
@@ -214,7 +214,7 @@ export default {
214
214
  | `serviceName` | `string` | `VUE_APP_SYSTEM_NAME` | 服务名称 |
215
215
  | `isDev` | `boolean` | `false` | 是否使用开发环境 API |
216
216
  | `globalLoading` | `boolean \| string` | `false` | 是否显示全局 Loading |
217
- | `showErrorMessage` | `boolean` | `true` | 仅对业务 **code 500** 是否显示默认错误提示,设为 `false` 时由业务自行处理 |
217
+ | `showErrorMessage` | `boolean` | `true` | 对业务 **code 500** 及其他非 200(不含 601)是否显示默认错误提示,设为 `false` 时由业务自行处理 |
218
218
  | `dedupe` | `boolean` | `false` | 请求去重开关 |
219
219
 
220
220
  ---
@@ -390,7 +390,7 @@ const handleSave = async () => {
390
390
  }
391
391
  }
392
392
 
393
- // 模式二:需要自定义 500 错误处理(关闭 code 500 的默认 notification)
393
+ // 模式二:需要自定义错误处理(关闭 500 / 其他非 200 的默认 notification)
394
394
  const handleSave = async () => {
395
395
  const { success, data, error } = await execute(formData, { showErrorMessage: false })
396
396
  if (success) {
@@ -415,9 +415,9 @@ const loadData = async () => {
415
415
  }
416
416
  ```
417
417
 
418
- ### 5. 关闭 code 500 的默认错误提示
418
+ ### 5. 关闭默认错误提示
419
419
 
420
- 当接口返回业务 **code 500**(或 HTTP 500)时,拦截器默认会在右上角弹出 `notification`。若需由业务自行处理 500 错误,在请求 `config` 中设置:
420
+ 当接口返回业务 **code 500**、**其他非 200**(或 HTTP 500)时,拦截器默认会在右上角弹出 `notification`。若需由业务自行处理,在请求 `config` 中设置:
421
421
 
422
422
  ```javascript
423
423
  post('/api/xxx', data, { showErrorMessage: false })
@@ -427,6 +427,6 @@ useRunLogic('logicName', { showErrorMessage: false })
427
427
 
428
428
  **注意:**
429
429
 
430
- - `showErrorMessage: false` **仅对 500** 生效;601、其他非 200401/403 等仍会弹出默认提示。
431
- - 不会阻止 Promise 进入 `reject`,仅关闭 500 的自动 notification。
430
+ - `showErrorMessage: false` **500** **其他非 200** 生效;**601**、401/403 等仍会弹出默认提示。
431
+ - 不会阻止 Promise 进入 `reject`,仅关闭上述场景的自动 notification。
432
432
  - 登录过期(401)等系统级 `loginExpire` 弹窗不受此配置影响。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue2-client",
3
- "version": "1.20.91",
3
+ "version": "1.20.92",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve --no-eslint",
@@ -24,7 +24,7 @@ import { post } from '@vue2-client/services/api/restTools'
24
24
  * @param {string} url - 请求地址
25
25
  * @param {object} defaultConfig - 默认配置
26
26
  * @param {boolean|string} defaultConfig.globalLoading - 是否显示全局 Loading
27
- * @param {boolean} defaultConfig.showErrorMessage - 业务 code 500 时是否显示默认错误提示(默认 true),设为 false 时由业务自行处理
27
+ * @param {boolean} defaultConfig.showErrorMessage - 业务 code 500 及其他非 200(不含 601)时是否显示默认错误提示(默认 true),设为 false 时由业务自行处理
28
28
  * @param {boolean} defaultConfig.dedupe - 是否启用请求去重(POST 默认开启,设为 false 可关闭)
29
29
  * @returns {UsePostReturn}
30
30
  *
@@ -47,7 +47,7 @@ import { post } from '@vue2-client/services/api/restTools'
47
47
  * await execute({ id: 1 })
48
48
  * // data 会自动更新,可直接在模板中使用
49
49
  */
50
- export function usePost (url, defaultConfig = {}) {
50
+ export function usePost(url, defaultConfig = {}) {
51
51
  // 响应式状态
52
52
  const state = Vue.observable({
53
53
  loading: false,
@@ -61,7 +61,7 @@ export function usePost (url, defaultConfig = {}) {
61
61
  * @param {object} config - 本次请求的配置(覆盖默认配置)
62
62
  * @returns {Promise<RequestResult>} 统一的结果结构
63
63
  */
64
- async function execute (params = {}, config = {}) {
64
+ async function execute(params = {}, config = {}) {
65
65
  state.loading = true
66
66
  state.error = null
67
67
 
@@ -80,7 +80,7 @@ export function usePost (url, defaultConfig = {}) {
80
80
  /**
81
81
  * 重置状态
82
82
  */
83
- function reset () {
83
+ function reset() {
84
84
  state.loading = false
85
85
  state.error = null
86
86
  state.data = null
@@ -88,9 +88,15 @@ export function usePost (url, defaultConfig = {}) {
88
88
 
89
89
  // 返回响应式属性的 getter,确保在模板中能正确响应
90
90
  return {
91
- get loading () { return state.loading },
92
- get error () { return state.error },
93
- get data () { return state.data },
91
+ get loading() {
92
+ return state.loading
93
+ },
94
+ get error() {
95
+ return state.error
96
+ },
97
+ get data() {
98
+ return state.data
99
+ },
94
100
  execute,
95
101
  reset
96
102
  }
@@ -117,7 +123,7 @@ export default usePost
117
123
  * @param {boolean} options.isDev - 是否为开发环境
118
124
  * @param {boolean|string} options.globalLoading - 是否显示全局 Loading
119
125
  * @param {boolean} options.dedupe - 是否启用请求去重(POST 默认开启,设为 false 可关闭)
120
- * @param {boolean} options.showErrorMessage - 业务 code 500 时是否显示默认错误提示(默认 true),设为 false 时由业务自行处理
126
+ * @param {boolean} options.showErrorMessage - 业务 code 500 及其他非 200(不含 601)时是否显示默认错误提示(默认 true),设为 false 时由业务自行处理
121
127
  * @returns {UseRunLogicReturn}
122
128
  *
123
129
  * @example
@@ -143,7 +149,7 @@ export default usePost
143
149
  * isDev: false
144
150
  * })
145
151
  */
146
- export function useRunLogic (logicName, options = {}) {
152
+ export function useRunLogic(logicName, options = {}) {
147
153
  const {
148
154
  serviceName = process.env.VUE_APP_SYSTEM_NAME,
149
155
  isDev = false,
@@ -165,7 +171,7 @@ export function useRunLogic (logicName, options = {}) {
165
171
  * @param {boolean} dev - 是否开发环境
166
172
  * @returns {string}
167
173
  */
168
- function buildUrl (svcName, dev) {
174
+ function buildUrl(svcName, dev) {
169
175
  const apiPre = dev ? '/devApi/' : '/api/'
170
176
  return `${apiPre}${svcName}/logic/${logicName}`
171
177
  }
@@ -176,7 +182,7 @@ export function useRunLogic (logicName, options = {}) {
176
182
  * @param {object} overrideOptions - 本次请求的配置(覆盖默认配置)
177
183
  * @returns {Promise<RequestResult>} 统一的结果结构
178
184
  */
179
- async function execute (params = {}, overrideOptions = {}) {
185
+ async function execute(params = {}, overrideOptions = {}) {
180
186
  state.loading = true
181
187
  state.error = null
182
188
 
@@ -191,7 +197,8 @@ export function useRunLogic (logicName, options = {}) {
191
197
  const requestConfig = {
192
198
  globalLoading: overrideOptions.globalLoading !== undefined ? overrideOptions.globalLoading : globalLoading,
193
199
  dedupe: overrideOptions.dedupe !== undefined ? overrideOptions.dedupe : dedupe,
194
- showErrorMessage: overrideOptions.showErrorMessage !== undefined ? overrideOptions.showErrorMessage : showErrorMessage
200
+ showErrorMessage:
201
+ overrideOptions.showErrorMessage !== undefined ? overrideOptions.showErrorMessage : showErrorMessage
195
202
  }
196
203
 
197
204
  try {
@@ -209,16 +216,22 @@ export function useRunLogic (logicName, options = {}) {
209
216
  /**
210
217
  * 重置状态
211
218
  */
212
- function reset () {
219
+ function reset() {
213
220
  state.loading = false
214
221
  state.error = null
215
222
  state.data = null
216
223
  }
217
224
 
218
225
  return {
219
- get loading () { return state.loading },
220
- get error () { return state.error },
221
- get data () { return state.data },
226
+ get loading() {
227
+ return state.loading
228
+ },
229
+ get error() {
230
+ return state.error
231
+ },
232
+ get data() {
233
+ return state.data
234
+ },
222
235
  execute,
223
236
  reset
224
237
  }
@@ -182,7 +182,7 @@ export function parseConfig(configContent, configType) {
182
182
  * @param {boolean} config.dedupe - 是否启用去重(默认 true)
183
183
  * @param {string} config.dedupeStrategy - 去重策略:'reject'(拒绝)或 'reuse'(复用结果)
184
184
  * @param {boolean|string} config.globalLoading - 是否显示全局 Loading
185
- * @param {boolean} config.showErrorMessage - 业务 code 500 时是否显示默认错误提示(默认 true),设为 false 时由业务自行处理
185
+ * @param {boolean} config.showErrorMessage - 业务 code 500 及其他非 200(不含 601)时是否显示默认错误提示(默认 true),设为 false 时由业务自行处理
186
186
  */
187
187
  export function runLogic(logicName, parameter, serviceName = process.env.VUE_APP_SYSTEM_NAME, isDev, config = {}) {
188
188
  let apiPre = '/api/'
@@ -18,7 +18,7 @@ function get (url, parameter) {
18
18
  * @param parameter 请求参数
19
19
  * @param config 配置项
20
20
  * @param {boolean|string} config.globalLoading - 是否显示全局 Loading,可传入字符串作为提示文字
21
- * @param {boolean} config.showErrorMessage - 业务 code 500 时是否显示默认错误提示(默认 true),设为 false 时由业务自行处理
21
+ * @param {boolean} config.showErrorMessage - 业务 code 500 及其他非 200(不含 601)时是否显示默认错误提示(默认 true),设为 false 时由业务自行处理
22
22
  * @param {boolean} config.dedupe - 是否启用请求去重(POST 默认开启,设为 false 可关闭)
23
23
  * @param {string} config.dedupeStrategy - 去重策略:'reject'(拒绝,默认)或 'reuse'(复用结果)
24
24
  * @returns {Promise<AxiosResponse<T>>}
@@ -30,7 +30,7 @@ import {
30
30
  let isReloginShow
31
31
 
32
32
  /**
33
- * 业务 code 500 时是否显示默认错误提示(notification)
33
+ * 业务 code 500 及其他非 200(不含 601)时是否显示默认错误提示(notification)
34
34
  * @param {import('axios').AxiosRequestConfig} [config]
35
35
  * @returns {boolean}
36
36
  */
@@ -401,10 +401,12 @@ function loadInterceptors() {
401
401
  description: msg
402
402
  })
403
403
  } else if (code !== 200) {
404
- notification.error({
405
- message: '失败',
406
- description: msg
407
- })
404
+ if (shouldShowErrorMessage(res.config)) {
405
+ notification.error({
406
+ message: '失败',
407
+ description: msg
408
+ })
409
+ }
408
410
  } else {
409
411
  // 请求成功,通知复用的请求并返回数据
410
412
  if (requestKey) {