Files
hfb_jysh/frontend/src/features/admin/labels.ts
T

221 lines
8.3 KiB
TypeScript

export type TagTone =
| 'default'
| 'success'
| 'processing'
| 'error'
| 'warning'
| 'gold'
| 'blue'
| 'cyan'
| 'orange'
| 'red'
| 'purple'
| 'geekblue'
| 'magenta'
| 'volcano'
| 'green'
export interface StatusMeta {
label: string
tone: TagTone
}
export interface StatusOption {
label: string
value: string
}
function toOptions(map: Record<string, StatusMeta>): StatusOption[] {
return Object.entries(map).map(([value, meta]) => ({ value, label: meta.label }))
}
export const orderStatusMap: Record<string, StatusMeta> = {
pending_payment: { label: '待支付', tone: 'gold' },
pending_handoff: { label: '待交接', tone: 'blue' },
renting: { label: '使用中', tone: 'cyan' },
overdue: { label: '已逾期', tone: 'volcano' },
pending_checkout_confirm: { label: '待号主确认结账', tone: 'orange' },
pending_checkout_accept: { label: '待租客确认修正', tone: 'orange' },
checkout_disputing: { label: '结账争议中', tone: 'red' },
disputing: { label: '申诉中', tone: 'red' },
completed: { label: '已完成', tone: 'success' },
cancelled: { label: '租客已取消', tone: 'default' },
closed: { label: '客服已关闭', tone: 'default' },
abnormal: { label: '客服介入', tone: 'magenta' },
}
export const handoffStatusMap: Record<string, StatusMeta> = {
none: { label: '未开始', tone: 'default' },
pending_owner: { label: '待号主交接', tone: 'blue' },
owner_timeout: { label: '号主交接超时', tone: 'volcano' },
pending_renter_confirm: { label: '待租客确认', tone: 'blue' },
received: { label: '租客已收号', tone: 'cyan' },
return_overdue: { label: '归还逾期', tone: 'volcano' },
pending_owner_checkout: { label: '待号主确认结账', tone: 'orange' },
pending_renter_checkout: { label: '待租客确认修正', tone: 'orange' },
checkout_disputed: { label: '结账争议中', tone: 'red' },
returned: { label: '已归还', tone: 'success' },
owner_return_confirm_timeout: { label: '号主确认结账超时', tone: 'red' },
owner_checkout_confirm_timeout: { label: '号主确认结账超时', tone: 'red' },
renter_confirm_timeout: { label: '租客确认超时', tone: 'red' },
cancelled: { label: '租客已取消', tone: 'default' },
admin_closed: { label: '客服已关闭', tone: 'default' },
admin_abnormal: { label: '客服介入', tone: 'magenta' },
arbitrated: { label: '已仲裁', tone: 'purple' },
}
export const settlementStatusMap: Record<string, StatusMeta> = {
unsettled: { label: '未结算', tone: 'default' },
pending: { label: '待结算', tone: 'gold' },
frozen: { label: '冻结中', tone: 'magenta' },
settled: { label: '已结算', tone: 'success' },
refunded: { label: '已退款', tone: 'blue' },
cancelled: { label: '结算已取消', tone: 'default' },
closed: { label: '结算已关闭', tone: 'default' },
disputed: { label: '争议中', tone: 'red' },
arbitrated: { label: '已仲裁', tone: 'purple' },
}
export const offlineSettlementStatusMap: Record<string, StatusMeta> = {
none: { label: '无需线下结算', tone: 'default' },
pending: { label: '待确认线下结算', tone: 'gold' },
settled: { label: '已确认线下结算', tone: 'success' },
}
export const handoffModeMap: Record<string, StatusMeta> = {
owner: { label: '正常订单', tone: 'default' },
platform: { label: '平台代管', tone: 'geekblue' },
}
export const settlementModeMap: Record<string, StatusMeta> = {
owner_wallet: { label: '号主钱包', tone: 'default' },
platform_managed: { label: '平台代管', tone: 'geekblue' },
}
export const checkoutStatusMap: Record<string, StatusMeta> = {
submitted: { label: '待确认', tone: 'gold' },
countered: { label: '已修正待确认', tone: 'orange' },
accepted: { label: '已接受', tone: 'success' },
disputed: { label: '争议中', tone: 'red' },
settled: { label: '仲裁已结案', tone: 'purple' },
}
export const refundStatusMap: Record<string, StatusMeta> = {
none: { label: '未退款', tone: 'default' },
pending: { label: '待退款', tone: 'gold' },
pending_review: { label: '待客服审核退款', tone: 'orange' },
refunding: { label: '退款中', tone: 'processing' },
refunded: { label: '已退款', tone: 'success' },
failed: { label: '退款失败', tone: 'red' },
}
export function readStatusMeta(map: Record<string, StatusMeta>, value?: string | null): StatusMeta {
if (!value) return { label: '—', tone: 'default' }
return map[value] ?? { label: value, tone: 'default' }
}
/**
* 平台代管订单的交接动作由客服执行,展示文案需要区别于普通号主订单。
*/
export function handoffStatusMeta(
status?: string | null,
order?: { handoff_mode?: string; settlement_mode?: string } | null
) {
const platformManaged =
order?.handoff_mode === 'platform' || order?.settlement_mode === 'platform_managed'
if (!platformManaged || !status) return readStatusMeta(handoffStatusMap, status)
const platformCopy: Record<string, StatusMeta> = {
pending_owner: { label: '待客服交接', tone: 'blue' },
owner_timeout: { label: '客服交接超时', tone: 'volcano' },
pending_owner_checkout: { label: '待客服确认结账', tone: 'orange' },
owner_checkout_confirm_timeout: { label: '客服确认结账超时', tone: 'red' },
}
return platformCopy[status] ?? readStatusMeta(handoffStatusMap, status)
}
export const orderStatusOptions = toOptions(orderStatusMap)
export const handoffStatusOptions = [
'pending_owner',
'owner_timeout',
'pending_renter_confirm',
'received',
'return_overdue',
'pending_owner_checkout',
'pending_renter_checkout',
'checkout_disputed',
'returned',
'admin_closed',
'admin_abnormal',
].map(value => ({ value, label: handoffStatusMap[value].label }))
export const handoffModeOptions = toOptions(handoffModeMap)
export const settlementStatusOptions = toOptions(settlementStatusMap)
export const offlineSettlementStatusOptions = ['pending', 'settled'].map(value => ({
value,
label: offlineSettlementStatusMap[value].label,
}))
export const userStatusMap: Record<string, StatusMeta> = {
active: { label: '正常', tone: 'success' },
frozen: { label: '已冻结', tone: 'red' },
disabled: { label: '已禁用', tone: 'default' },
}
export const realnameStatusMap: Record<string, StatusMeta> = {
unverified: { label: '未实名', tone: 'default' },
pending: { label: '认证中', tone: 'gold' },
verified: { label: '已实名', tone: 'success' },
rejected: { label: '认证失败', tone: 'red' },
}
export const riskStatusMap: Record<string, StatusMeta> = {
normal: { label: '正常', tone: 'success' },
watch: { label: '观察', tone: 'gold' },
restricted: { label: '受限', tone: 'orange' },
blocked: { label: '已拦截', tone: 'red' },
}
export const userStatusOptions = toOptions(userStatusMap)
export const realnameStatusOptions = toOptions(realnameStatusMap)
export const riskStatusOptions = toOptions(riskStatusMap)
export const withdrawalStatusMap: Record<string, StatusMeta> = {
pending: { label: '待审核', tone: 'gold' },
processing: { label: '待打款', tone: 'blue' },
completed: { label: '已完成', tone: 'success' },
rejected: { label: '已驳回', tone: 'red' },
cancelled: { label: '已取消', tone: 'default' },
}
export const withdrawalStatusOptions = toOptions(withdrawalStatusMap)
export const financeStatusMap: Record<string, StatusMeta> = {
normal: { label: '正常', tone: 'success' },
refund_pending: { label: '退款中', tone: 'blue' },
refund_failed: { label: '退款失败', tone: 'red' },
settlement_diff: { label: '结算差异', tone: 'orange' },
offline_settlement_pending: { label: '待线下结算', tone: 'gold' },
}
export const announcementStatusMap: Record<string, StatusMeta> = {
draft: { label: '草稿', tone: 'default' },
published: { label: '已发布', tone: 'success' },
archived: { label: '已归档', tone: 'default' },
}
export const announcementCategoryMap: Record<string, string> = {
notice: '通知',
tutorial: '教程',
rule: '规则',
faq: '常见问题',
}
export const announcementStatusOptions = Object.entries(announcementStatusMap).map(
([value, meta]) => ({ value, label: meta.label })
)
export const announcementCategoryOptions = Object.entries(announcementCategoryMap).map(
([value, label]) => ({ value, label })
)