Files
monkey-ai-web/src/components/dashboard/modals/SearchModal.jsx
T

218 lines
7.6 KiB
React

/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useRef } from 'react';
import { Modal, Form, Button } from '@/components/ui';
import { Filter, Calendar, Clock, User, Search, X } from 'lucide-react';
const SearchModal = ({
searchModalVisible,
handleSearchConfirm,
handleCloseModal,
isMobile,
isAdminUser,
inputs,
dataExportDefaultTime,
timeOptions,
handleInputChange,
t,
}) => {
const formRef = useRef();
const { start_timestamp, end_timestamp, username } = inputs;
// 自定义标题
const customTitle = (
<div className='flex items-center gap-3 pt-2'>
<div className='relative'>
<div className='absolute inset-0 bg-gradient-to-br from-blue-500 to-brand-to rounded-xl blur opacity-50' />
<div className='relative p-2.5 bg-gradient-to-br from-blue-500 to-brand-to rounded-xl shadow-lg shadow-blue-500/25'>
<Filter size={18} className='text-white' />
</div>
</div>
<div>
<h3 className='text-lg font-bold bg-clip-text text-transparent bg-gradient-to-r from-gray-900 to-gray-600 dark:from-white dark:to-gray-300'>
{t('筛选数据')}
</h3>
<p className='text-xs text-gray-400 dark:text-gray-500'>
{t('设置查询条件以筛选数据')}
</p>
</div>
</div>
);
// 自定义底部按钮
const customFooter = (
<div className='flex items-center justify-end gap-3'>
<Button
type='tertiary'
onClick={handleCloseModal}
className='!rounded-xl !px-5 !h-10 !bg-gray-100 dark:!bg-gray-700 !border-0 hover:!bg-gray-200 dark:hover:!bg-gray-600 !transition-all'
style={{ color: '#4b5563' }}
icon={<X size={16} style={{ color: '#4b5563' }} />}
>
{t('取消')}
</Button>
<Button
type='tertiary'
onClick={handleSearchConfirm}
className='!rounded-xl !px-5 !h-10 !bg-gradient-to-r !from-blue-500 !to-brand-to !border-0 hover:!opacity-90 !transition-all !shadow-lg !shadow-blue-500/25'
style={{ color: '#ffffff' }}
icon={<Search size={16} style={{ color: '#ffffff' }} />}
>
{t('查询')}
</Button>
</div>
);
// 表单字段包装器 - 紧凑版
const FormFieldWrapper = ({ icon: Icon, label, children, gradient }) => (
<div className='mb-3 last:mb-0'>
<div className='flex items-center gap-2 mb-1.5'>
<div
className={`w-5 h-5 rounded-md bg-gradient-to-br ${gradient} flex items-center justify-center`}
>
<Icon size={10} className='text-white' />
</div>
<span className='text-xs font-medium text-gray-600 dark:text-gray-400'>
{label}
</span>
</div>
<div className='relative'>{children}</div>
</div>
);
return (
<Modal
visible={searchModalVisible}
onCancel={handleCloseModal}
closeOnEsc={true}
size={isMobile ? 'full-width' : 'medium'}
centered
header={customTitle}
footer={customFooter}
className='search-modal-enhanced'
style={{ maxWidth: isMobile ? '100%' : '480px' }}
bodyStyle={{
padding: '16px 20px',
}}
>
<Form ref={formRef} layout='vertical' className='w-full'>
{/* 时间范围区域 */}
<div className='p-3 bg-gradient-to-br from-gray-50 to-gray-100/50 dark:from-gray-800/50 dark:to-gray-700/30 rounded-xl mb-3 border border-gray-100 dark:border-gray-700/50'>
<div className='flex items-center gap-2 mb-2'>
<div className='w-1 h-3 bg-gradient-to-b from-blue-500 to-brand-to rounded-full' />
<span className='text-xs font-semibold text-gray-600 dark:text-gray-300'>
{t('时间范围')}
</span>
</div>
{/* 时间选择器 - 单列布局确保宽度足够 */}
<FormFieldWrapper
icon={Calendar}
label={t('起始时间')}
gradient='from-emerald-500 to-teal-500'
>
<Form.DatePicker
field='start_timestamp'
noLabel
initValue={start_timestamp}
value={start_timestamp}
type='dateTime'
name='start_timestamp'
onChange={(value) => handleInputChange(value, 'start_timestamp')}
style={{ width: '100%' }}
className='[&_.ant-input-affix-wrapper]:!rounded-lg [&_.ant-input]:!text-sm'
/>
</FormFieldWrapper>
<FormFieldWrapper
icon={Calendar}
label={t('结束时间')}
gradient='from-orange-500 to-amber-500'
>
<Form.DatePicker
field='end_timestamp'
noLabel
initValue={end_timestamp}
value={end_timestamp}
type='dateTime'
name='end_timestamp'
onChange={(value) => handleInputChange(value, 'end_timestamp')}
style={{ width: '100%' }}
className='[&_.ant-input-affix-wrapper]:!rounded-lg [&_.ant-input]:!text-sm'
/>
</FormFieldWrapper>
</div>
{/* 其他选项区域 */}
<div className='p-3 bg-gradient-to-br from-gray-50 to-gray-100/50 dark:from-gray-800/50 dark:to-gray-700/30 rounded-xl border border-gray-100 dark:border-gray-700/50'>
<div className='flex items-center gap-2 mb-2'>
<div className='w-1 h-3 bg-gradient-to-b from-brand-from to-pink-500 rounded-full' />
<span className='text-xs font-semibold text-gray-600 dark:text-gray-300'>
{t('查询选项')}
</span>
</div>
<FormFieldWrapper
icon={Clock}
label={t('时间粒度')}
gradient='from-blue-500 to-brand-to'
>
<Form.Select
field='data_export_default_time'
noLabel
initValue={dataExportDefaultTime}
placeholder={t('时间粒度')}
name='data_export_default_time'
optionList={timeOptions}
onChange={(value) =>
handleInputChange(value, 'data_export_default_time')
}
style={{ width: '100%' }}
className='[&_.ant-select]:!rounded-lg'
/>
</FormFieldWrapper>
{isAdminUser && (
<FormFieldWrapper
icon={User}
label={t('用户名称')}
gradient='from-brand-from to-pink-500'
>
<Form.Input
field='username'
noLabel
value={username}
placeholder={t('可选值')}
name='username'
onChange={(value) => handleInputChange(value, 'username')}
style={{ width: '100%' }}
className='[&_.ant-input-affix-wrapper]:!rounded-lg'
/>
</FormFieldWrapper>
)}
</div>
</Form>
</Modal>
);
};
export default SearchModal;