liyong
2 天以前 93b8ceac34e2fbd5c57fe5ab4f5bac32c85408aa
src/views/officeProcessAutomation/EnterpriseNews/news-manage/enterpriseNewsUtils.js
@@ -8,13 +8,62 @@
  { value: "culture", label: "文化活动", color: "#67c23a" },
];
/** 发布状态 */
/** 企业新闻状态(与后端枚举一致) */
export const PUBLISH_STATUS_OPTIONS = [
  { value: "draft", label: "草稿", tag: "info" },
  { value: "pending_review", label: "待审核", tag: "warning" },
  { value: "published", label: "已发布", tag: "success" },
  { value: "archived", label: "已归档", tag: "" },
  { value: "DRAFT", label: "草稿", tag: "info" },
  { value: "PENDING", label: "待审批", tag: "warning" },
  { value: "PUBLISHED", label: "已发布", tag: "success" },
  { value: "REJECTED", label: "驳回", tag: "danger" },
  { value: "OFFLINE", label: "已下线", tag: "info" },
];
/** 企业新闻列表筛选 */
export const ENTERPRISE_NEWS_STATUS_SEARCH_OPTIONS = [...PUBLISH_STATUS_OPTIONS];
const LEGACY_PUBLISH_STATUS_MAP = {
  draft: "DRAFT",
  pending_review: "PENDING",
  published: "PUBLISHED",
  archived: "OFFLINE",
};
/** 后端数字状态码 → 枚举(0 草稿 1 待审批 2 已发布 3 驳回 4 已下线) */
const ENTERPRISE_NEWS_STATUS_NUMERIC_MAP = {
  0: "DRAFT",
  1: "PENDING",
  2: "PUBLISHED",
  3: "REJECTED",
  4: "OFFLINE",
};
const ENTERPRISE_NEWS_STATUS_LABEL_MAP = {
  草稿: "DRAFT",
  待审批: "PENDING",
  已发布: "PUBLISHED",
  驳回: "REJECTED",
  已驳回: "REJECTED",
  已下线: "OFFLINE",
};
/** 统一为后端状态枚举值 */
export function normalizeEnterpriseNewsStatus(v) {
  if (v == null || v === "") return "DRAFT";
  if (typeof v === "number" || (typeof v === "string" && /^\d+$/.test(v.trim()))) {
    const numKey = ENTERPRISE_NEWS_STATUS_NUMERIC_MAP[Number(v)];
    if (numKey) return numKey;
  }
  const raw = String(v).trim();
  if (ENTERPRISE_NEWS_STATUS_LABEL_MAP[raw]) {
    return ENTERPRISE_NEWS_STATUS_LABEL_MAP[raw];
  }
  const upper = raw.toUpperCase();
  if (upper === "APPROVED") return "PUBLISHED";
  const hit = PUBLISH_STATUS_OPTIONS.find((x) => x.value === upper);
  if (hit) return hit.value;
  const legacy = LEGACY_PUBLISH_STATUS_MAP[raw.toLowerCase()];
  if (legacy) return legacy;
  return upper;
}
/** 排版模板 */
export const LAYOUT_TEMPLATE_OPTIONS = [
@@ -63,11 +112,13 @@
}
export function publishStatusLabel(v) {
  return PUBLISH_STATUS_OPTIONS.find((x) => x.value === v)?.label || v || "—";
  const key = normalizeEnterpriseNewsStatus(v);
  return PUBLISH_STATUS_OPTIONS.find((x) => x.value === key)?.label || v || "—";
}
export function publishStatusTag(v) {
  return PUBLISH_STATUS_OPTIONS.find((x) => x.value === v)?.tag || "info";
  const key = normalizeEnterpriseNewsStatus(v);
  return PUBLISH_STATUS_OPTIONS.find((x) => x.value === key)?.tag || "info";
}
export function layoutTemplateLabel(v) {
@@ -99,7 +150,7 @@
    readScope: "all",
    targetDeptIds: [],
    targetUserIds: [],
    publishStatus: "draft",
    publishStatus: "DRAFT",
    publisherName: "",
    publishTime: "",
    readRecords: [],
@@ -109,6 +160,8 @@
    versions: [],
    versionNo: 1,
    requireReadConfirm: false,
    templateId: null,
    templateName: "",
  };
}