Files
zkxw/mobile-h5/utils/oa-badge.js
T
zlwuandCursor 5dad1bb0e3 fix: 协议子资源单事务保存,并补齐样本编码/OA/质检等近期能力
锁定缴费校验失败时整单回滚,避免样本半成功落库;前端禁止删除锁定缴费样本,改码走更正编码。同步落地样本更正、采集微信通知、OA提及未读、细胞产品套餐与相关迁移文档。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-26 11:02:25 +08:00

45 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {
fetchOaCcUnreadCount,
fetchOaInstanceDraftCount,
fetchOaMentionUnreadCount,
fetchOaPendingTaskCount
} from './oa-api.js'
const PATH_DRAFTS = '/pages/oa/drafts/index'
const PATH_PENDING = '/pages/oa/pending/index'
const PATH_CC = '/pages/oa/cc/index'
const PATH_MENTIONS = '/pages/oa/mentions/index'
function readCount(data) {
if (data == null) return 0
if (typeof data === 'number') return Math.max(0, data)
const n = Number(data.count)
return Number.isFinite(n) && n > 0 ? n : 0
}
/**
* 并行拉取草稿 / 待办 / 抄送未读 / 提到我的未读数量。
* @returns {Promise<Record<string, number>>} path → 原始 count(>99 仍保留真实数字)
*/
export async function refreshOaMenuBadges() {
const [draftRes, pendingRes, ccRes, mentionRes] = await Promise.all([
fetchOaInstanceDraftCount().catch(() => null),
fetchOaPendingTaskCount().catch(() => null),
fetchOaCcUnreadCount().catch(() => null),
fetchOaMentionUnreadCount().catch(() => null)
])
return {
[PATH_DRAFTS]: readCount(draftRes),
[PATH_PENDING]: readCount(pendingRes),
[PATH_CC]: readCount(ccRes),
[PATH_MENTIONS]: readCount(mentionRes)
}
}
/** 展示层:0 → 空串;>99 → `99+` */
export function formatOaBadgeCount(n) {
const c = Number(n) || 0
if (c <= 0) return ''
return c > 99 ? '99+' : String(c)
}