Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sdream-ai-fe
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
侯明涛
sdream-ai-fe
Commits
d920f8aa
Commit
d920f8aa
authored
Dec 01, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:注释mock数据
parent
122b11f9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
40 deletions
+21
-40
src/api/home.ts
+2
-14
src/api/mock/conversation.ts
+4
-0
src/api/mock/home.ts
+4
-0
src/components/ChatEditor/index.tsx
+4
-2
src/store/conversationSlice.ts
+7
-24
No files found.
src/api/home.ts
View file @
d920f8aa
import
http
from
'@/utils/request'
import
http
from
'@/utils/request'
import
{
mockFetchEfficiencyQuestionList
}
from
'@/api/mock/home'
/**
/**
* 查询推荐问题列表
* 查询推荐问题列表
...
@@ -28,17 +27,6 @@ export function fetchToolList(params?: { userRoles?: string[] }) {
...
@@ -28,17 +27,6 @@ export function fetchToolList(params?: { userRoles?: string[] }) {
* @params
* @params
* toolId: 工具id
* toolId: 工具id
*/
*/
const
shouldUseEfficiencyMock
=
(
import
.
meta
as
any
).
env
?.
VITE_USE_EFFICIENCY_MOCK
===
'true'
export
function
fetchEfficiencyQuestionList
(
data
:
any
)
{
return
http
.
post
(
'/conversation/api/conversation/mobile/v1/generate_question'
,
data
)
export
async
function
fetchEfficiencyQuestionList
(
data
:
any
)
{
if
(
shouldUseEfficiencyMock
)
return
mockFetchEfficiencyQuestionList
()
try
{
return
await
http
.
post
(
'/conversation/api/conversation/mobile/v1/generate_question'
,
data
)
}
catch
(
error
)
{
console
.
warn
(
'fetchEfficiencyQuestionList fallback to mock due to error:'
,
error
)
return
mockFetchEfficiencyQuestionList
()
}
}
}
src/api/mock/conversation.ts
View file @
d920f8aa
/*
import { subDays, subMinutes } from 'date-fns'
import { subDays, subMinutes } from 'date-fns'
import type { Conversation } from '@/types/conversation'
import type { Conversation } from '@/types/conversation'
...
@@ -104,3 +105,6 @@ const conversationPageMockResponse: ConversationPageResponse = {
...
@@ -104,3 +105,6 @@ const conversationPageMockResponse: ConversationPageResponse = {
export function mockFetchConversationPage() {
export function mockFetchConversationPage() {
return Promise.resolve(conversationPageMockResponse)
return Promise.resolve(conversationPageMockResponse)
}
}
*/
export
{}
src/api/mock/home.ts
View file @
d920f8aa
/*
interface EfficiencyQuestionResponse {
interface EfficiencyQuestionResponse {
code: string
code: string
message: string
message: string
...
@@ -28,3 +29,6 @@ const efficiencyQuestionMockResponse: EfficiencyQuestionResponse = {
...
@@ -28,3 +29,6 @@ const efficiencyQuestionMockResponse: EfficiencyQuestionResponse = {
export function mockFetchEfficiencyQuestionList(): Promise<EfficiencyQuestionResponse> {
export function mockFetchEfficiencyQuestionList(): Promise<EfficiencyQuestionResponse> {
return Promise.resolve(efficiencyQuestionMockResponse)
return Promise.resolve(efficiencyQuestionMockResponse)
}
}
*/
export
{}
src/components/ChatEditor/index.tsx
View file @
d920f8aa
...
@@ -11,6 +11,7 @@ import { fetchToolList } from '@/api/home'
...
@@ -11,6 +11,7 @@ import { fetchToolList } from '@/api/home'
import
{
clearCurrentToolId
,
createConversation
,
setCurrentToolId
}
from
'@/store/conversationSlice'
import
{
clearCurrentToolId
,
createConversation
,
setCurrentToolId
}
from
'@/store/conversationSlice'
import
{
getUserRolesForApi
}
from
'@/lib/utils'
import
{
getUserRolesForApi
}
from
'@/lib/utils'
/*
const MOCK_TOOL_LIST = [
const MOCK_TOOL_LIST = [
{
{
toolId: '6712395743241',
toolId: '6712395743241',
...
@@ -40,6 +41,7 @@ const MOCK_TOOL_LIST = [
...
@@ -40,6 +41,7 @@ const MOCK_TOOL_LIST = [
showOrder: 8,
showOrder: 8,
},
},
] as const
] as const
*/
interface
ChatEditorProps
{
interface
ChatEditorProps
{
onChange
?:
(
value
:
string
)
=>
void
onChange
?:
(
value
:
string
)
=>
void
...
@@ -81,12 +83,12 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
...
@@ -81,12 +83,12 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
setToolList
(
uniqueList
)
setToolList
(
uniqueList
)
}
}
else
{
else
{
setToolList
([
...
MOCK_TOOL_LIST
])
setToolList
([])
}
}
}
}
catch
(
error
)
{
catch
(
error
)
{
console
.
error
(
'获取工具列表失败:'
,
error
)
console
.
error
(
'获取工具列表失败:'
,
error
)
setToolList
([
...
MOCK_TOOL_LIST
])
setToolList
([])
}
}
}
}
...
...
src/store/conversationSlice.ts
View file @
d920f8aa
...
@@ -3,9 +3,6 @@ import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'
...
@@ -3,9 +3,6 @@ import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'
import
{
processConversationData
}
from
'./conversationSlice.helper'
import
{
processConversationData
}
from
'./conversationSlice.helper'
import
type
{
Conversation
,
ConversationState
}
from
'@/types/conversation'
import
type
{
Conversation
,
ConversationState
}
from
'@/types/conversation'
import
{
fetchCreateConversation
,
fetchDeleteUserConversation
,
fetchQueryUserConversationPage
}
from
'@/api/conversation'
import
{
fetchCreateConversation
,
fetchDeleteUserConversation
,
fetchQueryUserConversationPage
}
from
'@/api/conversation'
import
{
mockFetchConversationPage
}
from
'@/api/mock/conversation'
const
shouldUseConversationMock
=
(
import
.
meta
as
any
).
env
?.
VITE_USE_CONVERSATION_MOCK
===
'true'
const
initialState
:
ConversationState
=
{
const
initialState
:
ConversationState
=
{
conversations
:
[],
conversations
:
[],
...
@@ -21,30 +18,16 @@ export const fetchConversations = createAsyncThunk(
...
@@ -21,30 +18,16 @@ export const fetchConversations = createAsyncThunk(
'conversation/fetchConversations'
,
'conversation/fetchConversations'
,
async
(
_
,
{
rejectWithValue
})
=>
{
async
(
_
,
{
rejectWithValue
})
=>
{
try
{
try
{
const
response
=
shouldUseConversationMock
const
response
=
await
fetchQueryUserConversationPage
({
?
await
mockFetchConversationPage
()
keyword
:
''
,
:
await
fetchQueryUserConversationPage
({
pageNum
:
0
,
keyword
:
''
,
pageSize
:
100
,
pageNum
:
0
,
})
pageSize
:
100
,
const
records
=
response
.
data
?.
records
||
[]
})
return
processConversationData
(
records
)
const
records
=
response
.
data
.
records
const
processedData
=
records
.
length
===
0
&&
!
shouldUseConversationMock
?
processConversationData
((
await
mockFetchConversationPage
()).
data
.
records
)
:
processConversationData
(
records
)
return
processedData
}
}
// eslint-disable-next-line unused-imports/no-unused-vars
// eslint-disable-next-line unused-imports/no-unused-vars
catch
(
error
)
{
catch
(
error
)
{
if
(
!
shouldUseConversationMock
)
{
try
{
const
mockResponse
=
await
mockFetchConversationPage
()
return
processConversationData
(
mockResponse
.
data
.
records
)
}
catch
{
// ignore and fall through to reject
}
}
return
rejectWithValue
(
'Failed to fetch conversations'
)
return
rejectWithValue
(
'Failed to fetch conversations'
)
}
}
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment