import dayjs from "dayjs";
|
|
/** 公告类型 */
|
export const NOTICE_TYPE_OPTIONS = [
|
{ value: "emergency", label: "紧急通知", color: "#f56c6c" },
|
{ value: "employee", label: "员工公告", color: "#409eff" },
|
{ value: "company", label: "企业公告", color: "#e6a23c" },
|
];
|
|
/** 优先级 */
|
export const PRIORITY_OPTIONS = [
|
{ value: "urgent", label: "紧急", tag: "danger" },
|
{ value: "high", label: "重要", tag: "warning" },
|
{ value: "normal", label: "普通", tag: "info" },
|
];
|
|
/** 发布状态 */
|
export const PUBLISH_STATUS_OPTIONS = [
|
{ value: "draft", label: "草稿", tag: "info" },
|
{ value: "published", label: "已发布", tag: "success" },
|
{ value: "withdrawn", label: "已撤回", tag: "warning" },
|
{ value: "expired", label: "已过期", tag: "" },
|
];
|
|
/** 阅读范围 */
|
export const READ_SCOPE_OPTIONS = [
|
{ value: "all", label: "全员可见" },
|
{ value: "department", label: "指定部门" },
|
{ value: "management", label: "管理层" },
|
];
|
|
export const DEPT_OPTIONS = [
|
{ value: "101", label: "研发部" },
|
{ value: "102", label: "销售部" },
|
{ value: "103", label: "行政部" },
|
{ value: "104", label: "财务部" },
|
{ value: "105", label: "总经办" },
|
{ value: "106", label: "人力资源部" },
|
];
|
|
export const STORAGE_KEY = "oa_notice_announcement_v1";
|
|
export function noticeTypeLabel(v) {
|
return NOTICE_TYPE_OPTIONS.find((x) => x.value === v)?.label || v || "—";
|
}
|
|
export function noticeTypeColor(v) {
|
return NOTICE_TYPE_OPTIONS.find((x) => x.value === v)?.color || "#909399";
|
}
|
|
export function priorityLabel(v) {
|
return PRIORITY_OPTIONS.find((x) => x.value === v)?.label || v || "—";
|
}
|
|
export function priorityTag(v) {
|
return PRIORITY_OPTIONS.find((x) => x.value === v)?.tag || "info";
|
}
|
|
export function publishStatusLabel(v) {
|
return PUBLISH_STATUS_OPTIONS.find((x) => x.value === v)?.label || v || "—";
|
}
|
|
export function publishStatusTag(v) {
|
return PUBLISH_STATUS_OPTIONS.find((x) => x.value === v)?.tag || "info";
|
}
|
|
export function readScopeLabel(v) {
|
return READ_SCOPE_OPTIONS.find((x) => x.value === v)?.label || v || "—";
|
}
|
|
export function createEmptyForm() {
|
return {
|
id: "",
|
noticeNo: "",
|
title: "",
|
noticeType: "employee",
|
priority: "normal",
|
contentHtml: "",
|
publishDate: dayjs().format("YYYY-MM-DD"),
|
expireDate: "",
|
readScope: "all",
|
targetDeptIds: [],
|
requireReadConfirm: false,
|
publishStatus: "draft",
|
publisherName: "",
|
publishTime: "",
|
readCount: 0,
|
createTime: "",
|
updateTime: "",
|
};
|
}
|
|
export function createInitialMockNotices() {
|
return [
|
{
|
id: "notice_1",
|
noticeNo: "NA202605100001",
|
title: "关于台风天气居家办公的紧急通知",
|
noticeType: "emergency",
|
priority: "urgent",
|
contentHtml:
|
"<p><strong>紧急通知</strong></p><p>受台风影响,明日(5月17日)全体员工居家办公,请各部门负责人做好工作安排与员工联络。</p>",
|
publishDate: "2026-05-16",
|
expireDate: "2026-05-20",
|
readScope: "all",
|
targetDeptIds: [],
|
requireReadConfirm: true,
|
publishStatus: "published",
|
publisherName: "行政部",
|
publishTime: "2026-05-16 08:30:00",
|
readCount: 128,
|
createTime: "2026-05-16 08:00:00",
|
updateTime: "2026-05-16 08:30:00",
|
},
|
{
|
id: "notice_2",
|
noticeNo: "NA202605120002",
|
title: "2026年端午节放假安排公告",
|
noticeType: "employee",
|
priority: "high",
|
contentHtml:
|
"<p>根据国家法定节假日安排,端午节放假时间为 6月8日至6月10日,共3天。6月7日(周六)正常上班。</p>",
|
publishDate: "2026-05-12",
|
expireDate: "2026-06-15",
|
readScope: "all",
|
targetDeptIds: [],
|
requireReadConfirm: false,
|
publishStatus: "published",
|
publisherName: "人力资源部",
|
publishTime: "2026-05-12 10:00:00",
|
readCount: 256,
|
createTime: "2026-05-12 09:30:00",
|
updateTime: "2026-05-12 10:00:00",
|
},
|
{
|
id: "notice_3",
|
noticeNo: "NA202605140003",
|
title: "办公区域消防演练通知",
|
noticeType: "company",
|
priority: "normal",
|
contentHtml: "<p>定于 5月25日 14:00 在总部大楼进行消防演练,请各部门提前安排人员参加。</p>",
|
publishDate: "2026-05-14",
|
expireDate: "2026-05-26",
|
readScope: "department",
|
targetDeptIds: ["101", "102", "103"],
|
requireReadConfirm: false,
|
publishStatus: "draft",
|
publisherName: "行政部",
|
publishTime: "",
|
readCount: 0,
|
createTime: "2026-05-14 15:00:00",
|
updateTime: "2026-05-14 15:00:00",
|
},
|
];
|
}
|
|
export function loadStoredNotices() {
|
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 saveStoredNotices(rows) {
|
try {
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(rows));
|
} catch {
|
/* ignore */
|
}
|
}
|
|
export function nextNoticeNo() {
|
return `NA${dayjs().format("YYYYMMDD")}${String(Math.floor(Math.random() * 9000) + 1000)}`;
|
}
|
|
export function validateNoticeForm(form) {
|
const title = (form.title || "").trim();
|
if (!title) return { ok: false, message: "请输入公告标题" };
|
if (!form.publishDate) return { ok: false, message: "请选择发布日期" };
|
if (!form.noticeType) return { ok: false, message: "请选择公告类型" };
|
if (form.readScope === "department" && !(form.targetDeptIds || []).length) {
|
return { ok: false, message: "请选择可见部门" };
|
}
|
return { ok: true, title };
|
}
|
|
export function isExpired(row) {
|
if (!row.expireDate) return false;
|
return dayjs(row.expireDate).endOf("day").isBefore(dayjs());
|
}
|