新增数据,编辑数据初步完善
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import React, { useState } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
|
||||
interface BasicInfoProps {
|
||||
onChange?: (data: Record<string, unknown>) => void;
|
||||
initialData?: Record<string, any>;
|
||||
}
|
||||
|
||||
// 定义表单数据类型
|
||||
@@ -20,7 +21,7 @@ interface FormDataType {
|
||||
type: string;
|
||||
}
|
||||
|
||||
export function BasicInfo({ onChange }: BasicInfoProps) {
|
||||
export function BasicInfo({ onChange, initialData }: BasicInfoProps) {
|
||||
const [formData, setFormData] = useState<FormDataType>({
|
||||
name: '',
|
||||
code: '',
|
||||
@@ -39,6 +40,42 @@ export function BasicInfo({ onChange }: BasicInfoProps) {
|
||||
const [isDescExpanded, setIsDescExpanded] = useState(false);
|
||||
const [lawArticlesInput, setLawArticlesInput] = useState('');
|
||||
|
||||
// 当initialData变化时更新表单数据
|
||||
useEffect(() => {
|
||||
if (initialData) {
|
||||
const newFormData = {
|
||||
name: initialData.name || '',
|
||||
code: initialData.code || '',
|
||||
risk: initialData.risk || 'medium',
|
||||
is_enabled: initialData.is_enabled !== undefined ? initialData.is_enabled : true,
|
||||
description: initialData.description || '',
|
||||
references_laws: initialData.references_laws || {
|
||||
name: '',
|
||||
articles: [],
|
||||
content: ''
|
||||
},
|
||||
evaluation_point_groups_id: initialData.evaluation_point_groups_id || null,
|
||||
type: initialData.type || ''
|
||||
};
|
||||
|
||||
setFormData(newFormData);
|
||||
|
||||
// 更新法律条款输入框
|
||||
if (initialData.references_laws && Array.isArray(initialData.references_laws.articles)) {
|
||||
setLawArticlesInput(initialData.references_laws.articles.join(','));
|
||||
}
|
||||
|
||||
// 如果有描述或法律依据,默认展开详细信息
|
||||
if (initialData.description ||
|
||||
(initialData.references_laws &&
|
||||
(initialData.references_laws.name ||
|
||||
initialData.references_laws.content ||
|
||||
(initialData.references_laws.articles && initialData.references_laws.articles.length > 0)))) {
|
||||
setIsDescExpanded(true);
|
||||
}
|
||||
}
|
||||
}, [initialData]);
|
||||
|
||||
const handleToggleDescription = () => {
|
||||
setIsDescExpanded(!isDescExpanded);
|
||||
};
|
||||
@@ -210,102 +247,102 @@ export function BasicInfo({ onChange }: BasicInfoProps) {
|
||||
</select>
|
||||
<div className="form-tip">创建后是否立即启用此评查点</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-8">
|
||||
<div
|
||||
className={`flex justify-between items-center cursor-pointer ${isDescExpanded ? 'expanded' : ''}`}
|
||||
onClick={handleToggleDescription}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
handleToggleDescription();
|
||||
}
|
||||
}}
|
||||
tabIndex={0}
|
||||
role="button"
|
||||
>
|
||||
<label className="form-label mb-0" htmlFor="description-section">评查点描述与法律依据</label>
|
||||
<i className={`ri-arrow-${isDescExpanded ? 'up' : 'down'}-s-line text-lg expand-icon`}></i>
|
||||
</div>
|
||||
|
||||
<div className="col-span-1 md:col-span-3">
|
||||
<div
|
||||
className={`flex justify-between items-center cursor-pointer ${isDescExpanded ? 'expanded' : ''}`}
|
||||
onClick={handleToggleDescription}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
handleToggleDescription();
|
||||
}
|
||||
}}
|
||||
tabIndex={0}
|
||||
role="button"
|
||||
>
|
||||
<label className="form-label mb-0" htmlFor="description-section">评查点描述与法律依据</label>
|
||||
<i className="ri-arrow-down-s-line text-lg expand-icon"></i>
|
||||
<div className={`mt-2 ${isDescExpanded ? '' : 'hidden'}`} id="description-section">
|
||||
<div className="mb-4">
|
||||
<textarea
|
||||
id="rule-description"
|
||||
className="form-textarea"
|
||||
placeholder="请输入评查点的详细描述"
|
||||
style={{ minHeight: '80px' }}
|
||||
value={formData.description}
|
||||
onChange={handleInputChange}
|
||||
></textarea>
|
||||
<div className="form-tip">详细描述有助于其他用户了解该评查点的用途</div>
|
||||
</div>
|
||||
|
||||
<div className={`mt-2 ${isDescExpanded ? '' : 'hidden'}`} id="description-section">
|
||||
|
||||
{/* 引用法典输入区域 */}
|
||||
<div className="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.references_laws.name}
|
||||
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={lawArticlesInput}
|
||||
onChange={(e) => handleLawArticlesChange(e.target.value)}
|
||||
/>
|
||||
<div className="form-tip">多个条款用逗号分隔,将自动转换为数组格式</div>
|
||||
</div>
|
||||
|
||||
<div className="mb-4">
|
||||
<textarea
|
||||
id="rule-description"
|
||||
className="form-textarea"
|
||||
placeholder="请输入评查点的详细描述"
|
||||
style={{ minHeight: '80px' }}
|
||||
value={formData.description}
|
||||
<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.references_laws.content}
|
||||
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.references_laws.name}
|
||||
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={lawArticlesInput}
|
||||
onChange={(e) => handleLawArticlesChange(e.target.value)}
|
||||
/>
|
||||
<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.references_laws.content}
|
||||
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.references_laws.name || '《中华人民共和国民法典》'}
|
||||
</div>
|
||||
<div className="law-reference-articles" id="preview-law-articles">
|
||||
{formData.references_laws.articles.length > 0 ?
|
||||
formData.references_laws.articles.map((article, index) => (
|
||||
<span key={index} className="law-article">{article}</span>
|
||||
)) : (
|
||||
<>
|
||||
<span className="law-article">第五百八十五条</span>
|
||||
<span className="law-article">第五百八十六条</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div className="law-reference-content" id="preview-law-content">
|
||||
{formData.references_laws.content || '当事人应当按照约定全面履行自己的义务。'}
|
||||
</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="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.references_laws.name || '《中华人民共和国民法典》'}
|
||||
</div>
|
||||
<div className="law-reference-articles" id="preview-law-articles">
|
||||
{formData.references_laws.articles.length > 0 ?
|
||||
formData.references_laws.articles.map((article, index) => (
|
||||
<span key={index} className="law-article">{article}</span>
|
||||
)) : (
|
||||
<>
|
||||
<span className="law-article">第五百八十五条</span>
|
||||
<span className="law-article">第五百八十六条</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div className="law-reference-content" id="preview-law-content">
|
||||
{formData.references_laws.content || '当事人应当按照约定全面履行自己的义务。'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user