feat: 代码保持一致
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user