feat(client): show actionable customs count on sidebar
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import ClientSidebarMenuNode from '@/components/ClientSidebarMenuNode.vue'
|
||||
import {
|
||||
clientNavigation,
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
getNavigationParentKeys,
|
||||
} from '@/navigation/clientNavigation'
|
||||
import { useAuthStore } from '@/modules/auth/public'
|
||||
import { useCustomsPendingStore } from '@/modules/first-leg/public'
|
||||
|
||||
const props = defineProps<{
|
||||
activePath: string
|
||||
@@ -16,6 +17,28 @@ const emit = defineEmits<{
|
||||
navigate: [path: string]
|
||||
}>()
|
||||
const auth = useAuthStore()
|
||||
const customsPending = useCustomsPendingStore()
|
||||
const badges = computed(() => ({ 'first-leg-customs-documents': { count: customsPending.count, error: customsPending.error } }))
|
||||
watch(() => auth.isAuthenticated && auth.hasPermission('order:first-leg:customs-list') ? auth.user?.id ?? '' : '', scope => {
|
||||
customsPending.setScope(scope)
|
||||
if (scope) void customsPending.refresh()
|
||||
}, { immediate: true, flush: 'sync' })
|
||||
function refreshCustomsPending() {
|
||||
if (document.visibilityState === 'visible') void customsPending.refresh()
|
||||
}
|
||||
let refreshTimer: ReturnType<typeof setInterval> | undefined
|
||||
onMounted(() => {
|
||||
refreshTimer = setInterval(refreshCustomsPending, 60_000)
|
||||
window.addEventListener('focus', refreshCustomsPending)
|
||||
document.addEventListener('visibilitychange', refreshCustomsPending)
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
clearInterval(refreshTimer)
|
||||
window.removeEventListener('focus', refreshCustomsPending)
|
||||
document.removeEventListener('visibilitychange', refreshCustomsPending)
|
||||
customsPending.setScope('')
|
||||
})
|
||||
|
||||
const visibleNavigation = computed(() => filterNavigationByPermissions(clientNavigation, auth.permissionCodes))
|
||||
|
||||
const activeParentKeys = computed(() => new Set(getNavigationParentKeys(visibleNavigation.value, props.activePath)))
|
||||
@@ -47,6 +70,7 @@ function handleSelect(path: string) {
|
||||
v-for="node in visibleNavigation"
|
||||
:key="node.key"
|
||||
:node="node"
|
||||
:badges="badges"
|
||||
:active-path="activePath"
|
||||
:opened-keys="openedKeys"
|
||||
:active-parent-keys="activeParentKeys"
|
||||
|
||||
@@ -8,6 +8,7 @@ const props = defineProps<{
|
||||
activePath: string
|
||||
openedKeys: ReadonlySet<string>
|
||||
activeParentKeys: ReadonlySet<string>
|
||||
badges?: Readonly<Record<string, { count: number | null; error: string }>>
|
||||
level?: number
|
||||
}>()
|
||||
|
||||
@@ -16,6 +17,9 @@ const emit = defineEmits<{
|
||||
toggle: [key: string]
|
||||
}>()
|
||||
|
||||
const badge = computed(() => props.badges?.[props.node.key])
|
||||
const badgeTitle = computed(() => badge.value?.error || `${badge.value?.count ?? 0} 个柜次待上传资料或确认回执`)
|
||||
|
||||
const groupId = computed(() => `client-nav-group-${props.node.key}`)
|
||||
</script>
|
||||
|
||||
@@ -54,6 +58,7 @@ const groupId = computed(() => `client-nav-group-${props.node.key}`)
|
||||
v-for="child in node.children"
|
||||
:key="child.key"
|
||||
:node="child"
|
||||
:badges="badges"
|
||||
:active-path="activePath"
|
||||
:opened-keys="openedKeys"
|
||||
:active-parent-keys="activeParentKeys"
|
||||
@@ -78,6 +83,14 @@ const groupId = computed(() => `client-nav-group-${props.node.key}`)
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span>{{ node.title }}</span>
|
||||
<span v-if="badge?.error || (badge?.count != null && badge.count > 0)" class="client-nav-badge"
|
||||
:title="badgeTitle" :aria-label="badgeTitle" role="status">
|
||||
{{ badge?.error ? '!' : badge!.count! > 99 ? '99+' : badge?.count }}
|
||||
</span>
|
||||
</RouterLink>
|
||||
</li>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.client-sidebar-link .client-nav-badge { display: inline-flex; flex: 0 0 auto; min-width: 23px; height: 23px; align-items: center; justify-content: center; margin-left: auto; padding: 0 5px; border: 2px solid #fff; border-radius: 999px; background: #ef4444; color: #fff; box-shadow: 0 3px 9px rgb(239 68 68 / 24%); font-size: 12px; font-weight: 700; line-height: 1; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user