feat: 类型帖互动、积分经济与发帖体验
补齐问答采纳/重开、投票匿名与有票禁编、悬赏过期退回、抽奖回帖开奖,并接入积分账本与发帖附件可见性。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
61
frontend/lib/postMeta.ts
Normal file
61
frontend/lib/postMeta.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
/** 帖子类型 / 可见性 / 展示文案(前后端共用约定) */
|
||||
|
||||
export const POST_TYPES = [
|
||||
{ value: "discussion", label: "讨论", hint: "默认讨论帖" },
|
||||
{ value: "question", label: "问答", hint: "提问求解" },
|
||||
{ value: "poll", label: "投票", hint: "发起投票,读者可参与" },
|
||||
{ value: "bounty", label: "悬赏", hint: "发布时托管积分,采纳后发放" },
|
||||
{ value: "lottery", label: "抽奖", hint: "回帖即参与,截止自动开奖" },
|
||||
] as const;
|
||||
|
||||
export type PostTypeValue = (typeof POST_TYPES)[number]["value"];
|
||||
|
||||
export const CONTENT_ACCESS = [
|
||||
{ value: "public", label: "公开" },
|
||||
{ value: "login", label: "登录可见" },
|
||||
{ value: "reply", label: "回复可见" },
|
||||
{ value: "points", label: "积分可见" },
|
||||
] as const;
|
||||
|
||||
export type ContentAccessValue = (typeof CONTENT_ACCESS)[number]["value"];
|
||||
|
||||
export const BOUNTY_EXPIRE_DAYS = [3, 7, 14, 30] as const;
|
||||
export const LOTTERY_EXPIRE_DAYS = [1, 3, 7, 14] as const;
|
||||
|
||||
export function normalizePostType(t?: string): PostTypeValue {
|
||||
if (t === "normal" || !t) return "discussion";
|
||||
if (POST_TYPES.some((x) => x.value === t)) return t as PostTypeValue;
|
||||
return "discussion";
|
||||
}
|
||||
|
||||
export function postTypeLabel(t?: string): string {
|
||||
const n = normalizePostType(t);
|
||||
return POST_TYPES.find((x) => x.value === n)?.label || "讨论";
|
||||
}
|
||||
|
||||
export function contentAccessLabel(a?: string): string {
|
||||
const hit = CONTENT_ACCESS.find((x) => x.value === a);
|
||||
return hit?.label || "公开";
|
||||
}
|
||||
|
||||
/** 列表 type_status → 徽章文案 */
|
||||
export function typeStatusLabel(postType?: string, typeStatus?: string): string {
|
||||
const pt = normalizePostType(postType);
|
||||
const s = (typeStatus || "").toLowerCase();
|
||||
switch (pt) {
|
||||
case "question":
|
||||
return s === "solved" ? "已解决" : "未解决";
|
||||
case "poll":
|
||||
return s === "closed" ? "已结束" : "进行中";
|
||||
case "bounty":
|
||||
if (s === "solved") return "已采纳";
|
||||
if (s === "expired") return "已过期";
|
||||
return "进行中";
|
||||
case "lottery":
|
||||
if (s === "drawn") return "已开奖";
|
||||
if (s === "closed") return "已截止";
|
||||
return "进行中";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user