刘光辉
4 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
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
33
34
35
36
37
38
39
40
41
42
43
44
45
import { formatFormLabel } from '#/components/FormGenerator/src/helper/formLabel';
 
interface FormMappingRecord {
  fileList?: unknown;
  nodeName?: string;
  [key: string]: unknown;
}
 
interface FormMappingNode {
  nodeName?: string;
  type?: string;
}
 
function parseRecordFileList(fileList: unknown): unknown[] {
  if (Array.isArray(fileList)) return fileList;
  if (typeof fileList !== 'string' || !fileList) return [];
  try {
    const parsed: unknown = JSON.parse(fileList);
    return Array.isArray(parsed) ? parsed : [];
  } catch {
    return [];
  }
}
 
export function buildFormMappingRecord(record: FormMappingRecord, node: FormMappingNode) {
  return {
    ...record,
    title: formatFormLabel(node.nodeName || record.nodeName),
    actionLabel: node.type === 'processing' ? '办理' : '审核',
    fileList: parseRecordFileList(record.fileList),
  };
}
 
export function formatRecordDepartmentName(name: unknown, showRoot: number, level = 0): string {
  if (typeof name !== 'string' || !name) return '';
  if (level === 0 && showRoot !== 0) return name;
  return name
    .split('、')
    .map((path) => {
      const names = path.split('/');
      const start = Math.max(level > 0 ? names.length - level : 0, showRoot === 0 && names.length > 1 ? 1 : 0);
      return names.slice(start).join('/');
    })
    .join('、');
}