feat: 代码保持一致

This commit is contained in:
xingyu4j
2025-10-14 10:21:57 +08:00
parent c19097ec0c
commit 0a09970efb
6 changed files with 28 additions and 49 deletions

View File

@@ -6,48 +6,48 @@ import { isRef } from 'vue';
import formCreate from '@form-create/ant-design-vue';
// 编码表单 Conf
export const encodeConf = (designerRef: any) => {
export function encodeConf(designerRef: any) {
return JSON.stringify(designerRef.value.getOption());
};
}
// 编码表单 Fields
export const encodeFields = (designerRef: any) => {
export function encodeFields(designerRef: any) {
const rule = JSON.parse(designerRef.value.getJson());
const fields: string[] = [];
rule.forEach((item: unknown) => {
fields.push(JSON.stringify(item));
});
return fields;
};
}
// 解码表单 Fields
export const decodeFields = (fields: string[]) => {
export function decodeFields(fields: string[]) {
const rule: object[] = [];
fields.forEach((item) => {
rule.push(formCreate.parseJson(item));
});
return rule;
};
}
// 设置表单的 Conf 和 Fields适用 FcDesigner 场景
export const setConfAndFields = (
export function setConfAndFields(
designerRef: any,
conf: string,
fields: string | string[],
) => {
) {
designerRef.value.setOption(formCreate.parseJson(conf));
// 处理 fields 参数类型,确保传入 decodeFields 的是 string[] 类型
const fieldsArray = Array.isArray(fields) ? fields : [fields];
designerRef.value.setRule(decodeFields(fieldsArray));
};
}
// 设置表单的 Conf 和 Fields适用 form-create 场景
export const setConfAndFields2 = (
export function setConfAndFields2(
detailPreview: any,
conf: string,
fields: string[],
value?: any,
) => {
) {
if (isRef(detailPreview)) {
detailPreview = detailPreview.value;
}
@@ -56,4 +56,4 @@ export const setConfAndFields2 = (
if (value) {
detailPreview.value = value;
}
};
}

View File

@@ -6,11 +6,11 @@ const modules = import.meta.glob('../views/**/*.{vue,tsx}');
* 注册一个异步组件
* @param componentPath 例:/bpm/oa/leave/detail
*/
export const registerComponent = (componentPath: string) => {
export function registerComponent(componentPath: string) {
for (const item in modules) {
if (item.includes(componentPath)) {
// 使用异步组件的方式来动态加载组件
return defineAsyncComponent(modules[item] as any);
}
}
};
}

View File

@@ -1,19 +0,0 @@
// TODO @xingyu要不要抽到 package 里?
/**
* 将值复制到目标对象且以目标对象属性为准target: {a:1} source:{a:2,b:3} 结果为:{a:2}
* @param target 目标对象
* @param source 源对象
*/
export const copyValueToTarget = (target: any, source: any) => {
const newObj = Object.assign({}, target, source);
// 删除多余属性
Object.keys(newObj).forEach((key) => {
// 如果不是target中的属性则删除
if (!Object.keys(target).includes(key)) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete newObj[key];
}
});
// 更新目标对象值
Object.assign(target, newObj);
};

View File

@@ -5,13 +5,13 @@
import { isRef } from 'vue';
// 编码表单 Conf
export const encodeConf = (designerRef: object) => {
export function encodeConf(designerRef: object) {
// @ts-ignore designerRef.value is dynamically added by form-create-designer
return JSON.stringify(designerRef.value.getOption());
};
}
// 编码表单 Fields
export const encodeFields = (designerRef: object) => {
export function encodeFields(designerRef: object) {
// @ts-ignore designerRef.value is dynamically added by form-create-designer
const rule = JSON.parse(designerRef.value.getJson());
const fields: string[] = [];
@@ -19,36 +19,36 @@ export const encodeFields = (designerRef: object) => {
fields.push(JSON.stringify(item));
});
return fields;
};
}
// 解码表单 Fields
export const decodeFields = (fields: string[]) => {
export function decodeFields(fields: string[]) {
const rule: object[] = [];
fields.forEach((item) => {
rule.push(JSON.parse(item));
});
return rule;
};
}
// 设置表单的 Conf 和 Fields适用 FcDesigner 场景
export const setConfAndFields = (
export function setConfAndFields(
designerRef: object,
conf: string,
fields: string,
) => {
) {
// @ts-ignore designerRef.value is dynamically added by form-create-designer
designerRef.value.setOption(JSON.parse(conf));
// @ts-ignore designerRef.value is dynamically added by form-create-designer
designerRef.value.setRule(decodeFields(fields));
};
}
// 设置表单的 Conf 和 Fields适用 form-create 场景
export const setConfAndFields2 = (
export function setConfAndFields2(
detailPreview: object,
conf: string,
fields: string[],
value?: object,
) => {
) {
if (isRef(detailPreview)) {
// @ts-ignore detailPreview.value is dynamically added by form-create-designer
detailPreview = detailPreview.value;
@@ -61,4 +61,4 @@ export const setConfAndFields2 = (
// @ts-ignore detailPreview properties are dynamically added by form-create-designer
detailPreview.value = value;
}
};
}

View File

@@ -1,5 +1,3 @@
export * from './bean';
export * from './formCreate';
export * from './rangePickerProps';
export * from './routerHelper';
export { CommonStatusEnum } from '@vben/constants';

View File

@@ -5,11 +5,11 @@ const modules = import.meta.glob('../views/**/*.{vue,tsx}');
* 注册一个异步组件
* @param componentPath 例:/bpm/oa/leave/detail
*/
export const registerComponent = (componentPath: string) => {
export function registerComponent(componentPath: string) {
for (const item in modules) {
if (item.includes(componentPath)) {
// 使用异步组件的方式来动态加载组件
return defineAsyncComponent(modules[item] as any);
}
}
};
}