feat:【antd/ele】【组件】form-create 封装的代码统一评审

This commit is contained in:
YunaiV
2025-11-20 16:10:41 +08:00
parent 4aef96a8f8
commit 342a948bc0
17 changed files with 73 additions and 102 deletions

View File

@@ -8,37 +8,24 @@ import type { Recordable } from '@vben/types';
export interface DescriptionItemSchema {
labelMinWidth?: number;
contentMinWidth?: number;
// 自定义标签样式
labelStyle?: CSSProperties;
// 对应 data 中的字段名
field: string;
// 内容的描述
label: JSX.Element | string | VNode;
// 包含列的数量
span?: number;
// 是否显示
show?: (...arg: any) => boolean;
// 插槽名称
slot?: string;
// 自定义需要展示的内容
labelStyle?: CSSProperties; // 自定义标签样式
field: string; // 对应 data 中的字段名
label: JSX.Element | string | VNode; // 内容的描述
span?: number; // 包含列的数量
show?: (...arg: any) => boolean; // 是否显示
slot?: string; // 插槽名称
render?: (
val: any,
data?: Recordable<any>,
) => Element | JSX.Element | number | string | undefined | VNode;
) => Element | JSX.Element | number | string | undefined | VNode; // 自定义需要展示的内容
}
export interface DescriptionProps extends DescriptionsProps {
// 是否包含卡片组件
useCard?: boolean;
// 描述项配置
schema: DescriptionItemSchema[];
// 数据
data: Recordable<any>;
// 标题
title?: string;
// 是否包含边框
bordered?: boolean;
// 列数
useCard?: boolean; // 是否包含卡片组件
schema: DescriptionItemSchema[]; // 描述项配置
data: Recordable<any>; // 数据
title?: string; // 标题
bordered?: boolean; // 是否包含边框
column?:
| number
| {
@@ -48,7 +35,7 @@ export interface DescriptionProps extends DescriptionsProps {
xl: number;
xs: number;
xxl: number;
};
}; // 列数
}
export interface DescInstance {

View File

@@ -24,7 +24,7 @@ const props = withDefaults(defineProps<DictSelectProps>(), {
const attrs = useAttrs();
// 获得字典配置
/** 获得字典配置 */
const getDictOption = computed(() => {
switch (props.valueType) {
case 'bool': {

View File

@@ -16,7 +16,7 @@ export function useImagesUpload() {
},
},
setup() {
// TODO: @dhb52 其实还是靠 props 默认参数起作用,没能从 formCreate 传递
// TODO: @puhui999@dhb52 其实还是靠 props 默认参数起作用,没能从 formCreate 传递
return (props: { maxNumber?: number; multiple?: boolean }) => (
<ImageUpload maxNumber={props.maxNumber} multiple={props.multiple} />
);

View File

@@ -19,12 +19,12 @@ import {
useUploadImagesRule,
} from './rules';
// 编码表单 Conf
/** 编码表单 Conf */
export function encodeConf(designerRef: any) {
return JSON.stringify(designerRef.value.getOption());
}
// 编码表单 Fields
/** 编码表单 Fields */
export function encodeFields(designerRef: any) {
const rule = JSON.parse(designerRef.value.getJson());
const fields: string[] = [];
@@ -34,7 +34,7 @@ export function encodeFields(designerRef: any) {
return fields;
}
// 解码表单 Fields
/** 解码表单 Fields */
export function decodeFields(fields: string[]) {
const rule: Rule[] = [];
fields.forEach((item) => {
@@ -43,7 +43,7 @@ export function decodeFields(fields: string[]) {
return rule;
}
// 设置表单的 Conf 和 Fields适用 FcDesigner 场景
/** 设置表单的 Conf 和 Fields适用 FcDesigner 场景 */
export function setConfAndFields(
designerRef: any,
conf: string,
@@ -55,7 +55,7 @@ export function setConfAndFields(
designerRef.value.setRule(decodeFields(fieldsArray));
}
// 设置表单的 Conf 和 Fields适用 form-create 场景
/** 设置表单的 Conf 和 Fields适用 form-create 场景 */
export function setConfAndFields2(
detailPreview: any,
conf: string,
@@ -155,9 +155,7 @@ export async function useFormCreateDesigner(designer: Ref) {
const uploadImageRule = useUploadImageRule();
const uploadImagesRule = useUploadImagesRule();
/**
* 构建表单组件
*/
/** 构建表单组件 */
function buildFormComponents() {
// 移除自带的上传组件规则,使用 uploadFileRule、uploadImgRule、uploadImgsRule 替代
designer.value?.removeMenuItem('upload');
@@ -200,9 +198,7 @@ export async function useFormCreateDesigner(designer: Ref) {
event: ['click', 'change', 'visibleChange', 'clear', 'blur', 'focus'],
});
/**
* 构建系统字段菜单
*/
/** 构建系统字段菜单 */
function buildSystemMenu() {
// 移除自带的下拉选择器组件,使用 currencySelectRule 替代
// designer.value?.removeMenuItem('select')

View File

@@ -11,9 +11,7 @@ import {
} from '#/components/form-create/helpers';
import { selectRule } from '#/components/form-create/rules/data';
/**
* 字典选择器规则,如果规则使用到动态数据则需要单独配置不能使用 useSelectRule
*/
/** 字典选择器规则,如果规则使用到动态数据则需要单独配置不能使用 useSelectRule */
export function useDictSelectRule() {
const label = '字典选择器';
const name = 'DictSelect';