import { TemplateParamObjectName, TemplateParam, TemplateParamExtensionKey } from '../customObject';
|
import { flattenDeep } from 'lodash';
|
import { fabric } from 'fabric';
|
import { Message } from '@bole-core/core';
|
|
export type CanvasJson = ReturnType<fabric.StaticCanvas['toJSON']> & {
|
backgroundImage?: fabric.Image;
|
};
|
|
export function convertJsonMapToTemplateParamObjectList(jsonMap: Record<number, CanvasJson>) {
|
const jsonList = Object.values(jsonMap).map((x) =>
|
x.objects.filter((item) => item.type === TemplateParamObjectName)
|
);
|
return flattenDeep(jsonList) as TemplateParam[];
|
}
|
|
export function checkTemplateParamObjectListNotNull(templateParamList: TemplateParam[]) {
|
for (const templateParam of templateParamList) {
|
const nullTemplateParamKey = TemplateParamExtensionKey.find(
|
(key) =>
|
!templateParam[key] &&
|
templateParam[key] !== false &&
|
key !== 'pageNum' &&
|
key !== 'templateDataParamId'
|
);
|
if (nullTemplateParamKey) {
|
Message.warnMessage(`模板参数${templateParam.label}存在必填属性为空`);
|
return false;
|
}
|
}
|
return true;
|
}
|