From a1df9699594b0a0e46d26a0394eafb1eb030c68b Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期三, 20 五月 2026 17:42:09 +0800
Subject: [PATCH] 企业新闻

---
 src/views/officeProcessAutomation/EnterpriseNews/news-manage/enterpriseNewsUtils.js |  268 +++++++----------------------------------------------
 1 files changed, 37 insertions(+), 231 deletions(-)

diff --git a/src/views/officeProcessAutomation/EnterpriseNews/news-manage/enterpriseNewsUtils.js b/src/views/officeProcessAutomation/EnterpriseNews/news-manage/enterpriseNewsUtils.js
index edc7f7e..71ceaba 100644
--- a/src/views/officeProcessAutomation/EnterpriseNews/news-manage/enterpriseNewsUtils.js
+++ b/src/views/officeProcessAutomation/EnterpriseNews/news-manage/enterpriseNewsUtils.js
@@ -8,13 +8,36 @@
   { 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",
+};
+
+/** 缁熶竴涓哄悗绔姸鎬佹灇涓惧�� */
+export function normalizeEnterpriseNewsStatus(v) {
+  if (v == null || v === "") return "DRAFT";
+  const upper = String(v).trim().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[String(v).trim().toLowerCase()];
+  if (legacy) return legacy;
+  return upper;
+}
 
 /** 鎺掔増妯℃澘 */
 export const LAYOUT_TEMPLATE_OPTIONS = [
@@ -40,19 +63,8 @@
   { value: "editor", label: "鍐呭缂栬緫" },
 ];
 
-export const STORAGE_KEY = "oa_enterprise_news_v1";
-
-/** 婕旂ず鐢ㄧ洰鏍囧彈浼楋紙鍚庢湡瀵规帴缁勭粐鏋舵瀯锛� */
-export const MOCK_AUDIENCE = [
-  { userId: "u1", employeeNo: "zhangsan", name: "寮犱笁", deptName: "鐮斿彂閮�", isManagement: false },
-  { userId: "u2", employeeNo: "lisi", name: "鏉庡洓", deptName: "鐮斿彂閮�", isManagement: false },
-  { userId: "u3", employeeNo: "wangwu", name: "鐜嬩簲", deptName: "琛屾斂閮�", isManagement: false },
-  { userId: "u4", employeeNo: "zhaoliu", name: "璧靛叚", deptName: "閿�鍞儴", isManagement: false },
-  { userId: "u5", employeeNo: "sunqi", name: "瀛欎竷", deptName: "璐㈠姟閮�", isManagement: false },
-  { userId: "u6", employeeNo: "zhouba", name: "鍛ㄥ叓", deptName: "鎬荤粡鍔�", isManagement: true },
-  { userId: "u7", employeeNo: "wujiu", name: "鍚翠節", deptName: "鎬荤粡鍔�", isManagement: true },
-  { userId: "u8", employeeNo: "zhengshi", name: "閮戝崄", deptName: "浜哄姏璧勬簮閮�", isManagement: false },
-];
+/** 鐩爣鍙椾紬锛堝鎺ョ粍缁囨灦鏋� API 鍓嶄负绌猴級 */
+export const MOCK_AUDIENCE = [];
 
 const DEPT_OPTIONS = [
   { value: "101", label: "鐮斿彂閮�" },
@@ -74,11 +86,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) {
@@ -110,7 +124,7 @@
     readScope: "all",
     targetDeptIds: [],
     targetUserIds: [],
-    publishStatus: "draft",
+    publishStatus: "DRAFT",
     publisherName: "",
     publishTime: "",
     readRecords: [],
@@ -120,206 +134,9 @@
     versions: [],
     versionNo: 1,
     requireReadConfirm: false,
+    templateId: null,
+    templateName: "",
   };
