增加审批组件

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 DesignCanvas from './components/DesignCanvas';
import PropertyPanel from './components/PropertyPanel';
import FormPreview, { type FormPreviewRef } from './components/FormPreview';
import FormPreview, { type FormPreviewRef } from './Preview';
import { COMPONENT_LIST } from './config';
import type { FieldConfig, FormConfig, FormSchema } from './types';
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 { Form, message } from 'antd';
import type { Rule } from 'antd/es/form';
import dayjs from 'dayjs';
import type { FieldConfig, FormConfig, ValidationRule, LinkageRule } from '../types';
import FieldRenderer from './FieldRenderer';
import GridFieldPreview from './GridFieldPreview';
import '../styles.css';
import type { FieldConfig, FormConfig, ValidationRule, LinkageRule } from './types';
import FieldRenderer from './components/FieldRenderer';
import GridFieldPreview from './components/GridFieldPreview';
import './styles.css';
interface FormPreviewProps {
/**
* Props
*/
export interface FormPreviewProps {
/** 字段列表 */
fields: FieldConfig[];
/** 表单配置 */
formConfig: FormConfig;
}
/**
*
*/
export interface FormPreviewRef {
/** 提交表单(触发验证) */
submit: () => Promise<void>;
/** 重置表单 */
reset: () => void;
}

View File

@ -1,14 +1,18 @@
/**
*
*
*
*
* 1. FormDesigner -
* 2. FormRenderer -
* 2. FormPreview -
* 3. FormRenderer - 使 FormPreview
*/
export { default as FormDesigner } 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 type { FormRendererProps } from './Renderer';

View File

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