yyb
10 小时以前 a1df9699594b0a0e46d26a0394eafb1eb030c68b
src/views/officeProcessAutomation/EnterpriseNews/news-manage/enterpriseNewsApprovalBridge.js
@@ -1,98 +1,11 @@
import {
  createEmptyForm,
  publishStatusLabel,
  PUBLISH_STATUS_OPTIONS,
} from "./enterpriseNewsUtils.js";
import { normalizeApprovalStatusKey } from "../../ApproveManage/approve-list/approveListConstants.js";
/** formPayload 中存放完整企业新闻业务数据的键 */
export const ENTERPRISE_NEWS_PAYLOAD_KEY = "enterpriseNews";
export function extractEnterpriseNewsFromRow(row) {
  const payload = row?.formPayload || {};
  const raw = payload[ENTERPRISE_NEWS_PAYLOAD_KEY];
  if (raw && typeof raw === "object") {
    return { ...createEmptyForm(), ...raw };
  }
  return {
    ...createEmptyForm(),
    title: payload.title || row?.title || "",
    summary: payload.summary || "",
    newsType: payload.newsType || "announcement",
    contentHtml: payload.contentHtml || "",
  };
}
/** 列表行增强:主表展示新闻字段 */
export function enrichEnterpriseNewsListRow(row) {
  const news = extractEnterpriseNewsFromRow(row);
  const publishStatus =
    news.publishStatus || mapApprovalStatusToPublishStatus(row?.approvalStatus);
  return {
    ...row,
    newsNo: news.newsNo || row.instanceNo || "—",
    title: news.title || row.title || "—",
    summary: news.summary,
    newsType: news.newsType,
    publisherName: news.publisherName || row.applicantName || "—",
    publishTime: news.publishTime || row.createTime || "",
    updateTime: news.updateTime || row.createTime || "",
    publishStatus,
    _news: news,
  };
}
function mapApprovalStatusToPublishStatus(approvalStatus) {
  const key = normalizeApprovalStatusKey(approvalStatus);
  if (key === "approved") return "published";
  if (key === "pending") return "pending_review";
  if (key === "rejected") return "draft";
  return "draft";
}
/** 企业新闻表单 → 审批实例 formPayload */
export function syncNewsFormToSubmitPayload(newsForm, submitForm) {
  const snapshot = JSON.parse(JSON.stringify(newsForm));
  submitForm.formPayload = {
    ...(submitForm.formPayload || {}),
    [ENTERPRISE_NEWS_PAYLOAD_KEY]: snapshot,
    title: snapshot.title,
    summary: snapshot.summary,
  };
}
export function buildEnterpriseNewsTableColumns(buildTableActions) {
  return [
    { label: "编号", prop: "newsNo", width: 150 },
    { label: "标题", prop: "title", minWidth: 180, showOverflowTooltip: true },
    {
      label: "分类",
      prop: "newsType",
      width: 100,
      dataType: "slot",
      slot: "newsType",
    },
    {
      label: "状态",
      prop: "publishStatus",
      width: 90,
      dataType: "tag",
      formatData: (v) => publishStatusLabel(v),
      formatType: (v) => {
        const hit = PUBLISH_STATUS_OPTIONS.find((x) => x.value === v);
        return hit?.tag || "info";
      },
    },
    { label: "发布人", prop: "publisherName", width: 110 },
    { label: "发布时间", prop: "publishTime", width: 170 },
    { label: "更新时间", prop: "updateTime", width: 170 },
    {
      dataType: "action",
      label: "操作",
      align: "center",
      fixed: "right",
      width: 220,
      operation: buildTableActions(),
    },
  ];
}
/** @deprecated 请使用 enterpriseNewsMappers.js */
export {
  ENTERPRISE_NEWS_PAYLOAD_KEY,
  buildEnterpriseNewsSaveDto,
  buildEnterpriseNewsTableColumns,
  canEditEnterpriseNewsRow,
  extractEnterpriseNewsFromRow,
  mapApiRowToNewsForm,
  mapEnterpriseNewsFromApi,
  syncNewsFormToSubmitPayload,
} from "./enterpriseNewsMappers.js";