-}
-
-function buildReadRecords(readUserIds = []) {
-  const set = new Set(readUserIds);
-  return MOCK_AUDIENCE.map((u) => ({
-    userId: u.userId,
-    employeeNo: u.employeeNo,
-    name: u.name,
-    deptName: u.deptName,
-    readAt: set.has(u.userId) ? dayjs().subtract(2, "day").format("YYYY-MM-DD HH:mm:ss") : "",
-    lastRemindAt: "",
-  }));
-}
-
-function createVersionSnapshot(row, changeNote = "鍙戝竷") {
-  return {
-    versionNo: row.versionNo || 1,
-    title: row.title,
-    summary: row.summary,
-    contentHtml: row.contentHtml,
-    newsType: row.newsType,
-    publishTime: row.publishTime || dayjs().format("YYYY-MM-DD HH:mm:ss"),
-    archivedAt: dayjs().format("YYYY-MM-DD HH:mm:ss"),
-    changeNote,
-    publisherName: row.publisherName || "绯荤粺",
-  };
-}
-
-export function createInitialMockNews() {
-  const policyContent =
-    "<p><strong>2026 骞磋�冨嫟绠$悊鍒跺害锛堣瘯琛岋級</strong></p><p>涓�銆佷笂鐝椂闂� 9:00锛屽脊鎬ф墦鍗$獥鍙� 8:30鈥�9:30銆�</p><p>浜屻�佽鍋囬』鎻愬墠鍦� OA 鎻愪氦瀹℃壒銆�</p><p>涓夈�佹湰鍒跺害鑷� 2026-06-01 璧锋墽琛屻��</p>";
-  const cultureContent =
-    "<p>2026 浼佷笟骞翠細鍦嗘弧钀藉箷锛佹劅璋㈡瘡涓�浣嶅悓浜嬬殑鍙備笌锛屼互涓嬩负绮惧僵鐬棿鍥鹃泦銆�</p>";
-  const strategyContent =
-    "<p><strong>2026 涓嬪崐骞存垬鐣ユ柟鍚戯紙鍐呴儴锛�</strong></p><p>鑱氱劍鏍稿績浜у搧绾垮崌绾т笌娴峰甯傚満鎷撳睍锛屽叿浣撴寚鏍囪闄勪欢銆�</p>";
-
-  const policyRow = {
-    id: "news_1",
-    newsNo: "EN202605150001",
-    title: "鍏充簬鍙戝竷鏂拌�冨嫟鍒跺害鐨勯�氱煡",
-    summary: "璇峰叏浣撳憳宸ヨ鐪熼槄璇诲苟纭鐭ユ倝锛岃嚜 2026-06-01 璧锋墽琛屻��",
-    newsType: "policy",
-    layoutTemplate: "policy",
-    contentHtml: policyContent,
-    coverImage: "",
-    mediaList: [],
-    attachmentList: [{ name: "鑰冨嫟鍒跺害2026.pdf", url: "/mock/attendance-policy.pdf" }],
-    editorRole: "hr",
-    reviewerRole: "admin",
-    readScope: "all",
-    targetDeptIds: [],
-    targetUserIds: [],
-    publishStatus: "published",
-    publisherName: "浜哄姏璧勬簮閮�",
-    publishTime: "2026-05-15 10:00:00",
-    readRecords: buildReadRecords(["u6", "u7", "u8"]),
-    remindLogs: [],
-    likes: [],
-    comments: [],
-    versions: [
-      {
-        versionNo: 1,
-        title: "鍏充簬鍙戝竷鏂拌�冨嫟鍒跺害鐨勯�氱煡锛堝緛姹傛剰瑙佺锛�",
-        summary: "寰佹眰鎰忚绋�",
-        contentHtml: "<p>寰佹眰鎰忚绋匡細涓婄彮鏃堕棿 9:00鈥︹��</p>",
-        newsType: "policy",
-        publishTime: "2026-05-10 09:00:00",
-        archivedAt: "2026-05-15 09:55:00",
-        changeNote: "瀹氱鍙戝竷",
-        publisherName: "浜哄姏璧勬簮閮�",
-      },
-    ],
-    versionNo: 2,
-    requireReadConfirm: true,
-    createTime: "2026-05-10 09:00:00",
-    updateTime: "2026-05-15 10:00:00",
-  };
-
-  const cultureRow = {
-    id: "news_2",
-    newsNo: "EN202605200002",
-    title: "2026 浼佷笟骞翠細绮惧僵鐬棿",
-    summary: "骞翠細鍥鹃泦涓婄嚎锛屾杩庣偣璧炵暀瑷�锛屽叡寤轰紒涓氭枃鍖栥��",
-    newsType: "culture",
-    layoutTemplate: "gallery",
-    contentHtml: cultureContent,
-    coverImage: "/mock/annual-cover.jpg",
-    mediaList: [
-      { type: "image", name: "寮�鍦�.jpg", url: "/mock/annual-1.jpg" },
-      { type: "image", name: "棰佸.jpg", url: "/mock/annual-2.jpg" },
-      { type: "video", name: "骞翠細鑺辩诞.mp4", url: "/mock/annual.mp4" },
-    ],
-    attachmentList: [],
-    editorRole: "dept_manager",
-    reviewerRole: "admin",
-    readScope: "all",
-    targetDeptIds: [],
-    targetUserIds: [],
-    publishStatus: "published",
-    publisherName: "琛屾斂閮�",
-    publishTime: "2026-05-20 14:30:00",
-    readRecords: buildReadRecords(["u1", "u2", "u3", "u4", "u5", "u6", "u7"]),
-    remindLogs: [],
-    likes: [
-      { userId: "u1", name: "寮犱笁", time: "2026-05-20 15:01:00" },
-      { userId: "u2", name: "鏉庡洓", time: "2026-05-20 15:05:00" },
-      { userId: "u4", name: "璧靛叚", time: "2026-05-20 16:20:00" },
-    ],
-    comments: [
-      { id: "c1", userId: "u1", name: "寮犱笁", content: "鑺傜洰澶簿褰╀簡锛�", time: "2026-05-20 15:10:00" },
-      { id: "c2", userId: "u3", name: "鐜嬩簲", content: "鏈熷緟鏄庡勾鍐嶈仛锛�", time: "2026-05-20 17:00:00" },
-    ],
-    versions: [],
-    versionNo: 1,
-    requireReadConfirm: false,
-    createTime: "2026-05-20 14:00:00",
-    updateTime: "2026-05-20 14:30:00",
-  };
-
-  const strategyRow = {
-    id: "news_3",
-    newsNo: "EN202605220003",
-    title: "2026 涓嬪崐骞存垬鐣ヨ鍒掕鐐�",
-    summary: "浠呴檺绠$悊灞傞槄璇伙紝璇峰嬁瀵瑰浼犳挱銆�",
-    newsType: "announcement",
-    layoutTemplate: "briefing",
-    contentHtml: strategyContent,
-    coverImage: "",
-    mediaList: [],
-    attachmentList: [{ name: "鎴樼暐鎸囨爣.pdf", url: "/mock/strategy.pdf" }],
-    editorRole: "admin",
-    reviewerRole: "admin",
-    readScope: "management",
-    targetDeptIds: [],
-    targetUserIds: [],
-    publishStatus: "published",
-    publisherName: "鎬荤粡鍔�",
-    publishTime: "2026-05-22 09:00:00",
-    readRecords: buildReadRecords(["u6", "u7"]),
-    remindLogs: [],
-    likes: [],
-    comments: [],
-    versions: [],
-    versionNo: 1,
-    requireReadConfirm: false,
-    createTime: "2026-05-22 08:30:00",
-    updateTime: "2026-05-22 09:00:00",
-  };
-
-  const industryDraft = {
-    id: "news_4",
-    newsNo: "EN202605250004",
-    title: "鍒堕�犱笟鏁板瓧鍖栬浆鍨嬭秼鍔跨畝鎶�",
-    summary: "琛屼笟鍔ㄦ�佽崏绋匡紝寰呯鐞嗗憳瀹℃牳鍚庡彂甯冦��",
-    newsType: "industry",
-    layoutTemplate: "standard",
-    contentHtml: "<p>鏈湡绠�鎶ユ⒊鐞嗗伐涓氫簰鑱旂綉涓� AI 璐ㄦ搴旂敤妗堜緥鈥︹��</p>",
-    coverImage: "",
-    mediaList: [],
-    attachmentList: [],
-    editorRole: "editor",
-    reviewerRole: "admin",
-    readScope: "all",
-    targetDeptIds: [],
-    targetUserIds: [],
-    publishStatus: "pending_review",
-    publisherName: "甯傚満閮�",
-    publishTime: "",
-    readRecords: [],
-    remindLogs: [],
-    likes: [],
-    comments: [],
-    versions: [],
-    versionNo: 1,
-    requireReadConfirm: false,
-    createTime: "2026-05-25 11:00:00",
-    updateTime: "2026-05-25 11:00:00",
-  };
-
-  return [policyRow, cultureRow, strategyRow, industryDraft];
-}
-
-export function loadStoredNews() {
-  try {
-    const raw = localStorage.getItem(STORAGE_KEY);
-    if (!raw) return null;
-    const data = JSON.parse(raw);
-    return Array.isArray(data) ? data : null;
-  } catch {
-    return null;
-  }
-}
-
-export function saveStoredNews(rows) {
-  try {
-    localStorage.setItem(STORAGE_KEY, JSON.stringify(rows));
-  } catch {
-    /* ignore */
-  }
 }
 
 /** 鎸夐槄璇昏寖鍥磋В鏋愮洰鏍囧彈浼� */
@@ -351,17 +168,6 @@
   if (!audience.length) return 0;
   const readCount = (row.readRecords || []).filter((r) => r.readAt).length;
   return Math.round((readCount / audience.length) * 100);
-}
-
-export function nextNewsNo() {
-  return `EN${dayjs().format("YYYYMMDD")}${String(Math.floor(Math.random() * 9000) + 1000)}`;
-}
-
-export function pushVersionBeforeUpdate(row, changeNote) {
-  const versions = row.versions || [];
-  versions.unshift(createVersionSnapshot(row, changeNote));
-  row.versions = versions;
-  row.versionNo = (row.versionNo || 1) + 1;
 }
 
 export function validateNewsForm(form) {

--
Gitblit v1.9.3