Browse Source

fix(R26): 未读消息轮询改用unread接口+显示上限9+员工端未读统计

dev
cursor 1 day ago
parent
commit
dba3b42aec
3 changed files with 19 additions and 7 deletions
  1. +5
    -4
      pages/orders/orders.vue
  2. +12
    -3
      pages/staff/board.vue
  3. +2
    -0
      utils/constants.js

+ 5
- 4
pages/orders/orders.vue View File

@ -13,7 +13,7 @@
<button v-if="o.status===0" class="action-btn action-remind" @tap="onRemind(o.id)">🔔 催单</button>
<button v-if="o.status!==3 && o.status!==2" class="action-btn action-chat" @tap="onChat">
💬 联系调酒师
<text v-if="card.unread > 0" class="unread-dot">{{ card.unread }}</text>
<text v-if="card.unread > 0" class="unread-dot">{{ card.unread > 9 ? '9+' : card.unread }}</text>
</button>
</view>
</template>
@ -50,9 +50,9 @@ export default {
}
async function checkUnread() {
try {
const res = await get(API.MESSAGE_LIST, { card_no: card.cardNo, since: 0 })
if (Array.isArray(res)) {
card.unread = res.filter(m => m.senderType === 'staff').length
const res = await get(API.MESSAGE_UNREAD, { card_no: card.cardNo })
if (res && typeof res.count !== 'undefined') {
card.unread = res.count
}
} catch (e) {}
}
@ -94,3 +94,4 @@ export default {
.empty-text{font-size:28rpx;color:var(--text-muted);margin:16rpx 0}
.btn-back-menu{margin-top:40rpx;padding:16rpx 48rpx;border-radius:40rpx;background:var(--gold);color:#1A1A1A;font-size:28rpx;font-weight:700;border:none}
</style>

+ 12
- 3
pages/staff/board.vue View File

@ -10,7 +10,7 @@
</view>
</view>
<view class="staff-info">🧑🍳 {{ staff.nickname }} 别摸鱼了<text v-if="staff.unread > 0" style="color:var(--red);margin-left:16rpx">💬 {{ staff.unread }}条新消息</text></view>
<view class="staff-info">🧑🍳 {{ staff.nickname }} 别摸鱼了<text v-if="staff.unread > 0" style="color:var(--red);margin-left:16rpx">💬 {{ staff.unread > 9 ? '9+' : staff.unread }}条新消息</text></view>
<view class="board-tabs">
<view v-for="t in tabs" :key="t.status" class="board-tab" :class="{ active: activeTab === t.status }" @tap="switchTab(t.status)">
@ -85,6 +85,14 @@ export default {
}
} catch (e) {}
}
async function checkUnread() {
try {
const res = await get(API.MESSAGE_UNREAD, { card_no: 'all', staff_id: staff.staffId })
if (res && typeof res.count !== 'undefined') {
staff.unread = res.count
}
} catch (e) {}
}
function switchTab(s) { activeTab.value = s; loadOrders() }
async function onConfirm(id) { try { await post(API.STAFF_CONFIRM, { id }); uni.showToast({ title: '已接单', icon: 'none' }); loadOrders(); loadCounts() } catch (e) {} }
async function onCancel(id) { try { await post(API.STAFF_CANCEL, { id }); uni.showToast({ title: '已拒单', icon: 'none' }); loadOrders(); loadCounts() } catch (e) {} }
@ -95,11 +103,11 @@ export default {
function onLogout() { staff.logout(); uni.redirectTo({ url: '/pages/staff/login' }) }
onMounted(() => {
loadOrders(); loadCounts(); startPoll('board', () => { loadOrders(); loadCounts() }, 10000)
loadOrders(); loadCounts(); checkUnread(); startPoll('board', () => { loadOrders(); loadCounts(); checkUnread() }, 10000)
})
onUnmounted(() => stopPoll('board'))
return { staff, tabs, activeTab, orders, counts, recipeVisible, recipeCardNo, recipeItems, switchTab, onConfirm, onCancel, onDone, onDetail, onRecipe, onChat, onLogout }
return { staff, tabs, activeTab, orders, counts, recipeVisible, recipeCardNo, recipeItems, switchTab, onConfirm, onCancel, onDone, onDetail, onRecipe, onChat, onLogout, checkUnread }
}
}
</script>
@ -126,3 +134,4 @@ export default {
.empty-icon{font-size:112rpx;opacity:.3}
.empty-text{font-size:28rpx;color:var(--text-muted);margin-top:16rpx}
</style>

+ 2
- 0
utils/constants.js View File

@ -13,6 +13,7 @@ export const API = {
MESSAGE_LIST: '/api/message/list',
MESSAGE_SEND: '/api/message/send',
MESSAGE_READ: '/api/message/read',
MESSAGE_UNREAD: '/api/message/unread',
STAFF_LOGIN: '/api/staff/login',
STAFF_ORDERS: '/api/staff/orders',
STAFF_ORDER: '/api/staff/order',
@ -39,3 +40,4 @@ export const CONFIRM_PRESETS = [
{ label: '低度', icon: '🍹' },
]

Loading…
Cancel
Save