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
c4b8c5a6
Commit
c4b8c5a6
authored
Aug 13, 2024
by
HoMeTown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 管理对话记录
parent
3e81b31f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
5 deletions
+61
-5
src/api/conversation.ts
+10
-0
src/components/ConversationModal/index.tsx
+23
-4
src/store/conversationSlice.ts
+28
-1
No files found.
src/api/conversation.ts
View file @
c4b8c5a6
...
...
@@ -23,3 +23,13 @@ export function fetchCreateConversation<T>(data: T) {
export
function
fetchUserQaRecordPage
(
conversationId
:
string
)
{
return
http
.
post
(
'/conversation/api/conversation/mobile/v1/query_user_qa_record_list'
,
{
conversationId
})
}
/**
* 删除用户历史会话
* @params
*/
export
function
fetchDeleteUserConversation
(
conversationIdList
:
string
[])
{
return
http
.
post
(
'/conversation/api/conversation/mobile/v1/delete_user_conversation'
,
{
conversationIdList
,
})
}
src/components/ConversationModal/index.tsx
View file @
c4b8c5a6
import
{
Button
,
Modal
,
ModalBody
,
ModalContent
,
ModalFooter
,
ModalHeader
,
Table
,
TableBody
,
TableCell
,
TableColumn
,
TableHeader
,
TableRow
,
getKeyValue
}
from
'@nextui-org/react'
import
React
from
'react'
import
{
useDispatch
}
from
'react-redux'
import
{
useAppSelector
}
from
'@/store/hook'
import
{
deleteConversations
}
from
'@/store/conversationSlice'
import
useToast
from
'@/hooks/useToast'
interface
ConversationModalProps
{
isOpen
:
boolean
...
...
@@ -8,6 +11,9 @@ interface ConversationModalProps {
}
export
const
ConversationModal
:
React
.
FC
<
ConversationModalProps
>
=
({
isOpen
,
onClose
})
=>
{
const
dispatch
=
useDispatch
()
const
showToast
=
useToast
()
const
tableColumns
=
[
{
key
:
'conversationTitle'
,
...
...
@@ -26,8 +32,17 @@ export const ConversationModal: React.FC<ConversationModalProps> = ({ isOpen, on
setSelectedKeys
(
new
Set
([]))
onClose
()
}
const
handleDelete
=
()
=>
{
// console.log(selectedKeys, 'asd')
const
handleDelete
=
async
()
=>
{
const
selectedKeysArray
=
Array
.
from
(
selectedKeys
)
as
string
[]
if
(
selectedKeysArray
.
length
>
0
)
{
const
resultAction
=
await
dispatch
(
deleteConversations
(
selectedKeysArray
))
if
(
deleteConversations
.
fulfilled
.
match
(
resultAction
))
{
showToast
(
'删除成功'
,
'success'
)
}
else
{
showToast
(
'删除失败'
,
'error'
)
}
}
}
return
(
<
Modal
backdrop=
"blur"
size=
"3xl"
isOpen=
{
isOpen
}
onClose=
{
handleClose
}
>
...
...
@@ -37,7 +52,11 @@ export const ConversationModal: React.FC<ConversationModalProps> = ({ isOpen, on
<
ModalHeader
className=
"flex flex-col gap-1"
>
<
div
>
管理对话记录
<
span
className=
"text-[#8D9795] text-[14px]"
>
(共11条)
</
span
>
<
span
className=
"text-[#8D9795] text-[14px]"
>
(共
{
allItems
.
length
}
条)
</
span
>
</
div
>
</
ModalHeader
>
<
ModalBody
className=
"text-[#27353C]"
>
...
...
@@ -65,7 +84,7 @@ export const ConversationModal: React.FC<ConversationModalProps> = ({ isOpen, on
<
Button
onPress=
{
onClose
}
>
取消
</
Button
>
<
Button
color=
"primary"
onClick=
{
handleDelete
}
>
<
Button
isDisabled=
{
[...
selectedKeys
].
length
===
0
}
color=
"primary"
onClick=
{
handleDelete
}
>
删除所选
</
Button
>
</
ModalFooter
>
...
...
src/store/conversationSlice.ts
View file @
c4b8c5a6
...
...
@@ -2,7 +2,7 @@ import type { PayloadAction } from '@reduxjs/toolkit'
import
{
createAsyncThunk
,
createSlice
}
from
'@reduxjs/toolkit'
import
{
processConversationData
}
from
'./conversationSlice.helper'
import
type
{
Conversation
,
ConversationState
}
from
'@/types/conversation'
import
{
fetchCreateConversation
,
fetchQueryUserConversationPage
}
from
'@/api/conversation'
import
{
fetchCreateConversation
,
fetch
DeleteUserConversation
,
fetch
QueryUserConversationPage
}
from
'@/api/conversation'
const
initialState
:
ConversationState
=
{
conversations
:
[],
...
...
@@ -32,6 +32,29 @@ export const fetchConversations = createAsyncThunk(
},
)
export
const
deleteConversations
=
createAsyncThunk
<
boolean
,
string
[],
{
rejectValue
:
boolean
}
>
(
'conversation/deleteConversations'
,
async
(
conversationIds
,
{
dispatch
,
rejectWithValue
})
=>
{
try
{
// 调用删除会话的 API,传入 ID 集合
await
fetchDeleteUserConversation
(
conversationIds
)
// 删除成功后,重新获取会话列表
await
dispatch
(
fetchConversations
())
return
true
// 删除成功
}
catch
(
error
)
{
console
.
error
(
'Failed to delete conversations:'
,
error
)
return
rejectWithValue
(
false
)
// 删除失败
}
},
)
export
const
createConversation
=
createAsyncThunk
<
{
conversation
:
Conversation
,
shouldNavigate
:
boolean
,
shouldSendQuestion
:
string
},
{
conversationData
:
Partial
<
Conversation
>
,
shouldNavigate
:
boolean
,
shouldSendQuestion
:
string
},
...
...
@@ -102,6 +125,10 @@ const conversationSlice = createSlice({
state
.
isLoading
=
false
state
.
error
=
action
.
error
.
message
||
'Failed to create conversation'
})
.
addCase
(
deleteConversations
.
fulfilled
,
()
=>
{
})
.
addCase
(
deleteConversations
.
rejected
,
()
=>
{
})
},
})
...
...
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