Skip to content

Commit 27b4995

Browse files
xlorneclaude
andcommitted
feat: 接口请求超时时间支持动态配置 + 发布 @coding-flow/*@0.2.0(issue #211)
- feat: 接口请求超时时间可通过 localStorage 动态配置,未配置时回退默认值 - 新增 resolveHttpTimeout() / FLOW_HTTP_TIMEOUT_KEY - PC/移动端审批、设计器、示例应用去除 10000ms 硬编码 - 版本升级 0.1.9 -> 0.2.0(changeset fixed 模式同步全部 @coding-flow/* 包) - 生成各包 CHANGELOG Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4b20455 commit 27b4995

29 files changed

Lines changed: 187 additions & 21 deletions

File tree

apps/app-mobile/src/api/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {HttpClient} from "@coding-flow/flow-core";
1+
import {HttpClient, resolveHttpTimeout} from "@coding-flow/flow-core";
22
import { message } from "antd";
33

4-
export const httpClient = new HttpClient(10000,{
4+
export const httpClient = new HttpClient(resolveHttpTimeout(),{
55
success:(msg:string)=>{
66
message.success(msg)
77
},

apps/app-pc/src/api/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {HttpClient} from "@coding-flow/flow-core";
1+
import {HttpClient, resolveHttpTimeout} from "@coding-flow/flow-core";
22
import { message } from "antd";
33

4-
export const httpClient = new HttpClient(10000,{
4+
export const httpClient = new HttpClient(resolveHttpTimeout(),{
55
success:(msg:string)=>{
66
message.success(msg)
77
},

packages/flow-approval-presenter/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @coding-flow/flow-approval-presenter
22

3+
## 0.2.0
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- @coding-flow/flow-core@0.2.0
9+
- @coding-flow/flow-types@0.2.0
10+
311
## 0.1.9
412

513
### Patch Changes

packages/flow-approval-presenter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coding-flow/flow-approval-presenter",
3-
"version": "0.1.9",
3+
"version": "0.2.0",
44
"description": "flow-engine approval presenter framework ",
55
"type": "module",
66
"sideEffects": [

packages/flow-core/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# @coding-flow/flow-core
22

3+
## 0.2.0
4+
5+
### Minor Changes
6+
7+
- feat: 接口请求超时时间支持通过 localStorage 动态配置,未配置时回退默认值(issue #211
8+
9+
- 新增 `resolveHttpTimeout()` / `FLOW_HTTP_TIMEOUT_KEY`,从 localStorage 读取超时配置
10+
- 各调用点(PC/移动端审批、设计器、示例应用)去除写死的 10000ms 硬编码
11+
312
## 0.1.9
413

514
## 0.1.8

packages/flow-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coding-flow/flow-core",
3-
"version": "0.1.9",
3+
"version": "0.2.0",
44
"description": "flow-engine core lib framework ",
55
"type": "module",
66
"sideEffects": [

packages/flow-core/src/http.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@ export interface MessageBox {
88
error: (msg: string) => void;
99
}
1010

11+
/**
12+
* 接口请求超时时间(毫秒)在 localStorage 中的配置键。
13+
* 未配置时使用默认值 {@link DEFAULT_HTTP_TIMEOUT}。
14+
*/
15+
export const FLOW_HTTP_TIMEOUT_KEY = 'flow_http_timeout';
16+
17+
/** 默认接口请求超时时间(毫秒),未配置 localStorage 时生效。 */
18+
const DEFAULT_HTTP_TIMEOUT = 10000;
19+
20+
/**
21+
* 解析接口请求超时时间(毫秒)。
22+
* 优先读取 localStorage 中 {@link FLOW_HTTP_TIMEOUT_KEY} 对应的配置,
23+
* 未配置或配置值非法(非正数)时回退到默认值。
24+
*/
25+
export function resolveHttpTimeout(): number {
26+
const raw = localStorage.getItem(FLOW_HTTP_TIMEOUT_KEY);
27+
if (!raw) {
28+
return DEFAULT_HTTP_TIMEOUT;
29+
}
30+
const value = Number(raw);
31+
return Number.isFinite(value) && value > 0 ? value : DEFAULT_HTTP_TIMEOUT;
32+
}
33+
1134
export type Response = {
1235
success: boolean;
1336
errCode?: string;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import {describe, expect, it, beforeEach, afterEach} from '@rstest/core';
2+
import {FLOW_HTTP_TIMEOUT_KEY, resolveHttpTimeout} from "@/http";
3+
4+
describe('resolveHttpTimeout', () => {
5+
6+
beforeEach(() => {
7+
localStorage.removeItem(FLOW_HTTP_TIMEOUT_KEY);
8+
});
9+
10+
afterEach(() => {
11+
localStorage.removeItem(FLOW_HTTP_TIMEOUT_KEY);
12+
});
13+
14+
it('未配置 localStorage 时返回默认值 10000', () => {
15+
const timeout = resolveHttpTimeout();
16+
expect(timeout).toEqual(10000);
17+
});
18+
19+
it('已配置合法正整数时返回对应超时时间', () => {
20+
localStorage.setItem(FLOW_HTTP_TIMEOUT_KEY, '30000');
21+
const timeout = resolveHttpTimeout();
22+
expect(timeout).toEqual(30000);
23+
});
24+
25+
it('已配置 "0" 时视为非法,回退默认值', () => {
26+
localStorage.setItem(FLOW_HTTP_TIMEOUT_KEY, '0');
27+
const timeout = resolveHttpTimeout();
28+
expect(timeout).toEqual(10000);
29+
});
30+
31+
it('已配置负整数时视为非法,回退默认值', () => {
32+
localStorage.setItem(FLOW_HTTP_TIMEOUT_KEY, '-5000');
33+
const timeout = resolveHttpTimeout();
34+
expect(timeout).toEqual(10000);
35+
});
36+
37+
it('已配置非数字时视为非法,回退默认值', () => {
38+
localStorage.setItem(FLOW_HTTP_TIMEOUT_KEY, 'abc');
39+
const timeout = resolveHttpTimeout();
40+
expect(timeout).toEqual(10000);
41+
});
42+
43+
it('已配置小数时按原值返回', () => {
44+
localStorage.setItem(FLOW_HTTP_TIMEOUT_KEY, '2500.5');
45+
const timeout = resolveHttpTimeout();
46+
expect(timeout).toEqual(2500.5);
47+
});
48+
});

packages/flow-design/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# @coding-flow/flow-design
22

3+
## 0.2.0
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- @coding-flow/flow-core@0.2.0
9+
- @coding-flow/flow-icons@0.2.0
10+
- @coding-flow/flow-pc-ui@0.2.0
11+
- @coding-flow/flow-types@0.2.0
12+
313
## 0.1.9
414

515
### Patch Changes

packages/flow-design/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coding-flow/flow-design",
3-
"version": "0.1.9",
3+
"version": "0.2.0",
44
"description": "flow-engine design components ",
55
"type": "module",
66
"sideEffects": [

0 commit comments

Comments
 (0)