|
|
@ -1,4 +1,4 @@
|
|
|
|
import { useState } from 'react';
|
|
|
|
import { useState, useRef, useEffect } from 'react';
|
|
|
|
import { App, Popover, Flex, Button, List, Input } from 'antd';
|
|
|
|
import { App, Popover, Flex, Button, List, Input } from 'antd';
|
|
|
|
import { MessageOutlined, SendOutlined } from '@ant-design/icons';
|
|
|
|
import { MessageOutlined, SendOutlined } from '@ant-design/icons';
|
|
|
|
import { useAuthContext } from '@/stores/AuthContext';
|
|
|
|
import { useAuthContext } from '@/stores/AuthContext';
|
|
|
@ -22,18 +22,25 @@ const splitTemplate = (template) => {
|
|
|
|
return obj;
|
|
|
|
return obj;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const InputTemplate = ({ disabled = false, invokeSendMessage }) => {
|
|
|
|
const InputTemplate = ({ disabled = false, invokeSendMessage }) => {
|
|
|
|
|
|
|
|
const searchInputRef = useRef(null);
|
|
|
|
const { notification } = App.useApp();
|
|
|
|
const { notification } = App.useApp();
|
|
|
|
const { loginUser } = useAuthContext();
|
|
|
|
const { loginUser } = useAuthContext();
|
|
|
|
const { currentConversation, templates } = useConversationState();
|
|
|
|
const { currentConversation, templates } = useConversationState();
|
|
|
|
// 用于替换变量: customer, agent
|
|
|
|
// 用于替换变量: customer, agent
|
|
|
|
const valueMapped = { ...cloneDeep(currentConversation), ...objectMapper(loginUser, { username: [{ key: 'agent_name' }, { key: 'your_name' }] }) };
|
|
|
|
const valueMapped = { ...cloneDeep(currentConversation), ...objectMapper(loginUser, { username: [{ key: 'agent_name' }, { key: 'your_name' }] }) };
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
setDataSource(templates);
|
|
|
|
|
|
|
|
return () => {};
|
|
|
|
|
|
|
|
}, [templates]);
|
|
|
|
|
|
|
|
|
|
|
|
const [openTemplates, setOpenTemplates] = useState(false);
|
|
|
|
const [openTemplates, setOpenTemplates] = useState(false);
|
|
|
|
const [dataSource, setDataSource] = useState(templates);
|
|
|
|
const [dataSource, setDataSource] = useState(templates);
|
|
|
|
const [searchContent, setSearchContent] = useState('');
|
|
|
|
const [searchContent, setSearchContent] = useState('');
|
|
|
|
const handleSearchTemplates = (val) => {
|
|
|
|
const handleSearchTemplates = (val) => {
|
|
|
|
if (val.toLowerCase().trim() !== '') {
|
|
|
|
if (val.toLowerCase().trim() !== '') {
|
|
|
|
const res = templates.filter((item) => item.name.includes(val.toLowerCase().trim()) || item.components_origin.some((itemc) => itemc.text.toLowerCase().includes(val.toLowerCase().trim())));
|
|
|
|
const res = templates.filter(
|
|
|
|
|
|
|
|
(item) => item.name.includes(val.toLowerCase().trim()) || item.components_origin.some((itemc) => itemc.text.toLowerCase().includes(val.toLowerCase().trim()))
|
|
|
|
|
|
|
|
);
|
|
|
|
setDataSource(res);
|
|
|
|
setDataSource(res);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -117,9 +124,11 @@ const InputTemplate = ({ disabled = false, invokeSendMessage }) => {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
<Popover
|
|
|
|
<Popover
|
|
|
|
|
|
|
|
fresh
|
|
|
|
content={
|
|
|
|
content={
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
<Input.Search
|
|
|
|
<Input.Search
|
|
|
|
|
|
|
|
ref={searchInputRef}
|
|
|
|
onSearch={handleSearchTemplates}
|
|
|
|
onSearch={handleSearchTemplates}
|
|
|
|
allowClear
|
|
|
|
allowClear
|
|
|
|
value={searchContent}
|
|
|
|
value={searchContent}
|
|
|
@ -170,7 +179,7 @@ const InputTemplate = ({ disabled = false, invokeSendMessage }) => {
|
|
|
|
trigger='click'
|
|
|
|
trigger='click'
|
|
|
|
open={openTemplates}
|
|
|
|
open={openTemplates}
|
|
|
|
onOpenChange={setOpenTemplates}>
|
|
|
|
onOpenChange={setOpenTemplates}>
|
|
|
|
<Button type='primary' shape='circle' icon={<MessageOutlined />} size={'large'} disabled={disabled} />
|
|
|
|
<Button type='text' className=' rounded-none text-primary' icon={<MessageOutlined />} size={'middle'} disabled={disabled} />
|
|
|
|
</Popover>
|
|
|
|
</Popover>
|
|
|
|
</>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
);
|
|
|
|