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: "",
|
};
|
}
|
|
/** @deprecated 不再注入演示数据,初始列表为空 */
|
export function createInitialMockNotices() {
|
return [];
|
}
|
|
/** 不再使用前端本地缓存,列表数据以接口为准;并清除历史 localStorage 数据 */
|
export function loadStoredNotices() {
|
try {
|
localStorage.removeItem(STORAGE_KEY);
|
} catch {
|
/* ignore */
|
}
|
return [];
|
}
|
|
/** @deprecated 保留空实现,避免旧调用报错;不做任何持久化 */
|
export function saveStoredNotices() {}
|
|
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());
|
}
|