This commit is contained in:
2025-03-28 14:45:54 +08:00
parent d9b9ce4676
commit 0079786b25
14 changed files with 3718 additions and 6 deletions
+260
View File
@@ -0,0 +1,260 @@
import { useState } from 'react';
interface BasicInfoProps {
onChange?: (data: Record<string, unknown>) => void;
}
export function BasicInfo({ onChange }: BasicInfoProps) {
const [isDescriptionExpanded, setIsDescriptionExpanded] = useState(false);
const [formData, setFormData] = useState({
name: '',
code: '',
riskLevel: 'medium',
type: '',
group: 'contract-base',
enabled: true,
description: '',
lawName: '',
lawArticles: '',
lawContent: ''
});
const toggleDescription = () => {
setIsDescriptionExpanded(!isDescriptionExpanded);
};
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>) => {
const { id, value } = e.target;
let fieldName = id;
// 映射id到表单字段名
switch(id) {
case 'checkpoint-name': fieldName = 'name'; break;
case 'checkpoint-code': fieldName = 'code'; break;
case 'risk-level': fieldName = 'riskLevel'; break;
case 'checkpointType': fieldName = 'type'; break;
case 'rule-group': fieldName = 'group'; break;
case 'is-enabled': fieldName = 'enabled'; break;
case 'checkpoint-description': fieldName = 'description'; break;
case 'law-name': fieldName = 'lawName'; break;
case 'law-articles': fieldName = 'lawArticles'; break;
case 'law-content': fieldName = 'lawContent'; break;
}
const newData = {
...formData,
[fieldName]: id === 'is-enabled' ? value === 'true' : value
};
setFormData(newData);
if (onChange) {
onChange(newData);
}
};
return (
<div className="ant-card">
<div className="ant-card-header">
<h3></h3>
</div>
<div className="ant-card-body">
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
<div>
<label className="form-label" htmlFor="checkpoint-name">
<span className="required-mark">*</span>
</label>
<input
id="checkpoint-name"
type="text"
className="form-input"
placeholder="请输入评查点名称"
value={formData.name}
onChange={handleInputChange}
/>
<div className="form-tip">使30</div>
</div>
<div>
<label className="form-label" htmlFor="checkpoint-code">
<span className="required-mark">*</span>
</label>
<input
id="checkpoint-code"
type="text"
className="form-input"
placeholder="请输入评查点编码"
value={formData.code}
onChange={handleInputChange}
/>
<div className="form-tip"></div>
</div>
<div>
<label className="form-label" htmlFor="risk-level">
<span className="required-mark">*</span>
</label>
<select
id="risk-level"
className="form-select"
value={formData.riskLevel}
onChange={handleInputChange}
>
<option value="high"></option>
<option value="medium"></option>
<option value="low"></option>
</select>
<div className="form-tip"></div>
</div>
<div>
<label className="form-label" htmlFor="checkpointType">
<span className="required-mark">*</span>
</label>
<select
className="form-select"
id="checkpointType"
value={formData.type}
onChange={handleInputChange}
>
<option value=""></option>
<option value="essential"></option>
<option value="content"></option>
<option value="format"></option>
<option value="legal"></option>
<option value="business"></option>
</select>
<div className="form-tip">便</div>
</div>
<div>
<label className="form-label" htmlFor="rule-group"></label>
<select
id="rule-group"
className="form-select"
value={formData.group}
onChange={handleInputChange}
>
<option value="contract-base"></option>
<option value="contract-sales"></option>
<option value="contract-purchase"></option>
<option value="license"></option>
<option value="punishment"></option>
</select>
</div>
<div>
<label className="form-label" htmlFor="is-enabled"></label>
<select
id="is-enabled"
className="form-select"
value={formData.enabled ? 'true' : 'false'}
onChange={handleInputChange}
>
<option value="true"></option>
<option value="false"></option>
</select>
<div className="form-tip"></div>
</div>
<div className="col-span-1 md:col-span-3">
<div
className={`flex justify-between items-center cursor-pointer ${isDescriptionExpanded ? 'expanded' : ''}`}
onClick={toggleDescription}
role="button"
tabIndex={0}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
toggleDescription();
}
}}
aria-expanded={isDescriptionExpanded}
aria-controls="description-section"
>
<h4 className="form-label mb-0"></h4>
<i className="ri-arrow-down-s-line text-lg expand-icon"></i>
</div>
<div id="description-section" className={`mt-2 ${isDescriptionExpanded ? '' : 'hidden'}`}>
<div className="mb-4">
<label className="form-label" htmlFor="checkpoint-description"></label>
<textarea
id="checkpoint-description"
className="form-textarea"
style={{ minHeight: '80px' }}
placeholder="请输入评查点描述,包括适用场景、评查目的等"
value={formData.description}
onChange={handleInputChange}
></textarea>
<div className="form-tip"></div>
</div>
{/* 引用法典输入区域 */}
<div className="border-t border-gray-100 pt-4 mb-4">
<label className="form-label" htmlFor="law-section"></label>
<div className="mb-3" id="law-section">
<label className="text-sm text-gray-600 mb-1 block" htmlFor="law-name"></label>
<input
type="text"
className="form-input"
placeholder="例如:《中华人民共和国民法典》"
id="law-name"
value={formData.lawName}
onChange={handleInputChange}
/>
</div>
<div className="mb-3">
<label className="text-sm text-gray-600 mb-1 block" htmlFor="law-articles"> <span className="text-xs text-gray-400">()</span></label>
<input
type="text"
className="form-input"
placeholder="例如:第五百八十五条,第五百八十六条"
id="law-articles"
value={formData.lawArticles}
onChange={handleInputChange}
/>
<div className="form-tip"></div>
</div>
<div className="mb-3">
<label className="text-sm text-gray-600 mb-1 block" htmlFor="law-content"></label>
<textarea
className="form-textarea"
style={{ minHeight: '60px' }}
placeholder="例如:当事人应当按照约定全面履行自己的义务。"
id="law-content"
value={formData.lawContent}
onChange={handleInputChange}
></textarea>
</div>
<div className="p-3 bg-blue-50 border border-blue-200 rounded-md text-sm text-blue-700 mb-2">
<i className="ri-information-line mr-1"></i>
</div>
{/* 预览区域 */}
<div className="p-3 border border-gray-200 rounded-md bg-gray-50 mt-3">
<div className="text-sm font-medium mb-2"></div>
<div className="law-reference">
<div className="law-reference-title" id="preview-law-name">
{formData.lawName || '《中华人民共和国民法典》'}
</div>
<div className="law-reference-articles" id="preview-law-articles">
{formData.lawArticles ? formData.lawArticles.split(',').map((article, index) => (
<span key={index} className="law-article">{article.trim()}</span>
)) : (
<>
<span className="law-article"></span>
<span className="law-article"></span>
</>
)}
</div>
<div className="law-reference-content" id="preview-law-content">
{formData.lawContent || '当事人应当按照约定全面履行自己的义务。'}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
);
}