wupengfei
16 小时以前 08bcae11d27cf2b5f0f23d413192c5367cb05b3d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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;
}