Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
ai
/
ai-workflow
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 39273885
authored
May 24, 2026
by
imwangxiaozhou
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'ai-workflow-dev' of
http://192.168.3.233:8090/ai/ai-workflow
into ai-workflow-dev
2 parents
2b194304
b22f6505
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
12 deletions
workspace/agent-admin/single-page/openspec/changes/h5-real-api-integration/tasks.md
workspace/agent-admin/single-page/src/__tests__/apiClient.test.ts
workspace/agent-admin/single-page/src/__tests__/setup.ts
workspace/agent-admin/single-page/src/api/client.ts
workspace/agent-admin/single-page/openspec/changes/h5-real-api-integration/tasks.md
View file @
3927388
...
@@ -3,11 +3,11 @@
...
@@ -3,11 +3,11 @@
-
[
x
]
1.1 确认 H5 首页真实接口端点在 H5 API 模块中以
`/official-site/home`
相对路径表达;开发环境最终请求
`/api/v1/official-site/home`
,测试/生产环境最终请求
`/backend/api/v1/official-site/home`
。
-
[
x
]
1.1 确认 H5 首页真实接口端点在 H5 API 模块中以
`/official-site/home`
相对路径表达;开发环境最终请求
`/api/v1/official-site/home`
,测试/生产环境最终请求
`/backend/api/v1/official-site/home`
。
-
[
x
]
1.2 定义 H5
`ApiResponse<T>`
、首页数据响应类型和统一 API 错误类型,确保与既有 H5 首页字段契约兼容。
-
[
x
]
1.2 定义 H5
`ApiResponse<T>`
、首页数据响应类型和统一 API 错误类型,确保与既有 H5 首页字段契约兼容。
-
[
x
]
1.3 明确
`VITE_API_BASE_URL`
、
`VITE_API_PROXY_TARGET`
的优先级和默认值,其中开发代理默认目标为
`http://192.168.1.191:8000/`
。
-
[
x
]
1.3 明确
`VITE_API_BASE_URL`
、
`VITE_API_PROXY_TARGET`
的优先级和默认值,其中开发代理默认目标为
`http://192.168.1.191:8000/`
。
-
[
]
1.4 明确 H5 API client 默认 baseURL 与 Web 端保持一致:开发环境
`/api/v1`
,测试/生产环境
`/backend/api/v1`
,显式配置优先。
-
[
x
]
1.4 明确 H5 API client 默认 baseURL 与 Web 端保持一致:开发环境
`/api/v1`
,测试/生产环境
`/backend/api/v1`
,显式配置优先。
## 2. 测试先行
## 2. 测试先行
-
[
]
2.1 先编写 API client 测试,覆盖开发环境默认
`/api/v1`
、测试/生产环境默认
`/backend/api/v1`
、
`VITE_API_BASE_URL`
覆盖、
`code === 200/201`
解包、业务失败、HTTP 失败和网络失败。
-
[
x
]
2.1 先编写 API client 测试,覆盖开发环境默认
`/api/v1`
、测试/生产环境默认
`/backend/api/v1`
、
`VITE_API_BASE_URL`
覆盖、
`code === 200/201`
解包、业务失败、HTTP 失败和网络失败。
-
[
x
]
2.2 先编写首页 API 模块测试,验证请求
`GET /official-site/home`
并正确返回首页数据。
-
[
x
]
2.2 先编写首页 API 模块测试,验证请求
`GET /official-site/home`
并正确返回首页数据。
-
[
x
]
2.3 先编写
`useHomeData`
测试,覆盖真实接口成功加载、失败态、重试重新请求真实接口,以及失败时不展示 mock 兜底。
-
[
x
]
2.3 先编写
`useHomeData`
测试,覆盖真实接口成功加载、失败态、重试重新请求真实接口,以及失败时不展示 mock 兜底。
-
[
x
]
2.4 先编写 mock 边界测试或静态检查,验证 H5 运行时代码不 import
`src/mocks/api`
。
-
[
x
]
2.4 先编写 mock 边界测试或静态检查,验证 H5 运行时代码不 import
`src/mocks/api`
。
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
## 3. 实现真实接口接入
## 3. 实现真实接口接入
-
[
]
3.1 调整 H5 API client,统一处理 baseURL、响应解包和错误归一化,并按环境默认解析开发
`/api/v1`
、测试/生产
`/backend/api/v1`
。
-
[
x
]
3.1 调整 H5 API client,统一处理 baseURL、响应解包和错误归一化,并按环境默认解析开发
`/api/v1`
、测试/生产
`/backend/api/v1`
。
-
[
x
]
3.2 新增首页 API 模块,封装
`GET /api/v1/official-site/home`
真实接口调用。
-
[
x
]
3.2 新增首页 API 模块,封装
`GET /api/v1/official-site/home`
真实接口调用。
-
[
x
]
3.3 将
`useHomeData`
从
`src/mocks/api`
切换到首页 API 模块,并保留现有 loading、error、reload 状态模型。
-
[
x
]
3.3 将
`useHomeData`
从
`src/mocks/api`
切换到首页 API 模块,并保留现有 loading、error、reload 状态模型。
-
[
x
]
3.4 更新 Vite 配置,开发环境
`/api`
代理默认转发到
`http://192.168.1.191:8000/`
,并支持
`VITE_API_PROXY_TARGET`
覆盖。
-
[
x
]
3.4 更新 Vite 配置,开发环境
`/api`
代理默认转发到
`http://192.168.1.191:8000/`
,并支持
`VITE_API_PROXY_TARGET`
覆盖。
...
@@ -43,6 +43,6 @@
...
@@ -43,6 +43,6 @@
-
[
x
]
4.7 在浏览器验证 Banner 使用本地图片、胶囊标签展示”新一代智能协作平台”、方法论步骤图标位于步骤名称前方。
-
[
x
]
4.7 在浏览器验证 Banner 使用本地图片、胶囊标签展示”新一代智能协作平台”、方法论步骤图标位于步骤名称前方。
-
[
x
]
4.8 在浏览器验证岗位能力区左侧 Agent 素材下方不显示标题、英文副标题或描述,仅保留”立即体验”按钮。
-
[
x
]
4.8 在浏览器验证岗位能力区左侧 Agent 素材下方不显示标题、英文副标题或描述,仅保留”立即体验”按钮。
-
[
x
]
4.9 在浏览器验证 Agent 素材来自
`media_url`
、Agent 卡片图标来自
`icon_url`
、Agent 卡片概述来自
`speech_content`
。
-
[
x
]
4.9 在浏览器验证 Agent 素材来自
`media_url`
、Agent 卡片图标来自
`icon_url`
、Agent 卡片概述来自
`speech_content`
。
-
[
]
4.10 重新运行
`openspec validate "h5-real-api-integration" --strict`
。
-
[
x
]
4.10 重新运行
`openspec validate "h5-real-api-integration" --strict`
。
-
[
]
4.11 重新运行 H5 API client 相关单元测试,确认新增环境默认路径测试红绿通过。
-
[
x
]
4.11 重新运行 H5 API client 相关单元测试,确认新增环境默认路径测试红绿通过。
-
[
]
4.12 重新运行 H5 类型检查与构建,确认
`/backend/api/v1`
默认路径调整不破坏生产构建。
-
[
x
]
4.12 重新运行 H5 类型检查与构建,确认
`/backend/api/v1`
默认路径调整不破坏生产构建。
workspace/agent-admin/single-page/src/__tests__/apiClient.test.ts
View file @
3927388
import
{
describe
,
it
,
expect
,
vi
,
beforeEach
,
afterEach
}
from
'vitest'
;
import
{
describe
,
it
,
expect
,
vi
,
beforeEach
,
afterEach
}
from
'vitest'
;
import
{
createApiClient
}
from
'../api/client'
;
import
{
createApiClient
,
resolveApiBaseURL
}
from
'../api/client'
;
import
{
ApiError
,
isSuccessCode
}
from
'../api/types'
;
import
{
ApiError
,
isSuccessCode
}
from
'../api/types'
;
describe
(
'API Client 测试'
,
()
=>
{
describe
(
'API Client 测试'
,
()
=>
{
...
@@ -29,6 +29,18 @@ describe('API Client 测试', () => {
...
@@ -29,6 +29,18 @@ describe('API Client 测试', () => {
expect
(
mockFetch
).
toHaveBeenCalledWith
(
'/api/v1/test'
,
expect
.
any
(
Object
));
expect
(
mockFetch
).
toHaveBeenCalledWith
(
'/api/v1/test'
,
expect
.
any
(
Object
));
});
});
it
(
'开发环境默认 baseURL 为 /api/v1'
,
()
=>
{
expect
(
resolveApiBaseURL
({
MODE
:
'development'
,
DEV
:
true
})).
toBe
(
'/api/v1'
);
});
it
(
'测试环境默认 baseURL 为 /backend/api/v1'
,
()
=>
{
expect
(
resolveApiBaseURL
({
MODE
:
'test'
,
DEV
:
false
})).
toBe
(
'/backend/api/v1'
);
});
it
(
'生产环境默认 baseURL 为 /backend/api/v1'
,
()
=>
{
expect
(
resolveApiBaseURL
({
MODE
:
'production'
,
DEV
:
false
})).
toBe
(
'/backend/api/v1'
);
});
});
});
describe
(
'VITE_API_BASE_URL 覆盖'
,
()
=>
{
describe
(
'VITE_API_BASE_URL 覆盖'
,
()
=>
{
...
@@ -46,6 +58,16 @@ describe('API Client 测试', () => {
...
@@ -46,6 +58,16 @@ describe('API Client 测试', () => {
expect
(
mockFetch
).
toHaveBeenCalledWith
(
'https://custom.api.com/v2/test'
,
expect
.
any
(
Object
));
expect
(
mockFetch
).
toHaveBeenCalledWith
(
'https://custom.api.com/v2/test'
,
expect
.
any
(
Object
));
});
});
it
(
'环境变量覆盖开发/测试/生产默认值'
,
()
=>
{
expect
(
resolveApiBaseURL
({
MODE
:
'production'
,
DEV
:
false
,
VITE_API_BASE_URL
:
'https://custom.api.com/v2'
,
})
).
toBe
(
'https://custom.api.com/v2'
);
});
});
});
describe
(
'响应解包'
,
()
=>
{
describe
(
'响应解包'
,
()
=>
{
...
@@ -186,4 +208,4 @@ describe('isSuccessCode 辅助函数', () => {
...
@@ -186,4 +208,4 @@ describe('isSuccessCode 辅助函数', () => {
it
(
'500 不是成功码'
,
()
=>
{
it
(
'500 不是成功码'
,
()
=>
{
expect
(
isSuccessCode
(
500
)).
toBe
(
false
);
expect
(
isSuccessCode
(
500
)).
toBe
(
false
);
});
});
});
\ No newline at end of file
\ No newline at end of file
});
workspace/agent-admin/single-page/src/__tests__/setup.ts
View file @
3927388
import
'@testing-library/jest-dom'
;
\ No newline at end of file
\ No newline at end of file
import
'@testing-library/jest-dom'
;
import
{
vi
}
from
'vitest'
;
vi
.
stubEnv
(
'VITE_API_BASE_URL'
,
'/api/v1'
);
workspace/agent-admin/single-page/src/api/client.ts
View file @
3927388
...
@@ -10,10 +10,22 @@ export interface RequestOptions {
...
@@ -10,10 +10,22 @@ export interface RequestOptions {
body
?:
unknown
;
body
?:
unknown
;
}
}
const
DEFAULT_BASE_URL
=
import
.
meta
.
env
.
VITE_API_BASE_URL
??
'/api/v1'
;
export
interface
ApiRuntimeEnv
{
MODE
?:
string
;
DEV
?:
boolean
;
VITE_API_BASE_URL
?:
string
;
}
export
function
resolveApiBaseURL
(
env
:
ApiRuntimeEnv
=
import
.
meta
.
env
):
string
{
if
(
env
.
VITE_API_BASE_URL
)
{
return
env
.
VITE_API_BASE_URL
;
}
return
env
.
DEV
||
env
.
MODE
===
'development'
?
'/api/v1'
:
'/backend/api/v1'
;
}
export
function
createApiClient
(
options
:
ApiClientOptions
=
{})
{
export
function
createApiClient
(
options
:
ApiClientOptions
=
{})
{
const
baseUrl
=
options
.
baseUrl
??
DEFAULT_BASE_URL
;
const
baseUrl
=
options
.
baseUrl
??
resolveApiBaseURL
()
;
async
function
request
<
T
>
(
async
function
request
<
T
>
(
endpoint
:
string
,
endpoint
:
string
,
...
@@ -79,4 +91,4 @@ export function createApiClient(options: ApiClientOptions = {}) {
...
@@ -79,4 +91,4 @@ export function createApiClient(options: ApiClientOptions = {}) {
}
}
// Export types
// Export types
export
*
from
'./types'
;
\ No newline at end of file
\ No newline at end of file
export
*
from
'./types'
;
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment