yyb
8 小时以前 a1df9699594b0a0e46d26a0394eafb1eb030c68b
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { computed } from "vue";
import {
  businessApprovalStatusLabel,
  businessApprovalStatusTagType,
  formatFieldDisplayValue,
  resolveInstanceFormFields,
} from "../approve-list/approveListConstants.js";
 
/** 列表/详情不回显为独立列的填报项 key(避免覆盖实例系统字段) */
const DEFAULT_EXCLUDE_KEYS = new Set([
  "summary",
  "status",
  "approvalStatus",
  "approvalstatus",
  "instanceStatus",
  "publishStatus",
  "newsStatus",
]);
 
/** enrich 后必须保留的实例字段(不被 formConfig 铺平覆盖) */
const PRESERVE_INSTANCE_FIELDS = [
  "id",
  "approvalStatus",
  "statusRaw",
  "status",
  "instanceNo",
  "templateId",
  "templateName",
  "businessType",
  "businessId",
  "businessName",
  "applicantId",
  "applicantNo",
  "applicantName",
  "createTime",
  "applyTime",
  "finishTime",
  "title",
  "isApprove",
  "unread",
  "currentLevel",
  "newsStatus",
];
 
/**
 * 从行数据 formConfig 解析字段定义与填报值,并铺平到行上供主表 prop 绑定(展示用格式化值)
 */
export function enrichInstanceRowFromFormConfig(row, caches) {
  const { fields, formPayload, templateSnapshot } = resolveInstanceFormFields(row);
  const formDisplay = {};
  const displayRow = {
    ...row,
    formFieldDefs: fields,
    formPayload,
    templateSnapshot: row.templateSnapshot || templateSnapshot,
    formDisplay,
  };
 
  for (const f of fields) {
    if (!f?.key || DEFAULT_EXCLUDE_KEYS.has(f.key)) continue;
    const val = formPayload[f.key];
    let text = formatFieldDisplayValue(f, val, caches);
    if (
      text === String(val) &&
      row?.applicantName &&
      (f.label === "申请人" || f.key === "applicant" || f.key === "applicantName")
    ) {
      const idMatch =
        String(val) === String(row.applicantId) ||
        String(val) === String(row.applicantNo);
      if (idMatch) text = row.applicantName;
    }
    formDisplay[f.key] = text;
    displayRow[f.key] = text;
  }
 
  for (const key of PRESERVE_INSTANCE_FIELDS) {
    if (row[key] !== undefined) displayRow[key] = row[key];
  }
 
  return displayRow;
}
 
/**
 * 从列表首行 formConfig 生成主表动态列(label 取自模板字段 label)
 */
export function getFormConfigFieldColumns(firstRow, { excludeKeys = DEFAULT_EXCLUDE_KEYS } = {}) {
  const fields = (firstRow?.formFieldDefs || []).filter(
    (f) => f?.key && !excludeKeys.has(f.key)
  );
  return fields.map((f) => ({
    label: f.label || f.key,
    prop: f.key,
    minWidth: f.type === "textarea" ? 200 : f.type === "datetimerange" ? 160 : 120,
    showOverflowTooltip: true,
  }));
}
 
/**
 * 业务申请主表列:固定列 + formConfig 动态列 + 审批状态 + 操作
 */
export function buildInstanceTableColumns(tableDataRef, buildTableActions, options = {}) {
  const {
    excludeKeys = DEFAULT_EXCLUDE_KEYS,
    beforeFormColumns = [],
    extraColumns = [],
    afterFormColumns = [],
    actionWidth = 260,
  } = options;
 
  return computed(() => {
    const formCols = getFormConfigFieldColumns(tableDataRef.value?.[0], { excludeKeys });
    return [
      ...beforeFormColumns,
      ...formCols,
      ...extraColumns,
      ...afterFormColumns,
      { label: "创建时间", prop: "createTime", width: 170 },
      {
        label: "审批状态",
        prop: "approvalStatus",
        width: 110,
        dataType: "tag",
        formatData: (v) => businessApprovalStatusLabel(v),
        formatType: (v) => businessApprovalStatusTagType(v),
      },
      {
        dataType: "action",
        label: "操作",
        align: "center",
        fixed: "right",
        width: actionWidth,
        operation: buildTableActions(),
      },
    ];
  });
}