增加审批组件

This commit is contained in:
dengqichen 2025-10-25 00:05:45 +08:00
parent 50c8b4240b
commit 2f4ff4b6bd
4 changed files with 74 additions and 56 deletions

View File

@ -43,7 +43,7 @@ import { arrayMove } from '@dnd-kit/sortable';
import ComponentPanel from './components/ComponentPanel'; import ComponentPanel from './components/ComponentPanel';
import DesignCanvas from './components/DesignCanvas'; import DesignCanvas from './components/DesignCanvas';
import PropertyPanel from './components/PropertyPanel'; import PropertyPanel from './components/PropertyPanel';
import FormPreview, { type FormPreviewRef } from './components/FormPreview'; import FormPreview, { type FormPreviewRef } from './Preview';
import { COMPONENT_LIST } from './config'; import { COMPONENT_LIST } from './config';
import type { FieldConfig, FormConfig, FormSchema } from './types'; import type { FieldConfig, FormConfig, FormSchema } from './types';
import type { ComponentMeta } from './config'; import type { ComponentMeta } from './config';

View File

@ -1,24 +1,62 @@
/** /**
* *
* *
*
*
* - 使
* -
* -
* - API
* -
*
* @example
* ```tsx
* // 使用示例
* import { FormPreview, FormPreviewRef } from '@/components/FormDesigner';
*
* const MyComponent = () => {
* const previewRef = useRef<FormPreviewRef>(null);
*
* // 从后端获取表单定义
* const formSchema = await getFormDefinitionById(id);
*
* return (
* <FormPreview
* ref={previewRef}
* fields={formSchema.fields}
* formConfig={formSchema.formConfig}
* />
* );
* };
* ```
*/ */
import React, { useState, useEffect, useImperativeHandle, forwardRef } from 'react'; import React, { useState, useEffect, useImperativeHandle, forwardRef } from 'react';
import { Form, message } from 'antd'; import { Form, message } from 'antd';
import type { Rule } from 'antd/es/form'; import type { Rule } from 'antd/es/form';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import type { FieldConfig, FormConfig, ValidationRule, LinkageRule } from '../types'; import type { FieldConfig, FormConfig, ValidationRule, LinkageRule } from './types';
import FieldRenderer from './FieldRenderer'; import FieldRenderer from './components/FieldRenderer';
import GridFieldPreview from './GridFieldPreview'; import GridFieldPreview from './components/GridFieldPreview';
import '../styles.css'; import './styles.css';
interface FormPreviewProps { /**
* Props
*/
export interface FormPreviewProps {
/** 字段列表 */
fields: FieldConfig[]; fields: FieldConfig[];
/** 表单配置 */
formConfig: FormConfig; formConfig: FormConfig;
} }
/**
*
*/
export interface FormPreviewRef { export interface FormPreviewRef {
/** 提交表单(触发验证) */
submit: () => Promise<void>; submit: () => Promise<void>;
/** 重置表单 */
reset: () => void; reset: () => void;
} }

View File

@ -1,14 +1,18 @@
/** /**
* *
* *
* *
* 1. FormDesigner - * 1. FormDesigner -
* 2. FormRenderer - * 2. FormPreview -
* 3. FormRenderer - 使 FormPreview
*/ */
export { default as FormDesigner } from './Designer'; export { default as FormDesigner } from './Designer';
export type { FormDesignerProps } from './Designer'; export type { FormDesignerProps } from './Designer';
export { default as FormPreview } from './Preview';
export type { FormPreviewProps, FormPreviewRef } from './Preview';
export { default as FormRenderer } from './Renderer'; export { default as FormRenderer } from './Renderer';
export type { FormRendererProps } from './Renderer'; export type { FormRendererProps } from './Renderer';

View File

@ -4,13 +4,8 @@
*/ */
import React from 'react'; import React from 'react';
import { import { Modal } from 'antd';
Dialog, import { FormPreview } from '@/components/FormDesigner';
DialogContent,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog';
import { FormRenderer } from '@/components/FormDesigner';
import type { FormDefinitionResponse } from '@/pages/Form/Definition/types'; import type { FormDefinitionResponse } from '@/pages/Form/Definition/types';
interface FormPreviewModalProps { interface FormPreviewModalProps {
@ -28,48 +23,29 @@ const FormPreviewModal: React.FC<FormPreviewModalProps> = ({
return null; return null;
} }
const { schema } = formDefinition;
return ( return (
<Dialog open={open} onOpenChange={onClose}> <Modal
<DialogContent className="max-w-5xl max-h-[90vh] overflow-y-auto"> title={`预览表单:${formDefinition.name}`}
<DialogHeader> open={open}
<DialogTitle> onCancel={onClose}
{formDefinition.name} footer={null}
{formDefinition.description && ( width={schema.formConfig.formWidth || 600}
<span className="text-sm font-normal text-muted-foreground ml-2"> styles={{
{formDefinition.description} body: {
</span> maxHeight: '70vh',
)} overflowY: 'auto',
</DialogTitle> padding: 0,
</DialogHeader> }
}}
<div className="py-4"> >
<FormRenderer <FormPreview
schema={formDefinition.schema} fields={schema.fields}
readonly={false} formConfig={schema.formConfig}
showSubmit={false}
showCancel={false}
/> />
</div> </Modal>
<div className="text-xs text-muted-foreground border-t pt-3 space-y-1">
<div>{formDefinition.key}</div>
<div>v{formDefinition.formVersion}</div>
<div>
<span className={`ml-1 ${
formDefinition.status === 'PUBLISHED' ? 'text-green-600' :
formDefinition.status === 'DRAFT' ? 'text-yellow-600' :
'text-gray-600'
}`}>
{formDefinition.status === 'PUBLISHED' ? '已发布' :
formDefinition.status === 'DRAFT' ? '草稿' :
formDefinition.status}
</span>
</div>
</div>
</DialogContent>
</Dialog>
); );
}; };
export default FormPreviewModal; export default FormPreviewModal;