feat(oa): show draft pending cc badges on mobile home menu
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
06b1468bf1
commit
915253eefb
4 files changed
+101
No files matched your search
@@ -12,6 +12,7 @@
|
||||
:style="iconBoxStyle(m)"
|
||||
>
|
||||
<VanIcon :name="m.icon" :color="iconFg(m)" :size="iconSize(m)" />
|
||||
<text v-if="badgeText(m)" class="menu-badge">{{ badgeText(m) }}</text>
|
||||
</view>
|
||||
<text class="menu-title">{{ m.title }}</text>
|
||||
</view>
|
||||
@@ -21,6 +22,7 @@
|
||||
<script>
|
||||
import VanIcon from './van-icon/van-icon.vue'
|
||||
import { resolveMenuIconColors } from '../utils/menu-icon-colors.js'
|
||||
import { formatOaBadgeCount } from '../utils/oa-badge.js'
|
||||
|
||||
export default {
|
||||
name: 'MenuGrid',
|
||||
@@ -30,6 +32,14 @@
|
||||
},
|
||||
emits: ['select'],
|
||||
methods: {
|
||||
badgeText(m) {
|
||||
if (!m) return ''
|
||||
if (m.badge != null && String(m.badge).trim() !== '' && String(m.badge).trim() !== '0') {
|
||||
if (typeof m.badge === 'number') return formatOaBadgeCount(m.badge)
|
||||
return String(m.badge).trim()
|
||||
}
|
||||
return formatOaBadgeCount(m.badgeCount)
|
||||
},
|
||||
colors(m) {
|
||||
return resolveMenuIconColors(m)
|
||||
},
|
||||
|
||||
@@ -76,6 +76,10 @@
|
||||
import VanEmpty from '../../components/van-empty/van-empty.vue'
|
||||
import { clearSession, fetchCurrentUser, getUser } from '../../utils/auth.js'
|
||||
import { fetchMyMobileMenus } from '../../utils/menu.js'
|
||||
import {
|
||||
formatOaBadgeCount,
|
||||
refreshOaMenuBadges
|
||||
} from '../../utils/oa-badge.js'
|
||||
|
||||
const HOME_BANNER_VIDEO =
|
||||
'https://video.hfsxw.cn/d04ce57416a771f180684531958c0102/db7aa1b54f8e45d3b6b240176085803f-9224e7e7aa8db3dd79de34f341d9a452-hd-nbv2.mp4'
|
||||
@@ -136,17 +140,42 @@
|
||||
this.loadMenus()
|
||||
},
|
||||
methods: {
|
||||
mergeBadgesIntoMenus(menus, badgeMap) {
|
||||
const map = badgeMap || {}
|
||||
return (menus || []).map((m) => {
|
||||
const path = m && m.path ? m.path : ''
|
||||
if (!Object.prototype.hasOwnProperty.call(map, path)) {
|
||||
return m
|
||||
}
|
||||
const n = Number(map[path]) || 0
|
||||
return {
|
||||
...m,
|
||||
badgeCount: n,
|
||||
badge: formatOaBadgeCount(n)
|
||||
}
|
||||
})
|
||||
},
|
||||
async refreshMenuBadges() {
|
||||
try {
|
||||
const map = await refreshOaMenuBadges()
|
||||
this.menus = this.mergeBadgesIntoMenus(this.menus, map)
|
||||
} catch (_) {
|
||||
/* 角标失败不阻塞菜单 */
|
||||
}
|
||||
},
|
||||
async loadMenus() {
|
||||
try {
|
||||
const list = await fetchMyMobileMenus()
|
||||
if (list && list.length) {
|
||||
this.menus = list
|
||||
await this.refreshMenuBadges()
|
||||
return
|
||||
}
|
||||
} catch (e) {
|
||||
/* 接口未就绪或无权限时用过渡菜单 */
|
||||
}
|
||||
this.menus = [...FALLBACK_MENUS]
|
||||
await this.refreshMenuBadges()
|
||||
},
|
||||
onMenuSelect(m) {
|
||||
if (m.path) {
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
}
|
||||
|
||||
.menu-icon {
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
width: 96rpx;
|
||||
height: 96rpx;
|
||||
border-radius: 28rpx;
|
||||
@@ -34,6 +36,26 @@
|
||||
box-shadow: inset 0 0 0 1rpx rgba(15, 41, 30, 0.06);
|
||||
}
|
||||
|
||||
/* 微信风格数量角标:图标右上角 */
|
||||
.menu-badge {
|
||||
position: absolute;
|
||||
top: -8rpx;
|
||||
right: -12rpx;
|
||||
z-index: 1;
|
||||
min-width: 32rpx;
|
||||
height: 32rpx;
|
||||
padding: 0 8rpx;
|
||||
border-radius: 16rpx;
|
||||
background: #fa5151;
|
||||
color: #fff;
|
||||
font-size: 20rpx;
|
||||
font-weight: 600;
|
||||
line-height: 32rpx;
|
||||
text-align: center;
|
||||
box-sizing: border-box;
|
||||
box-shadow: 0 0 0 2rpx #fff;
|
||||
}
|
||||
|
||||
.menu-icon .v-icon--img {
|
||||
width: 52rpx;
|
||||
height: 52rpx;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import {
|
||||
fetchOaCcUnreadCount,
|
||||
fetchOaInstanceDraftCount,
|
||||
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'
|
||||
|
||||
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] = await Promise.all([
|
||||
fetchOaInstanceDraftCount().catch(() => null),
|
||||
fetchOaPendingTaskCount().catch(() => null),
|
||||
fetchOaCcUnreadCount().catch(() => null)
|
||||
])
|
||||
return {
|
||||
[PATH_DRAFTS]: readCount(draftRes),
|
||||
[PATH_PENDING]: readCount(pendingRes),
|
||||
[PATH_CC]: readCount(ccRes)
|
||||
}
|
||||
}
|
||||
|
||||
/** 展示层:0 → 空串;>99 → `99+` */
|
||||
export function formatOaBadgeCount(n) {
|
||||
const c = Number(n) || 0
|
||||
if (c <= 0) return ''
|
||||
return c > 99 ? '99+' : String(c)
|
||||
}
|
||||
Reference in new issue
Block a user