| | |
| | | import { mapAttachmentsFromApi } from "./approveTemplateConstants.js"; |
| | | import { |
| | | isDynamicOptionSource, |
| | | SELECT_OPTION_SOURCE, |
| | | selectOptionSourceLabel, |
| | | } from "./selectOptionSource.js"; |
| | | |
| | | export { selectOptionSourceLabel }; |
| | | |
| | | /** 填报项类型(与审批提交页 field.type 一致) */ |
| | | export const FORM_FIELD_TYPE_OPTIONS = [ |
| | | { value: "text", label: "单行文本" }, |
| | |
| | | min: 0, |
| | | precision: 0, |
| | | defaultValue: "", |
| | | optionSource: SELECT_OPTION_SOURCE.STATIC, |
| | | options: [{ label: "", value: "" }], |
| | | }; |
| | | } |
| | |
| | | min: f.min ?? 0, |
| | | precision: f.precision ?? 0, |
| | | defaultValue: normalizeDefaultValueFromApi(f), |
| | | optionSource: f.optionSource || SELECT_OPTION_SOURCE.STATIC, |
| | | options: (f.options || []).length |
| | | ? f.options.map((o) => ({ label: o.label || "", value: o.value ?? "" })) |
| | | : [{ label: "", value: "" }], |
| | |
| | | item.precision = f.precision ?? 0; |
| | | } |
| | | if (item.type === "select") { |
| | | const source = f.optionSource || SELECT_OPTION_SOURCE.STATIC; |
| | | item.optionSource = source; |
| | | if (!isDynamicOptionSource(source)) { |
| | | item.options = (f.options || []) |
| | | .filter((o) => (o.label || "").trim() || o.value !== "" && o.value != null) |
| | | .filter((o) => (o.label || "").trim() || (o.value !== "" && o.value != null)) |
| | | .map((o) => ({ label: (o.label || "").trim(), value: o.value })); |
| | | } |
| | | } |
| | | if (hasDefaultValue(f)) { |
| | | item.defaultValue = |
| | |
| | | if (keys.has(key)) return { ok: false, message: `字段标识「${key}」重复,请修改` }; |
| | | keys.add(key); |
| | | if (f.type === "select") { |
| | | const source = f.optionSource || SELECT_OPTION_SOURCE.STATIC; |
| | | if (isDynamicOptionSource(source)) continue; |
| | | const opts = (f.options || []).filter((o) => (o.label || "").trim() && o.value !== "" && o.value != null); |
| | | if (!opts.length) return { ok: false, message: `请为「${label}」配置至少一个下拉选项` }; |
| | | } |
| | |
| | | return dv.length === 2 ? `${dv[0]} ~ ${dv[1]}` : "—"; |
| | | } |
| | | if (field?.type === "select") { |
| | | if (isDynamicOptionSource(field.optionSource)) { |
| | | return `${selectOptionSourceLabel(field.optionSource)}:${String(dv)}`; |
| | | } |
| | | const opt = (field.options || []).find((o) => String(o.value) === String(dv)); |
| | | return opt?.label || String(dv); |
| | | } |
| | | return String(dv); |
| | | } |
| | | |
| | | /** 将后端模板行转为提交页模板结构(含 fields 默认值) */ |
| | | /** 将后端模板行转为提交页模板结构(含 fields 默认值、附件) */ |
| | | export function buildSubmitTemplateFromRow(row) { |
| | | const cfg = parseFormConfigToData(row?.formConfig); |
| | | const fields = (cfg.fields || []).map(({ _uid, ...rest }) => ({ |
| | |
| | | min: rest.min, |
| | | precision: rest.precision, |
| | | defaultValue: rest.defaultValue, |
| | | optionSource: rest.optionSource, |
| | | options: rest.options, |
| | | })); |
| | | return { |
| | |
| | | summaryPlaceholder: cfg.summaryPlaceholder || "", |
| | | approvalMode: cfg.approvalMode || "parallel", |
| | | fields, |
| | | storageBlobDTOs: mapAttachmentsFromApi(row), |
| | | }; |
| | | } |
| | | |